답안 #832304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832304 2023-08-21T08:41:52 Z TS_2392 Sailing Race (CEOI12_race) C++14
20 / 100
1010 ms 5324 KB
#include <bits/stdc++.h>
using namespace std;

#define fileIO(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
#define SPEED {ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);}
template<class T1, class T2> bool minimize(T1 &a, T2 b){return a > b ? a = b, true : false;}
template<class T1, class T2> bool maximize(T1 &a, T2 b){return a < b ? a = b, true : false;}

const int N = 503;
int n, type, res, res_vtx, nxt[N], prv[N];
int adj[N][N], dp1[N][N][2], dp2[N][N][2];
int main(){
    fileIO("text");
    cin >> n >> type;
    for(int u = 1, v; u <= n; ++u){
        cin >> v;
		while(v) {
			adj[u][v] = 1;
			cin >> v;
		}
        nxt[u] = u + 1; prv[u] = u - 1;
    }
    nxt[n] = 1; prv[1] = n;
    for(int len = 2; len < n; ++len){
        for(int i = 1; i <= n; ++i){
            int j = i + len - 1;
            if(j > n) j -= n;

            if(adj[i][j]) dp1[i][j][0] = 1;
            for(int k = nxt[i]; k != j; k = nxt[k]) if(adj[k][j] && dp1[i][k][0]){
                maximize(dp1[i][j][0], dp1[i][k][0] + 1);
            }

            if(adj[j][i]) dp1[i][j][1] = 1;
            for(int k = prv[j]; k != i; k = prv[k]) if(adj[k][i] && dp1[k][j][1]){
                maximize(dp1[i][j][1], dp1[k][j][1] + 1);
            }

        }
    }
    for(int len = 2; len < n; ++len){
        for(int i = 1; i <= n; ++i){
            int j = i + len - 1;
            if(j > n) j -= n;

            dp2[i][j][0] = dp2[i][prv[j]][0];
            if(adj[i][j]) maximize(dp2[i][j][0], dp2[nxt[i]][j][1] + 1);
            for(int k = nxt[i]; k != j; k = nxt[k]) if(adj[k][j] && dp1[i][k][0]){
                maximize(dp2[i][j][0], dp1[i][k][0] + 1 + dp2[nxt[k]][j][1]);
            }

            dp2[i][j][1] = dp2[nxt[i]][j][1];
            if(adj[j][i]) maximize(dp2[i][j][1], dp2[i][prv[j]][0] + 1);
            for(int k = prv[j]; k != i; k = prv[k]) if(adj[k][i] && dp1[k][j][1]){
                maximize(dp2[i][j][1], dp1[k][j][1] + 1 + dp2[i][prv[k]][0]);
            }

            if(maximize(res, dp2[i][j][0])) res_vtx = i;
            if(maximize(res, dp2[i][j][1])) res_vtx = j;
        }
    }
    cout << res << '\n' << res_vtx;
    return 0;
}

Compilation message

race.cpp: In function 'int main()':
race.cpp:4:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define fileIO(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:13:5: note: in expansion of macro 'fileIO'
   13 |     fileIO("text");
      |     ^~~~~~
race.cpp:4:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define fileIO(name) if(fopen(name".inp", "r")) {freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);}
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:13:5: note: in expansion of macro 'fileIO'
   13 |     fileIO("text");
      |     ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 468 KB Output isn't correct
3 Incorrect 1 ms 596 KB Output isn't correct
4 Incorrect 1 ms 596 KB Output isn't correct
5 Correct 2 ms 724 KB Output is correct
6 Incorrect 3 ms 852 KB Output isn't correct
7 Incorrect 5 ms 1012 KB Output isn't correct
8 Incorrect 4 ms 1108 KB Output isn't correct
9 Incorrect 9 ms 1104 KB Output isn't correct
10 Incorrect 6 ms 1236 KB Output isn't correct
11 Incorrect 14 ms 1304 KB Output isn't correct
12 Incorrect 61 ms 2268 KB Output isn't correct
13 Incorrect 163 ms 3224 KB Output isn't correct
14 Correct 359 ms 4196 KB Output is correct
15 Incorrect 832 ms 5292 KB Output isn't correct
16 Incorrect 928 ms 5172 KB Output isn't correct
17 Incorrect 835 ms 5220 KB Output isn't correct
18 Correct 632 ms 5184 KB Output is correct
19 Incorrect 1010 ms 5196 KB Output isn't correct
20 Incorrect 1008 ms 5324 KB Output isn't correct