답안 #423201

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423201 2021-06-10T19:57:09 Z MDario 고대 책들 (IOI17_books) C++11
50 / 100
169 ms 15284 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
long long minimum_walk(vector<int> p, int s){
    ll n=p.size(), r=0, x=n, y=0, z=-1;
    bool b[n];
    for(int i=0; i<n; i++){
        b[i]=0;
        if(p[i]==i)b[i]=1;
    }
    vector<pair<ll, ll>> v;
    for(ll i=0; i<n; i++){
        if(!b[i]){
            //cout << z << " ";
            if(i>=z){
                if(z!=-1)r+=2*(i-z);
            }
            r+=p[i]-i;
            y=p[i];
            while(y!=i){
                z=max(z, y);
                b[y]=1;
                r+=abs(p[y]-y);
                y=p[y];
            }
            b[y]=1;
            z=max(z, y);
            v.push_back({i, z});
        }
    }
    if(v.empty())return 0;
    unique(v.begin(), v.end());
    sort(v.begin(), v.end());
    if(s>v.back().S)return r+2*(s-v.back().S);
    if(s<v[0].F) return r+2*(v[0].F-s);
    x=0;
    z=0;
//    for(int i=0; i<v.size(); i++){
//        if(i+1==v.size()){
//            if(s>=v[i].F&&s<=v[i].S&&v[i].S>z){
//                //cout << v[i].F << " " << v[i].S << "\n";
//                x=min(s-v[i].F, v[i].S-s);
//                z=v[i].S;
//            }
//        }
//        else if(v[i+1].F!=v[i].F){
//            if(s>=v[i].F&&s<=v[i].S&&v[i].S>z){
//                x=min(s-v[i].F, v[i].S-s);
//                z=v[i].S;
//            }
//        }
//    }
	return r+2*x;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 288 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 1 ms 204 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 288 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 288 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 1 ms 204 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 288 KB Output is correct
18 Correct 1 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 204 KB Output is correct
22 Correct 1 ms 292 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 292 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 1 ms 204 KB Output is correct
2 Correct 1 ms 288 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 1 ms 204 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 288 KB Output is correct
18 Correct 1 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 204 KB Output is correct
22 Correct 1 ms 292 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 292 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 151 ms 10976 KB Output is correct
31 Correct 154 ms 11024 KB Output is correct
32 Correct 137 ms 10952 KB Output is correct
33 Correct 169 ms 15156 KB Output is correct
34 Correct 137 ms 15180 KB Output is correct
35 Correct 142 ms 15284 KB Output is correct
36 Correct 132 ms 15164 KB Output is correct
37 Correct 124 ms 11700 KB Output is correct
38 Correct 124 ms 11200 KB Output is correct
39 Correct 125 ms 11184 KB Output is correct
40 Correct 149 ms 10948 KB Output is correct
41 Correct 138 ms 11004 KB Output is correct
42 Correct 135 ms 10948 KB Output is correct
43 Correct 139 ms 15244 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 1 ms 204 KB Output is correct
2 Correct 1 ms 288 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 1 ms 204 KB Output is correct
8 Correct 0 ms 296 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 288 KB Output is correct
18 Correct 1 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 204 KB Output is correct
22 Correct 1 ms 292 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 292 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 151 ms 10976 KB Output is correct
31 Correct 154 ms 11024 KB Output is correct
32 Correct 137 ms 10952 KB Output is correct
33 Correct 169 ms 15156 KB Output is correct
34 Correct 137 ms 15180 KB Output is correct
35 Correct 142 ms 15284 KB Output is correct
36 Correct 132 ms 15164 KB Output is correct
37 Correct 124 ms 11700 KB Output is correct
38 Correct 124 ms 11200 KB Output is correct
39 Correct 125 ms 11184 KB Output is correct
40 Correct 149 ms 10948 KB Output is correct
41 Correct 138 ms 11004 KB Output is correct
42 Correct 135 ms 10948 KB Output is correct
43 Correct 139 ms 15244 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 -