結果
問題 | No.506 限られたジャパリまん |
ユーザー | ant2357 |
提出日時 | 2019-01-20 17:00:25 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 1,683 bytes |
コンパイル時間 | 1,907 ms |
コンパイル使用メモリ | 181,648 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-10 12:55:36 |
合計ジャッジ時間 | 3,070 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 8 ms
4,380 KB |
testcase_05 | AC | 8 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 25 ms
4,376 KB |
testcase_09 | AC | 18 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 23 ms
4,376 KB |
testcase_12 | AC | 12 ms
4,380 KB |
testcase_13 | AC | 2 ms
4,380 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 35 ms
4,376 KB |
testcase_17 | AC | 3 ms
4,376 KB |
testcase_18 | AC | 5 ms
4,376 KB |
testcase_19 | AC | 9 ms
4,376 KB |
testcase_20 | AC | 8 ms
4,376 KB |
testcase_21 | AC | 5 ms
4,376 KB |
testcase_22 | AC | 12 ms
4,376 KB |
testcase_23 | AC | 6 ms
4,376 KB |
testcase_24 | AC | 8 ms
4,376 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; const double PI = 3.1415926535897932384626433832795; const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { -1, 0, 1, 0 }; int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); } int lcm(int x, int y) { return x / gcd(x, y) * y; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } int h, w, k, p; vector<int> x, y; vector<string> name; ll f(int mask) { vector<int> friends; for (int i = 0; i < k; i++) { if (mask & (1 << i)) { friends.push_back(i); } } if (friends.size() != p) { return -1LL; } vector<vector<bool>> isMove(w + 1, vector<bool>(h + 1, true)); for (int i = 0; i < k; i++) { isMove[y[i]][x[i]] = false; } for (auto i : friends) { isMove[y[i]][x[i]] = true; } vector<vector<ll>> dp(w + 1, vector<ll>(h + 1)); dp[0][0] = 1LL; for (int i = 0; i <= w; i++) { for (int j = 0; j <= h; j++) { if (!isMove[i][j]) { continue; } dp[i][j] += 0 < i ? dp[i - 1][j] : 0; dp[i][j] += 0 < j ? dp[i][j - 1] : 0; } } return dp[w][h]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> h >> w >> k >> p; x.resize(k); y.resize(k); name.resize(k); for (int i = 0; i < k; i++) { cin >> x[i] >> y[i] >> name[i]; } ll ans = 0, ansMask = 0; for (int mask = 0; mask < (1 << k); mask++) { ll score = f(mask); if (score <= ans) { continue; } ans = score; ansMask = mask; } const ll MOD = 1e9 + 7; ans %= MOD; cout << ans << endl; for (int i = 0; i < k; i++) { if (ansMask & (1 << i)) { cout << name[i] << endl; } } return 0; }