結果

問題 No.506 限られたジャパリまん
ユーザー PachicobuePachicobue
提出日時 2017-08-03 07:32:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,063 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 177,784 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-10 12:55:13
合計ジャッジ時間 4,975 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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, 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;
}
0