結果
問題 | No.2983 Christmas Color Grid (Advent Calender ver.) |
ユーザー | KumaTachiRen |
提出日時 | 2024-12-08 01:03:18 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,372 bytes |
コンパイル時間 | 6,555 ms |
コンパイル使用メモリ | 316,020 KB |
実行使用メモリ | 18,688 KB |
最終ジャッジ日時 | 2024-12-08 01:04:46 |
合計ジャッジ時間 | 85,065 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,632 KB |
testcase_01 | AC | 2 ms
10,496 KB |
testcase_02 | TLE | - |
testcase_03 | AC | 344 ms
10,368 KB |
testcase_04 | AC | 6 ms
10,496 KB |
testcase_05 | AC | 52 ms
12,544 KB |
testcase_06 | TLE | - |
testcase_07 | AC | 2 ms
16,640 KB |
testcase_08 | AC | 2 ms
10,496 KB |
testcase_09 | TLE | - |
testcase_10 | AC | 208 ms
10,496 KB |
testcase_11 | AC | 2,205 ms
10,496 KB |
testcase_12 | AC | 5 ms
10,496 KB |
testcase_13 | AC | 323 ms
12,672 KB |
testcase_14 | AC | 885 ms
10,496 KB |
testcase_15 | AC | 2,190 ms
5,248 KB |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | AC | 202 ms
5,248 KB |
testcase_20 | AC | 874 ms
5,248 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 438 ms
5,248 KB |
testcase_23 | TLE | - |
testcase_24 | AC | 214 ms
5,248 KB |
testcase_25 | TLE | - |
testcase_26 | AC | 209 ms
5,248 KB |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | AC | 420 ms
5,248 KB |
testcase_30 | TLE | - |
testcase_31 | AC | 195 ms
5,248 KB |
testcase_32 | AC | 828 ms
5,248 KB |
testcase_33 | TLE | - |
testcase_34 | AC | 337 ms
5,248 KB |
testcase_35 | AC | 879 ms
5,248 KB |
testcase_36 | AC | 2,210 ms
5,248 KB |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
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 | 2 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 | 3 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 | 3 ms
5,248 KB |
testcase_54 | AC | 2 ms
5,248 KB |
testcase_55 | AC | 2 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 | 3 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
16,640 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using vm = vector<mint>; using vvm = vector<vm>; inline ostream &operator<<(ostream &os, const mint x) { return os << x.val(); }; inline istream &operator>>(istream &is, mint &x) { long long v; is >> v; x = v; return is; }; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define all(a) (a).begin(), (a).end() #define contains(a, x) ((a).find(x) != (a).end()) #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (a); i--) #define YN(b) cout << ((b) ? "YES" : "NO") << "\n"; #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define yn(b) cout << ((b) ? "yes" : "no") << "\n"; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using ll = long long; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { for (int i = 0; i < (int)vec.size(); i++) { os << vec[i] << (i + 1 == (int)vec.size() ? "" : " "); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < (int)vec.size(); i++) is >> vec[i]; return is; } ll floor(ll a, ll b) { return a >= 0 ? a / b : (a + 1) / b - 1; } ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; } struct dsu_ { public: dsu_() : _n(0) {} explicit dsu_(int n) : _n(n), parent_or_size(n, -1) { flg = vi(n); rep(i, 0, n) flg[i] = 1 << i; } void clear() { fill(all(parent_or_size), -1); rep(i, 0, flg.size()) flg[i] = 1 << i; } 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); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; flg[x] |= flg[y]; return x; } 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)]; } int f(int a) { assert(0 <= a && a < _n); return flg[leader(a)]; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; vi flg; }; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; void solve() { int h, w, m; ll k; cin >> h >> w >> k >> m; using mint = dynamic_modint<0>; mint::set_mod(m); vector<bool> ok(1 << (h * w), false), skip(1 << (h * w), false); dsu_ uf(h * w); rrep(bit, 1, 1 << (h * w)) { if (skip[bit]) continue; uf.clear(); for (int i = 0; i < h; i++) for (int j = 0; j + 1 < w; j++) if (((bit >> (w * i + j)) & 1) & ((bit >> (w * i + j + 1)) & 1)) uf.merge(w * i + j, w * i + j + 1); for (int i = 0; i + 1 < h; i++) for (int j = 0; j < w; j++) if (((bit >> (w * i + j)) & 1) & ((bit >> (w * i + j + w)) & 1)) uf.merge(w * i + j, w * i + j + w); vi fs; for (int i = 0; i < h * w; i++) if (((bit >> i) & 1) == 1 && uf.leader(i) == i) { int f = uf.f(i); fs.push_back(f); ok[f] = true; } rep(i, 1, 1 << int(fs.size())) { int v = 0; rep(j, 0, fs.size()) if ((i >> j) & 1) v |= fs[j]; skip[v] = true; } } vector<mint> cnt(h * w + 1, 0); rep(bit, 0, 1 << (h * w)) { if (!ok[bit]) continue; int pc = __builtin_popcount(bit); int c = 0; for (int x = 0; x < h; x++) for (int y = 0; y < w; y++) { if ((bit >> (w * x + y)) & 1) continue; bool f = false; for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue; f |= (bit >> (w * nx + ny)) & 1; } if (f) c++; } cnt[pc] += 1 << (h * w - pc - c); } mint ans = 0; rep(i, 0, h * w + 1) ans += mint(i).pow(k) * cnt[i]; mint p = 0; rep(i, 1, h * w + 1) p += mint(i).inv(); ans *= p; ans *= mint(2).inv().pow(h * w); cout << ans.val() << "\n"; } int main() { int t = 1; // cin >> t; while (t--) solve(); }