Submission #32042

# Submission time Handle Problem Language Result Execution time Memory
32042 2017-09-23T10:30:04 Z osmanorhan Shortcut (IOI16_shortcut) C++14
0 / 100
0 ms 16084 KB
#include "shortcut.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define all( x ) x.begin(), x.end()
#define umin( x, y ) x = min( x, (y) )
#define umax( x, y ) x = max( x, (y) )
#define pb push_back

using namespace std;

typedef long long Lint;
typedef pair<int,Lint> ii;

const int inf = 1e9 + 137;
const int maxn = 200020;

Lint pre[maxn], suf[maxn], x[maxn], smax[maxn], pmax[maxn];
ii st1[maxn];
int at1, al1;
ii st2[maxn];
int at2, al2;
int c;

Lint calc( vector<ii> &v ) {
    //if( v.size() ) {
        //for(int i=0;i<v.size();i++)
        //printf("-- %d %d\n",v[i].fi,v[i].se);
    //}
    Lint tot = v[v.size()-1].fi-v[0].fi+c;
    Lint ret = 0;
    at1 = 0, al1 = 1;
    at2 = 0, al2 = 1;
    for(int i=0,j=0;i<v.size()*2;i++) {
        ii t = v[i%v.size()];
        if( i >= v.size() ) t.fi += tot;

        while( j < i && j < v.size() && t.fi-v[j].fi > tot/2 ) {
            if( st1[al1].fi == j ) al1++;
            if( st2[al2].fi == j ) al2++;
            j++;
        }
        if( j >= v.size() ) break;
        if( al1 <= at1 ) {
            //printf("asd %d %d --> %d\n",j,i,st1[al1].se + t.se+t.fi);
            umax( ret, st1[al1].se + t.se+t.fi );
        }
        while( at1>=al1 && st1[at1].se <= t.se-t.fi ) at1--; st1[++at1] = ii( i, t.se-t.fi );
        while( at2>=al2 && st2[at2].se <= t.se+t.fi ) at2--; st2[++at2] = ii( i, t.se+t.fi );
    }
    return ret;
}

long long find_shortcut(int n, vector<int> l, vector<int> d, int C)
{
    c = C;
    x[0] = 0;
    for(int i=1;i<n;i++)
        x[i] = x[i-1]+l[i-1];

    for(int i=0;i<n;i++) {
        if( i == 0 ) pre[i] = d[i];
        else pre[i] = max( pre[i-1]+l[i-1], (Lint)d[i] ), pmax[i] = max( pmax[i-1], pre[i-1]+l[i-1]+ (Lint)d[i] );
    }

    for(int i=n-1;i>=0;i--) {
        if( i == n-1 ) suf[i] = d[i];
        else suf[i] = max( suf[i+1]+l[i], (Lint)d[i] ), smax[i] = max( suf[i+1]+l[i]+ (Lint)d[i], smax[i+1] );
    }
    Lint ans = 1e18 + 5;
    for(int i=0;i<n;i++) {
        vector<ii> v;
        v.pb( ii( x[i], pre[i] ) );
        for(int j=i+1;j<n;j++) {
            v.pb( ii( x[j], suf[j] ) );
            umin( ans, max( max( pmax[i], smax[j] ), calc( v ) ) );
            //printf("Asd %d %d --> %lld\n",i,j,ans);
            //if( i == 0 && j == 2 ) return ans;
            v[v.size()-1].se = d[j];
        }
    }
    return ans;
}

Compilation message

shortcut.cpp: In function 'Lint calc(std::vector<std::pair<int, long long int> >&)':
shortcut.cpp:34:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0,j=0;i<v.size()*2;i++) {
                      ^
shortcut.cpp:36:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if( i >= v.size() ) t.fi += tot;
               ^
shortcut.cpp:38:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while( j < i && j < v.size() && t.fi-v[j].fi > tot/2 ) {
                           ^
shortcut.cpp:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if( j >= v.size() ) break;
               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16084 KB n = 4, 80 is a correct answer
2 Correct 0 ms 16084 KB n = 9, 110 is a correct answer
3 Correct 0 ms 16084 KB n = 4, 21 is a correct answer
4 Correct 0 ms 16084 KB n = 3, 4 is a correct answer
5 Correct 0 ms 16084 KB n = 2, 62 is a correct answer
6 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
7 Correct 0 ms 16084 KB n = 3, 29 is a correct answer
8 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
9 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
10 Correct 0 ms 16084 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 16084 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 16084 KB n = 3, 3000000000 is a correct answer
13 Incorrect 0 ms 16084 KB n = 3, incorrect answer: jury 3000000000 vs contestant 0
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16084 KB n = 4, 80 is a correct answer
2 Correct 0 ms 16084 KB n = 9, 110 is a correct answer
3 Correct 0 ms 16084 KB n = 4, 21 is a correct answer
4 Correct 0 ms 16084 KB n = 3, 4 is a correct answer
5 Correct 0 ms 16084 KB n = 2, 62 is a correct answer
6 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
7 Correct 0 ms 16084 KB n = 3, 29 is a correct answer
8 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
9 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
10 Correct 0 ms 16084 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 16084 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 16084 KB n = 3, 3000000000 is a correct answer
13 Incorrect 0 ms 16084 KB n = 3, incorrect answer: jury 3000000000 vs contestant 0
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16084 KB n = 4, 80 is a correct answer
2 Correct 0 ms 16084 KB n = 9, 110 is a correct answer
3 Correct 0 ms 16084 KB n = 4, 21 is a correct answer
4 Correct 0 ms 16084 KB n = 3, 4 is a correct answer
5 Correct 0 ms 16084 KB n = 2, 62 is a correct answer
6 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
7 Correct 0 ms 16084 KB n = 3, 29 is a correct answer
8 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
9 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
10 Correct 0 ms 16084 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 16084 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 16084 KB n = 3, 3000000000 is a correct answer
13 Incorrect 0 ms 16084 KB n = 3, incorrect answer: jury 3000000000 vs contestant 0
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16084 KB n = 4, 80 is a correct answer
2 Correct 0 ms 16084 KB n = 9, 110 is a correct answer
3 Correct 0 ms 16084 KB n = 4, 21 is a correct answer
4 Correct 0 ms 16084 KB n = 3, 4 is a correct answer
5 Correct 0 ms 16084 KB n = 2, 62 is a correct answer
6 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
7 Correct 0 ms 16084 KB n = 3, 29 is a correct answer
8 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
9 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
10 Correct 0 ms 16084 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 16084 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 16084 KB n = 3, 3000000000 is a correct answer
13 Incorrect 0 ms 16084 KB n = 3, incorrect answer: jury 3000000000 vs contestant 0
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16084 KB n = 4, 80 is a correct answer
2 Correct 0 ms 16084 KB n = 9, 110 is a correct answer
3 Correct 0 ms 16084 KB n = 4, 21 is a correct answer
4 Correct 0 ms 16084 KB n = 3, 4 is a correct answer
5 Correct 0 ms 16084 KB n = 2, 62 is a correct answer
6 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
7 Correct 0 ms 16084 KB n = 3, 29 is a correct answer
8 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
9 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
10 Correct 0 ms 16084 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 16084 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 16084 KB n = 3, 3000000000 is a correct answer
13 Incorrect 0 ms 16084 KB n = 3, incorrect answer: jury 3000000000 vs contestant 0
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16084 KB n = 4, 80 is a correct answer
2 Correct 0 ms 16084 KB n = 9, 110 is a correct answer
3 Correct 0 ms 16084 KB n = 4, 21 is a correct answer
4 Correct 0 ms 16084 KB n = 3, 4 is a correct answer
5 Correct 0 ms 16084 KB n = 2, 62 is a correct answer
6 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
7 Correct 0 ms 16084 KB n = 3, 29 is a correct answer
8 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
9 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
10 Correct 0 ms 16084 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 16084 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 16084 KB n = 3, 3000000000 is a correct answer
13 Incorrect 0 ms 16084 KB n = 3, incorrect answer: jury 3000000000 vs contestant 0
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16084 KB n = 4, 80 is a correct answer
2 Correct 0 ms 16084 KB n = 9, 110 is a correct answer
3 Correct 0 ms 16084 KB n = 4, 21 is a correct answer
4 Correct 0 ms 16084 KB n = 3, 4 is a correct answer
5 Correct 0 ms 16084 KB n = 2, 62 is a correct answer
6 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
7 Correct 0 ms 16084 KB n = 3, 29 is a correct answer
8 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
9 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
10 Correct 0 ms 16084 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 16084 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 16084 KB n = 3, 3000000000 is a correct answer
13 Incorrect 0 ms 16084 KB n = 3, incorrect answer: jury 3000000000 vs contestant 0
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16084 KB n = 4, 80 is a correct answer
2 Correct 0 ms 16084 KB n = 9, 110 is a correct answer
3 Correct 0 ms 16084 KB n = 4, 21 is a correct answer
4 Correct 0 ms 16084 KB n = 3, 4 is a correct answer
5 Correct 0 ms 16084 KB n = 2, 62 is a correct answer
6 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
7 Correct 0 ms 16084 KB n = 3, 29 is a correct answer
8 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
9 Correct 0 ms 16084 KB n = 2, 3 is a correct answer
10 Correct 0 ms 16084 KB n = 2, 2000000001 is a correct answer
11 Correct 0 ms 16084 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 16084 KB n = 3, 3000000000 is a correct answer
13 Incorrect 0 ms 16084 KB n = 3, incorrect answer: jury 3000000000 vs contestant 0
14 Halted 0 ms 0 KB -