Submission #55417

#TimeUsernameProblemLanguageResultExecution timeMemory
55417kriiiMemory 2 (JOI16_memory2)C++17
100 / 100
3 ms924 KiB
#include <vector> #include "Memory2_lib.h" using namespace std; int mem[101][101],A[101]; int manage(int i, int j) { if (mem[i][j] == -1){ mem[i][j] = mem[j][i] = Flip(i,j); } return mem[i][j]; } void Solve(int T, int N){ if (N == 1){ Answer(0,1,0); return; } for (int i=0;i<2*N;i++) for (int j=0;j<2*N;j++) mem[i][j] = -1; vector<int> u; u.push_back(0); u.push_back(1); u.push_back(2); for (int i=3;i<2*N;i++){ u.push_back(i); for (int p=0;p<4;p++){ int k = -1; for (int q=0;q<4;q++) if (p != q){ if (k == -1) k = manage(u[p],u[q]); else if (k != manage(u[p],u[q])){ k = -2; break; } } if (k != -2){ A[u[p]] = k; u.erase(u.begin()+p); break; } } } int a = manage(u[0],u[1]); int b = manage(u[1],u[2]); int c = manage(u[2],u[0]); if (a == b){ A[u[0]] = c; A[u[1]] = a; A[u[2]] = c; } else if (b == c){ A[u[0]] = a; A[u[1]] = a; A[u[2]] = b; } else{ A[u[0]] = c; A[u[1]] = b; A[u[2]] = b; } for (int x=0;x<N;x++){ int p = -1,q = -1; for (int i=0;i<2*N;i++) if (A[i] == x){p = i; break;} for (int i=p+1;i<2*N;i++) if (A[i] == x){q = i; break;} Answer(p,q,x); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...