Submission #2548742


Source Code Expand

#include <iostream>
using namespace std;
const int INF = -1;
int a, b, p[1000], q[1000], dp[1000][1000];
int game(int x, int y) {
    if (dp[x][y] != INF) return dp[x][y];
    
    if (x == a && y == b) {
        return dp[x][y] = 0;
    } else if (x == a) {
        return dp[x][y] = game(x, y + 1) + ((x + y) % 2 == 0 ? q[y] : 0);
    } else if (y == b) {
        return dp[x][y] = game(x + 1, y) + ((x + y) % 2 == 0 ? p[x] : 0);
    } else if ((x + y) % 2 == 0) {
        return dp[x][y] = max(game(x + 1, y) + p[x], game(x, y + 1) + q[y]);
    } else {
        return dp[x][y] = min(game(x + 1, y), game(x, y + 1));
    }
}

int main(void){
    // Your code here!
    for (int i = 0; i < 1000; i++) {
        for (int j = 0; j < 1000; j++) {
            dp[i][j] = INF;
        }
    }
    cin >> a >> b;
    for (int i = 0; i < a; i++) cin >> p[i];
    for (int i = 0; i < b; i++) cin >> q[i];
    cout << game(0, 0) << endl;
}

Submission Info

Submission Time
Task B - ゲーム
User kwfumou1242
Language C++14 (GCC 5.4.1)
Score 0
Code Size 965 Byte
Status WA
Exec Time 21 ms
Memory 4224 KB

Judge Result

Set Name All
Score / Max Score 0 / 3
Status
AC × 4
WA × 1
Set Name Test Cases
All 00, 01, 02, 90, 91
Case Name Status Exec Time Memory
00 AC 3 ms 4096 KB
01 AC 14 ms 4224 KB
02 WA 21 ms 4224 KB
90 AC 3 ms 4096 KB
91 AC 3 ms 4096 KB