Submission #73670

# Submission time Handle Problem Language Result Execution time Memory
73670 2018-08-28T17:09:29 Z aquablitz11 Ancient Books (IOI17_books) C++14
50 / 100
313 ms 12412 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; ++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 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 3 ms 488 KB Output is correct
9 Correct 3 ms 488 KB Output is correct
10 Correct 2 ms 488 KB Output is correct
11 Correct 2 ms 488 KB Output is correct
12 Correct 3 ms 520 KB Output is correct
13 Correct 3 ms 568 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 3 ms 488 KB Output is correct
9 Correct 3 ms 488 KB Output is correct
10 Correct 2 ms 488 KB Output is correct
11 Correct 2 ms 488 KB Output is correct
12 Correct 3 ms 520 KB Output is correct
13 Correct 3 ms 568 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 3 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 4 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 3 ms 488 KB Output is correct
9 Correct 3 ms 488 KB Output is correct
10 Correct 2 ms 488 KB Output is correct
11 Correct 2 ms 488 KB Output is correct
12 Correct 3 ms 520 KB Output is correct
13 Correct 3 ms 568 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 3 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 4 ms 620 KB Output is correct
30 Correct 313 ms 12396 KB Output is correct
31 Correct 307 ms 12396 KB Output is correct
32 Correct 171 ms 12396 KB Output is correct
33 Correct 171 ms 12396 KB Output is correct
34 Correct 173 ms 12396 KB Output is correct
35 Correct 205 ms 12396 KB Output is correct
36 Correct 184 ms 12396 KB Output is correct
37 Correct 235 ms 12396 KB Output is correct
38 Correct 202 ms 12396 KB Output is correct
39 Correct 160 ms 12396 KB Output is correct
40 Correct 177 ms 12396 KB Output is correct
41 Correct 242 ms 12396 KB Output is correct
42 Correct 308 ms 12412 KB Output is correct
43 Correct 165 ms 12412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 12412 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 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 3 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 3 ms 488 KB Output is correct
9 Correct 3 ms 488 KB Output is correct
10 Correct 2 ms 488 KB Output is correct
11 Correct 2 ms 488 KB Output is correct
12 Correct 3 ms 520 KB Output is correct
13 Correct 3 ms 568 KB Output is correct
14 Correct 3 ms 568 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 2 ms 596 KB Output is correct
20 Correct 2 ms 596 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 3 ms 620 KB Output is correct
25 Correct 3 ms 620 KB Output is correct
26 Correct 3 ms 620 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 3 ms 620 KB Output is correct
29 Correct 4 ms 620 KB Output is correct
30 Correct 313 ms 12396 KB Output is correct
31 Correct 307 ms 12396 KB Output is correct
32 Correct 171 ms 12396 KB Output is correct
33 Correct 171 ms 12396 KB Output is correct
34 Correct 173 ms 12396 KB Output is correct
35 Correct 205 ms 12396 KB Output is correct
36 Correct 184 ms 12396 KB Output is correct
37 Correct 235 ms 12396 KB Output is correct
38 Correct 202 ms 12396 KB Output is correct
39 Correct 160 ms 12396 KB Output is correct
40 Correct 177 ms 12396 KB Output is correct
41 Correct 242 ms 12396 KB Output is correct
42 Correct 308 ms 12412 KB Output is correct
43 Correct 165 ms 12412 KB Output is correct
44 Incorrect 3 ms 12412 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -