Submission #1242007

#TimeUsernameProblemLanguageResultExecution timeMemory
1242007salmonMemory 2 (JOI16_memory2)C++20
0 / 100
0 ms328 KiB
#include "Memory2_lib.h" #include <bits/stdc++.h> using namespace std; void Solve(int T, int N){ if(T == 500) return; int name[N * 2 + 5]; for(int i = 0; i < N * 2; i++) name[i] = -1; vector<int> proc = {0,1,2,3}; for(int a = 0; a < N - 1; a++){ set<int> de[4]; for(int j = 0; j < 4; j++){ for(int k = j + 1; k < 4; k++){ int num = Flip(proc[j],proc[k]); de[j].insert(num); de[k].insert(num); } } vector<pair<int,int>> v; for(int i = 0; i < 4; i++) v.push_back({de[i].size(), i}); sort(v.begin(),v.end()); if(v[3].first == 3){ name[proc[v[0].second]] = *de[v[0].second].begin(); proc[v[0].second] = -1; de[v[1].second].erase(*de[v[0].second].begin()); name[proc[v[1].second]] = *de[v[1].second].begin(); proc[v[1].second] = -1; } else if(v[1].first == 1){ name[proc[v[0].second]] = *de[v[0].second].begin(); proc[v[0].second] = -1; name[proc[v[1].second]] = *de[v[1].second].begin(); proc[v[1].second] = -1; } else{ name[proc[v[0].second]] = *de[v[0].second].begin(); proc[v[0].second] = -1; de[v[1].second].erase(*de[v[0].second].begin()); name[proc[v[1].second]] = *de[v[1].second].begin(); proc[v[1].second] = -1; } if(a != N - 2){ int cont = a * 2 + 4; for(int i = 0; i < 4; i++){ if(proc[i] == -1){ proc[i] = cont; cont++; } } } //for(int i = 0; i < N * 2; i++) printf("%d ",name[i]); //printf("\n"); } vector<int> visited[N]; for(int i = 0; i < N * 2; i++){ if(name[i] != -1) visited[name[i]].push_back(i); } for(int i = 0; i < N; i++){ if(visited[i].empty()){ for(int j = 0; j < N * 2; j++){ if(name[j] == -1) visited[i].push_back(j); } } } for(int i = 0; i < N; i++){ Answer(visited[i][0],visited[i][1],i); } return; } /* 1 4 100000 0 1 2 3 0 1 2 3 0 1 2 3 1 4 100000 0 1 2 3 0 0 2 3 1 1 2 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...