백준

    [골4] 1647 - 도시 분할 계획

    #include #include #include #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ using namespace std; using IntPair = pair; using NodePair = pair; vector graph; int parent[100001]; int Find(int x) { if (parent[x] == x) return x; else return parent[x] = Find(parent[x]); } void Union(int a, int b) { a = Find(a), b = Find(b); parent[a] = b; } bool IsCycle(int a,..

    [실2] 2512 - 예산

    #include #include #include #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ using namespace std; int main() { FAST_IO(); int n, m; cin >> n; vector v(n); for (int i = 0; i > v[i]; sort(v.begin(), v.end()); cin >> m; int s = 0, e = v[n - 1]; int res = 0; while (s = sum) { res = mid; s = mid + 1; } else e = mid - 1; } cout

    [실3] 10158 - 개미

    #include #pragma region 입출력 속도향상 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion using namespace std; #define x first #define y second int main() { FAST_IO(); int w, h, p, q, t; cin >> w >> h >> p >> q >> t; p += t; q += t; p %= (2 * w); q %= (2 * h); if (p > w) p = 2 * w - p; if (q > h) q = 2 * h - q; cout

    [골4] 1715 - 카드 정렬하기

    #include #include #include #pragma region 입출력 속도향상 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion using namespace std; int main() { FAST_IO(); int n, ans = 0; cin >> n; priority_queue pq; if (n == 1) { cout tmp; pq.push(tmp); } while (!pq.empty()) { int sum = 0; sum += pq.top(); pq.pop(); if (!pq.empty()) { sum += pq.top(); pq.pop(); ..

    [실3] 16956 - 늑대와 양

    농장은 어떻게 출력되든 상관없다. #include #include #include #pragma region 입출력 속도향상 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion using namespace std; #define y first #define x second pair dir[] { {1, 0}, {-1, 0}, {0, -1}, {0, 1} }; int main() { FAST_IO(); int r, c; cin >> r >> c; // 농장 초기화 vector farm(r, vector(c)); queue pos; for (int y = 0; y <..

    [골3] 1005 - ACM Craft

    #include #include #include #pragma region 입출력 속도향상 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion using namespace std; #define MAX 1002 int main() { FAST_IO(); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; int time[MAX]; for (int i = 1; i > time[i]; vector adj[MAX]; queue q; int degree[MAX]{ 0 }; int res[MAX]{ 0 }; while (k-..

    [골5] 16500 - 문자열 판별

    #include #include using namespace std; #pragma region 입출력 속도향상 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion int main() { string a[100]; string s; int dp[101]; int n; cin >> s >> n; for (int i = 0; i > a[i]; int sl = s.length(); dp[sl] = 1; for (int i = sl - 1; i >= 0; i--) { for (int j = 0; j

    [골3] 1958 - LCS 3

    #include #include using namespace std; #pragma region 입출력 속도향상 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion #define MAX 101 int dp[MAX][MAX][MAX]; int max(int a, int b, int c) { return max(a, max(b, c)); } int main() { FAST_IO(); string s1, s2, s3; cin >> s1 >> s2 >> s3; int sz1 = s1.length(), sz2 = s2.length(), sz3 = s3.length(); f..

    [실4] 15489 - 파스칼의 삼각형

    dp를 활용했다 #pragma region 입출력 속도향상 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion #include using namespace std; #define SIZE 30 int dp[SIZE + 1][SIZE + 1]; int main() { FAST_IO(); int r, c, w; cin >> r >> c >> w; dp[1][1] = 1; for (int i = 1; i

    [실5] 16395 - 파스칼의 삼각형

    #pragma region 입출력 속도향상 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion #include #include using namespace std; int main() { FAST_IO(); int n, k; cin >> n >> k; vector pascal(n); for (int i = 0; i < n; i++) { int val = 1; for (int k = 0; k