Submission #151025

# Submission time Handle Problem Language Result Execution time Memory
151025 2019-09-01T15:09:23 Z Alexa2001 On the Grid (FXCUP4_grid) C++17
100 / 100
21 ms 504 KB
#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

grid.cpp: In function 'void solve()':
grid.cpp:31:26: warning: capture of variable 'val' with non-automatic storage duration
             auto cmp = [&val](int x, int y)
                          ^~~
grid.cpp:6:20: note: 'std::vector<int> val' declared here
 vector<int> v, mn, val;
                    ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 296 KB Output is correct
10 Correct 3 ms 248 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 252 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 248 KB Output is correct
16 Correct 3 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 296 KB Output is correct
10 Correct 3 ms 248 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 252 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 248 KB Output is correct
16 Correct 3 ms 320 KB Output is correct
17 Correct 5 ms 296 KB Output is correct
18 Correct 10 ms 376 KB Output is correct
19 Correct 16 ms 248 KB Output is correct
20 Correct 20 ms 420 KB Output is correct
21 Correct 16 ms 504 KB Output is correct
22 Correct 20 ms 376 KB Output is correct
23 Correct 21 ms 376 KB Output is correct
24 Correct 20 ms 376 KB Output is correct
25 Correct 20 ms 376 KB Output is correct
26 Correct 20 ms 248 KB Output is correct