結果

問題 No.2136 Dice Calendar?
ユーザー wasd314wasd314
提出日時 2023-09-07 12:57:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,653 bytes
コンパイル時間 3,354 ms
コンパイル使用メモリ 152,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 12:58:20
合計ジャッジ時間 24,565 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 114 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 8 ms
4,380 KB
testcase_06 AC 8 ms
4,384 KB
testcase_07 AC 15 ms
4,380 KB
testcase_08 AC 37 ms
4,380 KB
testcase_09 AC 109 ms
4,380 KB
testcase_10 AC 148 ms
4,380 KB
testcase_11 AC 468 ms
4,384 KB
testcase_12 AC 602 ms
4,384 KB
testcase_13 AC 463 ms
4,380 KB
testcase_14 AC 991 ms
4,384 KB
testcase_15 AC 3,472 ms
4,384 KB
testcase_16 AC 4,498 ms
4,384 KB
testcase_17 AC 2,838 ms
4,380 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>

#include <atcoder/all>

int main()
{
    using namespace std;
    using namespace atcoder;
    int n;
    cin >> n;
    vector has(n, vector(10, 0));
    vector cmp(n, vector<int>());
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 6; j++) {
            int a;
            cin >> a;
            has[i][a] = 1;
        }
        for (int j = 0; j < 10; j++) {
            if (has[i][j]) {
                cmp[i].push_back(j);
            }
        }
        
    }
    using mint = modint998244353;
    // mf_graph<int> g(n + 11);
    // for (int i = 1; i < 10; i++) {
    //     g.add_edge(i, 0, 0);
    // }
    // for (int i = 1; i < n; i++) {
    //     g.add_edge(10, 11 + i, 1);
    //     for (int j = 1; j < 10; j++) {
    //         if (has[i][j]) {
    //             g.add_edge(11 + i, j, 1);
    //         }
    //     }
    // }
    vector<int> app(10);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; j++) {
            app[j] += has[i][j];
        }
    }

    int nn = 100;
    vector<mint> fact(nn, 1), invfact(nn, 1);
    for (int i = 0; i < nn - 1; ++i) {
        fact[i + 1] = fact[i] * (i + 1);
    }
    invfact[nn - 1] = fact[nn - 1].inv();
    for (int i = nn - 2; i >= 0; --i) {
        invfact[i] = invfact[i + 1] * (i + 1);
    }

    mint ans = 0;
    vector<int> count(10);
    
    // auto print_vec = [](vector<int> v) {
    //     int l = v.size();
    //     for (int i = 0; i < l; i++) {
    //         std::cout << v[i] << (i < l - 1 ? ' ' : '\n');
    //     }
    // };
    
    auto dfs = [&](auto f, int d, int rem, mint invs) -> void {
        if (d == 10) {
            if (rem) {
                return;
            }
            mf_graph<int> g(n + 11);
            for (int i = 1; i < 10; i++) {
                // g.add_edge(i, 0, 0);
                if (count[i]) {
                    g.add_edge(i, 0, count[i]);
                }
            }
            for (int i = 0; i < n; i++) {
                g.add_edge(10, 11 + i, 1);
                for (int j: cmp[i]) {
                    g.add_edge(11 + i, j, 1);
                }
            }
            int flow = g.flow(10, 0);
            // cout << "\t\t" << flow << endl;
            if (flow < n) {
                return;
            }
            ans += invs;
            return;
        }
        for (int u = 0; u <= rem && u <= app[d]; ++u) {
            // g.change_edge(d - 1, u, 0);
            count[d] = u;
            f(f, d + 1, rem - u, invs * invfact[u]);
        }
    };
    dfs(dfs, 1, n, fact[n]);
    std::cout << ans.val() << endl;
}
0