Submission #619626

# Submission time Handle Problem Language Result Execution time Memory
619626 2022-08-02T13:49:01 Z Sergio_2357 Ancient Books (IOI17_books) C++17
12 / 100
2000 ms 300 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;

int n;
int s;
int l = 0;
int h = -1;
vi a;

int bst = INT_MAX;

bool correct()
{
    bool r = true;
    for (int i = 0; i < n; i++)
        if (a[i] != i)
            r = false;
    return r;
}

void bk(int p, int d)
{
    //cout << d << endl;
    if (p == s && correct()) {
        bst = min(bst, l);
        return;
    }
    swap(h, a[p]);
    if (p == s && correct()) {
        bst = min(bst, l);
        return;
    }
    swap(h, a[p]);
    if (l >= bst || d >= 15)
        return;
    for (int i = 0; i < n; i++) {
        if (i == p)
            continue;
        l += abs(p - i);
        swap(h, a[p]);
        bk(i, d + 1);
        swap(h, a[p]);
        bk(i, d + 1);
        l -= abs(p - i);
    }
}

long long minimum_walk(vector<int> p, int s_)
{
    //cout << "HELLO" << endl;
    n = p.size();
    s = s_;
    for (int x : p)
        a.push_back(x);
    bk(s, 0);
    return bst;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 16 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 14 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 16 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 16 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 14 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 16 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Execution timed out 2078 ms 300 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 16 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 14 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 16 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Execution timed out 2078 ms 300 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2067 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 16 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 14 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 16 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Execution timed out 2078 ms 300 KB Time limit exceeded
20 Halted 0 ms 0 KB -