제출 #488163

#제출 시각아이디문제언어결과실행 시간메모리
4881638e7Dungeons Game (IOI21_dungeons)C++17
0 / 100
7078 ms6928 KiB
//Challenge: Accepted #include "dungeons.h" #include <iostream> #include <algorithm> #include <vector> #include <utility> using namespace std; void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #define ll long long #define maxn 400005 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); int n; vector<int> s, p, w, l, disp; struct WIN{ int anc[19][maxn]; ll ma[19][maxn]; ll sum[19][maxn]; void build() { for (int i = 0;i < n;i++) { anc[0][i] = w[i]; ma[0][i] = s[i]; sum[0][i] = s[i]; } anc[0][n] = n; for (int i = 1;i < 19;i++) { for (int j = 0;j <= n;j++) { anc[i][j] = anc[i-1][anc[i-1][j]]; sum[i][j] = sum[i-1][j] + sum[i-1][anc[i-1][j]]; ma[i][j] = max(ma[i-1][j], ma[i-1][anc[i-1][j]] - sum[i-1][j]); } } } void move(int &x, ll &val) { //brings it to the nearest loss for (int i = 18;i >= 0;i--) { if (val >= ma[i][x]) { val += sum[i][x]; x = anc[i][x]; } } } } win; struct LOSE{ int anc[25][maxn]; ll sum[25][maxn]; int li; void build(int lim) { li = lim; for (int i = 0;i < n;i++) { if (lim > s[i]) sum[0][i] = s[i], anc[0][i] = w[i]; else sum[0][i] = p[i], anc[0][i] = l[i]; } anc[0][n] = n; for (int i = 1;i < 25;i++) { for (int j = 0;j <= n;j++) { anc[i][j] = anc[i-1][anc[i-1][j]]; sum[i][j] = sum[i-1][j] + sum[i-1][anc[i-1][j]]; } } } void move(int &x, ll &val) { //brings it to the nearest win for (int i = 24;i >= 0;i--) { if (val + sum[i][x] < li) { //debug(val, i, x, anc[i][x]); val += sum[i][x]; x = anc[i][x]; } } } } lose[5]; void init(int nv, vector<int> sv, vector<int> pv, vector<int> wv, vector<int> lv) { n = nv; s = sv, p = pv, w = wv, l = lv; win.build(); //lose.build(); disp = sv; sort(disp.begin(), disp.end()); disp.resize(int(unique(disp.begin(), disp.end()) - disp.begin())); for (int i = 0;i < disp.size();i++) { lose[i].build(disp[i]); } } long long simulate(int x, int z) { ll ans = z; //lose.move(x, ans); //win.move(x, ans); /* while (x != n) { win.move(x, ans); if (x == n) break; ans += p[x]; x = l[x]; } */ int ind = 0; while (x != n) { while (ind < disp.size() && ans >= disp[ind])ind++; if (ind < disp.size()) { lose[ind].move(x, ans); //debug("L", x, ans, ind); } win.move(x, ans); //debug("w", x, ans); } return ans; } /* 3 2 2 6 9 3 1 2 2 2 3 1 0 1 0 1 2 3 3 3 14 14 14 2 1 1 1 2 3 1 2 0 0 0 2 4 1 1 */

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

dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:86:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |  for (int i = 0;i < disp.size();i++) {
      |                 ~~^~~~~~~~~~~~~
dungeons.cpp: In function 'long long int simulate(int, int)':
dungeons.cpp:106:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |   while (ind < disp.size() && ans >= disp[ind])ind++;
      |          ~~~~^~~~~~~~~~~~~
dungeons.cpp:107:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   if (ind < disp.size()) {
      |       ~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...