답안 #977365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977365 2024-05-07T19:29:06 Z mariaclara 고대 책들 (IOI17_books) C++17
50 / 100
87 ms 13508 KB
#include "books.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second

ll minimum_walk(vector<int> p, int s) {
	int n = sz(p);
	vector<bool> vis(n);
	vector<pii> aux, range;

	ll ans = 0;
	for(int i = 0; i < n; i++) {
		int x = i, m = i;
		while(!vis[x]) {
			vis[x] = 1;
			x = p[x];
			m = max(m, x);
		}

		ans += abs(p[i]-i);
		if(i != m or i == s) aux.pb({i,m});
	}

	//cout << "ok" << endl;

	for(int i = 0; i < sz(aux);) {
		int l = aux[i].fr, r = aux[i].sc, j = i;
		while(j < sz(aux) and aux[j].fr <= r) {
			//cout << i << " " << j << " " << l << " " << r << endl;
			r = max(r, aux[j].sc);
			j++;
		}
		i=j;
		range.pb({l,r});
	}

	//cout << "ok" << endl;

	for(int i = 1; i < sz(range); i++)
		ans += 2*(range[i].fr - range[i-1].sc);

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 428 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 428 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 87 ms 8192 KB Output is correct
31 Correct 87 ms 8384 KB Output is correct
32 Correct 71 ms 8188 KB Output is correct
33 Correct 80 ms 12740 KB Output is correct
34 Correct 79 ms 12892 KB Output is correct
35 Correct 84 ms 13508 KB Output is correct
36 Correct 79 ms 11124 KB Output is correct
37 Correct 75 ms 8592 KB Output is correct
38 Correct 74 ms 8272 KB Output is correct
39 Correct 81 ms 8272 KB Output is correct
40 Correct 77 ms 8180 KB Output is correct
41 Correct 82 ms 8188 KB Output is correct
42 Correct 81 ms 8172 KB Output is correct
43 Correct 79 ms 10336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 428 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 87 ms 8192 KB Output is correct
31 Correct 87 ms 8384 KB Output is correct
32 Correct 71 ms 8188 KB Output is correct
33 Correct 80 ms 12740 KB Output is correct
34 Correct 79 ms 12892 KB Output is correct
35 Correct 84 ms 13508 KB Output is correct
36 Correct 79 ms 11124 KB Output is correct
37 Correct 75 ms 8592 KB Output is correct
38 Correct 74 ms 8272 KB Output is correct
39 Correct 81 ms 8272 KB Output is correct
40 Correct 77 ms 8180 KB Output is correct
41 Correct 82 ms 8188 KB Output is correct
42 Correct 81 ms 8172 KB Output is correct
43 Correct 79 ms 10336 KB Output is correct
44 Incorrect 1 ms 344 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -