답안 #411171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411171 2021-05-24T13:14:25 Z 송준혁(#7506) 매우 즐거운 카드 게임 (JOI15_cardgame2) C++17
100 / 100
229 ms 136508 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<62)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, ans;
bool D[550][550][550][2];
int A[550], B[550], C[550], S[550];

int main(){
	scanf("%d", &N);
	for (int i=1; i<=N; i++) scanf("%d %d %d", &A[i], &B[i], &C[i]), S[i]=S[i-1]+C[i];
	S[N+1] = S[N+2] = S[N];
	D[1][2][3][0] = D[1][2][3][1] = true;
	ans = max(C[1], C[3]);
	for (int i=1; i<=N; i++) for (int j=i+1; j<=N+1; j++) for (int k=j+1; k<=N+2; k++){
		if (k == j+1){
			for (int l=1; l<i; l++){
				if (D[l][i][j][0] && (A[l] == A[i] || B[l] == B[i])){
					D[i][j][k][0] = true;
					ans = max(ans, S[k-1] - C[j]);
				}
				if (D[l][i][j][0] && k<=N && (A[l] == A[k] || B[l] == B[k])){
					D[i][j][k][1] = true;
					ans = max(ans, S[k] - C[i] - C[j]);
				}
			}
		}
		else{
			if (D[i][j][k-1][1] && (A[k-1] == A[k] || B[k-1] == B[k])){
				D[i][j][k][1] = true;
				ans = max(ans, S[k] - C[i] - C[j]);
			}
			if (D[i][j][k-1][1] && (A[k-1] == A[i] || B[k-1] == B[i])){
				D[i][j][k][0] = true;
				ans = max(ans, S[k-1] - C[j]);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

cardgame2.cpp: In function 'int main()':
cardgame2.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
cardgame2.cpp:18:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  for (int i=1; i<=N; i++) scanf("%d %d %d", &A[i], &B[i], &C[i]), S[i]=S[i-1]+C[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 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 460 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 332 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 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 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 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 460 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 332 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 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 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 460 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 332 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 1356 KB Output is correct
33 Correct 1 ms 972 KB Output is correct
34 Correct 1 ms 1136 KB Output is correct
35 Correct 1 ms 716 KB Output is correct
36 Correct 1 ms 844 KB Output is correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 588 KB Output is correct
40 Correct 1 ms 716 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 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 460 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 332 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 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 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 460 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 332 KB Output is correct
28 Correct 1 ms 588 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 1 ms 1356 KB Output is correct
33 Correct 1 ms 972 KB Output is correct
34 Correct 1 ms 1136 KB Output is correct
35 Correct 1 ms 716 KB Output is correct
36 Correct 1 ms 844 KB Output is correct
37 Correct 1 ms 588 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 588 KB Output is correct
40 Correct 1 ms 716 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 204 KB Output is correct
44 Correct 65 ms 2420 KB Output is correct
45 Correct 64 ms 2260 KB Output is correct
46 Correct 63 ms 960 KB Output is correct
47 Correct 64 ms 836 KB Output is correct
48 Correct 68 ms 2836 KB Output is correct
49 Correct 64 ms 916 KB Output is correct
50 Correct 64 ms 836 KB Output is correct
51 Correct 65 ms 3400 KB Output is correct
52 Correct 74 ms 7680 KB Output is correct
53 Correct 68 ms 4928 KB Output is correct
54 Correct 72 ms 2628 KB Output is correct
55 Correct 64 ms 1832 KB Output is correct
56 Correct 65 ms 1028 KB Output is correct
57 Correct 66 ms 6088 KB Output is correct
58 Correct 66 ms 4076 KB Output is correct
59 Correct 65 ms 3704 KB Output is correct
60 Correct 65 ms 2432 KB Output is correct
61 Correct 68 ms 2620 KB Output is correct
62 Correct 69 ms 2088 KB Output is correct
63 Correct 229 ms 136508 KB Output is correct
64 Correct 169 ms 91052 KB Output is correct
65 Correct 134 ms 67404 KB Output is correct
66 Correct 106 ms 47592 KB Output is correct
67 Correct 113 ms 53008 KB Output is correct