Submission #355060

# Submission time Handle Problem Language Result Execution time Memory
355060 2021-01-22T08:42:30 Z kylych03 Ancient Books (IOI17_books) C++14
50 / 100
197 ms 22872 KB
#include "books.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int vis[1000001];
long long minimum_walk(std::vector<int> p, int s) {
	ll ans=0;
	vector <pair<ll, ll>> vec;
	for(int i = 0 ; i < p.size(); i++){
		ans+= abs( i - p[i]);
		int j = i;
		int l = i , r = i;
		while(vis[j]==0){
			l=min(l,j);
			r = max(r,j);
			vis[j]=1;
			j = p[j];
		}
		if(l!=r)
			vec.push_back(make_pair(l,r));
	}
	vec.push_back(make_pair(0,0));
	//cout << vec.size()<<endl;
	sort( vec.begin(), vec.end() );
	for(int i = 1; i < vec.size();i++){
		ans += (2 * max(0ll, vec[i].first - vec[i-1].second));
		vec[i].second = max(vec[i].second, vec[i-1].second);
	}
	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i = 0 ; i < p.size(); i++){
      |                  ~~^~~~~~~~~~
books.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i = 1; i < vec.size();i++){
      |                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 197 ms 18940 KB Output is correct
31 Correct 189 ms 18796 KB Output is correct
32 Correct 138 ms 18816 KB Output is correct
33 Correct 164 ms 21976 KB Output is correct
34 Correct 170 ms 21976 KB Output is correct
35 Correct 170 ms 22360 KB Output is correct
36 Correct 173 ms 22504 KB Output is correct
37 Correct 150 ms 19428 KB Output is correct
38 Correct 142 ms 19052 KB Output is correct
39 Correct 142 ms 19052 KB Output is correct
40 Correct 147 ms 18796 KB Output is correct
41 Correct 154 ms 18796 KB Output is correct
42 Correct 162 ms 18796 KB Output is correct
43 Correct 179 ms 22872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 197 ms 18940 KB Output is correct
31 Correct 189 ms 18796 KB Output is correct
32 Correct 138 ms 18816 KB Output is correct
33 Correct 164 ms 21976 KB Output is correct
34 Correct 170 ms 21976 KB Output is correct
35 Correct 170 ms 22360 KB Output is correct
36 Correct 173 ms 22504 KB Output is correct
37 Correct 150 ms 19428 KB Output is correct
38 Correct 142 ms 19052 KB Output is correct
39 Correct 142 ms 19052 KB Output is correct
40 Correct 147 ms 18796 KB Output is correct
41 Correct 154 ms 18796 KB Output is correct
42 Correct 162 ms 18796 KB Output is correct
43 Correct 179 ms 22872 KB Output is correct
44 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -