제출 #1058164

#제출 시각아이디문제언어결과실행 시간메모리
1058164TahirAliyev죄수들의 도전 (IOI22_prison)C++17
80 / 100
12 ms1624 KiB
#include "prison.h" #include <bits/stdc++.h> using namespace std; vector<vector<int>> ans; const int mxbit = 7; int pw[mxbit + 3]; int n; vector<vector<int>> devise_strategy(int N){ n = N; ans.resize(mxbit * 3 + 3); for(auto& a : ans) a.resize(N + 1, 0); pw[0] = 1; for(int i = 1; i <= mxbit; i++) pw[i] = pw[i - 1] * 3; ans[0][0] = 0; for(int j = 1; j <= n; j++){ ans[0][j] = mxbit * 3 + (j / pw[mxbit] % 3) - 1; } for(int i = 1; i <= mxbit * 3 + 2; i++){ if(i == 2) continue; int bit = i / 3; int a = i % 3; if(i != 1) i--; if(bit & 1){ ans[i][0] = 1; for(int j = 1; j <= n; j++){ int b = (j / pw[bit]) % 3; if(b > a) ans[i][j] = -1; else if(b < a) ans[i][j] = -2; else{ bit--; if(bit == 0){ if(j % 3 == 0) ans[i][j] = -2; else if(j % 3 == 2) ans[i][j] = -1; else ans[i][j] = 1; } else{ b = (j / pw[bit] % 3); ans[i][j] = bit * 3 + b - 1; } bit++; } } } else{ ans[i][0] = 0; for(int j = 1; j <= n; j++){ int b = (j / pw[bit]) % 3; if(b > a) ans[i][j] = -2; else if(b < a) ans[i][j] = -1; else{ if(bit == 0) continue; bit--; b = (j / pw[bit] % 3); ans[i][j] = bit * 3 + b - 1; bit++; } } } if(i != 1) i++; } ans.resize(mxbit * 3 + 2); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...