結果

問題 No.506 限られたジャパリまん
ユーザー hiyokko2hiyokko2
提出日時 2017-08-03 19:20:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 150,136 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:55:18
合計ジャッジ時間 2,363 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 10 ms
4,376 KB
testcase_12 AC 8 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 4 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>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
const int INF = 1e9;

int H, W, K, P;
int x[20], y[20];
string N[20];
int dp[40][40];
bool can_move[40][40];  //通れないところはfalse

signed main()
{
    cin >> H >> W >> K >> P;
    REP(i,K) cin >> x[i] >> y[i] >> N[i];

    int ma = 0;
    vector<string> ans;
    for (int i=0; i<(1<<K); i++) {
        //ビットが立っているところは通れない
        if (__builtin_popcount(i) != K - P) continue;

        REP(j,40) REP(k,40) can_move[j][k] = true;
        REP(j,K) if (i >> j & 1) can_move[x[j]][y[j]] = false;

        for (int x=0; x<=H; x++) {
            for (int y=0; y<=W; y++) {
                dp[x][y] = (x == 0 && y == 0 ? 1 : 0);
                if (0 <= x - 1) dp[x][y] += dp[x-1][y];
                if (0 <= y - 1) dp[x][y] += dp[x][y-1];
                if (!can_move[x][y]) dp[x][y] = 0;
            }
        }

        if (ma < dp[H][W]) {
            ma = dp[H][W];
            ans.clear();
            REP(j,K) if (~i >> j & 1) ans.push_back(N[j]);
        }
    }

    cout << ma % MOD << endl;
    REP(i,ans.size()) cout << ans[i] << endl;
}
0