AtCoder Beginner Contest 008

Submission #1588889

Source codeソースコード

#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) for(ll i=1;i<=(n);i++)
#define MOD 1000000007
#define int long long
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1e9;

int W, H;
int N;
int X[35], Y[35];

map<tuple<int, int, int, int>, int> dp;

int rec(int x1, int y1, int x2, int y2)
{
    if (dp.find(make_tuple(x1, y1, x2, y2)) != dp.end()) return dp[make_tuple(x1, y1, x2, y2)];

    int res = 0;
    REP(i,N) {
        if (x1 <= X[i] && X[i] <= x2 && y1 <= Y[i] && Y[i] <= y2) {
            res = max(res, (x2-x1+y2-y1+1) + rec(x1,y1,X[i]-1,Y[i]-1) + rec(X[i]+1,y1,x2,Y[i]-1) + rec(x1,Y[i]+1,X[i]-1,y2) + rec(X[i]+1,Y[i]+1,x2,y2));
        }
    }
    return dp[make_tuple(x1, y1, x2, y2)] = res;
}

signed main()
{
    cin >> W >> H;
    cin >> N;
    REP(i,N) {
        cin >> X[i] >> Y[i];
    }

    cout << rec(1, 1, W, H) << endl;
}

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt
Subtask1 80 / 80 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask1_21.txt,subtask1_22.txt,subtask1_23.txt,subtask1_24.txt,subtask1_25.txt
Subtask2 19 / 19 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask1_21.txt,subtask1_22.txt,subtask1_23.txt,subtask1_24.txt,subtask1_25.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt,subtask2_13.txt,subtask2_14.txt,subtask2_15.txt,subtask2_16.txt,subtask2_17.txt,subtask2_18.txt,subtask2_19.txt,subtask2_20.txt,subtask2_21.txt,subtask2_22.txt,subtask2_23.txt,subtask2_24.txt,subtask2_25.txt
Subtask3 1 / 1 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask1_21.txt,subtask1_22.txt,subtask1_23.txt,subtask1_24.txt,subtask1_25.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt,subtask2_13.txt,subtask2_14.txt,subtask2_15.txt,subtask2_16.txt,subtask2_17.txt,subtask2_18.txt,subtask2_19.txt,subtask2_20.txt,subtask2_21.txt,subtask2_22.txt,subtask2_23.txt,subtask2_24.txt,subtask2_25.txt,subtask3_01.txt,subtask3_02.txt,subtask3_03.txt,subtask3_04.txt,subtask3_05.txt,subtask3_06.txt,subtask3_07.txt,subtask3_08.txt,subtask3_09.txt,subtask3_10.txt,subtask3_11.txt,subtask3_12.txt,subtask3_13.txt,subtask3_14.txt,subtask3_15.txt,subtask3_16.txt,subtask3_17.txt,subtask3_18.txt,subtask3_19.txt,subtask3_20.txt,subtask3_21.txt,subtask3_22.txt,subtask3_23.txt,subtask3_24.txt,subtask3_25.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 1 ms 256 KB
subtask1_03.txt AC 1 ms 256 KB
subtask1_04.txt AC 1 ms 256 KB
subtask1_05.txt AC 1 ms 256 KB
subtask1_06.txt AC 1 ms 256 KB
subtask1_07.txt AC 1 ms 256 KB
subtask1_08.txt AC 1 ms 256 KB
subtask1_09.txt AC 1 ms 256 KB
subtask1_10.txt AC 1 ms 256 KB
subtask1_11.txt AC 1 ms 256 KB
subtask1_12.txt AC 1 ms 256 KB
subtask1_13.txt AC 1 ms 256 KB
subtask1_14.txt AC 1 ms 256 KB
subtask1_15.txt AC 1 ms 256 KB
subtask1_16.txt AC 1 ms 256 KB
subtask1_17.txt AC 1 ms 256 KB
subtask1_18.txt AC 1 ms 256 KB
subtask1_19.txt AC 1 ms 256 KB
subtask1_20.txt AC 1 ms 256 KB
subtask1_21.txt AC 1 ms 256 KB
subtask1_22.txt AC 1 ms 256 KB
subtask1_23.txt AC 1 ms 256 KB
subtask1_24.txt AC 1 ms 256 KB
subtask1_25.txt AC 1 ms 256 KB
subtask2_01.txt AC 3 ms 384 KB
subtask2_02.txt AC 3 ms 384 KB
subtask2_03.txt AC 5 ms 512 KB
subtask2_04.txt AC 5 ms 512 KB
subtask2_05.txt AC 8 ms 640 KB
subtask2_06.txt AC 11 ms 768 KB
subtask2_07.txt AC 11 ms 768 KB
subtask2_08.txt AC 11 ms 768 KB
subtask2_09.txt AC 21 ms 1024 KB
subtask2_10.txt AC 20 ms 1024 KB
subtask2_11.txt AC 20 ms 1024 KB
subtask2_12.txt AC 21 ms 1024 KB
subtask2_13.txt AC 11 ms 768 KB
subtask2_14.txt AC 10 ms 768 KB
subtask2_15.txt AC 2 ms 256 KB
subtask2_16.txt AC 11 ms 768 KB
subtask2_17.txt AC 21 ms 1024 KB
subtask2_18.txt AC 22 ms 1024 KB
subtask2_19.txt AC 21 ms 1024 KB
subtask2_20.txt AC 20 ms 1024 KB
subtask2_21.txt AC 21 ms 1024 KB
subtask2_22.txt AC 20 ms 1024 KB
subtask2_23.txt AC 21 ms 1024 KB
subtask2_24.txt AC 21 ms 1024 KB
subtask2_25.txt AC 22 ms 1024 KB
subtask3_01.txt AC 1 ms 256 KB
subtask3_02.txt AC 3 ms 384 KB
subtask3_03.txt AC 3 ms 384 KB
subtask3_04.txt AC 4 ms 384 KB
subtask3_05.txt AC 7 ms 640 KB
subtask3_06.txt AC 5 ms 512 KB
subtask3_07.txt AC 5 ms 512 KB
subtask3_08.txt AC 11 ms 768 KB
subtask3_09.txt AC 11 ms 768 KB
subtask3_10.txt AC 22 ms 1024 KB
subtask3_11.txt AC 19 ms 1024 KB
subtask3_12.txt AC 22 ms 1024 KB
subtask3_13.txt AC 21 ms 1024 KB
subtask3_14.txt AC 21 ms 1024 KB
subtask3_15.txt AC 20 ms 1024 KB
subtask3_16.txt AC 20 ms 1024 KB
subtask3_17.txt AC 21 ms 1024 KB
subtask3_18.txt AC 8 ms 640 KB
subtask3_19.txt AC 20 ms 1024 KB
subtask3_20.txt AC 10 ms 768 KB
subtask3_21.txt AC 22 ms 1024 KB
subtask3_22.txt AC 21 ms 1024 KB
subtask3_23.txt AC 20 ms 1024 KB
subtask3_24.txt AC 21 ms 1024 KB
subtask3_25.txt AC 19 ms 1024 KB