Submission #285241

#TimeUsernameProblemLanguageResultExecution timeMemory
285241CaroLindaSailing Race (CEOI12_race)C++14
75 / 100
3093 ms5112 KiB
#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 ; } int main() { scanf("%d%d", &N , &K ) ; for(int i = 0 , x ; i < N ; i++ ) while( scanf("%d", &x) && x != 0 ) { if(x == i+1) continue ; adj[i].push_back(x-1) ; edge.push_back( mk( i , x-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 ; int &ptr = dp[i][R][j] ; ptr = 0 ; for(int viz : adj[i] ) { if(!isInside(viz, i , R, t[j] ) ) continue ; ptr = max(ptr, 1 + dp[viz][R][j] ) ; ptr = max(ptr, 1 + dp[viz][ (i+t[j]+N)%N ][ !j ] ) ; if( dpLinha[viz][R][j] > 0 || viz == R ) dpLinha[i][R][j] = max( dpLinha[i][R][j] , 1 + dpLinha[viz][R][j] ) ; } if(ptr > ans ) { ans = ptr ; curId = i ; } } if(K == 0) { printf("%d %d\n" , ans, curId + 1 ); return 0 ; } for(int i = 0 ; i < sz(edge) ; i++ ) for(int j = 0 ; 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] ; if(valX == 0) continue ; if( ans < valY+valX+2 ) { ans = valY+valX+2 ; curId = A ; } } printf("%d %d\n" , ans, curId + 1 ) ; }

Compilation message (stderr)

race.cpp: In function 'int main()':
race.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |     scanf("%d%d", &N , &K ) ;
      |     ~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...