結果
| 問題 |
No.506 限られたジャパリまん
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2017-04-21 22:50:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 749 ms / 2,000 ms |
| コード長 | 2,164 bytes |
| コンパイル時間 | 1,990 ms |
| コンパイル使用メモリ | 166,224 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-28 04:10:23 |
| 合計ジャッジ時間 | 6,379 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:73:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
73 | scanf("%d%d%d%d",&h,&w,&k,&p);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;
int h,w,k,p;
pii pts[16];
string name[16];
int mp[35][35];
ll dp[35][35];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
ll check(){
if(mp[0][0] == -1)return 0;
queue<pii> Q;
Q.push(pii(0,0));
mp[0][0] = 0;
REP(i,h+1)REP(j,w+1)dp[i][j] = 0;
dp[0][0] = 1;
while(!Q.empty()){
pii P = Q.front(); Q.pop();
int i = P.first;
int j = P.second;
int d = mp[i][j];
ll yo = dp[i][j];
REP(a,4){
int ni = i+dy[a];
int nj = j+dx[a];
if(ni<0 || nj<0 || ni>h || nj>w)continue;
if(mp[ni][nj] == d+1){
dp[ni][nj] += yo;
}else if(mp[ni][nj] > d+1){
mp[ni][nj] = d+1;
dp[ni][nj] = yo;
Q.push(pii(ni,nj));
}
}
}
return dp[h][w];
}
int main(){
scanf("%d%d%d%d",&h,&w,&k,&p);
REP(i,k){
cin>>pts[i].first>>pts[i].second>>name[i];
}
int mindist = 252521;
ll mx = 0;
int mxmask = 0;
REP(mask,1<<k){
if(__builtin_popcount(mask)>p)continue;
REP(i,h+1)REP(j,w+1)mp[i][j] = 252521;
REP(i,k)if(!((mask>>i)&1)){
mp[pts[i].first][pts[i].second] = -1;
}
ll val = check();
if(mp[h][w] < mindist || (mp[h][w]==mindist && val>mx)){
mindist = mp[h][w];
mx = val;
mxmask = mask;
}
}
cout<<(mx%MOD)<<endl;
REP(i,k)if((mxmask>>i)&1){
cout<<name[i]<<endl;
}
return 0;
}
rickytheta