Submission #260685

# Submission time Handle Problem Language Result Execution time Memory
260685 2020-08-10T17:49:01 Z georgerapeanu Sailing Race (CEOI12_race) C++11
40 / 100
945 ms 5496 KB
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n;
int k;

const int NMAX = 500;

int dp[NMAX + 5][NMAX + 5][2];
int force[NMAX + 5][NMAX + 5][2];
int bst[NMAX + 5][NMAX + 5];

int graph[NMAX + 5][NMAX + 5];

bool is_in(int st,int dr,int pos){
    if(st <= dr){
        return st <= pos && pos <= dr;
    }
    return st <= pos || pos <= dr;
}

int nxt(int pos,int d = 1){
    return (pos + d - 1) % n + 1;
}

int ant(int pos){
    return nxt(pos,n - 1);
}

int dist(int i,int j){
    if(j >= i){
        return j - i;
    }
    return i + n - j;
}

int main(){

    scanf("%d %d",&n,&k);

    for(int i = 1;i <= n;i++){
        int u = i,v = -1;
        while(scanf("%d",&v) == 1){
            if(v == 0){
                break;
            }
            graph[u][v] = 1;
        }
    }

    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            dp[i][j][0] = 0;
            dp[i][j][1] = 0;
            force[i][j][0] = -2 * n * (i != j);
            force[i][j][1] = -2 * n * (i != j);
        }
    }

    for(int l = 1;l < n;l++){
        for(int i = 1;i <= n;i++){
            int j = nxt(i,l);
            for(int k = nxt(i);k != j;k = nxt(k)){
                if(graph[i][k]){
                    dp[i][j][0] = max(dp[i][j][0],1 + max(dp[i][k][1],dp[k][j][0]));
                }
            }
            for(int k = ant(j);k != i;k = ant(k)){
                if(graph[j][k]){
                    dp[i][j][1] = max(dp[i][j][1],1 + max(dp[k][j][0],dp[i][k][1]));
                }
            }
        }
    }

    int ans = 0;
    int fst = -1;

    for(int i = 1;i <= n;i++){
        for(int k = nxt(i);k != i;k = nxt(k)){
            if(graph[i][k] == 1){
                int a = dp[i][k][1];
                int b = dp[k][i][0];
                if(ans < 1 + max(a,b)){
                    ans = 1 + max(a,b);
                    fst = i;
                }
            }
        }
    }
/*
    if(k){

        for(int j = 1;j <= n;j++){
            for(int k = nxt(j);k != j;k = nxt(k)){
                int bst_ext = -1;
                int bst_int = -1;
                for(auto i:graphT[j]){
                    if(is_in(j,k,i) == false){
                        if(bst_ext == -1 || dist(k,i) < dist(k,bst_ext)){
                            bst_ext = i;
                        }
                    }
                    else{
                        if(bst_int == -1 || dist(i,k) < dist(bst_int,k)){
                            bst_int = i;
                        }
                    }
                }
                for(auto l:graph[k]){
                    if(is_in(j,k,l) == false){
                        if(bst_ext != -1 && is_in(k,l,bst_ext)){
                            int a = dp[l][ant(j)][0];
                            int b = dp[nxt(bst_ext)][l][1]; 
                            if(ans < 2 + max(a,b) + force[j][k][0]){
                                ans = 2 + max(a,b) + force[j][k][0];
                                //printf("%d %d %d %d and %d %d %d\n",j,k,l,bst_ext,force[j][k][0],a,b);
                                fst = bst_ext;
                            }
                        }
                    }
                    else{
                        if(bst_int != -1 && is_in(l,k,bst_int)){
                            int a = dp[nxt(j)][l][1];
                            int b = dp[l][ant(bst_int)][0]; 
                            if(ans < 2 + max(a,b) + force[k][j][1]){
                                ans = 2 + max(a,b) + force[k][j][1];
                                //printf("%d %d %d %d and %d %d %d\n",j,k,l,bst_int,force[k][j][1],a,b);
                                fst = bst_int;
                            }
                        }
                    }
                }
            }
        }
    }
*/
    printf("%d\n%d\n",ans,fst);

    return 0;
}

Compilation message

race.cpp: In function 'int main()':
race.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     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 640 KB Output isn't correct
4 Incorrect 1 ms 768 KB Output isn't correct
5 Correct 2 ms 768 KB Output is correct
6 Incorrect 3 ms 896 KB Output isn't correct
7 Correct 4 ms 1024 KB Output is correct
8 Incorrect 4 ms 1152 KB Output isn't correct
9 Correct 8 ms 1152 KB Output is correct
10 Correct 9 ms 1280 KB Output is correct
11 Correct 12 ms 1280 KB Output is correct
12 Incorrect 61 ms 2304 KB Output isn't correct
13 Incorrect 178 ms 3328 KB Output isn't correct
14 Correct 392 ms 4352 KB Output is correct
15 Incorrect 847 ms 5404 KB Output isn't correct
16 Incorrect 896 ms 5496 KB Output isn't correct
17 Incorrect 842 ms 5408 KB Output isn't correct
18 Correct 728 ms 5248 KB Output is correct
19 Incorrect 943 ms 5496 KB Output isn't correct
20 Incorrect 945 ms 5496 KB Output isn't correct