結果

問題 No.506 限られたジャパリまん
ユーザー PachicobuePachicobue
提出日時 2017-08-03 07:48:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 2,394 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 178,484 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 12:55:20
合計ジャッジ時間 4,598 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 271 ms
4,380 KB
testcase_05 AC 270 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 69 ms
4,376 KB
testcase_09 AC 33 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 137 ms
4,380 KB
testcase_12 AC 83 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 46 ms
4,376 KB
testcase_17 AC 21 ms
4,380 KB
testcase_18 AC 94 ms
4,376 KB
testcase_19 AC 83 ms
4,376 KB
testcase_20 AC 136 ms
4,376 KB
testcase_21 AC 132 ms
4,376 KB
testcase_22 AC 255 ms
4,376 KB
testcase_23 AC 66 ms
4,380 KB
testcase_24 AC 74 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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, 0));
        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 = 0; x <= H; x++) {
            if (ok[x][0]) {
                dp[x][0] = 1;
            } else {
                break;
            }
        }
        for (int y = 0; y <= W; y++) {
            if (ok[0][y]) {
                dp[0][y] = 1;
            } else {
                break;
            }
        }

        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]);
                }
            }
        }
        if (maxi < dp[H][W]) {
            maxi = dp[H][W];
            maxf = i;
        }
    }
    cout << maxi % MOD << endl;
    if (maxi > 0) {
        for (int i = 0; i < K; i++) {
            if (maxf % 2 == 0) {
                cout << f[i].name << endl;
            }
            maxf /= 2;
        }
    }


    return 0;
}
0