답안 #384800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384800 2021-04-02T09:47:21 Z kshitij_sodani 고대 책들 (IOI17_books) C++14
50 / 100
527 ms 120404 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define endl '\n'


#include "books.h"
llo ans=0;
llo n;
vector<llo> adj[1000001];
llo vis[1000001];
vector<llo> ss;
void dfs(int no){
	vis[no]=1;
	ss.pb(no);
	for(auto j:adj[no]){
		if(vis[j]==0){
			dfs(j);
		}
	}
}
long long minimum_walk(std::vector<int> p, int s) {
	while(p.size()){
		if(p.back()+1==p.size()){
			p.pop_back();
		}
		else{
			break;
		}
	}


	n=p.size();
//cout<<p.size()<<":"<<endl;
	if(n==0){
		return 0;
	}
	for(int i=0;i<n;i++){
		adj[i].pb(p[i]);
	}
	//llo co=0;
	llo ans=0;
	vector<pair<llo,llo>> tt;
	for(int i=0;i<n;i++){
		if(vis[i]==0){
			ss.clear();
			dfs(i);
			/*if(ss.size()==0){
				continue;
			}*/
			llo mi=ss[0];
			llo ma=ss[0];
			for(auto j:ss){
				mi=min(mi,j);
				ma=max(ma,j);
			}
			tt.pb({mi,ma});
			//co++;
			
			for(int j=0;j+1<ss.size();j++){
				ans+=abs(ss[j]-ss[j+1]);
			}
		/*	for(auto j:ss){
				cout<<j<<",,";
			}
			cout<<endl;*/
			ans+=(abs(ss[0]-ss.back()));
		}
	}
	sort(tt.begin(),tt.end());
	vector<pair<llo,llo>> tt2;
	for(auto j:tt){
		if(tt2.size()==0){
			tt2.pb(j);
		}
		else{
			if(tt2.back().b<j.a){
				tt2.pb(j);
			}
			else{
				tt2[tt2.size()-1].b=max(tt2[tt2.size()-1].b,j.b);
			}
		}
	}
	llo xx=tt2.size();
	ans+=2*(xx-1);


	//ans+=2*(co-1);

	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:29:16: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   if(p.back()+1==p.size()){
      |      ~~~~~~~~~~^~~~~~~~~~
books.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |    for(int j=0;j+1<ss.size();j++){
      |                ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23788 KB Output is correct
4 Correct 17 ms 23788 KB Output is correct
5 Correct 17 ms 23788 KB Output is correct
6 Correct 17 ms 23788 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 17 ms 23788 KB Output is correct
10 Correct 17 ms 23788 KB Output is correct
11 Correct 17 ms 23788 KB Output is correct
12 Correct 17 ms 23788 KB Output is correct
13 Correct 17 ms 23796 KB Output is correct
14 Correct 17 ms 23788 KB Output is correct
15 Correct 17 ms 23788 KB Output is correct
16 Correct 18 ms 23788 KB Output is correct
17 Correct 18 ms 23788 KB Output is correct
18 Correct 17 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23788 KB Output is correct
4 Correct 17 ms 23788 KB Output is correct
5 Correct 17 ms 23788 KB Output is correct
6 Correct 17 ms 23788 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 17 ms 23788 KB Output is correct
10 Correct 17 ms 23788 KB Output is correct
11 Correct 17 ms 23788 KB Output is correct
12 Correct 17 ms 23788 KB Output is correct
13 Correct 17 ms 23796 KB Output is correct
14 Correct 17 ms 23788 KB Output is correct
15 Correct 17 ms 23788 KB Output is correct
16 Correct 18 ms 23788 KB Output is correct
17 Correct 18 ms 23788 KB Output is correct
18 Correct 17 ms 23788 KB Output is correct
19 Correct 17 ms 23860 KB Output is correct
20 Correct 18 ms 23916 KB Output is correct
21 Correct 17 ms 23788 KB Output is correct
22 Correct 17 ms 23916 KB Output is correct
23 Correct 18 ms 23916 KB Output is correct
24 Correct 17 ms 23916 KB Output is correct
25 Correct 17 ms 23916 KB Output is correct
26 Correct 17 ms 23916 KB Output is correct
27 Correct 17 ms 23916 KB Output is correct
28 Correct 17 ms 23916 KB Output is correct
29 Correct 17 ms 24052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23788 KB Output is correct
4 Correct 17 ms 23788 KB Output is correct
5 Correct 17 ms 23788 KB Output is correct
6 Correct 17 ms 23788 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 17 ms 23788 KB Output is correct
10 Correct 17 ms 23788 KB Output is correct
11 Correct 17 ms 23788 KB Output is correct
12 Correct 17 ms 23788 KB Output is correct
13 Correct 17 ms 23796 KB Output is correct
14 Correct 17 ms 23788 KB Output is correct
15 Correct 17 ms 23788 KB Output is correct
16 Correct 18 ms 23788 KB Output is correct
17 Correct 18 ms 23788 KB Output is correct
18 Correct 17 ms 23788 KB Output is correct
19 Correct 17 ms 23860 KB Output is correct
20 Correct 18 ms 23916 KB Output is correct
21 Correct 17 ms 23788 KB Output is correct
22 Correct 17 ms 23916 KB Output is correct
23 Correct 18 ms 23916 KB Output is correct
24 Correct 17 ms 23916 KB Output is correct
25 Correct 17 ms 23916 KB Output is correct
26 Correct 17 ms 23916 KB Output is correct
27 Correct 17 ms 23916 KB Output is correct
28 Correct 17 ms 23916 KB Output is correct
29 Correct 17 ms 24052 KB Output is correct
30 Correct 527 ms 120404 KB Output is correct
31 Correct 489 ms 99048 KB Output is correct
32 Correct 146 ms 38508 KB Output is correct
33 Correct 299 ms 112952 KB Output is correct
34 Correct 271 ms 113048 KB Output is correct
35 Correct 263 ms 101448 KB Output is correct
36 Correct 243 ms 87644 KB Output is correct
37 Correct 260 ms 78576 KB Output is correct
38 Correct 270 ms 78188 KB Output is correct
39 Correct 276 ms 78188 KB Output is correct
40 Correct 281 ms 79720 KB Output is correct
41 Correct 429 ms 96112 KB Output is correct
42 Correct 397 ms 86240 KB Output is correct
43 Correct 270 ms 92892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23916 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23788 KB Output is correct
4 Correct 17 ms 23788 KB Output is correct
5 Correct 17 ms 23788 KB Output is correct
6 Correct 17 ms 23788 KB Output is correct
7 Correct 17 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 17 ms 23788 KB Output is correct
10 Correct 17 ms 23788 KB Output is correct
11 Correct 17 ms 23788 KB Output is correct
12 Correct 17 ms 23788 KB Output is correct
13 Correct 17 ms 23796 KB Output is correct
14 Correct 17 ms 23788 KB Output is correct
15 Correct 17 ms 23788 KB Output is correct
16 Correct 18 ms 23788 KB Output is correct
17 Correct 18 ms 23788 KB Output is correct
18 Correct 17 ms 23788 KB Output is correct
19 Correct 17 ms 23860 KB Output is correct
20 Correct 18 ms 23916 KB Output is correct
21 Correct 17 ms 23788 KB Output is correct
22 Correct 17 ms 23916 KB Output is correct
23 Correct 18 ms 23916 KB Output is correct
24 Correct 17 ms 23916 KB Output is correct
25 Correct 17 ms 23916 KB Output is correct
26 Correct 17 ms 23916 KB Output is correct
27 Correct 17 ms 23916 KB Output is correct
28 Correct 17 ms 23916 KB Output is correct
29 Correct 17 ms 24052 KB Output is correct
30 Correct 527 ms 120404 KB Output is correct
31 Correct 489 ms 99048 KB Output is correct
32 Correct 146 ms 38508 KB Output is correct
33 Correct 299 ms 112952 KB Output is correct
34 Correct 271 ms 113048 KB Output is correct
35 Correct 263 ms 101448 KB Output is correct
36 Correct 243 ms 87644 KB Output is correct
37 Correct 260 ms 78576 KB Output is correct
38 Correct 270 ms 78188 KB Output is correct
39 Correct 276 ms 78188 KB Output is correct
40 Correct 281 ms 79720 KB Output is correct
41 Correct 429 ms 96112 KB Output is correct
42 Correct 397 ms 86240 KB Output is correct
43 Correct 270 ms 92892 KB Output is correct
44 Incorrect 17 ms 23916 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -