답안 #59306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59306 2018-07-21T13:08:33 Z wilwxk Sailing Race (CEOI12_race) C++11
5 / 100
14 ms 4876 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=103;
vector<int> g[MAXN];
int dp[MAXN][MAXN][MAXN];
int n, k;

int dist(int a, int b) { if(b>a) return b-a; else return n-a+b; }
bool dentro(int ini, int fim, int val) {
    if(ini<=fim) return (ini<=val&&val<=fim);
    else {
        if(val==ini||val==fim) return 1;
        fim+=n; val+=n;
        return (ini<=val&&val<=fim);
    }
}
//int parte(int ini, int mid, int fim, int val) { if(ini<=fim) return (mid<=val&&val<=fim); else return (mid>=va) }

int fazdp(int cur, int ini, int fim) {
    if(dp[cur][ini][fim]!=-1) return dp[cur][ini][fim];
    if(ini==fim&&cur==ini) return 0; if(ini<1||fim<1) return 0;
    //printf("chama %d %d %d\n", cur, ini, fim);

    dp[cur][ini][fim]=0; int resp=0;

    for(auto viz : g[cur]) {
        //if(!dentro(ini, fim, viz)) printf("fora %d %d %d\n", ini, fim, viz);
        if(!dentro(ini, fim, viz)) continue;

        int vini, vfim;
        if(viz>cur) {
            vini=viz+1;
            vfim=fim;
        }
        else {
            vini=ini;
            vfim=viz-1;
        }
        if(vini>n) vini%=n; if(vfim>n) vfim%=n;

        //printf("viz: %d %d %d // %d %d\n", ini, fim, viz, vini, vfim);
        resp=max(resp,  fazdp(viz, vini, vfim)+1 );

    }

    //printf("%d %d %d = %d\n", cur, ini, fim, resp);
    return dp[cur][ini][fim]=resp;
}

int main() {
    scanf("%d %d", &n, &k);
    for(int i=1; i<=n; i++) {
        while(1) {
            int a; scanf("%d", &a);
            if(a==0) break;
            g[i].push_back(a);
        }
    }

    memset(dp, -1, sizeof(dp)); int resp=0; int respp=1;

    for(int i=1; i<=n; i++) {
        if(fazdp(i, i+1, i-1)>resp) {
            resp=fazdp(i, i+1, i-1);
            respp=i;
        }
    }

    printf("%d\n%d\n", resp, respp);
}

Compilation message

race.cpp: In function 'int fazdp(int, int, int)':
race.cpp:22:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(ini==fim&&cur==ini) return 0; if(ini<1||fim<1) return 0;
     ^~
race.cpp:22:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     if(ini==fim&&cur==ini) return 0; if(ini<1||fim<1) return 0;
                                      ^~
race.cpp:40:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
         if(vini>n) vini%=n; if(vfim>n) vfim%=n;
         ^~
race.cpp:40:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
         if(vini>n) vini%=n; if(vfim>n) vfim%=n;
                             ^~
race.cpp: In function 'int main()':
race.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
race.cpp:55:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             int a; scanf("%d", &a);
                    ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4604 KB Output isn't correct
2 Incorrect 7 ms 4604 KB Output isn't correct
3 Incorrect 7 ms 4744 KB Output isn't correct
4 Incorrect 6 ms 4744 KB Output isn't correct
5 Incorrect 7 ms 4744 KB Output isn't correct
6 Incorrect 6 ms 4796 KB Output isn't correct
7 Incorrect 9 ms 4876 KB Output isn't correct
8 Incorrect 7 ms 4876 KB Output isn't correct
9 Incorrect 10 ms 4876 KB Output isn't correct
10 Correct 14 ms 4876 KB Output is correct
11 Incorrect 9 ms 4876 KB Output isn't correct
12 Runtime error 5 ms 4876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 4 ms 4876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 4 ms 4876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 5 ms 4876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 4 ms 4876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 4 ms 4876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 4 ms 4876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 4 ms 4876 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 5 ms 4876 KB Execution killed with signal 11 (could be triggered by violating memory limits)