Submission #46914

# Submission time Handle Problem Language Result Execution time Memory
46914 2018-04-24T17:00:29 Z SpaimaCarpatilor Ancient Books (IOI17_books) C++17
50 / 100
253 ms 17300 KB
#include "books.h"
#include<bits/stdc++.h>

using namespace std;

int nr, N, S, p[1000009], mars[1000009];
bool useful[1000009];

long long minimum_walk (vector < int > pp, int ss)
{
    N = pp.size (), S = ss + 1;
    for (int i=1; i<=N; i++)
        p[i] = pp[i - 1] + 1;
    long long ans = 0;
    for (int i=1; i<=N; i++)
    {
        int curr = i - p[i];
        if (curr < 0) curr = -curr;
        ans += curr;
    }
    for (int i=1; i<=N; i++)
        if (i != p[i])
        {
            int l = i, r = p[i];
            if (l > r) swap (l, r);
            mars[l] ++, mars[r] --;
            useful[i] = 1;
        }
    useful[S] = 1;
    int usefulToRight = 0, usefulToLeft = 0;
    for (int i=1; i<=N; i++)
        usefulToRight += useful[i];
    for (int i=1; i<N; i++)
        mars[i] += mars[i - 1];
    for (int i=1; i<N; i++)
    {
        usefulToRight -= useful[i];
        usefulToLeft += useful[i];
        if (usefulToLeft > 0 && usefulToRight > 0 && mars[i] == 0)
            ans += 2;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 244 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 244 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 2 ms 736 KB Output is correct
27 Correct 2 ms 736 KB Output is correct
28 Correct 3 ms 736 KB Output is correct
29 Correct 2 ms 736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 244 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 2 ms 736 KB Output is correct
27 Correct 2 ms 736 KB Output is correct
28 Correct 3 ms 736 KB Output is correct
29 Correct 2 ms 736 KB Output is correct
30 Correct 182 ms 17220 KB Output is correct
31 Correct 177 ms 17220 KB Output is correct
32 Correct 148 ms 17220 KB Output is correct
33 Correct 172 ms 17276 KB Output is correct
34 Correct 156 ms 17276 KB Output is correct
35 Correct 160 ms 17276 KB Output is correct
36 Correct 166 ms 17300 KB Output is correct
37 Correct 253 ms 17300 KB Output is correct
38 Correct 210 ms 17300 KB Output is correct
39 Correct 160 ms 17300 KB Output is correct
40 Correct 240 ms 17300 KB Output is correct
41 Correct 174 ms 17300 KB Output is correct
42 Correct 175 ms 17300 KB Output is correct
43 Correct 158 ms 17300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 17300 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 244 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 616 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 736 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 736 KB Output is correct
26 Correct 2 ms 736 KB Output is correct
27 Correct 2 ms 736 KB Output is correct
28 Correct 3 ms 736 KB Output is correct
29 Correct 2 ms 736 KB Output is correct
30 Correct 182 ms 17220 KB Output is correct
31 Correct 177 ms 17220 KB Output is correct
32 Correct 148 ms 17220 KB Output is correct
33 Correct 172 ms 17276 KB Output is correct
34 Correct 156 ms 17276 KB Output is correct
35 Correct 160 ms 17276 KB Output is correct
36 Correct 166 ms 17300 KB Output is correct
37 Correct 253 ms 17300 KB Output is correct
38 Correct 210 ms 17300 KB Output is correct
39 Correct 160 ms 17300 KB Output is correct
40 Correct 240 ms 17300 KB Output is correct
41 Correct 174 ms 17300 KB Output is correct
42 Correct 175 ms 17300 KB Output is correct
43 Correct 158 ms 17300 KB Output is correct
44 Incorrect 2 ms 17300 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -