Submission #112076

#TimeUsernameProblemLanguageResultExecution timeMemory
112076mechfrog88Memory 2 (JOI16_memory2)C++14
0 / 100
3 ms384 KiB
#include "Memory2_lib.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; void Solve(int T, int N){ vector <ll> num(N*2,-1); vector <ll> arr(N*2); srand(time(0)); for (int z=0;z<N*2;z++){ arr[z] = z; } random_shuffle(arr.begin(),arr.end()); ll p=-1,q=-1,r=-1; while (arr.size() > 4){ if (p == -1){ p = arr[rand()%arr.size()]; while (num[p] != -1 || p==q || p==r){ p = arr[rand()%arr.size()]; } } if (q == -1){ q = arr[rand()%arr.size()]; while (num[q] != -1 || p==q || q==r){ q = rand()%arr.size(); } } if (r == -1){ r = arr[rand()%arr.size()]; while (num[r] != -1 || r==p || q==r){ r = rand()%arr.size(); } } ll a = Flip(p,q); ll b = Flip(p,r); ll c = Flip(q,r); if (a == b && b == c && c == a) continue; if (a == b){ num[p] = a; for (int z=0;z<arr.size();z++){ if (arr[z] == p){ arr.erase(arr.begin()+z); break; } } p = -1; } else if (b == c){ num[r] = b; for (int z=0;z<arr.size();z++){ if (arr[z] == r){ arr.erase(arr.begin()+z); break; } } r = -1; } else if (c == a){ num[q] = c; for (int z=0;z<arr.size();z++){ if (arr[z] == q){ arr.erase(arr.begin()+z); break; } } q = -1; } } vector <vector<ll>> d(arr.size(),vector<ll>(arr.size())); for (int z=0;z<arr.size();z++){ for (int x=z+1;x<arr.size();x++){ d[z][x] = Flip(arr[z],arr[x]); d[x][z] = d[z][x]; } } ll s = arr.size(); vector <ll> visited(arr.size(),false); ll ca = arr.size(); while (ca > 1){ for (int z=0;z<s;z++){ if (visited[z]) continue; ll first = 0; ll count = 1; while (visited[first] || first == z){ first++; } for (int x=0;x<s;x++){ if (z == x) continue; if (visited[x]) continue; if (d[z][x] == d[z][first])count++; } if (count == ca){ num[arr[z]] = d[z][first]; ca--; visited[z] = true; break; } } } ll last; vector<vector<ll>> ans(N); for (int z=0;z<N*2;z++){ if (num[z] == -1) { last = z; continue; } ans[num[z]].push_back(z); } for (int z=0;z<N;z++){ if (ans[z].size() == 1){ ans[z].push_back(last); } Answer(ans[z][0],ans[z][1],z); } return; }

Compilation message (stderr)

memory2.cpp: In function 'void Solve(int, int)':
memory2.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int z=0;z<arr.size();z++){
                 ~^~~~~~~~~~~
memory2.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int z=0;z<arr.size();z++){
                 ~^~~~~~~~~~~
memory2.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int z=0;z<arr.size();z++){
                 ~^~~~~~~~~~~
memory2.cpp:73:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int z=0;z<arr.size();z++){
               ~^~~~~~~~~~~
memory2.cpp:74:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int x=z+1;x<arr.size();x++){
                  ~^~~~~~~~~~~
memory2.cpp:103:5: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
  ll last;
     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...