Submission #423024

# Submission time Handle Problem Language Result Execution time Memory
423024 2021-06-10T16:03:55 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];


pii cycle[n+4]; //cycle[i]={representante,size}
for(i=0;i<n;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;
}

ans+=2*maxi;

	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 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 1 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 1 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 1 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 1 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 1 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 1 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 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -