제출 #842621

#제출 시각아이디문제언어결과실행 시간메모리
842621WLZ죄수들의 도전 (IOI22_prison)C++17
100 / 100
14 ms1132 KiB
#include "prison.h" #include <bits/stdc++.h> using namespace std; int n; tuple<int, int, int> get_range(int x, int idx) { int l = 1, r = n, part; for (int i = 0; i <= idx; i++) { if (x == l) return {-1, -1, -1}; if (x == r) return {-2, -2, -2}; l++; r--; int len = r - l + 1; int sz1 = len / 3 + (len % 3 >= 1), sz2 = len / 3 + (len % 3 >= 2), sz3 = len / 3; int m1 = l + sz1 - 1, m2 = l + sz1 + sz2 - 1; if (x <= m1) { part = 0; r = m1; } else if (x <= m2) { part = 1; l = m1 + 1, r = m2; } else { part = 2; l = m2 + 1; } } return {l, r, part}; } int get(int x, int idx) { auto p = get_range(x, idx); if (get<0>(p) == -1) return -1; if (get<0>(p) == -2) return 3; return get<2>(p); } vector< vector<int> > devise_strategy(int N) { n = N; vector< vector<int> > s(21, vector<int>(N + 1)); s[0][0] = 0; for (int x = 1; x <= N; x++) { int tmp = get(x, 0); if (tmp == -1) s[0][x] = -1; else if (tmp == 3) s[0][x] = -2; else s[0][x] = tmp + 1; } for (int i = 0; i < 6; i++) { for (int j = 0; j < 3; j++) { int idx = i * 3 + j + 1; s[idx][0] = 1 - (i % 2); for (int x = 1; x <= N; x++) { if (get(x, i) < j) { if (i % 2 == 0) s[idx][x] = -2; else s[idx][x] = -1; } else if (get(x, i) > j) { if (i % 2 == 0) s[idx][x] = -1; else s[idx][x] = -2; } else { auto p = get_range(x, i); int l = get<0>(p), r = get<1>(p), part = get<2>(p); if (x == l) { if (i % 2 == 0) s[idx][x] = -2; else s[idx][x] = -1; } else if (x == r) { if (i % 2 == 0) s[idx][x] = -1; else s[idx][x] = -2; } else { if (i < 5) { s[idx][x] = (i + 1) * 3 + get(x, i + 1) + 1; } else { l++; r--; if (x <= (l + r) / 2) s[idx][x] = 19; else s[idx][x] = 20; } } } } } } s[19][0] = s[20][0] = 1; for (int x = 1; x <= N; x++) { auto p = get_range(x, 5); int l = get<0>(p) + 1, r = get<1>(p) - 1; if (x == l - 1) { s[19][x] = s[20][x] = -2; } else if (x == r + 1) { s[19][x] = s[20][x] = -1; } else if (x <= (l + r) / 2) { s[20][x] = -2; if (x == l) s[19][x] = -2; else s[19][x] = -1; } else { s[19][x] = -1; if (x == r) s[20][x] = -1; else s[20][x] = -2; } } return s; }

컴파일 시 표준 에러 (stderr) 메시지

prison.cpp: In function 'std::tuple<int, int, int> get_range(int, int)':
prison.cpp:14:77: warning: unused variable 'sz3' [-Wunused-variable]
   14 |         int sz1 = len / 3 + (len % 3 >= 1), sz2 = len / 3 + (len % 3 >= 2), sz3 = len / 3;
      |                                                                             ^~~
prison.cpp: In function 'std::vector<std::vector<int> > devise_strategy(int)':
prison.cpp:60:55: warning: unused variable 'part' [-Wunused-variable]
   60 |                     int l = get<0>(p), r = get<1>(p), part = get<2>(p);
      |                                                       ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...