結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 12 ms
4,380 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
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,0));
    rep(i,k) maze[friends[i].x][friends[i].y] = 1;
    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] = 0;
                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] = 1;
        }
        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 << endl;
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}
0