Submission #117666

# Submission time Handle Problem Language Result Execution time Memory
117666 2019-06-17T05:28:59 Z sealnot123 Ancient Books (IOI17_books) C++14
0 / 100
2 ms 384 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);
    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]--;
    }
    for(i=1;i<n;i++) qsl[i]+=qsl[i-1],qsr[i]+=qsr[i-1];
    int l=0,r=n-1;
    for(i=0;i<n;i++){
        if(qsl[i] || qsr[i]){
            l=i; break;
        }
    }
    for(i=n-1;i>=0;i--){
        if(qsl[i] || qsr[i]){
            r=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;
                     ^
# 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 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '0', found: '8'
10 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 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '0', found: '8'
10 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 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '0', found: '8'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
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 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '0', found: '8'
10 Halted 0 ms 0 KB -