Submission #69662

# Submission time Handle Problem Language Result Execution time Memory
69662 2018-08-21T11:11:59 Z aquablitz11 Ancient Books (IOI17_books) C++14
50 / 100
323 ms 12476 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using plpii = pair<ll, pii>;

const int N = 1e6+10;
const ll INF = 1e9;

int qs[N];

ll minimum_walk(vector<int> p, int s)
{
    int n = p.size();
    ll dist = 0;
    for (int i = 0; i < n; ++i) {
        if (p[i] == -1) continue;
        if (p[i] == i) continue;
        int u = i;
        while (p[u] != -1) {
            int v = p[u];
            dist += abs(u-v);
            p[u] = -1;
            qs[min(u, v)] += 1;
            qs[max(u, v)] -= 1;
            u = v;
        }
    }
    int last = -1;
    if (p[s] == s) p[s] = -1;
    for (int i = 0; i < n-1; ++i) {
        if (i > 0) qs[i] += qs[i-1];
        if (last != -1 && p[i] == -1) {
            dist += 2*(i-last);
            last = -1;
        }
        if (qs[i] == 0 && p[i] == -1)
            last = i;
    }

    return dist;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 2 ms 552 KB Output is correct
8 Correct 4 ms 572 KB Output is correct
9 Correct 2 ms 580 KB Output is correct
10 Correct 2 ms 580 KB Output is correct
11 Correct 2 ms 580 KB Output is correct
12 Correct 3 ms 636 KB Output is correct
13 Correct 3 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 3 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 2 ms 552 KB Output is correct
8 Correct 4 ms 572 KB Output is correct
9 Correct 2 ms 580 KB Output is correct
10 Correct 2 ms 580 KB Output is correct
11 Correct 2 ms 580 KB Output is correct
12 Correct 3 ms 636 KB Output is correct
13 Correct 3 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 3 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 3 ms 636 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 3 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 2 ms 552 KB Output is correct
8 Correct 4 ms 572 KB Output is correct
9 Correct 2 ms 580 KB Output is correct
10 Correct 2 ms 580 KB Output is correct
11 Correct 2 ms 580 KB Output is correct
12 Correct 3 ms 636 KB Output is correct
13 Correct 3 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 3 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 3 ms 636 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 3 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 278 ms 12476 KB Output is correct
31 Correct 323 ms 12476 KB Output is correct
32 Correct 198 ms 12476 KB Output is correct
33 Correct 189 ms 12476 KB Output is correct
34 Correct 162 ms 12476 KB Output is correct
35 Correct 210 ms 12476 KB Output is correct
36 Correct 181 ms 12476 KB Output is correct
37 Correct 172 ms 12476 KB Output is correct
38 Correct 187 ms 12476 KB Output is correct
39 Correct 161 ms 12476 KB Output is correct
40 Correct 208 ms 12476 KB Output is correct
41 Correct 234 ms 12476 KB Output is correct
42 Correct 209 ms 12476 KB Output is correct
43 Correct 177 ms 12476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 12476 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 2 ms 552 KB Output is correct
8 Correct 4 ms 572 KB Output is correct
9 Correct 2 ms 580 KB Output is correct
10 Correct 2 ms 580 KB Output is correct
11 Correct 2 ms 580 KB Output is correct
12 Correct 3 ms 636 KB Output is correct
13 Correct 3 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 3 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 3 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 3 ms 636 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 3 ms 748 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 2 ms 748 KB Output is correct
29 Correct 2 ms 748 KB Output is correct
30 Correct 278 ms 12476 KB Output is correct
31 Correct 323 ms 12476 KB Output is correct
32 Correct 198 ms 12476 KB Output is correct
33 Correct 189 ms 12476 KB Output is correct
34 Correct 162 ms 12476 KB Output is correct
35 Correct 210 ms 12476 KB Output is correct
36 Correct 181 ms 12476 KB Output is correct
37 Correct 172 ms 12476 KB Output is correct
38 Correct 187 ms 12476 KB Output is correct
39 Correct 161 ms 12476 KB Output is correct
40 Correct 208 ms 12476 KB Output is correct
41 Correct 234 ms 12476 KB Output is correct
42 Correct 209 ms 12476 KB Output is correct
43 Correct 177 ms 12476 KB Output is correct
44 Incorrect 3 ms 12476 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -