답안 #411169

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411169 2021-05-24T13:11:48 Z 송준혁(#7506) 매우 즐거운 카드 게임 (JOI15_cardgame2) C++17
0 / 100
1 ms 204 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];
	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 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -