답안 #423019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423019 2021-06-10T15:58:43 Z Pbezz 고대 책들 (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)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=-1,ans=0;
for(i=1;i<=count;i++){
maxi=max(maxi,cycle[i].first);
ans+=cycle[i].second;
}

ans+=2*maxi;

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4736'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -