Typical DP Contest

Submission #5874854

Source codeソースコード

#include <iostream>
#include <cstdio>
// #include <math>
using namespace std;

const int MAXN = 1001;
int a,b;
int as[MAXN], bs[MAXN];
int score[MAXN][MAXN] = {};

int solve(int i, int j) {
    if (score[i][j] > 0) {
        return score[i][j];
    }
    if (i >= a && j >= b) return 0;

    int m1=-1, m2=-1;
    if (i < a) {
        m1 = solve(i + 1, j);
    }
    if (j < b) {
        m2 = solve(i, j+1);
    }
    int ret;
    if ((i+j) % 2 == 0) { // Player A
        ret = m1 != -1 ? max(m1 + as[i], m2 + bs[j]) : m2 + bs[j];
    } else {  // Player B
        ret = m1 == -1 ? m2 : (m2 == -1? m1 : min(m1, m2));
    }
    // printf("%d, %d => %d,%d => %d\n", i, j, m1, m2, ret);
    return ret;
}

int main(int argc, char *argv[])
{
    // cin >> a >> b;
    scanf("%d %d", &a, &b);
    for (int i = 0; i < a; ++i) {
        scanf("%d", &as[i]);
    }
    for (int i = 0; i < b; ++i) {
        scanf("%d", &bs[i]);
    }

    int s = solve(0, 0);
    printf("%d\n", s);
    return 0;
}

Submission

Task問題 B - ゲーム
User nameユーザ名 vintersnow
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 TLE
Score得点 0
Source lengthソースコード長 1040 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:37:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &a, &b);
^
./Main.cpp:39:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &as[i]);
^
./Main.cpp:42:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &bs[i]);
^

Test case

Set

Set name Score得点 / Max score Cases
All 0 / 3 00,01,02,90,91

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00 AC 4 ms 256 KB
01 TLE
02 TLE
90 AC 1 ms 256 KB
91 AC 1 ms 256 KB