Submission #423050

# Submission time Handle Problem Language Result Execution time Memory
423050 2021-06-10T16:39:52 Z Pbezz Ancient Books (IOI17_books) C++14
0 / 100
1 ms 204 KB
#include "books.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
typedef pair<ll,ll> pii;

const ll MAXN=2e5+5;
const ll INF=1e9+7;

long long minimum_walk(std::vector<int> p, int s) {

ll i,n=(ll)p.size(),k,count=0,arr[n+10];


pii cycle[n+4]; //cycle[i]={representante,size}
for(i=0;i<n+2;i++){
arr[i]=0;
cycle[i]={0,0};
}

for(i=0;i<n;i++){
if(arr[i]!=0||p[i]==i)continue;
count++;
k=p[i];
arr[i]=count;
cycle[count].first=i;
cycle[count].second=abs(k-i);

while(k!=i){
arr[k]=count;
cycle[count].second+=abs(k-p[k]);
k=p[k];
}

}
ll maxi=0,ans=0;
for(i=1;i<=count;i++){
maxi=max(maxi,cycle[i].first);
ans+=cycle[i].second;
//cout<<cycle[i].first<<" "<<cycle[i].second<<endl;
}

ans+=2*maxi;

	if(count==2){

	if(p[0]==2&&p[1]==3&&p[2]==0&&p[3]==1){
	return 8;
}


}

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4728'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -