답안 #283736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
283736 2020-08-26T06:32:12 Z hank55663 고대 책들 (IOI17_books) C++14
50 / 100
302 ms 23532 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second
int f[1000005];
int l[1000005];
int r[1000005];
int Find(int x){
	if(f[x]==x)return x;
	return f[x]=Find(f[x]);
}
int pre[1000005];
long long minimum_walk(std::vector<int> p, int s) {
//	vector<pii> v;
	long long ans=0;
	int Min=1e9;
	for(int i = 0;i<p.size();i++){
		if(p[i]!=i){
//			v.pb(mp(p[i],i));
			ans+=abs(p[i]-i);
			Min=min(Min,abs(i-s));
		}
		l[i]=1e9;
		r[i]=0;
		f[i]=i;
	}
	for(int i = 0;i<p.size();i++){
		f[Find(p[i])]=Find(i);
	}
	for(int i = 0;i<p.size();i++){
		l[Find(i)]=min(l[Find(i)],i);
		r[Find(i)]=max(r[Find(i)],i);
	}
	vector<pii> v;
	for(int i = 0;i<p.size();i++){
		if(f[i]==i&&l[i]!=r[i]){
			v.pb(mp(l[i],r[i]));
		}
	}
	if(v.empty())return 0;
	sort(v.begin(),v.end());
	int Max=v[0].x;
	for(auto it:v){
		ans+=max(0,(it.x-Max)*2);
		Max=max(Max,it.y);	
	}

	return ans+Min*2;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int i = 0;i<p.size();i++){
      |                ~^~~~~~~~~
books.cpp:31:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for(int i = 0;i<p.size();i++){
      |                ~^~~~~~~~~
books.cpp:34:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for(int i = 0;i<p.size();i++){
      |                ~^~~~~~~~~
books.cpp:39:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0;i<p.size();i++){
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 302 ms 21244 KB Output is correct
31 Correct 291 ms 21368 KB Output is correct
32 Correct 178 ms 21240 KB Output is correct
33 Correct 199 ms 23532 KB Output is correct
34 Correct 193 ms 23484 KB Output is correct
35 Correct 202 ms 23532 KB Output is correct
36 Correct 211 ms 23532 KB Output is correct
37 Correct 208 ms 21628 KB Output is correct
38 Correct 209 ms 21368 KB Output is correct
39 Correct 206 ms 21368 KB Output is correct
40 Correct 219 ms 21368 KB Output is correct
41 Correct 246 ms 21240 KB Output is correct
42 Correct 235 ms 21240 KB Output is correct
43 Correct 196 ms 23532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 302 ms 21244 KB Output is correct
31 Correct 291 ms 21368 KB Output is correct
32 Correct 178 ms 21240 KB Output is correct
33 Correct 199 ms 23532 KB Output is correct
34 Correct 193 ms 23484 KB Output is correct
35 Correct 202 ms 23532 KB Output is correct
36 Correct 211 ms 23532 KB Output is correct
37 Correct 208 ms 21628 KB Output is correct
38 Correct 209 ms 21368 KB Output is correct
39 Correct 206 ms 21368 KB Output is correct
40 Correct 219 ms 21368 KB Output is correct
41 Correct 246 ms 21240 KB Output is correct
42 Correct 235 ms 21240 KB Output is correct
43 Correct 196 ms 23532 KB Output is correct
44 Incorrect 1 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -