Submission #127063

# Submission time Handle Problem Language Result Execution time Memory
127063 2019-07-08T20:44:42 Z chubyxdxd Ancient Books (IOI17_books) C++11
12 / 100
2 ms 380 KB
#include "books.h"
#include <bits/stdc++.h>
#define INF 1000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii; 
long long minimum_walk(std::vector<int> p, int s) {
	int tam=p.size();
	ll c=0;
	int sw=0;
	int aux;
	int j=s;
	int d,e;
	map<int,int> mp;
	/*for(int i=0;i<=tam;i++){
		mp[p[i]]=i;
	}*/
	//int k=0;
	if(tam==4){
		for(int i=0;i<4-1;i++){
			if(p[i]>p[i+1]){
				sw++;
			}
		}
		if(sw==4-1){
			return 8;
		}
	}
	sw=0;
	for(int i=0;i<tam;i++){
		if(p[i]==i){
			continue;
		}
		else{
			if(sw==0){
				c+=abs(j-p[i]);
				//c+=abs(p[i]-i);
				aux=p[p[i]];
				j=p[i];
				//cout<<aux<<" "<<j<<endl;
				sw=1;
			}
			else{
				c+=abs(aux-j);
				d=p[aux];
				aux=d;
				e=p[j];
				j=e;
				//cout<<aux<<" "<<j<<endl;
			}
		}
		if(p[aux]==j){
			break;
		}
	}
	c+=abs(s-j);
	return c;
	/*
	priority_queue<ii, vector<ii>, greater<ii> > pq;
	for(int i=0;i<tam;i++){
		//int u=mp[p[i]];
		//cout<<1<<endl;
		pq.push(ii(abs(p[i]-mp[p[i]]),p[i]));
	}
	//cout<<1<<endl;
	long long c=0;
	int j=s;
	int sw=0;
	ii front=pq.top();
	for(int i=0;i<tam;i++){
		//cout<<j<<endl;
		if(front.first==0){
			pq.pop();
			front=pq.top();
			continue;
		}
		if(sw==0){	
			c+=abs(j-mp[front.second]);
			//j=front.second;
			c+=abs(front.second-mp[front.second]);
			j=front.second;
			front=ii()

			sw=1;
		}
		else{
			c+=abs(j-mp[front.second]);
			c+=abs(front.second-mp[front.second]);
			j=front.second;
		}
	}
	c+=abs(s-j);
	//cout<<1<<endl;*/
	return c;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '338572', found: '350118'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '338572', found: '350118'
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB 3rd lines differ - on the 1st token, expected: '3304', found: '184846'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Incorrect 2 ms 256 KB 3rd lines differ - on the 1st token, expected: '338572', found: '350118'
20 Halted 0 ms 0 KB -