Submission #6414333
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i)) using ll = long long; using P = pair<int, int>; using namespace std; int dp[1010][1010]; int main() { int A, B; cin >> A >> B; vector<int> a(A), b(B); rep(i, A) cin >> a[i]; rep(i, B) cin >> b[i]; for (int i=A; i>=0; --i) { for (int j=B; j>=0; --j) { // 最終手番はスキップ if (i == A and j == B) continue; if ((i+j)%2 == 0) { // 自分の手番 if (i == A) { // Aの山札が空 dp[i][j] = b[j] + dp[i][j+1]; } else if (j == B) { // Bの山札が空 dp[i][j] = a[i] + dp[i+1][j]; } else { dp[i][j] = max(dp[i][j+1] + b[j], a[i] + dp[i+1][j]); } } else { // 相手の手番 if (i == A) { dp[i][j] = dp[i][j+1]; } else if (j == B) { dp[i][j] = dp[i+1][j]; } else { dp[i][j] = min(dp[i+1][j], dp[i][j+1]); } } } } cout << dp[0][0] << endl; }
Submission Info
Submission Time | |
---|---|
Task | B - ゲーム |
User | dsytk7 |
Language | C++14 (GCC 5.4.1) |
Score | 3 |
Code Size | 1413 Byte |
Status | AC |
Exec Time | 6 ms |
Memory | 4224 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 3 / 3 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 00, 01, 02, 90, 91 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00 | AC | 1 ms | 256 KB |
01 | AC | 5 ms | 3456 KB |
02 | AC | 6 ms | 4224 KB |
90 | AC | 1 ms | 256 KB |
91 | AC | 1 ms | 256 KB |