답안 #390987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
390987 2021-04-17T13:27:01 Z alishahali1382 고대 책들 (IOI17_books) C++14
50 / 100
177 ms 16380 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<#x<<", "<<#y<<" = "<<x<<", "<<y<<"\n";}
#define pb push_back
#define all(x) x.begin(), x.end()

const int inf=1000000100;
const int MAXN=1000010;

ll ans; // :)
int n, m, k, s;
int P[MAXN], ps[MAXN];

ll minimum_walk(vector<int> _p, int s){
	n=_p.size();
	for (int i=0; i<n; i++){
		P[i]=_p[i];
		ans+=abs(i-P[i]);
		ps[min(i, P[i])]++;
		ps[max(i, P[i])]--;
	}
	if (!ans) return 0;
	while (P[n-1]==n-1) n--;
	int L=0;
	while (P[L]==L) L++;
	for (int i=1; i<n; i++) ps[i]+=ps[i-1];
	for (int i=L; i+1<n; i++) if (!ps[i]) ans+=2;
	if (s<L) ans+=2*(L-s);
	else if (n<s) ans+=2*(s-n);
	else{
		int res=inf;
		for (int i=L; i<n; i++) if (P[i]!=i) res=min(res, abs(i-s));
		ans+=res;
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 139 ms 16268 KB Output is correct
31 Correct 164 ms 16252 KB Output is correct
32 Correct 131 ms 16224 KB Output is correct
33 Correct 129 ms 16380 KB Output is correct
34 Correct 129 ms 16256 KB Output is correct
35 Correct 135 ms 16240 KB Output is correct
36 Correct 129 ms 16256 KB Output is correct
37 Correct 146 ms 16252 KB Output is correct
38 Correct 127 ms 16256 KB Output is correct
39 Correct 127 ms 16324 KB Output is correct
40 Correct 128 ms 16256 KB Output is correct
41 Correct 133 ms 16380 KB Output is correct
42 Correct 177 ms 16256 KB Output is correct
43 Correct 137 ms 16252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 308 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 139 ms 16268 KB Output is correct
31 Correct 164 ms 16252 KB Output is correct
32 Correct 131 ms 16224 KB Output is correct
33 Correct 129 ms 16380 KB Output is correct
34 Correct 129 ms 16256 KB Output is correct
35 Correct 135 ms 16240 KB Output is correct
36 Correct 129 ms 16256 KB Output is correct
37 Correct 146 ms 16252 KB Output is correct
38 Correct 127 ms 16256 KB Output is correct
39 Correct 127 ms 16324 KB Output is correct
40 Correct 128 ms 16256 KB Output is correct
41 Correct 133 ms 16380 KB Output is correct
42 Correct 177 ms 16256 KB Output is correct
43 Correct 137 ms 16252 KB Output is correct
44 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -