백준(C, C++)/플래티넘 4

백준 14939: 불 끄기

https://www.acmicpc.net/problem/14939 14939번: 불 끄기 전구 100개가 10×10 정사각형 모양으로 늘어서 있다. 전구에 달린 스위치를 누르면 그 전구와 위, 아래, 왼쪽, 오른쪽에 있는 전구의 상태도 바뀐다. 전구 100개의 상태가 주어지면 모든 전구를 끄 www.acmicpc.net 코드 #include #include using namespace std; #define fastio() ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int ans[10], res = 1111111; void dfs(int y, int x, int before, int now, int then, int cnt) { if (x == 10) { if..

백준 1047: 울타리 [C/C++]

https://www.acmicpc.net/problem/1047 1047번: 울타리 첫째 줄에 N이 주어진다. N은 2보다 크거나 같고, 40보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에 각 나무가 심어져 있는 위치와 그 나무로 만들 수 있는 울타리의 길이가 순서대로 주어 www.acmicpc.net 코드 #include #include #include static const auto fastio = []() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }(); using namespace std; typedef struct Tree { int y, x, v, n; } tr..

백준 3163: 떨어지는 개미 [C언어]

https://www.acmicpc.net/problem/3163 3163번: 떨어지는 개미 첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스의 첫째 줄에는 N, L, k가 주어진다. 다음 N개 줄에는 pi와 ai가 주어진다. ai는 개미의 ID이고, pi는 그 개미의 초기 위치이다. 항상 p www.acmicpc.net #include int T, N, L, K; int p[1000001]; int id[1000001]; int front, rear; int plus[1000001]; int pn, pp; int minus[1000001]; int mn, mp; void merge(int data[], int p, int q, int r) { int i = p, j = q+1, k = ..

백준 2505: 두 번 뒤집기 [C/C++]

https://www.acmicpc.net/problem/2505 2505번: 두 번 뒤집기 첫줄에는 숫자판의 크기를 나타내는 정수 N (5 ≤ N ≤ 10,000)이 주어진다. 그 다음 줄에는 두 개의 구간이 뒤집혀진 놀이판의 상태를 나타내는 숫자들이 하나의 공백을 두고 나타난다. www.acmicpc.net #include using namespace std; #define nn 10001 #define f first #define s second typedef vector vpii; int n, a[nn], b1[nn], b2[nn]; int m=0, l1=1, r1=1, l2=1, r2=1; vpii seg; void turn(int l, int r){ for( int i=l; i