Submission #289517

# Submission time Handle Problem Language Result Execution time Memory
289517 2020-09-02T17:35:24 Z eohomegrownapps Simurgh (IOI17_simurgh) C++14
Compilation error
0 ms 0 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

vector<ll> cycle;
vector<int> p;
ll n;

ll minc = 1e9;
ll maxc = -1e9;

ll findcycle(ll i, ll ptr){
	cycle[i] = ptr;
	minc=min(minc,i);
	maxc=max(maxc,i);
	if (cycle[p[i]]!=-1){
		return abs(i-p[i]);
	} else {
		return abs(i-p[i]) + findcycle(p[i], ptr);
	}
}

ll minimum_walk(std::vector<int> px, int s) {
	p = px;
	n = p.size();
	cycle.resize(n,-1);

	ll cycledist = 0;
	ll ptr = 0;
	vector<ll> cyclewidth(n+1);
	for (ll i = 0; i<n; i++){
		if (cycle[i]!=-1){continue;}
		minc=1e9;maxc=-1e9;
		ll dist = findcycle(i,ptr);
		cyclewidth[minc]++;
		cyclewidth[maxc]--;
		cycledist+=dist;
		ptr++;
	}

	ll prev = 0;
	bool iszero = true;
	ll ctr = 0;
	ll minabove=1e9;
	ll maxbelow=-1e9;
	bool isbetween = false;
	for (ll i = 0; i<=n; i++){
		ctr+=cyclewidth[i];
		if (ctr==0&&i==s){
			isbetween=true;
		}
		if (iszero&&ctr>0){
			if (i<=s){
				maxbelow=max(maxbelow,i);
			}
			if (prev!=0){cycledist+=2*(i-prev);}
			iszero = false;
		} else if ((!iszero)&&ctr==0){
			if (i-1>=s){
				minabove=min(minabove,i-1);
			}
			prev = i;
			iszero = true;
		}
	}
	if (!isbetween){
		cycledist+=2*(min(minabove-s,s-maxbelow));
	}
	return cycledist;
}

Compilation message

simurgh.cpp:1:10: fatal error: books.h: No such file or directory
    1 | #include "books.h"
      |          ^~~~~~~~~
compilation terminated.