Submission #70341

# Submission time Handle Problem Language Result Execution time Memory
70341 2018-08-22T16:24:13 Z gnoor Ancient Books (IOI17_books) C++17
0 / 100
3 ms 392 KB
#include "books.h"

#include <vector>
#include <algorithm>

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];
		while (cur!=i) {
			visit[cur]=true;
			mx=max(mx,cur);
			mn=min(mn,cur);
			cur=p[cur];
		}
		ans+=(mx-mn)*2;
		coord.push_back({mn,mx});
	}
	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;
			});
	int r=coord[0].second;
	for (int i=1;i<(int)coord.size();i++) {
		if (coord[i].first>r) {
			ans+=(coord[i].first-r)*2;
		}
		r=coord[i].second;
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 3 ms 356 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 3 ms 356 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 3 ms 356 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 392 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4156'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 3 ms 356 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -