Submission #32032

# Submission time Handle Problem Language Result Execution time Memory
32032 2017-09-23T07:49:46 Z osmanorhan Roller Coaster Railroad (IOI16_railroad) C++14
0 / 100
113 ms 9872 KB
#include "railroad.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,int> ii;

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

int a, n;
ii segment[maxn];
vector<ii> inc, de;

ii find( int l, int r ) {
    ii t = ii( inf, n+1 );
    for(l+=n, r+=n;l<=r;l=(l+1)>>1, r=(r-1)>>1) {
        if( l&1 ) umin( t, segment[l] );
        if( ~r&1 ) umin( t, segment[r] );
    }
    return t;
}

Lint plan_roller_coaster(vector<int> s, vector<int> ti) {

    a = s.size();
    for(int i=0;i<a;i++) {
        if( s[i] > ti[i] ) de.pb( ii( ti[i], s[i] ) );
        else inc.pb( ii( s[i], ti[i] ) );
    }
    sort( all( inc ) );
    sort( all( de ) );


    n = 1;
    while( n < inc.size() ) n <<= 1;

    for(int i=1;i<n+n;i++)
        segment[i] = ii( inf, n+1 );

    for(int i=0;i<inc.size();i++)
        segment[i+n] = ii( inc[i].se, i );

    for(int i=n-1;i>=1;i--)
        segment[i] = min( segment[i+i], segment[i+i+1] );

    for(int i=0,now=1;i<de.size();i++) {
        int last = de[i].se;
        //printf("asd--  %d %d\n",last,inc.size());
        bool flag = 1;
        int go = now;
        while( flag ) {
            ii t = find( lower_bound( all( inc ), ii( go, 0 ) ) - inc.begin(), n-1 );
                //printf("--- %d %d -- %d %d\n",t.fi,last,go,n-1);
            if( t.fi <= last ) {
                segment[t.se+n] = ii( inf, n+1 );
                for(int k=(t.se+n)>>1;k;k>>=1)
                    segment[k] = min( segment[k+k], segment[k+k+1] );
                go = t.fi;
            } else break;
        }
        now = de[i].fi;
    }
    ii t = find( 0, n-1 );
    if( t.fi >= inf ) return 0;
    return 1;
}

Compilation message

railroad.cpp: In function 'Lint plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:43:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while( n < inc.size() ) n <<= 1;
              ^
railroad.cpp:48:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<inc.size();i++)
                  ^
railroad.cpp:54:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0,now=1;i<de.size();i++) {
                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3580 KB n = 2
2 Correct 0 ms 3580 KB n = 2
3 Correct 0 ms 3580 KB n = 2
4 Correct 0 ms 3580 KB n = 2
5 Correct 0 ms 3580 KB n = 2
6 Incorrect 0 ms 3580 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3580 KB n = 2
2 Correct 0 ms 3580 KB n = 2
3 Correct 0 ms 3580 KB n = 2
4 Correct 0 ms 3580 KB n = 2
5 Correct 0 ms 3580 KB n = 2
6 Incorrect 0 ms 3580 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 109 ms 9872 KB n = 199999
2 Runtime error 113 ms 9364 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3580 KB n = 2
2 Correct 0 ms 3580 KB n = 2
3 Correct 0 ms 3580 KB n = 2
4 Correct 0 ms 3580 KB n = 2
5 Correct 0 ms 3580 KB n = 2
6 Incorrect 0 ms 3580 KB answer is not correct: 1 instead of 523688153
7 Halted 0 ms 0 KB -