Submission #70452

# Submission time Handle Problem Language Result Execution time Memory
70452 2018-08-22T23:05:36 Z bnahmad15 Ancient Books (IOI17_books) C++17
50 / 100
281 ms 30296 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
 
int n;
bool vis[N];
vector<pair<vector<int>,long long> > v;
priority_queue <int> points;
long long minimum_walk(std::vector<int> p, int s) {
	n = p.size();
	for(int i = 0;i<n;i++)
		vis[i] = 0;
	v.clear();
	for(int i = 0;i<n;i++){
		if(p[i] != i && vis[i] == false){
			v.push_back(make_pair(vector<int>(),0));
			v.back().first.push_back(i);
			vis[i] = true;
			v.back().second += 1LL * abs(p[i] - i);
			int j = p[i];
			while (j != i){
				vis[j] = true;
				v.back().first.push_back(j);
				v.back().second += 1LL * abs(p[j] - j);
				j = p[j];
			}
		}
	}
	long long res = 0;
	if(v.size()){
		points.push(0);
		for(int i = 0;i<v.size();i++){
			res += 1LL * v[i].second;
			if(v[i].first[0] > points.top())
				res += 2LL * abs(v[i].first[0] - points.top());	
			for(int j = 0;j<v[i].first.size();j++)
				points.push(v[i].first[j]);
		}
	}
	return res;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i<v.size();i++){
                 ~^~~~~~~~~
books.cpp:37:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j = 0;j<v[i].first.size();j++)
                  ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 3 ms 612 KB Output is correct
15 Correct 2 ms 612 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 628 KB Output is correct
18 Correct 3 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 3 ms 612 KB Output is correct
15 Correct 2 ms 612 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 628 KB Output is correct
18 Correct 3 ms 628 KB Output is correct
19 Correct 2 ms 628 KB Output is correct
20 Correct 2 ms 628 KB Output is correct
21 Correct 3 ms 628 KB Output is correct
22 Correct 2 ms 628 KB Output is correct
23 Correct 3 ms 628 KB Output is correct
24 Correct 4 ms 628 KB Output is correct
25 Correct 3 ms 628 KB Output is correct
26 Correct 2 ms 628 KB Output is correct
27 Correct 2 ms 628 KB Output is correct
28 Correct 2 ms 628 KB Output is correct
29 Correct 2 ms 628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 3 ms 612 KB Output is correct
15 Correct 2 ms 612 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 628 KB Output is correct
18 Correct 3 ms 628 KB Output is correct
19 Correct 2 ms 628 KB Output is correct
20 Correct 2 ms 628 KB Output is correct
21 Correct 3 ms 628 KB Output is correct
22 Correct 2 ms 628 KB Output is correct
23 Correct 3 ms 628 KB Output is correct
24 Correct 4 ms 628 KB Output is correct
25 Correct 3 ms 628 KB Output is correct
26 Correct 2 ms 628 KB Output is correct
27 Correct 2 ms 628 KB Output is correct
28 Correct 2 ms 628 KB Output is correct
29 Correct 2 ms 628 KB Output is correct
30 Correct 272 ms 21764 KB Output is correct
31 Correct 249 ms 21764 KB Output is correct
32 Correct 141 ms 21764 KB Output is correct
33 Correct 212 ms 25688 KB Output is correct
34 Correct 233 ms 25816 KB Output is correct
35 Correct 254 ms 30296 KB Output is correct
36 Correct 273 ms 30296 KB Output is correct
37 Correct 238 ms 30296 KB Output is correct
38 Correct 206 ms 30296 KB Output is correct
39 Correct 281 ms 30296 KB Output is correct
40 Correct 220 ms 30296 KB Output is correct
41 Correct 281 ms 30296 KB Output is correct
42 Correct 248 ms 30296 KB Output is correct
43 Correct 241 ms 30296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 30296 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 3 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 2 ms 612 KB Output is correct
14 Correct 3 ms 612 KB Output is correct
15 Correct 2 ms 612 KB Output is correct
16 Correct 3 ms 620 KB Output is correct
17 Correct 3 ms 628 KB Output is correct
18 Correct 3 ms 628 KB Output is correct
19 Correct 2 ms 628 KB Output is correct
20 Correct 2 ms 628 KB Output is correct
21 Correct 3 ms 628 KB Output is correct
22 Correct 2 ms 628 KB Output is correct
23 Correct 3 ms 628 KB Output is correct
24 Correct 4 ms 628 KB Output is correct
25 Correct 3 ms 628 KB Output is correct
26 Correct 2 ms 628 KB Output is correct
27 Correct 2 ms 628 KB Output is correct
28 Correct 2 ms 628 KB Output is correct
29 Correct 2 ms 628 KB Output is correct
30 Correct 272 ms 21764 KB Output is correct
31 Correct 249 ms 21764 KB Output is correct
32 Correct 141 ms 21764 KB Output is correct
33 Correct 212 ms 25688 KB Output is correct
34 Correct 233 ms 25816 KB Output is correct
35 Correct 254 ms 30296 KB Output is correct
36 Correct 273 ms 30296 KB Output is correct
37 Correct 238 ms 30296 KB Output is correct
38 Correct 206 ms 30296 KB Output is correct
39 Correct 281 ms 30296 KB Output is correct
40 Correct 220 ms 30296 KB Output is correct
41 Correct 281 ms 30296 KB Output is correct
42 Correct 248 ms 30296 KB Output is correct
43 Correct 241 ms 30296 KB Output is correct
44 Incorrect 3 ms 30296 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -