結果
問題 | No.506 限られたジャパリまん |
ユーザー |
|
提出日時 | 2023-09-03 20:00:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,201 bytes |
コンパイル時間 | 1,781 ms |
コンパイル使用メモリ | 177,488 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 04:29:47 |
合計ジャッジ時間 | 2,630 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 WA * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w, k, p, ans = 0; cin >> h >> w >> k >> p; vector<string> name(k); vector<vector<int>> S(h + 1, vector<int>(w + 1)); ll mx = 0; for(int i = 0; i < k; i++){ int y, x; cin >> y >> x >> name[i]; S[y][x] = 1 << i; } if(p){ for(int comb = (1 << p) - 1; comb < (1 << k); ){ vector<vector<ll>> dp(h + 1, vector<ll>(w + 1)); dp[0][0] = 1; for(int y = 0; y <= h; y++){ for(int x = 0; x <= w; x++){ if((S[y][x] & comb) != S[y][x]) continue; if(y + 1 <= h) dp[y + 1][x] += dp[y][x]; if(x + 1 <= w) dp[y][x + 1] += dp[y][x]; } } if(dp[h][w] > mx){ mx = dp[h][w]; ans = comb; } int x = comb & (-comb), y = comb + x; comb = ((comb & ~y) / x >> 1) | y; } } cout << mx % 1000000007 << '\n'; for(int i = 0; i < k; i++){ if(ans >> i & 1) cout << name[i] << '\n'; } }