코딩테스트
[실2] 2805 - 나무 자르기
#include #include #include using namespace std; #pragma region 입출력 속도향상 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion vector v; int main() { FAST_IO(); long n, m; cin >> n >> m; v.resize(n); for (int i = 0; i > v[i]; sort(v.begin(), v.end()); long l = 0, r = v[n - 1]; long res = 0; while (l mid) sum += v[i] - mid; } if..
[골4] 2110 - 공유기 설치
#include #include #include using namespace std; vector v; int main() { int n, c; cin >> n >> c; v.resize(n); for (int i = 0; i > v[i]; sort(v.begin(), v.end()); int l = 1, r = v[n - 1]; int res = 0; while (l
[골2] 1766 - 문제집
#include #include #include #include #pragma region 빠른 입출력 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion using namespace std; vector degree; vector graph; priority_queue pq; int main() { FAST_IO(); int n, m; cin >> n >> m; graph.assign(100001, vector()); degree.assign(n + 1, 0); for (int i = 0; i > a >> b; g..
[골3] 2252 - 줄 세우기
#include #include #include #include #pragma region 빠른 입출력 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion using namespace std; vector degree; vector graph; queue q; int main() { FAST_IO(); int n, m; cin >> n >> m; graph.assign(100001, vector()); degree.assign(n + 1, 0); for (int i = 0; i > a >> b; graph[a].pu..
[골5] 1717 - 집합의 표현
#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 graph[1000001]; int GetParent(int x) { if (graph[x] == x) return x; else return graph[x] = GetParent(graph[x]); } void Union(int a, int b) { a = GetParent(a), b = GetParent(b); graph[a] = b; } void Find(int a, int b..
[골4] 4386 - 별자리 만들기
#include #include #include #include #pragma region 빠른 입출력 #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #pragma endregion using namespace std; using dp = pair; #define MAX 101 #define x first #define y second vector star; vector coord; int parent[MAX]; double ans; int GetParent(int a) { return (parent[a] == a) ? a : parent[a] = GetParent(parent[a]); }..
[골5] 2166 - 다각형의 면적
#include #include #include #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ #define x first #define y second using namespace std; using dp = pair; double Calculate(double x1, double x2, double x3, double y1, double y2, double y3) { double res = x1 * y2 + x2 * y3 + x3 * y1; res -= x2 * y1 + x3 * y2 + x1 * y3; return res / 2; } int main() { FAST_IO(); int ..
[골5] 2467 - 용액
#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; cin >> n ; vector v(n); for (int i = 0; i > v[i]; int s = 0, e = n - 1, min = 2e9; pair res; while (s < e) { int a = v[s], b = v[e]; int val = abs(a + b); if (val < min) { min = val; res = { a, b }; } if (a + b < ..
[골5] 19951 - 태상이의 훈련소 생활
#include #include #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ using namespace std; int n, m; int main() { FAST_IO(); cin >> n >> m; vector v(n + 1), s(n + 2); for (int i = 1; i > v[i]; // 입력 for (int i = 1; i > a >> b >> k; // 답 도출 s[a] += k; s[b + 1] -= k; } int sum = 0; for (int i = 1; i
[골5] 24891 - 단어 마방진
#include #include #include #include #define FAST_IO() \ {\ ios::sync_with_stdio(false);\ cin.tie(NULL); \ cout.tie(NULL); \ }\ using namespace std; vector ans(20), s(20); vector vis(20); int l, n; void DFS(int cnt = 0) { if (cnt == l) { bool flag = true; for (int i = 0; i < l; i++) { for (int j = i + 1; j < l; j++) { if (flag) flag = (ans[i][j] == ans[j][i]); } } if (flag) { for (int i = 0; i < ..