Submission #56734

#TimeUsernameProblemLanguageResultExecution timeMemory
56734top34051Memory 2 (JOI16_memory2)C++17
100 / 100
8 ms4736 KiB
#include "Memory2_lib.h" #include<bits/stdc++.h> using namespace std; const int maxn = 1e3 + 5; int n; int bad[maxn]; vector<int> pos[maxn]; int rec[maxn][maxn]; int ask(int x, int y) { if(x>y) swap(x,y); if(rec[x][y]!=-1) return rec[x][y]; return rec[x][y] = Flip(x,y); } int solve(int x) { for(int i=0;i<n;i++) pos[i].clear(); for(int i=0;i<2*n;i++) { if(i!=x) pos[ask(i,x)].push_back(i);//, printf("%d : %d\n",i,ask(i,x)); } int cnt = 0; for(int i=0;i<n;i++) { if(pos[i].size()==1) pos[i].push_back(x), cnt++; if(pos[i].size()!=2) return 0; } if(cnt>1) return 0; for(int i=0;i<n;i++) Answer(pos[i][0],pos[i][1],i); return 1; } void Solve(int T, int N) { memset(rec,-1,sizeof(rec)); n = N; int x = 0, noey = 0; while(1) { // printf("x = %d\n",x); int ok = 0; for(int y=x+1;y<2*n;y++) { if(bad[y]) continue; int tmp = ask(x,y); // printf("\ty = %d : %d\n",y,tmp); pos[tmp].push_back(y); if(pos[tmp].size()==3) { x = pos[tmp][0]; noey = pos[tmp][1]; for(int i=0;i<n;i++) { if(i==tmp) continue; for(auto t : pos[i]) bad[t] = 1; } for(int i=0;i<n;i++) pos[i].clear(); ok = 1; break; } } if(!ok) break; } if(solve(x)) return ; solve(noey); return ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...