답안 #292953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292953 2020-09-07T14:59:16 Z amoo_safar 고대 책들 (IOI17_books) C++17
50 / 100
341 ms 16380 KB
#include "books.h"

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

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

const int N = 1e6 + 10;

int mk[N];

ll minimum_walk(vector<int> p, int s) {
	int n = p.size();
	ll ans = 0;
	ll near = n;
	for(int i = 0; i < n; i++){
		if(p[i] != i){
			ans += abs(p[i] - i);
			near = min(near, (ll) abs(s - i));
		} else mk[i] = 1;
	}
	int com = 0;
	vector<pii> seg;
	for(int i = 0; i < n; i++){
		if(mk[i]) continue;
		com ++;
		vector<int> vis;
		int nw = i;
		while(!mk[nw]){
			mk[nw] = 1;
			vis.pb(nw);
			nw = p[nw];
		}
		sort(all(vis));
		seg.pb({vis[0], vis.back()});
	}
	if(com == 0) return 0;
	sort(all(seg));
	int mxr = seg[0].S;
	for(int i = 1; i < (int)seg.size(); i++){
		if(mxr < seg[i].F)
			ans += 2 * (seg[i].F - mxr);
		mxr = max(mxr, seg[i].S);
	}
	ans += 2 * near;
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 341 ms 16380 KB Output is correct
31 Correct 332 ms 14268 KB Output is correct
32 Correct 136 ms 12152 KB Output is correct
33 Correct 176 ms 14264 KB Output is correct
34 Correct 170 ms 14264 KB Output is correct
35 Correct 176 ms 14188 KB Output is correct
36 Correct 181 ms 14188 KB Output is correct
37 Correct 190 ms 12408 KB Output is correct
38 Correct 210 ms 12228 KB Output is correct
39 Correct 219 ms 12224 KB Output is correct
40 Correct 230 ms 12348 KB Output is correct
41 Correct 265 ms 14256 KB Output is correct
42 Correct 251 ms 12972 KB Output is correct
43 Correct 172 ms 14188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 360 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 341 ms 16380 KB Output is correct
31 Correct 332 ms 14268 KB Output is correct
32 Correct 136 ms 12152 KB Output is correct
33 Correct 176 ms 14264 KB Output is correct
34 Correct 170 ms 14264 KB Output is correct
35 Correct 176 ms 14188 KB Output is correct
36 Correct 181 ms 14188 KB Output is correct
37 Correct 190 ms 12408 KB Output is correct
38 Correct 210 ms 12228 KB Output is correct
39 Correct 219 ms 12224 KB Output is correct
40 Correct 230 ms 12348 KB Output is correct
41 Correct 265 ms 14256 KB Output is correct
42 Correct 251 ms 12972 KB Output is correct
43 Correct 172 ms 14188 KB Output is correct
44 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -