Submission #151586

#TimeUsernameProblemLanguageResultExecution timeMemory
151586aintaOn the Grid (FXCUP4_grid)C++17
43 / 100
16 ms376 KiB
#include "grid.h" #include<algorithm> #include<vector> using namespace std; #define pii pair<int,int> vector<int>w, TP; int Len[1010]; vector<int> SortDisks(int n) { int i; for (i = 0; i < n; i++) { w.push_back(i); Len[i] = -1; } int prev = PutDisks(w); while (1) { for (i = 0; i < n; i++) { if (Len[w[i]] != -1)break; } int L = i; if (L == 0)break; TP = w; int z = w[L-1]; for (i = L-1; i > 0; i--)w[i] = w[i - 1]; w[0] = z; int cur = PutDisks(w); if (cur == prev - 1) { prev = cur; continue; } else { Len[w[0]] = cur - n + 1; w = TP; vector<pii>V; for (i = L - 1; i < n; i++) { V.push_back({ Len[w[i]],w[i] }); } sort(V.begin(), V.end()); int pv = L - 1; for (auto &t : V)w[pv++] = t.second; prev = PutDisks(w); } } vector<int>Ans(n); for (i = 0; i < n; i++)Ans[i] = Len[i]; return Ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...