Submission #423613

# Submission time Handle Problem Language Result Execution time Memory
423613 2021-06-11T10:26:13 Z arayi Ancient Books (IOI17_books) C++17
50 / 100
229 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 = 1, 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 && i > nx) ans += 2*(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;
    else if(dz == -1) ans += 2*abs(aj - s);
    else if(aj == -1) ans += 2*abs(dz - s);
    else if(col[dz] == col[aj]) ans += 2*min(aj - s, s - dz);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 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 0 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 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 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 0 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 1 ms 204 KB Output is correct
18 Correct 0 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 1 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 204 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 1 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 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 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 0 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 1 ms 204 KB Output is correct
18 Correct 0 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 1 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 204 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 197 ms 24056 KB Output is correct
31 Correct 229 ms 19948 KB Output is correct
32 Correct 126 ms 12024 KB Output is correct
33 Correct 130 ms 15904 KB Output is correct
34 Correct 129 ms 15924 KB Output is correct
35 Correct 153 ms 15852 KB Output is correct
36 Correct 128 ms 15852 KB Output is correct
37 Correct 125 ms 15848 KB Output is correct
38 Correct 142 ms 15980 KB Output is correct
39 Correct 131 ms 15956 KB Output is correct
40 Correct 132 ms 16232 KB Output is correct
41 Correct 146 ms 19396 KB Output is correct
42 Correct 151 ms 17528 KB Output is correct
43 Correct 127 ms 15940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 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 1 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 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 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 0 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 1 ms 204 KB Output is correct
18 Correct 0 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 1 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 204 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 197 ms 24056 KB Output is correct
31 Correct 229 ms 19948 KB Output is correct
32 Correct 126 ms 12024 KB Output is correct
33 Correct 130 ms 15904 KB Output is correct
34 Correct 129 ms 15924 KB Output is correct
35 Correct 153 ms 15852 KB Output is correct
36 Correct 128 ms 15852 KB Output is correct
37 Correct 125 ms 15848 KB Output is correct
38 Correct 142 ms 15980 KB Output is correct
39 Correct 131 ms 15956 KB Output is correct
40 Correct 132 ms 16232 KB Output is correct
41 Correct 146 ms 19396 KB Output is correct
42 Correct 151 ms 17528 KB Output is correct
43 Correct 127 ms 15940 KB Output is correct
44 Incorrect 0 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -