# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151025 | Alexa2001 | On the Grid (FXCUP4_grid) | C++17 | 21 ms | 504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "grid.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> v, mn, val;
int n, ep;
void solve()
{
int last = PutDisks(v) - n;
int i;
while(1)
{
vector<int> last_v = v;
int id = v[ep];
for(i=ep; i; --i) v[i] = v[i-1];
v[0] = id;
int now = PutDisks(v) - n;
if(!now) return;
if(now > last - 1)
{
val[id] = now + 1;
v = last_v;
--ep;
auto cmp = [&val](int x, int y)
{
assert(val[x] && val[y]);
return val[x] < val[y];
};
sort(v.begin() + ep + 1, v.end(), cmp);
// solve();
// break;
}
else last--, mn[id] = min(mn[id], now + 1);
}
}
vector<int> SortDisks(int _n)
{
int i; n = _n;
v.resize(n);
val.resize(n);
mn.resize(n, n);
for(i=0; i<n; ++i) v[i] = i;
ep = n-1;
solve();
vector<int> ans(n);
for(i=0; i<n; ++i)
ans[v[i]] = i+1;
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |