Submission #73104

# Submission time Handle Problem Language Result Execution time Memory
73104 2018-08-27T16:15:47 Z aleksam Ancient Books (IOI17_books) C++14
0 / 100
3 ms 488 KB
#include "books.h"

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

struct cikl{
	int l, r;//Najlevlji i najdesnji
	long long sum;//suma p_i-i na ciklusu.
};
vector<cikl> C;
int numcyc=0, numcom=0;//broj ciklova
int N;
long long ans=0;
bool mark[MAX_N];

long long minimum_walk(vector<int> p, int s){
	//Ako je s=0 i n<1000
	N=p.size();
	while(N && p[N-1]==N-1){
		N--;//Ovaj deo mi ionako ne treba
	}
	if(!N)return 0;
	for(int i=0; i<N; ++i){
		if(!mark[i]){
			numcyc++;
			cikl A;
			A.l=A.r=i;
			mark[i]=1;
			int cur=i;
			do{
				cur=p[cur];
				if(cur>A.r)A.r=cur;
				if(cur<A.l)A.l=cur;
				A.sum+=abs(p[cur]-cur);
				mark[cur]=1;
			}while(i!=cur);
			C.push_back(A);
			//Ovako formiran niz ciklova je sortiran prema levom kraju--koji je uvek i
		}
	}
	int r=0;//Desna granica dosadasnjih ciklova;
	for(int i=0; i<numcyc; ++i){
		ans+=C[i].sum;
		if(C[i].l<=r){
			//Mogu da ga uhvatim, i dalje sam u istoj komponenti
		}
		else{
			numcom++;
		}
		if(C[i].r>r)
			r=C[i].r;
	}
	ans+=2*numcom;
	return numcom;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 380 KB 3rd lines differ - on the 1st token, expected: '6', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 380 KB 3rd lines differ - on the 1st token, expected: '6', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 380 KB 3rd lines differ - on the 1st token, expected: '6', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 488 KB 3rd lines differ - on the 1st token, expected: '3304', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 380 KB 3rd lines differ - on the 1st token, expected: '6', found: '1'
2 Halted 0 ms 0 KB -