답안 #70366

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
70366 2018-08-22T17:07:45 Z gnoor 고대 책들 (IOI17_books) C++17
50 / 100
315 ms 14148 KB
#include "books.h"

#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

bool visit[1000100];

long long minimum_walk(vector<int> p, int s) {
	int n=(int)p.size();
	vector<pair<int,int>> coord;
	long long ans=0;
	for (int i=0;i<n;i++) {
		if (visit[i]) continue;
		visit[i]=true;
		int mn=i;
		int mx=i;
		int cur=p[i];
		ans+=abs(p[i]-i);
		while (cur!=i) {
			visit[cur]=true;
			mx=max(mx,cur);
			mn=min(mn,cur);
			ans+=abs(p[cur]-cur);
			cur=p[cur];
		}
		if (mn!=mx) coord.push_back({mn,mx});
	}
	coord.push_back({s,s});
	sort(coord.begin(),coord.end(),[](const pair<int,int> &a,const pair<int,int> &b) {
			if (a.second!=b.second) return a.second<b.second;
			return a.first<b.first;
			});
	vector<pair<int,int>> re;
	for (int i=0;i<(int)coord.size();i++) {
		int curl=coord[i].first;
		//if (!re.empty()&&coord[i].second==re.back().second) continue;
		while (!re.empty()&&coord[i].first<=re.back().second) {
			curl=min(curl,re.back().first);
			re.pop_back();
		}
		re.push_back({curl,coord[i].second});
	}
	for (int i=1;i<(int)re.size();i++) {
		ans+=(re[i].first-re[i-1].second)*2;
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 528 KB Output is correct
11 Correct 2 ms 528 KB Output is correct
12 Correct 3 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 3 ms 572 KB Output is correct
15 Correct 3 ms 572 KB Output is correct
16 Correct 3 ms 572 KB Output is correct
17 Correct 3 ms 572 KB Output is correct
18 Correct 2 ms 572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 528 KB Output is correct
11 Correct 2 ms 528 KB Output is correct
12 Correct 3 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 3 ms 572 KB Output is correct
15 Correct 3 ms 572 KB Output is correct
16 Correct 3 ms 572 KB Output is correct
17 Correct 3 ms 572 KB Output is correct
18 Correct 2 ms 572 KB Output is correct
19 Correct 3 ms 572 KB Output is correct
20 Correct 3 ms 572 KB Output is correct
21 Correct 2 ms 572 KB Output is correct
22 Correct 3 ms 572 KB Output is correct
23 Correct 4 ms 572 KB Output is correct
24 Correct 3 ms 572 KB Output is correct
25 Correct 4 ms 624 KB Output is correct
26 Correct 3 ms 624 KB Output is correct
27 Correct 2 ms 624 KB Output is correct
28 Correct 3 ms 624 KB Output is correct
29 Correct 3 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 528 KB Output is correct
11 Correct 2 ms 528 KB Output is correct
12 Correct 3 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 3 ms 572 KB Output is correct
15 Correct 3 ms 572 KB Output is correct
16 Correct 3 ms 572 KB Output is correct
17 Correct 3 ms 572 KB Output is correct
18 Correct 2 ms 572 KB Output is correct
19 Correct 3 ms 572 KB Output is correct
20 Correct 3 ms 572 KB Output is correct
21 Correct 2 ms 572 KB Output is correct
22 Correct 3 ms 572 KB Output is correct
23 Correct 4 ms 572 KB Output is correct
24 Correct 3 ms 572 KB Output is correct
25 Correct 4 ms 624 KB Output is correct
26 Correct 3 ms 624 KB Output is correct
27 Correct 2 ms 624 KB Output is correct
28 Correct 3 ms 624 KB Output is correct
29 Correct 3 ms 624 KB Output is correct
30 Correct 300 ms 9340 KB Output is correct
31 Correct 315 ms 9476 KB Output is correct
32 Correct 141 ms 9540 KB Output is correct
33 Correct 194 ms 14020 KB Output is correct
34 Correct 226 ms 14080 KB Output is correct
35 Correct 226 ms 14148 KB Output is correct
36 Correct 201 ms 14148 KB Output is correct
37 Correct 168 ms 14148 KB Output is correct
38 Correct 218 ms 14148 KB Output is correct
39 Correct 187 ms 14148 KB Output is correct
40 Correct 201 ms 14148 KB Output is correct
41 Correct 229 ms 14148 KB Output is correct
42 Correct 247 ms 14148 KB Output is correct
43 Correct 185 ms 14148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 14148 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 3 ms 488 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 3 ms 528 KB Output is correct
11 Correct 2 ms 528 KB Output is correct
12 Correct 3 ms 572 KB Output is correct
13 Correct 3 ms 572 KB Output is correct
14 Correct 3 ms 572 KB Output is correct
15 Correct 3 ms 572 KB Output is correct
16 Correct 3 ms 572 KB Output is correct
17 Correct 3 ms 572 KB Output is correct
18 Correct 2 ms 572 KB Output is correct
19 Correct 3 ms 572 KB Output is correct
20 Correct 3 ms 572 KB Output is correct
21 Correct 2 ms 572 KB Output is correct
22 Correct 3 ms 572 KB Output is correct
23 Correct 4 ms 572 KB Output is correct
24 Correct 3 ms 572 KB Output is correct
25 Correct 4 ms 624 KB Output is correct
26 Correct 3 ms 624 KB Output is correct
27 Correct 2 ms 624 KB Output is correct
28 Correct 3 ms 624 KB Output is correct
29 Correct 3 ms 624 KB Output is correct
30 Correct 300 ms 9340 KB Output is correct
31 Correct 315 ms 9476 KB Output is correct
32 Correct 141 ms 9540 KB Output is correct
33 Correct 194 ms 14020 KB Output is correct
34 Correct 226 ms 14080 KB Output is correct
35 Correct 226 ms 14148 KB Output is correct
36 Correct 201 ms 14148 KB Output is correct
37 Correct 168 ms 14148 KB Output is correct
38 Correct 218 ms 14148 KB Output is correct
39 Correct 187 ms 14148 KB Output is correct
40 Correct 201 ms 14148 KB Output is correct
41 Correct 229 ms 14148 KB Output is correct
42 Correct 247 ms 14148 KB Output is correct
43 Correct 185 ms 14148 KB Output is correct
44 Incorrect 2 ms 14148 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -