結果

問題 No.506 限られたジャパリまん
ユーザー Konton7Konton7
提出日時 2020-02-06 16:57:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,901 bytes
コンパイル時間 2,430 ms
コンパイル使用メモリ 204,404 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 12:56:13
合計ジャッジ時間 3,594 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 20 ms
4,376 KB
testcase_05 AC 20 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 10 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 14 ms
4,380 KB
testcase_12 AC 8 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 10 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 10 ms
4,380 KB
testcase_20 AC 15 ms
4,380 KB
testcase_21 AC 11 ms
4,380 KB
testcase_22 AC 28 ms
4,376 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 9 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)


const int mod = 1e9 + 7;
int h, w, k, p, k2;
vector<vector<int>> field, friendsxy;

ll bfs(int x)
{
    ll ret = 0;
    int c, y, bits[k];
    ll dp[h + 1][w + 1];
    rep(i, h + 1)
        rep(j, w + 1)
            dp[i][j] = 1;
    y = x;
    c = k;
    rep(i, k)
    {
        if (y % 2 == 1)
        {
            c--;
            dp[friendsxy[i][0]][friendsxy[i][1]] = 0;
        }
        y /= 2;
    }

    if (c == p)
    {
        rep(i, h)
            dp[i + 1][0] = dp[i + 1][0] * dp[i][0];
        rep(i, w)
            dp[0][i + 1] = dp[0][i + 1] * dp[0][i];

        rep(i, h)
            rep(j, w)
                dp[i + 1][j + 1] = dp[i + 1][j + 1] * (dp[i][j + 1] + dp[i + 1][j]);
        ret = dp[h][w];
    }
    return ret;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int y, x;
    PLL ans;
    ll d;
    string name;
    cin >> w >> h >> k >> p;
    field.resize(h + 1);
    string friends[k];
    friendsxy.resize(k);
    ans.first = 0, ans.second = 0;
    k2 = pow(2, k);

    rep(i, k)
    {
        cin >> x >> y >> name;
        friends[i] = name;
        friendsxy[i].push_back(y), friendsxy[i].push_back(x);
    }

    rep(i, k2)
    {
        d =  bfs(i);
        if (ans.first < d)
        {
            ans.first = d;
            ans.second = i;
        }
    }
    cout << ans.first % mod << endl;
    if (ans.first != 0){
        d = ans.second;
        rep(i, k)
        {
            if (d % 2 == 0)
                cout << friends[i] << endl;
            d /= 2;

        }
    }
    

    return 0;
}
0