結果
問題 | No.2983 Christmas Color Grid (Advent Calender ver.) |
ユーザー | KumaTachiRen |
提出日時 | 2024-12-08 02:48:20 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 7,012 bytes |
コンパイル時間 | 3,170 ms |
コンパイル使用メモリ | 260,904 KB |
実行使用メモリ | 153,552 KB |
最終ジャッジ日時 | 2024-12-08 02:49:09 |
合計ジャッジ時間 | 46,686 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | MLE | - |
testcase_01 | AC | 2 ms
13,640 KB |
testcase_02 | MLE | - |
testcase_03 | AC | 137 ms
7,680 KB |
testcase_04 | AC | 6 ms
5,248 KB |
testcase_05 | AC | 34 ms
5,248 KB |
testcase_06 | AC | 1,649 ms
74,752 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 1,575 ms
74,844 KB |
testcase_10 | AC | 74 ms
7,680 KB |
testcase_11 | AC | 656 ms
20,988 KB |
testcase_12 | AC | 4 ms
5,248 KB |
testcase_13 | AC | 143 ms
7,664 KB |
testcase_14 | AC | 296 ms
12,160 KB |
testcase_15 | AC | 660 ms
21,120 KB |
testcase_16 | AC | 1,348 ms
39,040 KB |
testcase_17 | AC | 2,998 ms
74,880 KB |
testcase_18 | TLE | - |
testcase_19 | AC | 74 ms
7,548 KB |
testcase_20 | AC | 340 ms
21,248 KB |
testcase_21 | AC | 1,520 ms
74,880 KB |
testcase_22 | AC | 156 ms
12,160 KB |
testcase_23 | AC | 1,553 ms
74,880 KB |
testcase_24 | AC | 82 ms
7,680 KB |
testcase_25 | AC | 1,570 ms
74,880 KB |
testcase_26 | AC | 77 ms
7,680 KB |
testcase_27 | TLE | - |
testcase_28 | AC | 1,579 ms
74,880 KB |
testcase_29 | AC | 159 ms
12,032 KB |
testcase_30 | AC | 1,536 ms
74,920 KB |
testcase_31 | AC | 72 ms
7,680 KB |
testcase_32 | AC | 352 ms
21,116 KB |
testcase_33 | AC | 1,542 ms
74,752 KB |
testcase_34 | AC | 145 ms
7,680 KB |
testcase_35 | AC | 306 ms
12,152 KB |
testcase_36 | AC | 628 ms
21,120 KB |
testcase_37 | AC | 1,313 ms
38,912 KB |
testcase_38 | AC | 2,861 ms
74,880 KB |
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 | 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 | 2 ms
5,248 KB |
testcase_55 | AC | 2 ms
5,248 KB |
testcase_56 | AC | 2 ms
5,248 KB |
testcase_57 | AC | 1 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 | 1 ms
5,248 KB |
testcase_63 | AC | 1 ms
5,248 KB |
testcase_64 | AC | 2 ms
5,248 KB |
testcase_65 | AC | 2 ms
5,248 KB |
testcase_66 | MLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> 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; } 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; if (h < w) swap(h, w); using mint = dynamic_modint<0>; mint::set_mod(m); vector<int> rev(1 << w, 0); rep(v, 0, 1 << w) rep(i, 0, w) rev[v] |= ((v >> i) & 1) << (w - 1 - i); int mask = (1 << w) - 1; int mask1 = 0; rep(i, 0, h) mask1 |= 1 << (w * i); vector<bool> ok(1 << (h * w), false), ok_seen(1 << (h * w), false); vector<bool> seen(1 << (h * w), false); vector<mint> pow(h * w + 1), memo(1 << (h * w), 0); rep(i, 0, pow.size()) pow[i] = mint(i).pow(k); mint ans = 0; int vc[] = {0, 0, 0, 0}; rep(bit, 1, 1 << (h * w)) { if (!ok_seen[bit]) { int v = 0, cm = 0; rep(i, 0, h + 1) rep(j, 0, w) { int u = w * i + j; int z = (v >> (j * 2)) & 3; if ((bit >> u) & 1) { if (z) { int y = j ? ((v >> (j * 2 - 2)) & 3) : 0; if (y > 0 && y != z) { rep(x, 0, w) if (((v >> (x * 2)) & 3) == y) { v ^= ((y ^ z) << (x * 2)); vc[y]--; vc[z]++; } } } else { int y = j ? (v >> (j * 2 - 2)) & 3 : 0; if (y) { z = y; } else { z = 1; while (vc[z]) z++; } vc[z]++; v |= z << (j * 2); } } else { if (vc[z] == 1) cm++; vc[z]--; v &= ~(3 << (j * 2)); } } bool f = cm == 1; int rbit = 0; rep(i, 0, h) rbit |= rev[(bit >> (i * w)) & mask] << (i * w); int cbit = 0; rep(i, 0, h) cbit |= ((bit >> (i * w)) & mask) << ((h - 1 - i) * w); int rcbit = 0; rep(i, 0, h) rcbit |= rev[(bit >> (i * w)) & mask] << ((h - 1 - i) * w); rep(i, 0, 4) { int s = i == 0 ? bit : (i == 1 ? rbit : (i == 2 ? cbit : rcbit)); for (int x = s;; x <<= w) { ok_seen[x] = true, ok[x] = f; if (x & (mask << ((h - 1) * w))) break; } for (int x = s;; x >>= w) { ok_seen[x] = true, ok[x] = f; if (x & mask) break; } for (int x = s;; x <<= 1) { ok_seen[x] = true, ok[x] = f; if (x & (mask1 << (w - 1))) break; } for (int x = s;; x >>= 1) { ok_seen[x] = true, ok[x] = f; if (x & mask1) break; } } } if (!seen[bit]) { mint val = 0; if (ok[bit]) { 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++; } val = pow[pc] * (1 << (h * w - pc - c)); } int rbit = 0; rep(i, 0, h) rbit |= rev[(bit >> (i * w)) & mask] << (i * w); int cbit = 0; rep(i, 0, h) cbit |= ((bit >> (i * w)) & mask) << ((h - 1 - i) * w); int rcbit = 0; rep(i, 0, h) rcbit |= rev[(bit >> (i * w)) & mask] << ((h - 1 - i) * w); seen[bit] = true, memo[bit] = val; seen[rbit] = true, memo[rbit] = val; seen[cbit] = true, memo[cbit] = val; seen[rcbit] = true, memo[rcbit] = val; } ans += memo[bit]; } 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(); }