Submission #1039319

#TimeUsernameProblemLanguageResultExecution timeMemory
1039319Maite_MoralePrisoner Challenge (IOI22_prison)C++17
5 / 100
3 ms604 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll x=26; ll bsbit=13; ll r[2]={-1,-2};//Respuesta vector<int> bs(bsbit,(1LL<<bsbit)/2); std::vector<std::vector<int>> devise_strategy(int N) { for(int i=1;i<=bsbit;i++)bs[i]=bs[i-1]/2; vector<vector<int>> v (x+50,vector<int> (N + 1, 0)); v[0][0]=1; for(int i=1;i<=N;i++){ ll actualbit=i/bs[0]; actualbit%=2; /// value bit v[0][i]=actualbit*bsbit+0; v[0][i]++; } for(int i=1;i<=x;i++){ ll inf=i-1; ll bit=inf%bsbit; inf/=bsbit; v[i][0]=bit%2;//Bolsa //cerr<<"bit: "<<12-bit<<" bolsa:"<<v[i][0]<<" contenido de la otra:"<<inf<<"\n"; //cerr<<"\n\n\n\n"<<v[i][0]<<" "; for(int j=1;j<=N;j++){ ll actualbit=j/bs[bit]; actualbit%=2; //cerr<<"\t"<<actualbit<<"\n"; if(actualbit!=inf){ if(actualbit<inf)v[i][j]=r[v[i][0]]; else v[i][j]=r[1-v[i][0]]; } else{ if(bit==12)continue; // value bit v[i][j]=((j/bs[bit+1])%2)*bsbit+(bit+1); v[i][j]++; } //cerr<<v[i][j]<<" "; } } // cout<<"\n(:\n"; return v; } /* static constexpr int kNumPrisoners = 500; static void invalid_strategy(std::string message) { printf("%s\n", message.c_str()); exit(0); } int main() { int N; assert(1 == scanf("%d", &N)); std::vector<std::vector<int>> strategy = devise_strategy(N); if (strategy.size() == 0) { invalid_strategy("s is an empty array"); } int x = strategy.size() - 1; for (int i = 0; i <= x; ++i) { if (static_cast<int>(strategy[i].size()) != N + 1) { invalid_strategy("s[i] contains incorrect length"); } if (strategy[i][0] < 0 || strategy[i][0] > 1) { invalid_strategy("First element of s[i] is non-binary"); } for (int j = 1; j <= N; ++j) { if (strategy[i][j] < -2 || strategy[i][j] > x) { // cout<<strategy[i][j]<<" "<<i<<" "<<j<<"\n"; invalid_strategy("s[i][j] contains incorrect value"); } } } //FILE *log_file = fopen("log.txt","w"); int A, B; while (1 == scanf("%d", &A) && A != -1) { assert(1 == scanf("%d", &B)); bool answer = false; int whiteboard = 0; for (int i = 0; i < kNumPrisoners && !answer; ++i) { int check = strategy[whiteboard][0]; whiteboard = strategy[whiteboard][check == 0 ? A : B]; if (whiteboard < 0) { answer = true; printf("%c\n", "BA"[whiteboard + 2]); } else { if (i > 0) { printf( " "); } printf( "%d", whiteboard); } } if (!answer) { printf("X\n"); } printf( "\n"); } } //*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...