Submission #760175

#TimeUsernameProblemLanguageResultExecution timeMemory
760175jk410On the Grid (FXCUP4_grid)C++17
43 / 100
3 ms324 KiB
#include <bits/stdc++.h> #include "grid.h" using namespace std; bool used[1001]; bool usedIdx[1000]; int myQuery(vector<int>& v1, vector<int>& v2,int k) { vector<int> v; for (int i = (int)v1.size() - k; i < (int)v1.size(); i++) v.push_back(v1[i]); for (int i = 0; i < (int)v1.size() - k; i++) v.push_back(v1[i]); for (int i : v2) v.push_back(i); return PutDisks(v); } std::vector<int> SortDisks(int N) { vector<int> ret(N); vector<int> revret(N+1); fill(revret.begin(), revret.end(), -1); for (int i = 1; i < N; i++) { vector<int> v, v2; for (int j = 0; j < N; j++) { if (!usedIdx[j]) v.push_back(j); } for (int j = 1; j <= N; j++) { if (revret[j] != -1) v2.push_back(revret[j]); } int cur = myQuery(v, v2, 0); int l = 1, r = (int)v.size() - 1, x = 0, y = cur; while (l <= r) { int m = (l + r) >> 1; int tmp = myQuery(v, v2, m); if (tmp > cur) { x = m; y = tmp; r = m - 1; } else l = m + 1; } x = v[((int)v.size() - x) % (int)v.size()]; y -= N - 1; ret[x] = y; revret[y] = x; used[y] = true; usedIdx[x] = true; } int x, y; for (int i = 0; i < N; i++) { if (!usedIdx[i]) x = i; } for (int i = 1; i <= N; i++) { if (!used[i]) y = i; } ret[x] = y; return ret; }

Compilation message (stderr)

grid.cpp: In function 'std::vector<int> SortDisks(int)':
grid.cpp:62:7: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |  ret[x] = y;
      |       ^
grid.cpp:62:9: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |  ret[x] = y;
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...