답안 #411103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411103 2021-05-24T11:19:32 Z 반딧불(#7588) 매우 즐거운 카드 게임 (JOI15_cardgame2) C++17
100 / 100
2425 ms 251816 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
int c[502], a[502], v[502];
int sum[502];
int ans;

bool DP[4][502][502][502];

inline void dfs(int t, int x, int y, int z){
    DP[t][x][y][z] = 1;
    if(t == 0){
        ans = max(ans, sum[y]);
        if(y+1 <= n && (a[x] == a[y+1] || c[x] == c[y+1]) && !DP[0][y+1][y+1][0]){
            dfs(0, y+1, y+1, 0);
        }
        if(y+3 <= n && (a[x] == a[y+3] || c[x] == c[y+3]) && !DP[2][y+3][y][0]){
            dfs(2, y+3, y, 0);
        }
    }
    else if(t==1){
        ans = max(ans, sum[y] + sum[z] - sum[y+1]);
        if((a[x] == a[y+1] || c[x] == c[y+1]) && !DP[0][y+1][z][0]){
            dfs(0, y+1, z, 0);
        }
        if(z+2 <= n && (a[x] == a[z+2] || c[x] == c[z+2]) && !DP[3][z+2][y][z]){
            dfs(3, z+2, y, z);
        }
    }
    else if(t==2){
        ans = max(ans, sum[y] + sum[x] - sum[y+2]);
        if((a[x] == a[y+1] || c[x] == c[y+1]) && !DP[1][y+1][y+1][x]){
            dfs(1, y+1, y+1, x);
        }
        if(x+1 <= n && (a[x] == a[x+1] || c[x] == c[x+1]) && !DP[2][x+1][y][0]){
            dfs(2, x+1, y, 0);
        }
    }
    else{
        ans = max(ans, sum[y] + sum[z] - sum[y+1] + sum[x] - sum[z+1]);
        if((a[x] == a[y+1] || c[x] == c[y+1]) && !DP[1][y+1][z][x]){
            dfs(1, y+1, z, x);
        }
        if(x+1 <= n && (a[x] == a[x+1] || c[x] == c[x+1]) && !DP[3][x+1][y][z]){
            dfs(3, x+1, y, z);
        }
    }
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d %d %d", &c[i], &a[i], &v[i]);
        sum[i] = sum[i-1] + v[i];
    }

    dfs(0, 1, 1, 0);
    if(3<=n) dfs(2, 3, 0, 0);
    printf("%d", ans);
}

Compilation message

cardgame2.cpp: In function 'int main()':
cardgame2.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
cardgame2.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         scanf("%d %d %d", &c[i], &a[i], &v[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 2 ms 844 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 2 ms 844 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 844 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 1228 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 2 ms 2764 KB Output is correct
33 Correct 2 ms 1868 KB Output is correct
34 Correct 2 ms 2380 KB Output is correct
35 Correct 2 ms 1612 KB Output is correct
36 Correct 1 ms 1484 KB Output is correct
37 Correct 1 ms 1100 KB Output is correct
38 Correct 1 ms 588 KB Output is correct
39 Correct 1 ms 972 KB Output is correct
40 Correct 1 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 2 ms 844 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 844 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 1228 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 2 ms 2764 KB Output is correct
33 Correct 2 ms 1868 KB Output is correct
34 Correct 2 ms 2380 KB Output is correct
35 Correct 2 ms 1612 KB Output is correct
36 Correct 1 ms 1484 KB Output is correct
37 Correct 1 ms 1100 KB Output is correct
38 Correct 1 ms 588 KB Output is correct
39 Correct 1 ms 972 KB Output is correct
40 Correct 1 ms 1356 KB Output is correct
41 Correct 1 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 1 ms 292 KB Output is correct
44 Correct 4 ms 5580 KB Output is correct
45 Correct 4 ms 4940 KB Output is correct
46 Correct 1 ms 844 KB Output is correct
47 Correct 2 ms 308 KB Output is correct
48 Correct 5 ms 6220 KB Output is correct
49 Correct 1 ms 844 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 5 ms 6988 KB Output is correct
52 Correct 13 ms 18788 KB Output is correct
53 Correct 8 ms 11084 KB Output is correct
54 Correct 4 ms 6092 KB Output is correct
55 Correct 4 ms 3660 KB Output is correct
56 Correct 2 ms 972 KB Output is correct
57 Correct 10 ms 14752 KB Output is correct
58 Correct 9 ms 10444 KB Output is correct
59 Correct 7 ms 9036 KB Output is correct
60 Correct 4 ms 5324 KB Output is correct
61 Correct 4 ms 5452 KB Output is correct
62 Correct 3 ms 4428 KB Output is correct
63 Correct 2425 ms 251816 KB Output is correct
64 Correct 1280 ms 181552 KB Output is correct
65 Correct 722 ms 135672 KB Output is correct
66 Correct 405 ms 101704 KB Output is correct
67 Correct 457 ms 98972 KB Output is correct