답안 #824944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824944 2023-08-14T12:12:50 Z kwongweng 고대 책들 (IOI17_books) C++17
50 / 100
110 ms 14176 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second

ll minimum_walk(vi p, int s) {
	int n=p.size();
	vi used(n);
	vii r; ll ans=0;
	FOR(i,0,n){
		if (used[i] || p[i]==i) continue;
		int cur=i; int mx=0;
		while (p[cur] != i){
			ans += abs(p[cur]-cur);
			mx=max(mx,cur); used[cur]=1; cur=p[cur];
		}
		ans += abs(i-cur); mx=max(mx,cur); used[cur]=1;
		r.pb({i,mx});
	}
	if (r.empty()) return ans;
	int len=r.size(); bool sol=true; if (p[s]!=s) s=false;
	if (r[0].fi>s) {ans += 2*(r[0].fi-s); sol=false;}
	int mx=r[0].fi;
	FOR(i,0,len){
		if (r[i].fi > mx) {
			ans += 2*(r[i].fi-mx);
			if (r[i].fi > s && s > mx) sol=false;
		}
		mx=max(mx,r[i].se);
	}
	if (s>mx) {ans += 2*(s-mx); sol=false;}
	if (!sol) return ans;
	int L=s,R=s;
	while (p[L]==L) L--;
	while (p[R]==R) R++;
	ans += 2*min(s-L,R-s);
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 276 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 276 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 110 ms 12024 KB Output is correct
31 Correct 93 ms 12012 KB Output is correct
32 Correct 71 ms 12024 KB Output is correct
33 Correct 80 ms 14176 KB Output is correct
34 Correct 78 ms 14176 KB Output is correct
35 Correct 78 ms 14172 KB Output is correct
36 Correct 107 ms 14176 KB Output is correct
37 Correct 74 ms 12404 KB Output is correct
38 Correct 74 ms 12140 KB Output is correct
39 Correct 76 ms 12020 KB Output is correct
40 Correct 75 ms 12024 KB Output is correct
41 Correct 84 ms 11980 KB Output is correct
42 Correct 88 ms 12012 KB Output is correct
43 Correct 76 ms 14144 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 0 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 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 276 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 110 ms 12024 KB Output is correct
31 Correct 93 ms 12012 KB Output is correct
32 Correct 71 ms 12024 KB Output is correct
33 Correct 80 ms 14176 KB Output is correct
34 Correct 78 ms 14176 KB Output is correct
35 Correct 78 ms 14172 KB Output is correct
36 Correct 107 ms 14176 KB Output is correct
37 Correct 74 ms 12404 KB Output is correct
38 Correct 74 ms 12140 KB Output is correct
39 Correct 76 ms 12020 KB Output is correct
40 Correct 75 ms 12024 KB Output is correct
41 Correct 84 ms 11980 KB Output is correct
42 Correct 88 ms 12012 KB Output is correct
43 Correct 76 ms 14144 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 -