結果
問題 | No.2983 Christmas Color Grid (Advent Calender ver.) |
ユーザー | t98slider |
提出日時 | 2024-12-08 02:00:44 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,162 bytes |
コンパイル時間 | 4,625 ms |
コンパイル使用メモリ | 269,840 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-08 02:00:58 |
合計ジャッジ時間 | 14,290 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 162 ms
5,248 KB |
testcase_04 | AC | 6 ms
5,248 KB |
testcase_05 | AC | 39 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 3 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | WA | - |
testcase_10 | AC | 257 ms
5,248 KB |
testcase_11 | AC | 687 ms
5,248 KB |
testcase_12 | AC | 4 ms
5,248 KB |
testcase_13 | AC | 162 ms
5,248 KB |
testcase_14 | AC | 364 ms
5,248 KB |
testcase_15 | AC | 692 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 229 ms
5,248 KB |
testcase_20 | AC | 999 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 524 ms
5,248 KB |
testcase_23 | WA | - |
testcase_24 | AC | 245 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 244 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | AC | 500 ms
5,248 KB |
testcase_30 | WA | - |
testcase_31 | AC | 229 ms
5,248 KB |
testcase_32 | AC | 965 ms
5,248 KB |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | AC | 193 ms
5,248 KB |
testcase_35 | AC | 338 ms
5,248 KB |
testcase_36 | AC | 690 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | AC | 2 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
testcase_40 | AC | 2 ms
5,248 KB |
testcase_41 | AC | 2 ms
5,248 KB |
testcase_42 | AC | 2 ms
5,248 KB |
testcase_43 | AC | 2 ms
5,248 KB |
testcase_44 | AC | 1 ms
5,248 KB |
testcase_45 | AC | 2 ms
5,248 KB |
testcase_46 | AC | 2 ms
5,248 KB |
testcase_47 | AC | 2 ms
5,248 KB |
testcase_48 | AC | 2 ms
5,248 KB |
testcase_49 | AC | 2 ms
5,248 KB |
testcase_50 | AC | 2 ms
5,248 KB |
testcase_51 | AC | 2 ms
5,248 KB |
testcase_52 | AC | 2 ms
5,248 KB |
testcase_53 | AC | 2 ms
5,248 KB |
testcase_54 | AC | 3 ms
5,248 KB |
testcase_55 | AC | 3 ms
5,248 KB |
testcase_56 | AC | 2 ms
5,248 KB |
testcase_57 | AC | 2 ms
5,248 KB |
testcase_58 | AC | 2 ms
5,248 KB |
testcase_59 | AC | 2 ms
5,248 KB |
testcase_60 | AC | 2 ms
5,248 KB |
testcase_61 | AC | 2 ms
5,248 KB |
testcase_62 | AC | 2 ms
5,248 KB |
testcase_63 | AC | 2 ms
5,248 KB |
testcase_64 | AC | 2 ms
5,248 KB |
testcase_65 | AC | 2 ms
5,248 KB |
testcase_66 | AC | 2 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using ll = long long; using mint = atcoder::modint; struct dsu { public: int csz; dsu() : _n(0) {} dsu(int n) : _n(n), csz(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); csz--; parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; int main(){ vector<vector<vector<int>>> A(26, vector<vector<int>>(26)); A[1][25] = {0,113246208,54525952,26214400,12582912,6029312,2883584,1376256,655360,311296,147456,69632,32768,15360,7168,3328,1536,704,320,144,64,28,12,5,2,1}; A[5][5] = {0,51380224,17301504,11501568,7749632,5599232,4361216,3564416,3023760,2603088,2265120,1971974,1703398,1448460,1194986,939036,687581,454452,258314,119182,42437,11295,2192,296,25,1}; A[1][24] = {0,54525952,26214400,12582912,6029312,2883584,1376256,655360,311296,147456,69632,32768,15360,7168,3328,1536,704,320,144,64,28,12,5,2,1}; A[2][12] = {0,29360128,11534336,9437184,6455296,4308992,2992128,2021376,1374592,929088,625544,419408,279656,185376,122088,80112,52888,35200,22416,12160,4967,1388,244,24,1}; A[4][6] = {0,25165824,8519680,5668864,3856384,2863104,2288896,1868032,1553240,1299184,1090650,919360,774295,643000,517972,394544,274893,167464,83894,32492,9316,1920,272,24,1}; A[1][23] = {0,26214400,12582912,6029312,2883584,1376256,655360,311296,147456,69632,32768,15360,7168,3328,1536,704,320,144,64,28,12,5,2,1}; ios::sync_with_stdio(false); cin.tie(0); int h, w; ll k; int m; cin >> h >> w >> k >> m; if (h > w) swap(h, w); mint::set_mod(m); vector<mint> tb(26); mint div; const int r = h * w; for(int i = 1; i <= 25; i++) tb[i] = mint(i).pow(k); for(int i = 1; i <= h * w; i++) div += mint(1) / i; dsu uf(h * w); auto f = [&](int S){ auto &&tmp = uf.parent_or_size; fill(tmp.begin(), tmp.end(), -1); int T = S; while(T){ int b = T & -T; T -= b; b = __lg(b); int y = b / w, x = b - y * w; if(x + 1 < w && (T >> (b + 1) & 1)) uf.merge(b, b + 1); if(y + 1 < h && (T >> (b + w) & 1)) uf.merge(b, b + w); } mint res; while(S){ int b = S & -S; S -= b; b = __lg(b); if (uf.leader(b) == b) res += tb[uf.size(b)]; } return res; }; mint ans; if(h * w >= 23){ for(int i = 1; i < A[h][w].size(); i++){ ans += A[h][w][i] * tb[i]; } }else{ for(int S = 1; S < (1 << (h * w)); S++) ans += f(S); } ans *= div; ans /= 1 << h * w; cout << ans.val() << '\n'; }