답안 #949593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
949593 2024-03-19T11:44:48 Z qin 고대 책들 (IOI17_books) C++17
50 / 100
96 ms 20964 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define vv vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1;
ll minimum_walk(vv<int> p, int s){
		int n = ssize(p);
		vv<int> vis(n, 0);
		int l = 0;
		ll result = 0;
		vv<pii> st;
		for(int i = 0; i < n; ++i) if(!vis[i]){
				//~ printf("%d\n", i);
				int mx = i; vis[i] = ++l; result += abs(i-p[i]);
				for(int u = p[i]; u != i; u = p[u]) vis[u] = l, mx = max(mx, u), result += abs(u-p[u]);
				if(st.empty()) {if(mx != i) st.emplace_back(i, mx);}
				else{
						if(i < st.back().se) st.back().se = max(st.back().se, mx);
						else if(mx != i) st.emplace_back(i, mx);
				}
				//~ printf("%d %lld\n", i, result);
		}
		//~ printf("a\n");
		for(int i = 1; i < ssize(st); ++i) result += 2*(st[i].fi-st[i-1].se);
		if(ssize(st) && st[0].fi != 0) result += 2*st[0].fi;
		return result;
}
#ifdef LOCAL
int main(){
		int T = 1;
		for(++T; --T; ){
				int n, s; scanf("%d%d", &n, &s);
				vv<int> p(n);
				for(int i = 0; i < n; ++i) scanf("%d", &p[i]);
				ll result = minimum_walk(p, s);
				printf("%lld\n", result);
		}
		return 0;
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 436 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 432 KB Output is correct
27 Correct 0 ms 436 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 436 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 432 KB Output is correct
27 Correct 0 ms 436 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 87 ms 18796 KB Output is correct
31 Correct 87 ms 18908 KB Output is correct
32 Correct 96 ms 18808 KB Output is correct
33 Correct 78 ms 20932 KB Output is correct
34 Correct 79 ms 20964 KB Output is correct
35 Correct 79 ms 20932 KB Output is correct
36 Correct 81 ms 19916 KB Output is correct
37 Correct 75 ms 18924 KB Output is correct
38 Correct 74 ms 18772 KB Output is correct
39 Correct 79 ms 18668 KB Output is correct
40 Correct 76 ms 18672 KB Output is correct
41 Correct 86 ms 18668 KB Output is correct
42 Correct 85 ms 18668 KB Output is correct
43 Correct 79 ms 19164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 440 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 436 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 432 KB Output is correct
27 Correct 0 ms 436 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 87 ms 18796 KB Output is correct
31 Correct 87 ms 18908 KB Output is correct
32 Correct 96 ms 18808 KB Output is correct
33 Correct 78 ms 20932 KB Output is correct
34 Correct 79 ms 20964 KB Output is correct
35 Correct 79 ms 20932 KB Output is correct
36 Correct 81 ms 19916 KB Output is correct
37 Correct 75 ms 18924 KB Output is correct
38 Correct 74 ms 18772 KB Output is correct
39 Correct 79 ms 18668 KB Output is correct
40 Correct 76 ms 18672 KB Output is correct
41 Correct 86 ms 18668 KB Output is correct
42 Correct 85 ms 18668 KB Output is correct
43 Correct 79 ms 19164 KB Output is correct
44 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -