답안 #581794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581794 2022-06-23T06:29:08 Z alireza_kaviani 고대 책들 (IOI17_books) C++17
50 / 100
204 ms 36284 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define sep			' '
#define X			first
#define Y			second
#define all(x)		(x).begin() , (x).end()
#define SZ(x)		int(x.size())

const int MAXN = 1e6 + 10;

ll n , s , sum , P[MAXN] , mark[MAXN];

ll minimum_walk(vector<int> p, int S) {
	n = SZ(p); s = S;
	for(int i = 0 ; i < n ; i++){
		P[i] = p[i];
		sum += abs(P[i] - i);
	}
	vector<pii> vec;
	while(n > 0 && P[n - 1] == n - 1)	n--;
	if(n == 0){
		return 0;
	}
	for(int i = 0 ; i < n ; i++){
		if(!mark[i]){
			int mn = MAXN , mx = 0 , x = i;
			while(!mark[x]){
				mark[x] = 1;
				mn = min(mn , x);
				mx = max(mx , x);
				x = P[x];
			}
			vec.push_back({mn , mx});
		}
	}
	sort(all(vec));
	vector<int> comps;
	for(pii i : vec){
		if(SZ(comps) == 0 || comps.back() < i.X){
			comps.push_back(i.Y);
		}
		else{
			comps[SZ(comps) - 1] = max(comps.back() , i.Y);
		}
	}

	return sum + SZ(comps) * 2 - 2;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 224 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 224 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 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 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 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 340 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 224 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 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 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 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 340 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 200 ms 24244 KB Output is correct
31 Correct 204 ms 24232 KB Output is correct
32 Correct 108 ms 16324 KB Output is correct
33 Correct 128 ms 36208 KB Output is correct
34 Correct 139 ms 36284 KB Output is correct
35 Correct 134 ms 32420 KB Output is correct
36 Correct 117 ms 27836 KB Output is correct
37 Correct 113 ms 24804 KB Output is correct
38 Correct 117 ms 24452 KB Output is correct
39 Correct 116 ms 24812 KB Output is correct
40 Correct 130 ms 24608 KB Output is correct
41 Correct 146 ms 24664 KB Output is correct
42 Correct 143 ms 24580 KB Output is correct
43 Correct 129 ms 31576 KB Output is correct
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 224 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 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 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 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 340 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 200 ms 24244 KB Output is correct
31 Correct 204 ms 24232 KB Output is correct
32 Correct 108 ms 16324 KB Output is correct
33 Correct 128 ms 36208 KB Output is correct
34 Correct 139 ms 36284 KB Output is correct
35 Correct 134 ms 32420 KB Output is correct
36 Correct 117 ms 27836 KB Output is correct
37 Correct 113 ms 24804 KB Output is correct
38 Correct 117 ms 24452 KB Output is correct
39 Correct 116 ms 24812 KB Output is correct
40 Correct 130 ms 24608 KB Output is correct
41 Correct 146 ms 24664 KB Output is correct
42 Correct 143 ms 24580 KB Output is correct
43 Correct 129 ms 31576 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 -