Submission #423608

# Submission time Handle Problem Language Result Execution time Memory
423608 2021-06-11T10:19:26 Z arayi Ancient Books (IOI17_books) C++17
50 / 100
187 ms 24056 KB
#include "books.h"
#include <bits/stdc++.h>
#define lli long long
#define ad push_back
#define fr first
#define sc second
#define MP make_pair
using namespace std;

const int N = 1e6 + 30;

int i1, n;
int col[N], a[N];
lli ans;
int dfs(int v)
{
    col[v] = i1;
    if(!col[a[v]]) return max(v, dfs(a[v]));
    return v;
}
long long minimum_walk(vector<int> p, int s)
{
	n = p.size();
	for(int i = 0; i < n; i++) a[i] = p[i], ans += abs(a[i] - i);
	int nx = -1;
	for(int i = 0; i < n; i++)
    {
        if(a[i] == i) continue;
        if(!col[i])
        {
            if(nx >= 0) ans += 2*max(0, (i - nx));
            i1++;
            nx = max(nx, dfs(i));
        }
    }
    int dz = -1, aj = -1;
    for(int i = s; i < n; i++)
    {
        if(col[i])
        {
            aj = i;
            break;
        }
    }
    for(int i = s; i >= 0; i--)
    {
        if(col[i])
        {
            dz = i;
            break;
        }
    }
    if(dz == -1 && aj == -1) return ans;
    if(dz == -1) ans += 2*abs(aj - s);
    if(aj == -1) ans += 2*abs(dz - s);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 284 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 284 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 187 ms 24056 KB Output is correct
31 Correct 179 ms 19968 KB Output is correct
32 Correct 162 ms 12012 KB Output is correct
33 Correct 139 ms 15848 KB Output is correct
34 Correct 127 ms 15852 KB Output is correct
35 Correct 126 ms 15864 KB Output is correct
36 Correct 126 ms 15852 KB Output is correct
37 Correct 126 ms 15852 KB Output is correct
38 Correct 135 ms 15992 KB Output is correct
39 Correct 143 ms 15984 KB Output is correct
40 Correct 130 ms 16324 KB Output is correct
41 Correct 165 ms 19436 KB Output is correct
42 Correct 150 ms 17604 KB Output is correct
43 Correct 127 ms 15852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 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 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 284 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 187 ms 24056 KB Output is correct
31 Correct 179 ms 19968 KB Output is correct
32 Correct 162 ms 12012 KB Output is correct
33 Correct 139 ms 15848 KB Output is correct
34 Correct 127 ms 15852 KB Output is correct
35 Correct 126 ms 15864 KB Output is correct
36 Correct 126 ms 15852 KB Output is correct
37 Correct 126 ms 15852 KB Output is correct
38 Correct 135 ms 15992 KB Output is correct
39 Correct 143 ms 15984 KB Output is correct
40 Correct 130 ms 16324 KB Output is correct
41 Correct 165 ms 19436 KB Output is correct
42 Correct 150 ms 17604 KB Output is correct
43 Correct 127 ms 15852 KB Output is correct
44 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -