답안 #605713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605713 2022-07-25T23:49:34 Z dnass 고대 책들 (IOI17_books) C++17
50 / 100
308 ms 110644 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

lld n;

lld minimum_walk(vector<int> p, int s){
	n = (lld) p.size();
	lld ans = 0;
	for(lld i=0;i<n;i++) ans+=abs(p[i]-i);
	vector<bool> vis(n, false);
	vector<vector<lld>> cycles;
	vector<pair<lld,lld>> evs;
	for(lld i=0;i<n;i++){
		if(!vis[i]){
			vector<lld> tmp;
			lld x = i;
			while(true){
				if(vis[x]) break;
				tmp.push_back(x);
				vis[x] = true;
				x = p[x];
			}
			cycles.push_back(tmp);
			sort(tmp.begin(), tmp.end());
			evs.push_back({tmp[0], 0});
			evs.push_back({*tmp.rbegin(), 1});
		}
	}
	sort(evs.begin(), evs.end());
	lld op = 0;
	deque<pair<lld,lld>> blocks;
	lld beg = 0;
	for(lld i=0;i<(lld)evs.size();i++){
		if(evs[i].second==0){
			if(op==0) beg = evs[i].first;
			op++;
		}else{
			op--;
			if(op==0) blocks.push_back({beg,evs[i].first});
		}
	}
	while(!blocks.empty()&&blocks.back().first==blocks.back().second&&blocks.back().first>s) blocks.pop_back();
	while(!blocks.empty()&&blocks.front().first==blocks.front().second&&blocks.front().first<s) blocks.pop_front();
	for(lld i=1;i<(lld)blocks.size();i++){
		ans += 2*(blocks[i].first-blocks[i-1].second);
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 0 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 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 1 ms 212 KB Output is correct
4 Correct 1 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 0 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 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 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 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 1 ms 212 KB Output is correct
4 Correct 1 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 0 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 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 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 213 ms 20560 KB Output is correct
31 Correct 223 ms 17796 KB Output is correct
32 Correct 308 ms 110644 KB Output is correct
33 Correct 256 ms 78916 KB Output is correct
34 Correct 258 ms 78796 KB Output is correct
35 Correct 240 ms 71064 KB Output is correct
36 Correct 182 ms 36504 KB Output is correct
37 Correct 134 ms 19108 KB Output is correct
38 Correct 135 ms 16460 KB Output is correct
39 Correct 136 ms 16364 KB Output is correct
40 Correct 150 ms 16164 KB Output is correct
41 Correct 183 ms 16760 KB Output is correct
42 Correct 164 ms 16836 KB Output is correct
43 Correct 289 ms 72032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 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 1 ms 212 KB Output is correct
4 Correct 1 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 0 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 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 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 213 ms 20560 KB Output is correct
31 Correct 223 ms 17796 KB Output is correct
32 Correct 308 ms 110644 KB Output is correct
33 Correct 256 ms 78916 KB Output is correct
34 Correct 258 ms 78796 KB Output is correct
35 Correct 240 ms 71064 KB Output is correct
36 Correct 182 ms 36504 KB Output is correct
37 Correct 134 ms 19108 KB Output is correct
38 Correct 135 ms 16460 KB Output is correct
39 Correct 136 ms 16364 KB Output is correct
40 Correct 150 ms 16164 KB Output is correct
41 Correct 183 ms 16760 KB Output is correct
42 Correct 164 ms 16836 KB Output is correct
43 Correct 289 ms 72032 KB Output is correct
44 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -