結果
問題 | No.2159 Filling 4x4 array |
ユーザー |
|
提出日時 | 2022-12-22 22:04:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,102 bytes |
コンパイル時間 | 1,060 ms |
コンパイル使用メモリ | 85,444 KB |
最終ジャッジ日時 | 2025-02-09 18:28:12 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 TLE * 1 |
other | AC * 25 TLE * 20 |
ソースコード
#include <array>#include <iostream>#include <map>#include <atcoder/modint>using mint = atcoder::modint998244353;constexpr int L = 30;constexpr int N = 4;int main() {std::array<int, N> r, c;for (auto&& e : r) std::cin >> e, e -= 4;for (auto&& e : c) std::cin >> e, e -= 4;using key = std::pair<std::array<int, N>, std::array<int, N>>;std::array<std::map<key, mint>, L + 1> dp{};dp[0][{ r, c }] = 1;for (int i = 0; i < L; ++i) {for (const auto& [k, v] : dp[i]) {for (int s = 0; s < 1 << ((N - 1) * (N - 1)); ++s) {auto [r, c] = k;std::array<std::array<int, N>, N> d;for (int a = 0; a < N - 1; ++a) {for (int b = 0; b < N - 1; ++b) {int bit = (s >> (a * (N - 1) + b)) & 1;d[a][b] = bit;r[a] -= bit, c[b] -= bit;}}for (int a = 0; a < N - 1; ++a) {const int b = N - 1;int bit = r[a] & 1;d[a][b] = bit;r[a] -= bit, c[b] -= bit;}for (int b = 0; b < N - 1; ++b) {const int a = N - 1;int bit = c[b] & 1;d[a][b] = bit;r[a] -= bit, c[b] -= bit;}{int bit = r[N - 1] & 1;d[N - 1][N - 1] = bit;r[N - 1] -= bit, c[N - 1] -= bit;}bool ok = (c[N - 1] & 1) == 0;for (int a = 0; a < N; ++a) {ok &= r[a] >= 0;r[a] >>= 1;}for (int b = 0; b < N; ++b) {ok &= c[b] >= 0;c[b] >>= 1;}if (ok) {dp[i + 1][{ r, c }] += v;}}}}std::cout << dp[L][key{}].val() << std::endl;return 0;}