Submission #828156

# Submission time Handle Problem Language Result Execution time Memory
828156 2023-08-17T06:07:38 Z tranxuanbach Ancient Books (IOI17_books) C++17
50 / 100
110 ms 31492 KB
#include "books.h"

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define bend(a) (a).begin(), (a).end()
#define isz(a) ((signed)a.size())

using ll = long long;

const int N = 1e6 + 5;

int n, s;
int a[N];

bool vis[N];
int cnt_edge[N];
ll pref_cnt_edge[N];

ll ans;

ll minimum_walk(vector <int> _a, int _s){
	n = isz(_a);
	s = _s;
	For(i, 0, n){
		a[i] = _a[i];
	}

	For(i, 0, n){
		if (vis[i]){
			continue;
		}
		ll tans = 0;
		int l = i, r = i;
		{
			int u = i;
			do{
				vis[u] = true;
				l = min(l, u);
				r = max(r, u);
				int v = a[u];
				tans += abs(u - v);
				u = v;
			} while (u != i);
		}
		ans += tans;
		cnt_edge[l]++;
		cnt_edge[r]--;
	}
	For(i, 1, n){
		cnt_edge[i] += cnt_edge[i - 1];
	}
	For(i, 0, n){
		pref_cnt_edge[i] = (i != 0 ? pref_cnt_edge[i - 1] : 0ll) + cnt_edge[i];
	}
	For(i, 0, n - 1){
		if (cnt_edge[i] == 0 and pref_cnt_edge[n - 1] - (i != 0 ? pref_cnt_edge[i - 1] : 0ll) != 0){
			ans += 2;
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 312 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 312 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 312 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 103 ms 31468 KB Output is correct
31 Correct 106 ms 31408 KB Output is correct
32 Correct 87 ms 31460 KB Output is correct
33 Correct 92 ms 31460 KB Output is correct
34 Correct 93 ms 31480 KB Output is correct
35 Correct 97 ms 31492 KB Output is correct
36 Correct 94 ms 31408 KB Output is correct
37 Correct 87 ms 31436 KB Output is correct
38 Correct 88 ms 31472 KB Output is correct
39 Correct 88 ms 31464 KB Output is correct
40 Correct 87 ms 31408 KB Output is correct
41 Correct 103 ms 31472 KB Output is correct
42 Correct 95 ms 31476 KB Output is correct
43 Correct 110 ms 31468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 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 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 312 KB Output is correct
16 Correct 0 ms 312 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 316 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 103 ms 31468 KB Output is correct
31 Correct 106 ms 31408 KB Output is correct
32 Correct 87 ms 31460 KB Output is correct
33 Correct 92 ms 31460 KB Output is correct
34 Correct 93 ms 31480 KB Output is correct
35 Correct 97 ms 31492 KB Output is correct
36 Correct 94 ms 31408 KB Output is correct
37 Correct 87 ms 31436 KB Output is correct
38 Correct 88 ms 31472 KB Output is correct
39 Correct 88 ms 31464 KB Output is correct
40 Correct 87 ms 31408 KB Output is correct
41 Correct 103 ms 31472 KB Output is correct
42 Correct 95 ms 31476 KB Output is correct
43 Correct 110 ms 31468 KB Output is correct
44 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -