結果
| 問題 |
No.506 限られたジャパリまん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-03 07:32:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,063 bytes |
| コンパイル時間 | 1,843 ms |
| コンパイル使用メモリ | 179,488 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-28 04:19:54 |
| 合計ジャッジ時間 | 5,091 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 19 |
ソースコード
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
os << "sz=" << v.size() << "\n[";
for (const auto& p : v) {
os << p << ",";
}
os << "]\n";
return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
os << "(" << p.first << "," << p.second
<< ")";
return os;
}
constexpr ll MOD = 1e9 + 7;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;
struct Friend {
int x;
int y;
string name;
};
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int H, W, K, P;
cin >> H >> W >> K >> P;
vector<Friend> f(K);
for (ll i = 0; i < K; i++) {
cin >> f[i].x >> f[i].y >> f[i].name;
}
const int maximum = 1LL << K;
ll maxi = 0;
ll maxf = -1;
for (ll i = 0; i < maximum; i++) {
vector<vector<bool>> ok(H + 1, vector<bool>(W + 1, true));
vector<vector<ll>> dp(H + 1, vector<ll>(W + 1, 1));
ll num = i;
int cnt = 0;
for (int j = 0; j < K; j++) {
if (num % 2 == 1) {
ok[f[j].x][f[j].y] = false;
dp[f[j].x][f[j].y] = 0;
} else {
cnt++;
}
num /= 2;
}
if (cnt > P) {
continue;
}
for (int x = 1; x <= H; x++) {
for (int y = 1; y <= W; y++) {
if (ok[x][y]) {
dp[x][y] = (dp[x - 1][y] + dp[x][y - 1]) % MOD;
}
}
}
if (maxi < dp[H][W]) {
maxi = dp[H][W];
maxf = i;
}
}
cout << maxi << endl;
if (maxi > 0) {
for (int i = 0; i < K; i++) {
if (maxf % 2 == 0) {
cout << f[i].name << endl;
}
maxf /= 2;
}
}
return 0;
}