結果

問題 No.506 限られたジャパリまん
ユーザー ミドリムシミドリムシ
提出日時 2018-04-21 16:59:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,903 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 87,556 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:55:35
合計ジャッジ時間 2,165 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 24 ms
4,380 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 20 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct friends{
    int y, x;
    string name;
};

int H, W, K, P;
vector<vector<bool>> space;

vector<vector<long>> dp;

long move(int now_y, int now_x){
    if(dp[now_y][now_x] != -1){
        return dp[now_y][now_x];
    }else if(now_y == H && now_x == W){
        return dp[now_y][now_x] = 1;
    }else if(now_y == H){
        return dp[now_y][now_x] = move(now_y, now_x + 1) * space[now_y][now_x + 1];
    }else if(now_x == W){
        return dp[now_y][now_x] = move(now_y + 1, now_x) * space[now_y + 1][now_x];
    }else{
        return dp[now_y][now_x] = move(now_y, now_x + 1) * space[now_y][now_x + 1] + move(now_y + 1, now_x) * space[now_y + 1][now_x];
    }
}

int main(){
    cin >> H >> W >> K >> P;
    space.resize(H + 1, vector<bool>(W + 1, true));
    friends friendss[K];
    for(int i = 0; i < K; i++){
        cin >> friendss[i].y >> friendss[i].x >> friendss[i].name;
    }
    long ans = -1;
    int ans_number = -1;
    dp.resize(H + 1, vector<long>(W + 1));
    for(int i = 0; i < (1 << K); i++){
        if(__builtin_popcount(i) == P){
            for(int j = 0; j < K; j++){
                if(~(i >> j) & 1){
                    space[friendss[j].y][friendss[j].x] = false;
                }
            }
            for(int j = 0; j <= H; j++){
                for(int k = 0; k <= W; k++){
                    dp[j][k] = -1;
                }
            }
            long this_ans = move(0, 0);
            if(this_ans > ans){
                ans = this_ans;
                ans_number = i;
            }
            for(int j = 0; j < K; j++){
                space[friendss[j].y][friendss[j].x] = true;
            }
        }
    }
    cout << ans << endl;
    for(int i = 0; i < K; i++){
        if((ans_number >> i) & 1){
            cout << friendss[i].name << endl;
        }
    }
}
0