結果

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

テストケース

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

ソースコード

diff #

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


typedef long long ll;
int mod = 1000000007;
int H, W, K, P;
int X[40], Y[40]; string N[40];
//-----------------------------------------------------------------------------------
int B[40][40];
ll cnt[40][40];
ll 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 - 1];
        if (0 < y) cnt[y][x] += cnt[y - 1][x];
    }

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

    ll 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[X[i]][Y[i]] = 1;
        for (int i : friends) B[X[i]][Y[i]] = 0;
        ll c = count();
        if (ma < c) {
            ma = c;
            ma_f = flag;
        }
    }

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