답안 #806310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
806310 2023-08-04T05:53:45 Z fatemetmhr 고대 책들 (IOI17_books) C++17
50 / 100
112 ms 24688 KB
//  ~ Be Name Khoda ~  //

#include "books.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")

using namespace std;

typedef long long ll;

#define pb       push_back

#define mp       make_pair
#define all(x)   x.begin(), x.end()
#define fi       first
#define se       second

const int maxn  =  1e6   + 10;
const int maxn5 =  1e6   + 10;
const int maxnt =  1.2e6 + 10;
const int maxn3 =  1e3   + 10;
const int mod   =  1e9   + 7;
const ll  inf   =  1e18;

int cmp[maxn5], lef[maxn5], rig[maxn5], num = 0;
bool mark[maxn5];
vector <int> per;

void expa(int &l, int &r){
	int lq = l, rq = r;
	while(true){
		lq = min({lq, lef[cmp[l]], lef[cmp[r]]});
		rq = max({rq, rig[cmp[l]], rig[cmp[r]]});
		//cout << "haaaa " << l << ' ' << r << ' ' << lq << ' ' << rq << endl;
		if(l > lq){
			l--;
			continue;
		}
		if(r < rq){
			r++;
			continue;
		}
		break;
	}
}

int solve(int lq, int rq, int s){
	int l = s, r = s;
	expa(l, r);
	int ans = 0;
	//cout << l << ' ' << r << ' ' << lq << ' ' << rq << endl;
	while(l > lq || r < rq){
		int c1 = 0, c2 = 0;
		int l1 = l, r1 = r, l2 = l, r2 = r;
		while(r1 <= r && l1 > lq){
			l1--;
			c1++;
			expa(l1, r1);
		}
		while(l2 >= l && r2 < rq){
			r2++;
			//cout << r2 << ' ' << cmp[r2] << ' ' << rig[cmp[r2]] << endl;
			c2++;
			expa(l2, r2);
			//cout << "hoy " << l2 << ' ' << r2 << ' ' << rig[cmp[r2]] << ' ' << cmp[r2] << endl;
		}
		ans += min(c1, c2) * 2;
		l = min(l1, l2);
		r = max(r1, r2);
		if(l == lq && r == rq && cmp[lq] != cmp[rq])
			ans += max(c1, c2) * 2;
		//cout << l << ' ' << r << ' ' << ans << ' ' << c1 << ' ' << c2 << endl;
	}
	return ans;
}

void dfs(int v){
	mark[v] = true;
	cmp[v] = num;
	lef[num] = min(lef[num], v);
	rig[num] = max(rig[num], v);
	if(!mark[per[v]])
		dfs(per[v]);
}


long long minimum_walk(std::vector<int> PER, int s) {
	per = PER;
	int n = per.size();
	int r = s, l = s;
	ll ans = 0;
	for(int i = 0; i < n; i++){
		if(!mark[i]){
			lef[num] = rig[num] = i;
			dfs(i);
			num++;
		}
		//cout << i << ' ' << per[i] << ' ' << cmp[i] << endl;
		ans += abs(per[i] - i);
		if(i != per[i]){
			l = min(l, i);
			r = max(r, i);
		}
	}
	if(l == r)
		return 0;
	//cout << "ha? " << ans << endl;
	return solve(l, r, s) + 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 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 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 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 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 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 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 96 ms 16892 KB Output is correct
31 Correct 112 ms 17016 KB Output is correct
32 Correct 79 ms 24688 KB Output is correct
33 Correct 93 ms 22304 KB Output is correct
34 Correct 89 ms 22348 KB Output is correct
35 Correct 92 ms 21116 KB Output is correct
36 Correct 87 ms 18892 KB Output is correct
37 Correct 79 ms 17136 KB Output is correct
38 Correct 77 ms 16880 KB Output is correct
39 Correct 80 ms 16880 KB Output is correct
40 Correct 81 ms 16884 KB Output is correct
41 Correct 94 ms 16916 KB Output is correct
42 Correct 98 ms 16932 KB Output is correct
43 Correct 87 ms 22648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '9800', found: '10032'
3 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 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 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 96 ms 16892 KB Output is correct
31 Correct 112 ms 17016 KB Output is correct
32 Correct 79 ms 24688 KB Output is correct
33 Correct 93 ms 22304 KB Output is correct
34 Correct 89 ms 22348 KB Output is correct
35 Correct 92 ms 21116 KB Output is correct
36 Correct 87 ms 18892 KB Output is correct
37 Correct 79 ms 17136 KB Output is correct
38 Correct 77 ms 16880 KB Output is correct
39 Correct 80 ms 16880 KB Output is correct
40 Correct 81 ms 16884 KB Output is correct
41 Correct 94 ms 16916 KB Output is correct
42 Correct 98 ms 16932 KB Output is correct
43 Correct 87 ms 22648 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '9800', found: '10032'
46 Halted 0 ms 0 KB -