Submission #605658

# Submission time Handle Problem Language Result Execution time Memory
605658 2022-07-25T21:22:04 Z dnass Ancient Books (IOI17_books) C++17
0 / 100
1 ms 340 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

lld n;

lld minimum_walk(vector<int> p, int s){
	n = (lld) p.size();
	lld ans = 0;
	for(lld i=0;i<n;i++) ans+=abs(p[i]-i);
	vector<bool> vis(n, false);
	vector<vector<lld>> cycles;
	vector<pair<lld,lld>> evs;
	for(lld i=0;i<n;i++){
		if(!vis[i]){
			vector<lld> tmp;
			lld x = i;
			while(true){
				if(vis[x]) break;
				tmp.push_back(x);
				vis[x] = true;
				x = p[x];
			}
			cycles.push_back(tmp);
			sort(tmp.begin(), tmp.end());
			evs.push_back({tmp[0], 0});
			evs.push_back({*tmp.rbegin(), 1});
		}
	}
	sort(evs.begin(), evs.end());
	lld op = 0;
	vector<lld> newcycle;
	for(lld i=0;i<(lld)evs.size();i++){
		if(evs[i].second==0){
			if(op==0) newcycle.push_back(evs[i].first);
			op++;
		}else{
			op--;
		}
	}
	return ans+2*(*newcycle.rbegin());
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '10'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '10'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '10'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 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 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '4', found: '10'
6 Halted 0 ms 0 KB -