Submission #19426989


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  vector<int> A(a), B(b);
  for(auto &e: A) cin >> e;
  for(auto &e: B) cin >> e;
  vector dp(a+1, vector(b+1, -1));
  dp[a][b] = 0;
  auto is_Snuke = [&](int i, int j){
    return (i + j) % 2 == 0;
  };
  auto dfs = [&](auto dfs, int i, int j){
    if(dp[i][j] >= 0) return dp[i][j];
    if(is_Snuke(i, j)){
      int score = 0;
      if(i < a) score = max(score, dfs(dfs, i + 1, j) + A[i]);
      if(j < b) score = max(score, dfs(dfs, i, j + 1) + B[j]);
      dp[i][j] = score;
    }
    else{
      int score = 1e9;
      if(i < a) score = min(score, dfs(dfs, i + 1, j));
      if(j < b) score = min(score, dfs(dfs, i, j + 1));
      dp[i][j] = score;
    }
    return dp[i][j];
  };
  cout << dfs(dfs, 0, 0) << endl;
}

Submission Info

Submission Time
Task B - ゲーム
User yahoobb
Language C++ (GCC 9.2.1)
Score 3
Code Size 838 Byte
Status AC
Exec Time 30 ms
Memory 7684 KB

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 8 ms 3480 KB
01 AC 23 ms 6508 KB
02 AC 30 ms 7684 KB
90 AC 8 ms 3476 KB
91 AC 2 ms 3528 KB