結果

問題 No.506 限られたジャパリまん
ユーザー imulanimulan
提出日時 2017-04-22 12:09:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,322 bytes
コンパイル時間 1,636 ms
コンパイル使用メモリ 174,800 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:53:25
合計ジャッジ時間 2,659 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

ll mod=1e9+7;
ll dp[33][33];
int ban[33][33];

int main()
{
    int H,W,K,P;
    cin >>H >>W >>K >>P;

    vector<int> x(K),y(K);
    vector<string> N(K);
    rep(i,K) cin >>x[i] >>y[i] >>N[i];

    ll ans=0;
    set<string> s;
    rep(mask,1<<K)
    {
        if(__builtin_popcount(mask) != P) continue;

        fill(ban[0],ban[33],0);
        rep(i,K)
        {
            if(!(mask>>i&1)) ban[x[i]][y[i]]=1;

        }

        fill(dp[0],dp[33],0);
        if(!ban[0][0]) dp[0][0]=1;
        for(int i=1; i<=H; ++i)if(!ban[i][0]) dp[i][0] = dp[i-1][0];
        for(int i=1; i<=W; ++i)if(!ban[0][i]) dp[0][i] = dp[0][i-1];

        for(int i=1; i<=H; ++i)for(int j=1; j<=W; ++j)
        {
            if(!ban[i][j]) dp[i][j] = dp[i-1][j]+dp[i][j-1];
        }

        if(dp[H][W]>ans)
        {
            ans = dp[H][W];
            s.clear();
            rep(i,K)if(mask>>i&1) s.insert(N[i]);
        }
    }

    // output
    cout << ans%mod << endl;
    for(const auto &name:s) cout << name << endl;
    return 0;
}
0