Submission #628767

#TimeUsernameProblemLanguageResultExecution timeMemory
628767tutisPrisoner Challenge (IOI22_prison)C++17
60 / 100
16 ms1200 KiB
#include "prison.h" #include <bits/stdc++.h> using namespace std; std::vector<std::vector<int>> devise_strategy(int N) { vector<vector<int>>ret; vector<pair<int, int>>S = {{1, N}}; vector<pair<int, int>>S_; bool fst = true; while (!S.empty()) { S_ = {}; int x = (int)ret.size(); int mx = 0; ret.push_back(vector<int>(N + 1, 0)); if (fst == false) { for (int i = 0; i < (int)S.size(); i++) { int lo = S[i].first; int hi = S[i].second; ret[x][lo] = -1; ret[x][hi] = -2; lo++; hi--; if (lo <= hi) S_.push_back({lo, hi}); } S = S_; S_ = {}; } if (S.empty()) break; for (int i = 0; i < (int)S.size(); i++) { int lo = S[i].first; int hi = S[i].second; lo++; hi--; mx = max(mx, hi - lo + 1); } if (mx >= 7) { for (int t = 0; t < 4; t++) ret.push_back(vector<int>(N + 1, 0)); for (int t = 0; t < 4; t++) ret[x + 1 + t][0] = 1; vector<int>&v = ret[x]; v[0] = 0; for (int i = 0; i < (int)S.size(); i++) { int lo = S[i].first; int hi = S[i].second; v[lo] = -1; v[hi] = -2; lo++; hi--; int sz = hi - lo + 1; if (sz >= 1) { int k = (sz + 3) / 4; k = max(k, 2); for (int t = 0; t < 4; t++) { int l = lo + t * k; int r = lo + (t + 1) * k - 1; r = min(r, hi); if (l <= r) { for (int i = l; i <= r; i++) { ret[(x + 1) + t][i] = x + 5; v[i] = x + 1 + t; } for (int i = lo - 1; i <= l; i++) { ret[(x + 1) + t][i] = -2; } for (int i = r; i <= hi + 1; i++) { ret[(x + 1) + t][i] = -1; } if (r - l + 1 > 2) { S_.push_back({l, r}); } } } } } S = S_; } else if (mx >= 5) { for (int t = 0; t < 3; t++) ret.push_back(vector<int>(N + 1, 0)); for (int t = 0; t < 3; t++) ret[x + 1 + t][0] = 1; vector<int>&v = ret[x]; v[0] = 0; for (int i = 0; i < (int)S.size(); i++) { int lo = S[i].first; int hi = S[i].second; v[lo] = -1; v[hi] = -2; lo++; hi--; int sz = hi - lo + 1; if (sz >= 1) { int k = (sz + 2) / 3; k = max(k, 2); for (int t = 0; t < 3; t++) { int l = lo + t * k; int r = lo + (t + 1) * k - 1; r = min(r, hi); if (l <= r) { for (int i = l; i <= r; i++) { ret[(x + 1) + t][i] = x + 4; v[i] = x + 1 + t; } for (int i = lo - 1; i <= l; i++) { ret[(x + 1) + t][i] = -2; } for (int i = r; i <= hi + 1; i++) { ret[(x + 1) + t][i] = -1; } if (r - l + 1 > 2) { S_.push_back({l, r}); } } } } } S = S_; } else if (mx >= 3) { for (int t = 0; t < 2; t++) ret.push_back(vector<int>(N + 1, 0)); for (int t = 0; t < 2; t++) ret[x + 1 + t][0] = 1; vector<int>&v = ret[x]; v[0] = 0; for (int i = 0; i < (int)S.size(); i++) { int lo = S[i].first; int hi = S[i].second; v[lo] = -1; v[hi] = -2; lo++; hi--; int sz = hi - lo + 1; if (sz >= 1) { int k = (sz + 1) / 2; k = max(k, 2); for (int t = 0; t < 2; t++) { int l = lo + t * k; int r = lo + (t + 1) * k - 1; r = min(r, hi); if (l <= r) { for (int i = l; i <= r; i++) { ret[(x + 1) + t][i] = x + 3; v[i] = x + 1 + t; } for (int i = lo - 1; i <= l; i++) { ret[(x + 1) + t][i] = -2; } for (int i = r; i <= hi + 1; i++) { ret[(x + 1) + t][i] = -1; } if (r - l + 1 > 2) { S_.push_back({l, r}); } } } } } S = S_; } else if (mx >= 1) { for (int t = 0; t < 1; t++) ret.push_back(vector<int>(N + 1, 0)); for (int t = 0; t < 1; t++) ret[x + 1 + t][0] = 1; vector<int>&v = ret[x]; v[0] = 0; for (int i = 0; i < (int)S.size(); i++) { int lo = S[i].first; int hi = S[i].second; v[lo] = -1; v[hi] = -2; lo++; hi--; int sz = hi - lo + 1; if (sz >= 1) { int k = (sz + 1) / 1; k = max(k, 2); for (int t = 0; t < 1; t++) { int l = lo + t * k; int r = lo + (t + 1) * k - 1; r = min(r, hi); if (l <= r) { for (int i = l; i <= r; i++) { ret[(x + 1) + t][i] = x + 2; v[i] = x + 1 + t; } for (int i = lo - 1; i <= l; i++) { ret[(x + 1) + t][i] = -2; } for (int i = r; i <= hi + 1; i++) { ret[(x + 1) + t][i] = -1; } if (r - l + 1 > 2) { S_.push_back({l, r}); } } } } } S = S_; } else { vector<int>&v = ret[x]; v[0] = 0; for (int i = 0; i < (int)S.size(); i++) { int lo = S[i].first; int hi = S[i].second; v[lo] = -1; v[hi] = -2; } S = S_; } int x1 = ret.size(); fst = false; //cout << mx << " " << x1 - x << endl; } int mx = (int)ret.size() - 1; for (vector<int> &i : ret) for (int &j : i) j = min(j, mx); return ret; }

Compilation message (stderr)

prison.cpp: In function 'std::vector<std::vector<int> > devise_strategy(int)':
prison.cpp:258:13: warning: unused variable 'x1' [-Wunused-variable]
  258 |         int x1 = ret.size();
      |             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...