#include using namespace std; typedef long long ll; typedef pair pii; /* 2^(n^2) 다른색 끼리는 영향이 없음 -> 다른색은 볼 필요가 없음 -> 개별적으로 계산 가능 -> 판이 판 / 2 가됨..? */ int n; // usedRTL[x + n - y - 1] = T | F bool usedRTL[30]; // usedLTR[n - x - 1 + n - y - 1] = T | F bool usedLTR[30]; // placeAbles[idx] = {y , x}; vector placeAbles; vector placeAblesBl; // R to L fomu :x + n - y - 1 // L to R fomu : n - x - 1 + n..
#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long ull; typedef pair pii; typedef uint16_t cint; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; cint needLiter[1005][1005]; cint n; // 급유지 cint k; // 최대 연료 충전 수 struct Pos { cint x; cint y; }; vector poses; int calc_dist(cint x, cint y, cint..
#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair pii; int dx[] = {0 , 0 , 1 , -1}; int dy[] = {1 , -1 , 0 , 0}; int n , m; struct MAX{ int arr[50005]; int tree[50005 * 4]; int etd = -1; inline int Max(int a, int b){ return a > b ? a : b; } void build (int now, int s, int e){ if (s == e){ tree[now] = ..
#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair pii; int dx[] = {0 , 0 , 1 , -1}; int dy[] = {1 , -1 , 0 , 0}; int main(){ cin.tie(0); cout.tie(0); priority_queue minq , maxq; int n , mid; cin >> n >> mid; cout a >> b; if(a < mid) maxq.push(a); else minq.push(-a); if(b < mid) maxq.push(b); else minq..
#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long ull; typedef pair pii; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int n; int r[51]; int d[51][51]; int main() { cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i f >> t; if (f == -1 || t == -1) break; d[f][t] = 1; d[t][f] ..
#include #include #include using namespace std; int m, n, k; int c; int arrCount = 0; int map[110][110]; int arr[10000]; int moveX[4] = { 0, 1, 0, -1 }; int moveY[4] = { 1, 0, -1, 0 }; void DFS(int a, int b) { if (map[a][b] == 0) { map[a][b] = 1; ++c; for (int l = 0; l = 0 && y >= 0 && x < m && y < n) { DFS(x, y); } } } } int main(in..
#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair pii; typedef vector vi; #define s second; #define l first int dx[] = {0 , 0 , 1 , -1}; int dy[] = {1 , -1 , 0 , 0}; vi path[10005]; int n; int uping[10005]; int main(){ cin.tie(0); cout.tie(0); cin >> n; for(int i = 0;i < n - 1;i++) { int par , chi; ci..
#include using namespace std; typedef long long ll; typedef pair pii; int n; int wo[25] , woc; int findLCost(int woidx , int oa , int ob){ if(woidx >= woc) { return 0; } int nowo = wo[woidx]; int tc1 = abs(oa - nowo) + findLCost(woidx + 1 , nowo , ob); // 왼쪽으로 밀기 int tc2 = abs(ob - nowo) + findLCost(woidx + 1 , oa , nowo); // 오른쪽으로 return min(tc1 , tc2); } int main(){ cin.tie(0); cout.tie(0); in..
#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair pii; typedef vector vi; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; int N; int moveK[22]; int moveCnt(int n) { if (n N; int ans = moveCnt(N); cout