結果

問題 No.506 限られたジャパリまん
ユーザー どららどらら
提出日時 2017-04-21 22:55:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,240 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 175,252 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:51:24
合計ジャッジ時間 4,717 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007

int H, W, K, P;
int x[20];
int y[20];
string name[20];


int main(){
  cin >> H >> W >> K >> P;
  rep(i,K){
    cin >> x[i] >> y[i] >> name[i];
  }

  ll mx = 0;
  ll mx_S = 0;
  for(ll S=0; S<(1<<K); S++){
    int cnt = 0;
    vector<vector<int>> f(H+1, vector<int>(W+1, 0));
    vector<vector<ll>> dp(H+1, vector<ll>(W+1, 0));
    rep(i,K){
      if((S>>i)&1){
        cnt++;
      }else{
        f[x[i]][y[i]] = -1;
      }
    }
    if(cnt>P) continue;
    dp[0][0] = 1;
    rep(i,H+1){
      rep(j,W+1){
        if(i==0 && j==0) continue;
        if(f[i][j] == -1) continue;
        if(i-1>=0) dp[i][j] += dp[i-1][j];
        dp[i][j] %= MOD;
        if(j-1>=0) dp[i][j] += dp[i][j-1];
        dp[i][j] %= MOD;
      }
    }
    if(mx < dp[H][W]){
      mx = dp[H][W];
      mx_S = S;
    }
  }

  cout << mx << endl;
  rep(i,K){
    if((mx_S>>i)&1){
      cout << name[i] << endl;
    }
  }
  
  return 0;
}

0