結果
| 問題 |
No.506 限られたジャパリまん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-26 14:03:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,523 bytes |
| コンパイル時間 | 2,016 ms |
| コンパイル使用メモリ | 185,008 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-28 04:23:37 |
| 合計ジャッジ時間 | 2,950 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 12 |
ソースコード
#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]%MOD;
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;
}