답안 #132680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
132680 2019-07-19T10:26:12 Z MoNsTeR_CuBe 고대 책들 (IOI17_books) C++17
50 / 100
160 ms 8184 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;

long long minimum_walk(std::vector<int> p, int s) {
	#define int long long 
	int l = 0, r = p.size()-1;
	int maxi = -1;
	int ans = -2;
	int n = p.size();
	for(int i = 0; i < (int)p.size(); i++){
		l = i;
		if(p[i] != i){
			break;
		}
	}
	
	for(int i = (int)p.size()-1; i >= 0; i--){
		r = i;
		if(p[i] != i){
			break;
		}
	}
	
	if(l >= r) return 0;
	
	if(s == 0){
		for(int i = l; i <= r; i++){
			ans += abs(p[i]-i);
			maxi = max(maxi, (int)p[i]);
			if(i >= maxi){
				ans += 2;
			}
		}
		
		return ans + 2*l;
	}
	
	vector< bool > visited(n, false);
	
	ans = 0;
	
	int REP = numeric_limits<int>::max();
	
	int curr = s;
	while(curr >= 0){
		if(p[curr] != curr){
			REP = min(REP, s-curr);
			break;
		}
		curr--;
	}
	curr = s;
	while(curr < n){
		if(p[curr] != curr){
			REP = min(REP, curr-s);
			break;
		}
		curr++;
	}
	
	for(int i = 0; i < n; i++){
		ans += abs(i-p[i]);
		for(int j = i; j < p[i]; j++){
			visited[j] = true;
		}
	}
	
	for(int i = min(l,(int)s); i <= max((int)s,r); i++){
		ans += (!visited[i])*2;
	}
	return ans + 2*REP;
	#undef int
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 252 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 252 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 128 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 252 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 128 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 157 ms 8160 KB Output is correct
31 Correct 160 ms 8124 KB Output is correct
32 Correct 137 ms 8120 KB Output is correct
33 Correct 144 ms 8164 KB Output is correct
34 Correct 132 ms 8156 KB Output is correct
35 Correct 133 ms 8156 KB Output is correct
36 Correct 133 ms 8184 KB Output is correct
37 Correct 151 ms 8156 KB Output is correct
38 Correct 144 ms 8128 KB Output is correct
39 Correct 143 ms 8184 KB Output is correct
40 Correct 154 ms 8120 KB Output is correct
41 Correct 154 ms 8124 KB Output is correct
42 Correct 152 ms 8184 KB Output is correct
43 Correct 135 ms 8156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2746'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 252 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 128 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 157 ms 8160 KB Output is correct
31 Correct 160 ms 8124 KB Output is correct
32 Correct 137 ms 8120 KB Output is correct
33 Correct 144 ms 8164 KB Output is correct
34 Correct 132 ms 8156 KB Output is correct
35 Correct 133 ms 8156 KB Output is correct
36 Correct 133 ms 8184 KB Output is correct
37 Correct 151 ms 8156 KB Output is correct
38 Correct 144 ms 8128 KB Output is correct
39 Correct 143 ms 8184 KB Output is correct
40 Correct 154 ms 8120 KB Output is correct
41 Correct 154 ms 8124 KB Output is correct
42 Correct 152 ms 8184 KB Output is correct
43 Correct 135 ms 8156 KB Output is correct
44 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2746'
45 Halted 0 ms 0 KB -