結果

問題 No.506 限られたジャパリまん
ユーザー t98slidert98slider
提出日時 2023-09-03 20:00:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,201 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 175,144 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:58:58
合計ジャッジ時間 2,818 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k, p, ans = 0;
    cin >> h >> w >> k >> p;
    vector<string> name(k);
    vector<vector<int>> S(h + 1, vector<int>(w + 1));
    ll mx = 0;
    for(int i = 0; i < k; i++){
        int y, x;
        cin >> y >> x >> name[i];
        S[y][x] = 1 << i;
    }
    if(p){
        for(int comb = (1 << p) - 1; comb < (1 << k); ){
            vector<vector<ll>> dp(h + 1, vector<ll>(w + 1));
            dp[0][0] = 1;
            for(int y = 0; y <= h; y++){
                for(int x = 0; x <= w; x++){
                    if((S[y][x] & comb) != S[y][x]) continue;
                    if(y + 1 <= h) dp[y + 1][x] += dp[y][x];
                    if(x + 1 <= w) dp[y][x + 1] += dp[y][x];
                }
            }
            if(dp[h][w] > mx){
                mx = dp[h][w];
                ans = comb;
            }
            int x = comb & (-comb), y = comb + x;
            comb = ((comb & ~y) / x >> 1) | y;
        }
    }
    cout << mx % 1000000007 << '\n';
    for(int i = 0; i < k; i++){
        if(ans >> i & 1) cout << name[i] << '\n';
    }
}
0