Submission #285217

# Submission time Handle Problem Language Result Execution time Memory
285217 2020-08-28T12:00:01 Z CaroLinda Sailing Race (CEOI12_race) C++14
5 / 100
3000 ms 4984 KB
#include <bits/stdc++.h>

#define sz(x) (int)x.size()
#define mkt make_tuple
#define lp(i,a,b) for(int i = a ; i < b ; i++ )
#define ff first
#define ss second
#define eb push_back
#define ll long long
#define mk make_pair
#define pii pair<int,int>
#define debug printf
#define all(x) x.begin(),x.end()

const int MAXN = 510 ;

using namespace std ;

int N , K , ans, curId ;
int t[2] = {-1,1} ;
int dp[MAXN][MAXN][2] , dpLinha[MAXN][MAXN][2] ;
vector<int> adj[MAXN] ;
vector<pii> edge ;

bool isInside(int x, int L , int R , int type )
{

    if(type == -1) swap(L,R) ;

    if( L > R ) return (L <= x || x <= R ) ;
    return L <= x && x <= R ;

}

void solve()
{
    lp(i,0,N) dpLinha[i][i][0] = dpLinha[i][i][1] = 1 ;

    for(int diff = 1 ; diff < N ; diff++ )
        for(int i = 0 ; i < N ; i++ )
            for(int j = 0 ; j < 2 ; j++ )
            {
                int R = ( i + diff * t[j] + N ) % N ;

                for(int viz : adj[i] )
                {
                    if(!isInside(viz, i , R, t[j] ) ) continue ;

                    dp[i][R][j] = max(dp[viz][ (i+t[j]+N)%N ][ !j ], dp[viz][R][j] ) + 1 ;

                    if( dpLinha[viz][R][j] ) dpLinha[i][R][j] = max( dpLinha[i][R][j] , 1 + dpLinha[viz][R][j] ) ;

                }

                if(dp[i][R][j] > ans )
                {
                    ans = dp[i][R][j] ;
                    curId = i ;
                }
            }
    lp(i,0,N)
        lp(j,0,N)
            lp(g,0,2)
                if(dpLinha[i][j][g]) dpLinha[i][j][g]-- ;
}

int main()
{
    scanf("%d%d", &N , &K ) ;
    for(int i = 0 , x ; i < N ; i++ )
        while( scanf("%d", &x) && x != 0 )
        {
            adj[i].push_back(x-1) ;
            edge.push_back( mk( i , x-1 ) ) ;
        }

    solve() ;

    if(K == 0)
    {
        printf("%d %d\n" , ans, curId + 1 );
        return 0 ;
    }

   /* for(int i = 0 ; i < N ; i++ )
    {
        for(int j = 0 ; j < N ; j++ )
            for(int g = 0 ; g < 2 ; g++ )
            {
                printf("dp[%d][%d][%d] = %d\n", i , j , g , dp[i][j][g] ) ;
            }
    } */

    ans = curId = 0 ;

    for(int i = 0 ; i < sz(edge) ; i++ )
        for(int j = i+1 ; j < sz(edge) ; j++ )
        {
            int A = edge[i].ff, B = edge[i].ss ;
            int X = edge[j].ff, Y = edge[j].ss ;

            if( A == X || A == Y || B == X || B == Y ) continue ;
            if( isInside(X, A, B, 1) == isInside(Y, A, B, 1) ) continue ;

            int typeB = isInside(A, Y, B, 1) ? 0 : 1 ;
            int typeA = !typeB ;

            int valY = max( dp[Y][ (B+t[typeA]+N)%N ][typeB] , dp[Y][ (A+t[typeB]+N)%N ][typeA] ) ;
            int valX = dpLinha[B][X][typeB] ;

            //debug("Em %d %d %d %d, valx eh %d e valy eh %d com typeB = %d\n" , A , B , X , Y , valX , valY , typeB ) ;
           // debug("%d %d e %d %d\n", Y, (B+t[typeA]+N)%N, Y , (A+t[typeB]+N)%N ) ;

            if( ans < valY+valX )
            {
                ans = valY+valX ;
                curId = A ;
            }

        }

    printf("%d %d\n" , ans+2, curId + 1 ) ;

}

Compilation message

race.cpp: In function 'int main()':
race.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |     scanf("%d%d", &N , &K ) ;
      |     ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 512 KB Output isn't correct
3 Incorrect 1 ms 512 KB Output isn't correct
4 Incorrect 2 ms 640 KB Output isn't correct
5 Incorrect 2 ms 768 KB Output isn't correct
6 Incorrect 6 ms 768 KB Output isn't correct
7 Incorrect 3 ms 896 KB Output isn't correct
8 Incorrect 6 ms 1024 KB Output isn't correct
9 Incorrect 4 ms 1152 KB Output isn't correct
10 Incorrect 10 ms 1328 KB Output isn't correct
11 Incorrect 6 ms 1280 KB Output isn't correct
12 Incorrect 176 ms 2048 KB Output isn't correct
13 Incorrect 273 ms 2816 KB Output isn't correct
14 Incorrect 68 ms 3756 KB Output isn't correct
15 Execution timed out 3083 ms 4732 KB Time limit exceeded
16 Execution timed out 3090 ms 4856 KB Time limit exceeded
17 Execution timed out 3075 ms 4732 KB Time limit exceeded
18 Incorrect 106 ms 4480 KB Output isn't correct
19 Execution timed out 3050 ms 4984 KB Time limit exceeded
20 Execution timed out 3068 ms 4984 KB Time limit exceeded