Submission #2113241


Source Code Expand

#include <bits/stdc++.h>
#define MAX_OBJECT 1005
#define MAX 1000001
 
using namespace std;
 
int a_max = 0;
int b_max = 0;
int a_side[MAX_OBJECT] = {0};
int b_side[MAX_OBJECT] = {0};
int dp[2][MAX_OBJECT][MAX_OBJECT] = {{{0}}};

int rec(bool player = true, int a = 0, int b = 0){
    
    int &res = dp[player][a][b];
    if(~res) return res;
    if(a == a_max && b == b_max) return 0;
    
    res = 0;
    int x = (player) ? 0 : MAX;
    int y = (player) ? 0 : MAX;
    int s = (player) ? a_side[a] : 0;
    int r = (player) ? b_side[b] : 0;
    if(a < a_max) x = rec(!player, (a + 1), b) + s;
    if(b < b_max) y = rec(!player, a, (b + 1)) + r;
    if(player){
        res += (x > y) ? x : y;
    }
    else{
        res += (x < y) ? x : y;
    }

    return res;
}
 
int main(void){
    
    scanf("%d", &a_max);
    scanf("%d", &b_max);
    
    int i;
    for(i = 0; i < a_max; ++i){
        scanf("%d", &a_side[i]);
    }
    for(i = 0; i < b_max; ++i){
        scanf("%d", &b_side[i]);
    }
    
    memset(dp, -1, sizeof(dp));
    
    printf("%d\n", rec());
    
    return 0;
}

Submission Info

Submission Time
Task B - ゲーム
User sgneet
Language C++14 (GCC 5.4.1)
Score 3
Code Size 1147 Byte
Status AC
Exec Time 17 ms
Memory 8320 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:39:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &a_max);
                        ^
./Main.cpp:40:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &b_max);
                        ^
./Main.cpp:44:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a_side[i]);
                                ^
./Main.cpp:47:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &b_side[i]);
                                ^

Judge Result

Set Name All
Score / Max Score 3 / 3
Status
AC × 5
Set Name Test Cases
All 00, 01, 02, 90, 91
Case Name Status Exec Time Memory
00 AC 5 ms 8192 KB
01 AC 13 ms 8320 KB
02 AC 17 ms 8320 KB
90 AC 5 ms 8192 KB
91 AC 5 ms 8192 KB