結果
| 問題 |
No.2136 Dice Calendar?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-07 12:57:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,653 bytes |
| コンパイル時間 | 3,372 ms |
| コンパイル使用メモリ | 160,448 KB |
| 最終ジャッジ日時 | 2025-02-16 19:14:28 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 TLE * 7 |
ソースコード
#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;
}