Submission #5890142
Source Code Expand
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1e9+7)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " " ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;
int main(void)
{
int A,B;
cin >> A >> B;
vector<int> a(A), b(B);
REP(i, A){
cin >> a[i];
}
REP(i, B){
cin >> b[i];
}
vector<vector<int>> dp(A+1, vector<int>(B+1, -1));
dp[A][B]=0;
RREP(i, A+1){
RREP(j, B+1){
if(i==0 && j == 0) continue;
if((i+j % 2)==0){//後手
if(i>0)
dp[i-1][j] = min(dp[i][j] + a[i], (dp[i-1][j]<0?1000:dp[i-1][j]));
else
dp[i][j-1] = min(dp[i][j] + b[j], dp[i][j-1]);
if(j>0)
dp[i][j-1] = min(dp[i][j] + b[j], (dp[i][j-1]<0?1000:dp[i][j-1]));
else
dp[i-1][j] = min(dp[i][j] + a[j], dp[i-1][j]);
}else{
if(i>0)
dp[i-1][j] = max(dp[i][j] + a[i], (dp[i-1][j]<0?0:dp[i-1][j]));
else
dp[i][j-1] = max(dp[i][j] + b[j], dp[i][j-1]);
if(j>0)
dp[i][j-1] = max(dp[i][j] + b[j], (dp[i][j-1]<0?0:dp[i][j-1]));
else
dp[i-1][j] = max(dp[i][j] + a[j], dp[i-1][j]);
}
}
}
// REP(i, A+1){
// REP(j, B+1){
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
pr(dp[0][0]);
}
Submission Info
Submission Time |
|
Task |
B - ゲーム |
User |
Shun2019 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2535 Byte |
Status |
WA |
Exec Time |
8 ms |
Memory |
4224 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 |
256 KB |
01 |
WA |
6 ms |
2944 KB |
02 |
WA |
8 ms |
4224 KB |
90 |
AC |
1 ms |
256 KB |
91 |
WA |
1 ms |
256 KB |