結果

問題 No.506 限られたジャパリまん
ユーザー kappybarkappybar
提出日時 2020-04-26 15:16:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,537 bytes
コンパイル時間 2,120 ms
コンパイル使用メモリ 183,320 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:56:26
合計ジャッジ時間 3,172 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const  int MOD = 1000000007;

struct animal{
    int x,y;
    string name;
};

int main(){
    int h,w,k,p;
    cin >> h >> w >> k >> p;
    vector<animal> friends(k);
    rep(i,k) cin >> friends[i].x >> friends[i].y >> friends[i].name;
    vector<vector<bool>> maze(h+1,vector<bool>(w+1,false));
    rep(i,k) maze[friends[i].x][friends[i].y] = true;
    vector<string> ans;
    ll mx = 0;
    rep(bit,1<<k){
        int s = __builtin_popcount(bit);
        vector<int> res;
        if(s != p) continue;
        rep(i,k){
            if(bit>>i &1){
                maze[friends[i].x][friends[i].y] = false;
                res.push_back(i);
            }
        }
        vector<vector<ll>> dp(h+1,vector<ll>(w+1,0));
        dp[0][0] = 1;
        rep(i,h+1)rep(j,w+1){
            if(maze[i][j]){
                dp[i][j] = 0;
                continue;
            }
            if(i>0) dp[i][j] += dp[i-1][j];
            if(j>0) dp[i][j] += dp[i][j-1];
        }
        for(int i:res){
            maze[friends[i].x][friends[i].y] = true;
        }
        if(dp[h][w] > mx){
            mx = dp[h][w];
            vector<string> empty;
            swap(empty,ans);
            for(int i:res){
                ans.push_back(friends[i].name);
            }
        }
    }

    cout << mx%MOD << endl;
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}
0