Submission #887173

# Submission time Handle Problem Language Result Execution time Memory
887173 2023-12-14T00:35:55 Z VicBVic Sailing Race (CEOI12_race) C++17
40 / 100
189 ms 5364 KB
#include <bits/stdc++.h>

using namespace std;

const int MN = 505;

int d[MN*2][MN*2];
int n,k;
bool adj[MN*2][MN*2];

int main()
{
    cin>>n>>k;
    assert(k==0);
    for(int i=1;i<=n;i++)
    {
        int nr=-1;
        while(true)
        {
            cin>>nr;
            if(!nr) break;
            adj[i][nr]=adj[i+n][nr]=adj[i][nr+n]=adj[i+n][nr+n]=1;
        }
    }

    for(int l=1;l<n;l++)
    {
        for(int i=1;i+l<=2*n;i++)
        {
            int j=i+l;
            for(int y=i+1;y<=j;y++)
            {
                if(adj[i][y]) d[i][j]=max(d[i][j],1 + max( d[y][i+1], d[y][j]));
            }

            for(int y=j-1;y>=i;y--)
            {
                if(adj[j][y]) d[j][i]=max(d[j][i],1 + max( d[y][j-1], d[y][i]));
            }
        }
    }

    /*for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=2*n;j++)
        {
            cout<<d[i][j]<<' ';
        }
        cout<<'\n';
    }*/

    int mx=0, mxc=0;
    for(int i=1;i<=n;i++)
    {
        if(d[i][i+n-1]>mx) mx=d[i][i+n-1], mxc=i;
    }
    cout<<mx<<'\n'<<mxc<<'\n';
    return 0;
}
/*
7 0
5 0
5 0
7 0
3 0
4 0
4 3 0
2 1 0
5 2
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Runtime error 2 ms 4700 KB Execution killed with signal 6
3 Runtime error 2 ms 4744 KB Execution killed with signal 6
4 Runtime error 2 ms 4700 KB Execution killed with signal 6
5 Correct 1 ms 2396 KB Output is correct
6 Runtime error 2 ms 4700 KB Execution killed with signal 6
7 Correct 2 ms 2396 KB Output is correct
8 Runtime error 3 ms 4700 KB Execution killed with signal 6
9 Correct 5 ms 2652 KB Output is correct
10 Correct 5 ms 2652 KB Output is correct
11 Correct 6 ms 2652 KB Output is correct
12 Runtime error 3 ms 4700 KB Execution killed with signal 6
13 Runtime error 3 ms 4700 KB Execution killed with signal 6
14 Correct 111 ms 4584 KB Output is correct
15 Runtime error 2 ms 4700 KB Execution killed with signal 6
16 Runtime error 2 ms 4700 KB Execution killed with signal 6
17 Runtime error 2 ms 4700 KB Execution killed with signal 6
18 Correct 189 ms 5364 KB Output is correct
19 Runtime error 2 ms 4700 KB Execution killed with signal 6
20 Runtime error 3 ms 4696 KB Execution killed with signal 6