답안 #423130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423130 2021-06-10T18:23:22 Z Pbezz 고대 책들 (IOI17_books) C++14
50 / 100
194 ms 33128 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],maxi,ans=0;


pii cycle[n+4]; //cycle[i]={representante left,representante right}
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;

maxi = max(i,(ll)p[i]);
count++;	arr[i]=count;
k=p[i];
cycle[count].first=i;

ans+=abs(k-i);

while(k!=i){
arr[k]=count;
ans+=abs(k-p[k]);
k=p[k];	maxi = max(maxi,k);
}
cycle[count].second=maxi;
}
//cout<<ans<<endl;

ll cur=0;
for(i=1;i<=count;i++){

while(i<=count && cycle[i].first<=cur){
cur=max(cur,cycle[i].second);
i++;
}
if(i==count+1)break;

if(cur!=0)ans+=2*(cycle[i].first-cur);
//cout<<i<<" "<<cycle[i].first-cur<<endl;
cur=cycle[i].second; 
//cout<<cycle[i].first<<" "<<cycle[i].second<<endl;
}

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

if(s>maxi){
ans+=2*(s-maxi);
}else if(s<cycle[1].first){//cout<<"haha "<<cycle[0]
ans+=2*(cycle[1].first-s);
}
//adicionar o pedaço do bundle em que o s se insere
	return ans;
}
# 결과 실행 시간 메모리 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 190 ms 32996 KB Output is correct
31 Correct 194 ms 32916 KB Output is correct
32 Correct 131 ms 32996 KB Output is correct
33 Correct 133 ms 32904 KB Output is correct
34 Correct 141 ms 33000 KB Output is correct
35 Correct 134 ms 32988 KB Output is correct
36 Correct 133 ms 32992 KB Output is correct
37 Correct 135 ms 32872 KB Output is correct
38 Correct 159 ms 32976 KB Output is correct
39 Correct 154 ms 33000 KB Output is correct
40 Correct 138 ms 32876 KB Output is correct
41 Correct 178 ms 33004 KB Output is correct
42 Correct 162 ms 32964 KB Output is correct
43 Correct 142 ms 33128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 190 ms 32996 KB Output is correct
31 Correct 194 ms 32916 KB Output is correct
32 Correct 131 ms 32996 KB Output is correct
33 Correct 133 ms 32904 KB Output is correct
34 Correct 141 ms 33000 KB Output is correct
35 Correct 134 ms 32988 KB Output is correct
36 Correct 133 ms 32992 KB Output is correct
37 Correct 135 ms 32872 KB Output is correct
38 Correct 159 ms 32976 KB Output is correct
39 Correct 154 ms 33000 KB Output is correct
40 Correct 138 ms 32876 KB Output is correct
41 Correct 178 ms 33004 KB Output is correct
42 Correct 162 ms 32964 KB Output is correct
43 Correct 142 ms 33128 KB Output is correct
44 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -