Submission #3272925
Source Code Expand
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
if (n == 0)return 1;
if (n == 1)return x%MOD;
ll res = sq(mod_pow(x, n / 2));
res %= MOD;
if (n % 2 == 1) {
res *= x;
res %= MOD;
}
return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }
int A,B;
ll a[1000];
ll b[1000];
ll dp[2001][1001];
int main(){
cin >> A >> B;
rep(i,A)cin >> a[i];
rep(i,B)cin >> b[i];
rep(i,A+B){
rep(j,1001){
if((i+1)%2 == 0)dp[i+1][j] = INF;
else dp[i+1][j] = -1;
}
rep(j,i+1){
if(i%2 == 0){
if(dp[i][j] == INF)continue;
if(j+1 <= A)dp[i+1][j+1] = max(dp[i][j] + a[j],dp[i+1][j+1]);
if(i+1-j <= B)dp[i+1][j] = max(dp[i][j] + b[i - j],dp[i+1][j]);
}
else{
if(dp[i][j] == -1)continue;
if(j+1 <= A)dp[i+1][j+1] = dp[i][j];
if(i+1-j <= B)dp[i+1][j] = dp[i][j];
}
}
}
ll ans = ((A+B)%2 ? 0 : INF);
// rep(i,A+B+1){
// rep(j,i+1){
// if(dp[i][j] == INF)cout << -1 << " ";
// else cout << dp[i][j] << " ";
// }
// cout << endl;
// }
rep(i,A+1){
// if(dp[A+B][i] == INF)cout << -1 << " ";
// else cout << dp[A+B][i] << " ";
if((A+B)%2)ans = max(ans,dp[A+B][i]);
else ans = min(ans,dp[A+B][i]);
}
// cout << endl;
cout << ans << endl;
}
Submission Info
Submission Time |
|
Task |
B - ゲーム |
User |
jimmy |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2337 Byte |
Status |
WA |
Exec Time |
11 ms |
Memory |
15872 KB |
Judge Result
Set Name |
All |
Score / Max Score |
0 / 3 |
Status |
|
Set Name |
Test Cases |
All |
00, 01, 02, 90, 91 |
Case Name |
Status |
Exec Time |
Memory |
00 |
WA |
1 ms |
384 KB |
01 |
WA |
9 ms |
14592 KB |
02 |
WA |
11 ms |
15872 KB |
90 |
AC |
1 ms |
256 KB |
91 |
AC |
1 ms |
384 KB |