Submission #628743

#TimeUsernameProblemLanguageResultExecution timeMemory
628743abdzagPrisoner Challenge (IOI22_prison)C++17
0 / 100
0 ms212 KiB
#include<bits/stdc++.h> #include "prison.h" using namespace std; string convert_to_3(int val){ string ans=""; while(val){ ans+=(val%3)+'0'; val/=3; } while(ans.size()<13)ans+='0'; reverse(ans.begin(),ans.end()); return ans; } std::vector<std::vector<int>> devise_strategy(int N) { int n=N; vector<vector<int>> ans(25,vector<int>(N+1)); ans[0][0]=1; for(int i=1;i<=n;i++){ int next_index=7; string s=convert_to_3(i); ans[0][i]=next_index*3+(s[next_index]-'0'); } for(int i=1;i<=24;i++){ int current_index=(i-1)/3; int current_value=(i-1)%3; ans[i][0]=current_index%2; // if(i==3)cout<<current_index<<" "<<current_value<<endl; for(int j=1;j<=n;j++){ string s =convert_to_3(j); if(s[current_index]<current_value+'0'){ if(ans[i][0])ans[i][j]=-2; else ans[i][j]=-1; } else if(s[current_index]>current_value+'0'){ if(ans[i][0])ans[i][j]=-1; else ans[i][j]=-2; } else { int next_index=current_index-1; if(next_index>=0) ans[i][j]=next_index*3+(s[next_index]-'0'); } } } return ans; } // int simulate(vector<vector<int>> ans, int a, int b){ // int cur=0; // while(cur>=0){ // // cout<<cur<<endl; // if(!ans[cur][0])cur=ans[cur][a]; // else cur=ans[cur][b]; // } // return cur; // } // int main(){ // int n;cin>>n; // vector<vector<int>> ans=devise_strategy(abs(n)); // if(n>0){ // for(int i=1;i<=n;i++){ // for(int j=1;j<=n;j++){ // if(i==j)continue; // if(simulate(ans,i,j)==-1 ^ i<j){ // cout<<"failed when "<<i<<" "<<j<<" "<<simulate(ans,i,j)<<endl; // return 0; // } // } // } // } // else { // while(1){ // int a, b; // cin>>a>>b; // cout<<simulate(ans,a,b)<<endl; // } // } // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...