結果

問題 No.506 限られたジャパリまん
ユーザー beetbeet
提出日時 2017-04-21 23:12:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 923 ms / 2,000 ms
コード長 1,164 bytes
コンパイル時間 1,357 ms
コンパイル使用メモリ 158,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:52:13
合計ジャッジ時間 7,386 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
int MOD=1000000007LL;
int ans,bit;
int h,w,k,p;
int x[20],y[20];
string n[20];
int dp[40][40];
bool used[40][40];
typedef pair<int,int> P;
struct st{
  int y,x;
  st(){}
  st(int y,int x):y(y),x(x){}
};
signed main(){
  cin>>h>>w>>k>>p;
  for(int i=0;i<k;i++) cin>>x[i]>>y[i]>>n[i];
  map<P,int> m;
  for(int i=0;i<k;i++) m[P(y[i],x[i])]=i;
  int ax[2]={1,0};
  int ay[2]={0,1};
  ans=0;bit=0;
  for(int b=0;b<(1<<k);b++){
    if(__builtin_popcount(b)>p) continue;
    memset(dp,0,sizeof(dp));
    memset(used,0,sizeof(used));
    queue<st> q;
    dp[0][0]=1;
    used[0][0]=1;
    q.push(st(0,0));
    while(!q.empty()){
      st s=q.front();q.pop();
      int cy=s.y,cx=s.x;
      for(int l=0;l<2;l++){
	int ny=cy+ay[l],nx=cx+ax[l];
	if(ny<0||ny>w||nx<0||nx>h) continue;
	if(m.count(P(ny,nx))&&((b>>m[P(ny,nx)])&1)==0) continue; 
	dp[ny][nx]+=dp[cy][cx];
	if(!used[ny][nx]){
	  used[ny][nx]=1;
	  q.push(st(ny,nx));
	}
      }
    }
    if(ans<dp[w][h]){
      ans=dp[w][h];
      bit=b;
    }
  }
  cout<<ans%MOD<<endl;
  for(int i=0;i<k;i++)
    if((bit>>i)&1) cout<<n[i]<<endl;
  return 0;
}
0