Submission #299751

# Submission time Handle Problem Language Result Execution time Memory
299751 2020-09-15T14:58:04 Z errorgorn Ancient Books (IOI17_books) C++14
0 / 100
1 ms 384 KB
#include "books.h"

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<int,int>
#define fi first
#define se second

#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

int n;
vector<int> arr;

int fwd[1000005];
vector<int> imp;

long long minimum_walk(std::vector<int> p, int s) {
	n=sz(p);
	arr=p;
	
	rep(x,0,n){
		if (x<arr[x]){
			fwd[x]++,fwd[arr[x]]--;
			imp.push_back(x);
			imp.push_back(arr[x]);
		}
	}
	
	rep(x,0,n) fwd[x+1]+=fwd[x];
	
	int l=0,r=n-1;
	while (l<s && fwd[l]==0) l++;
	while (s<=r && fwd[r]==0) r--;
	
	ll ans=1e9;
	if (imp.empty()) ans=0;
	else for (auto &it:imp) ans=min(ans,(ll)abs(s-it));
	
	rep(x,l,r+1){
		ans+=max(fwd[x],1);
	}
	
	return ans*2;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 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 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -