Typical DP Contest

Submission #5890418

Source codeソースコード

#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));
    dp[A][B]=0;
    RREP(i, A+1){
        RREP(j, B+1){
            if(i==A && j == B) continue;

            if(((i+j) % 2)==0){
                if(i==A){
                    dp[i][j]=dp[i][j+1] + b[j];
                }else if(j==B){
                    dp[i][j]=dp[i+1][j] + a[i];
                }else{
                    dp[i][j]=max(dp[i+1][j]+a[i], dp[i][j+1]+b[j]);
                }
            }else{
                if(i==A){
                    dp[i][j]=dp[i][j+1];
                }else if(j==B){
                    dp[i][j]=dp[i+1][j];
                }else{
                    dp[i][j]=min(dp[i+1][j], dp[i][j+1]);
                }
            }
        }
    }

    REP(i, A+1){
        REP(j, B+1){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    pr(dp[0][0]);
}

Submission

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

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 WA
01 WA
02 WA
90 WA
91 WA