Submission #535433

# Submission time Handle Problem Language Result Execution time Memory
535433 2022-03-10T09:22:56 Z mario05092929 Ancient Books (IOI17_books) C++14
50 / 100
187 ms 24164 KB
#include "books.h"
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair <int,int> pi;
typedef vector <int> vec;
using namespace std;
vec a;
int n;
int c[1000005],mn,mx;
vector <pi> line;

void dfs(int x) {
    if(c[x]) return;
    c[x] = 1;
    mn = min(mn,x);
    mx = max(mx,x);
    dfs(a[x]);
}

ll minimum_walk(vec P,int st) {
    ll ans = 0;
	a = P;
	n = a.size();
	line.push_back({0,0});
    for(int i = 0;i < n;i++) {
        ans += abs(i-a[i]);
        if(c[i]||i == a[i]) continue;
        mn = INF, mx = -INF;
        dfs(i);
        if(mn > line.back().y) {
            line.push_back({mn,mx});
        }
        else {
            line.back().y = max(line.back().y,mx);
        }
    }
    int m = line.size();
    for(int i = 1;i < m;i++) {
        ans += (line[i].x-line[i-1].y)*2;
    }
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 224 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 224 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 220 KB Output is correct
25 Correct 1 ms 224 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 224 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 220 KB Output is correct
25 Correct 1 ms 224 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 167 ms 22636 KB Output is correct
31 Correct 187 ms 22696 KB Output is correct
32 Correct 121 ms 18688 KB Output is correct
33 Correct 131 ms 24156 KB Output is correct
34 Correct 149 ms 24160 KB Output is correct
35 Correct 107 ms 24164 KB Output is correct
36 Correct 120 ms 23476 KB Output is correct
37 Correct 125 ms 22768 KB Output is correct
38 Correct 111 ms 22640 KB Output is correct
39 Correct 112 ms 22636 KB Output is correct
40 Correct 147 ms 22640 KB Output is correct
41 Correct 155 ms 22656 KB Output is correct
42 Correct 136 ms 22636 KB Output is correct
43 Correct 114 ms 22640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 320 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 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 224 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 224 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 220 KB Output is correct
25 Correct 1 ms 224 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 167 ms 22636 KB Output is correct
31 Correct 187 ms 22696 KB Output is correct
32 Correct 121 ms 18688 KB Output is correct
33 Correct 131 ms 24156 KB Output is correct
34 Correct 149 ms 24160 KB Output is correct
35 Correct 107 ms 24164 KB Output is correct
36 Correct 120 ms 23476 KB Output is correct
37 Correct 125 ms 22768 KB Output is correct
38 Correct 111 ms 22640 KB Output is correct
39 Correct 112 ms 22636 KB Output is correct
40 Correct 147 ms 22640 KB Output is correct
41 Correct 155 ms 22656 KB Output is correct
42 Correct 136 ms 22636 KB Output is correct
43 Correct 114 ms 22640 KB Output is correct
44 Incorrect 1 ms 320 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -