Submission #423986

# Submission time Handle Problem Language Result Execution time Memory
423986 2021-06-11T14:58:59 Z cfalas Ancient Books (IOI17_books) C++14
0 / 100
2000 ms 229224 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
#define len(x) ((int)x.size())

int t, n;
vi a, b;
int s;

vi p;

int d=0;
int dist(int pos, int b, int prev){
	//cout<<d<<endl;
	if(pos<0) return MOD;
	if(pos>=len(p)) return MOD;
	if(d>len(p)*len(p)*len(p)) return MOD;
	int done=1;
	FOR(i,len(p)) if(p[i]!=i) done = 0;
	//if(done) cout<<"FOUND\n";
	if(done) return abs(pos-s);
	d++;
	//FOR(i,d) cout<<" |";
	//cout<<pos<<" "<<b<<" | ";
	//FOA(v,p) cout<<v<<" ";
	//cout<<endl;

	int ans=MOD;
	// switch
		int t=p[pos];
		p[pos] = b;
		ans = min(ans, dist(pos, t, -1));
		p[pos] = t;
	if(pos+1!=prev){
		ans = min(ans, 1+dist(pos+1, b, pos));
	}
	if(pos-1!=prev){
		ans = min(ans, 1+dist(pos-1, b, pos));
	}
	d--;
	return ans;
}

long long minimum_walk(std::vector<int> pp, int ss) {
	s = ss;
	p = pp;
	return dist(s,-1, -1);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2094 ms 229224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -