답안 #618064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
618064 2022-08-01T20:57:46 Z StrawHatWess 고대 책들 (IOI17_books) C++17
50 / 100
159 ms 18764 KB
#include "books.h"

#include <bits/stdc++.h>
using namespace std; 

typedef long long ll; 
typedef vector<int>vi;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)

void dbgv(vi vec){for(int x: vec) cout << x << ' '; cout << endl; }

//---------------------------

int N; 

int dist(int i, int j){
	return abs(i-j); 
}

ll minimum_walk(vi p, int s) {
	N=sz(p); 

		
	int l=0, r=N-1; 
	while(p[l]==l) l++; 
	while(p[r]==r) r--; 

	vi vec(N+1,0); 
	ll ans=0;
	FOR(i,0,N){
		ans+=dist(i,p[i]); 

		int x=i, y=p[i]; 
		if(x>y) swap(x,y); 

		vec[x]++; vec[y]--;  
	}
	FOR(i,1,N) vec[i]+=vec[i-1]; 

	FOR(i,0,r){
		if(i<l || !vec[i]) ans+=2;  
	}
	
	return ans; 
}


/*

4 0
0 2 3 1


*/

/*

3 0
2 0 1

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 292 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 292 KB Output is correct
30 Correct 107 ms 18652 KB Output is correct
31 Correct 111 ms 18652 KB Output is correct
32 Correct 137 ms 18676 KB Output is correct
33 Correct 106 ms 18652 KB Output is correct
34 Correct 159 ms 18652 KB Output is correct
35 Correct 152 ms 18656 KB Output is correct
36 Correct 113 ms 18648 KB Output is correct
37 Correct 105 ms 18764 KB Output is correct
38 Correct 146 ms 18688 KB Output is correct
39 Correct 93 ms 18764 KB Output is correct
40 Correct 104 ms 18636 KB Output is correct
41 Correct 107 ms 18656 KB Output is correct
42 Correct 152 ms 18760 KB Output is correct
43 Correct 113 ms 18660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 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 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 292 KB Output is correct
30 Correct 107 ms 18652 KB Output is correct
31 Correct 111 ms 18652 KB Output is correct
32 Correct 137 ms 18676 KB Output is correct
33 Correct 106 ms 18652 KB Output is correct
34 Correct 159 ms 18652 KB Output is correct
35 Correct 152 ms 18656 KB Output is correct
36 Correct 113 ms 18648 KB Output is correct
37 Correct 105 ms 18764 KB Output is correct
38 Correct 146 ms 18688 KB Output is correct
39 Correct 93 ms 18764 KB Output is correct
40 Correct 104 ms 18636 KB Output is correct
41 Correct 107 ms 18656 KB Output is correct
42 Correct 152 ms 18760 KB Output is correct
43 Correct 113 ms 18660 KB Output is correct
44 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -