結果

問題 No.506 限られたジャパリまん
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-21 22:45:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,287 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 169,700 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:50:59
合計ジャッジ時間 2,854 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



int mod = 1000000007;
int H, W, K, P;
int X[40], Y[40]; string N[40];
//-----------------------------------------------------------------------------------
int B[40][40], cnt[40][40];
int count() {
    rep(i, 0, 40) rep(j, 0, 40) cnt[i][j] = 0;

    cnt[0][0] = 1;
    rep(y, 0, H + 1) rep(x, 0, W + 1) if(!B[y][x]){
        if (0 < x) cnt[y][x] = (cnt[y][x] + cnt[y][x - 1]) % mod;
        if (0 < y) cnt[y][x] = (cnt[y][x] + cnt[y - 1][x]) % mod;
    }

    return cnt[H][W];
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> H >> W >> K >> P;
    rep(i, 0, K) cin >> X[i] >> Y[i] >> N[i];

    int ma = 0, ma_f = 0;
    rep(flag, 0, 1 << K) {
        vector<int> friends;
        rep(i, 0, K) if (flag & (1 << i)) friends.push_back(i);
        if (friends.size() != P) continue;

        rep(y, 0, H + 1) rep(x, 0, W + 1) B[y][x] = 0;
        rep(i, 0, K) B[Y[i]][X[i]] = 1;
        for (int i : friends) B[Y[i]][X[i]] = 0;
        int c = count();
        if (ma < c) {
            ma = c;
            ma_f = flag;
        }
    }

    cout << ma << endl;
    rep(i, 0, K) {
        if (ma_f & (1 << i)) cout << N[i] << endl;
    }
}
0