Submission #117673

# Submission time Handle Problem Language Result Execution time Memory
117673 2019-06-17T05:47:00 Z sealnot123 Ancient Books (IOI17_books) C++14
50 / 100
168 ms 23928 KB
#include "books.h"
//#include "grader.cpp"
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
typedef double D;
typedef long double LD;
const int N = 1000007;
int n;
LL qsl[N],qsr[N];
long long minimum_walk(vector<int> p, int s) {
    int a,b,c,d,i,j,k;
    n = SZ(p);
    if(n==1) return 0;
    for(i=0;i<n;i++){
        a = p[i];
        b = i;
        if(a==b) continue;
        if(a>b) qsl[b]++,qsl[a]--;
        else qsr[a]++,qsr[b]--;
        if(a<s && b>s){
            if(s-a <= b-s) qsr[a]++,qsr[s]--;
            else qsl[s]++,qsl[b]--;
        }
    }
    for(i=1;i<n;i++) qsl[i]+=qsl[i-1],qsr[i]+=qsr[i-1];
//    for(i=0;i<n;i++) printf("%lld ",qsl[i]);
//    printf("\n");
//    for(i=0;i<n;i++) printf("%lld ",qsr[i]);
//    printf("\n");
    int l,r;
    for(i=0;i<n;i++){
        l = i;
        if(qsl[i] || qsr[i]) break;
    }
    for(i=n-1;i>=0;i--){
        r = i;
        if(qsl[i] || qsr[i]) break;
    }
    if(l>r) return 0;
    LL ans = 0;
    for(i=s;i<=r;i++) ans += max(1ll,max(qsl[i],qsr[i]));
    for(i=s-1;i>=l;i--) ans += max(1ll,max(qsl[i],qsr[i]));
    return 2*ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:20:13: warning: unused variable 'c' [-Wunused-variable]
     int a,b,c,d,i,j,k;
             ^
books.cpp:20:15: warning: unused variable 'd' [-Wunused-variable]
     int a,b,c,d,i,j,k;
               ^
books.cpp:20:19: warning: unused variable 'j' [-Wunused-variable]
     int a,b,c,d,i,j,k;
                   ^
books.cpp:20:21: warning: unused variable 'k' [-Wunused-variable]
     int a,b,c,d,i,j,k;
                     ^
books.cpp:39:11: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int l,r;
           ^
books.cpp:39:9: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int l,r;
         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 156 ms 23872 KB Output is correct
31 Correct 168 ms 23904 KB Output is correct
32 Correct 130 ms 23864 KB Output is correct
33 Correct 134 ms 23904 KB Output is correct
34 Correct 133 ms 23928 KB Output is correct
35 Correct 133 ms 23868 KB Output is correct
36 Correct 135 ms 23904 KB Output is correct
37 Correct 134 ms 23860 KB Output is correct
38 Correct 137 ms 23904 KB Output is correct
39 Correct 141 ms 23928 KB Output is correct
40 Correct 135 ms 23856 KB Output is correct
41 Correct 150 ms 23864 KB Output is correct
42 Correct 154 ms 23924 KB Output is correct
43 Correct 133 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3596'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 156 ms 23872 KB Output is correct
31 Correct 168 ms 23904 KB Output is correct
32 Correct 130 ms 23864 KB Output is correct
33 Correct 134 ms 23904 KB Output is correct
34 Correct 133 ms 23928 KB Output is correct
35 Correct 133 ms 23868 KB Output is correct
36 Correct 135 ms 23904 KB Output is correct
37 Correct 134 ms 23860 KB Output is correct
38 Correct 137 ms 23904 KB Output is correct
39 Correct 141 ms 23928 KB Output is correct
40 Correct 135 ms 23856 KB Output is correct
41 Correct 150 ms 23864 KB Output is correct
42 Correct 154 ms 23924 KB Output is correct
43 Correct 133 ms 23900 KB Output is correct
44 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3596'
45 Halted 0 ms 0 KB -