Submission #688339

#TimeUsernameProblemLanguageResultExecution timeMemory
688339heeheeheehaawPermutation Recovery (info1cup17_permutation)C++17
25 / 100
1 ms340 KiB
#include <iostream> #include <algorithm> #define int long long using namespace std; int v[405], sp[405]; struct element { int poz, val; }; element ord[405]; bool cmp(element a, element b) { return a.poz < b.poz; } signed main() { int n; cin>>n; for(int i = 1; i <= n; i++) { cin>>v[i]; int nrsubsir = (v[i] - v[i - 1]) - 1, st = 1, dr = i - 1, mij = 0; if(i > 1 || nrsubsir != 0) { mij = -1; while(st <= dr) { mij = (st + dr) / 2; if(sp[mij] == nrsubsir) break; else if(sp[mij] < nrsubsir) st = mij + 1; else dr = mij - 1; } } if(nrsubsir == 0 || i <= 1) mij = 1; else mij++; for(int j = i - 1; j >= mij; j--) { sp[j + 1] = sp[j] + nrsubsir + 1; ord[j + 1].poz = ord[j].poz; } ord[mij].poz = i; sp[mij] = sp[mij - 1] + nrsubsir + 1; } for(int i = 1; i <= n; i++) ord[i].val = i; sort(ord + 1, ord + n + 1, cmp); for(int i = 1; i <= n; i++) cout<<ord[i].val<<" "; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...