結果

問題 No.506 限られたジャパリまん
ユーザー rickythetarickytheta
提出日時 2017-04-21 22:42:26
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,072 bytes
コンパイル時間 1,266 ms
コンパイル使用メモリ 150,788 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-10 12:50:53
合計ジャッジ時間 6,580 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 128 ms
4,380 KB
testcase_09 AC 36 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 98 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,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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) %= MOD;
      }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];
  }
  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(val>mx){
      mx = val;
      mxmask = mask;
    }
  }
  cout<<mx<<endl;
  REP(i,k)if((mxmask>>i)&1){
    cout<<name[i]<<endl;
  }
  return 0;
}
0