結果

問題 No.506 限られたジャパリまん
ユーザー tossytossy
提出日時 2017-04-21 23:05:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,305 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 167,752 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:51:45
合計ジャッジ時間 3,040 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,376 KB
testcase_04 AC 76 ms
4,380 KB
testcase_05 AC 75 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 34 ms
4,376 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 12 ms
4,376 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 20 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 38 ms
4,380 KB
testcase_21 AC 37 ms
4,376 KB
testcase_22 AC 70 ms
4,380 KB
testcase_23 AC 18 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600123456
#define MOD 1000000007

long dp[35][35];
int fld[35][35];

int main(){
  int h,w,k,p;
  cin>>h>>w>>k>>p;
  fill(fld[0],fld[35],-1);
  vector<string> name(k);
  rep(i,k){
    int x,y;
    cin>>x>>y;
    fld[x][y] = i;
    cin>>name[i];
  }

  long mx = -1;
  long mmask = -1;
  rep(mask,1<<k) if(__builtin_popcount(mask)<=p){
    fill(dp[0], dp[35],0);
    dp[0][0]=1;
    rep(i,h+1)rep(j,w+1)if(fld[i][j]==-1 || (mask&(1<<fld[i][j])) ){
      dp[i+1][j] += dp[i][j];
      dp[i][j+1] += dp[i][j];
    }
    if(dp[h][w]>mx){
      mx = dp[h][w];
      mmask = mask;
    }
  }

  cout << mx%MOD << endl;
  rep(i,k) if(mmask&(1<<i)) cout <<name[i] << endl;


  return 0;
}
0