結果
問題 | No.2437 Fragile Multiples of 11 |
ユーザー | rniya |
提出日時 | 2023-08-18 23:15:01 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 518 ms / 2,000 ms |
コード長 | 2,788 bytes |
コンパイル時間 | 3,494 ms |
コンパイル使用メモリ | 204,520 KB |
実行使用メモリ | 39,424 KB |
最終ジャッジ日時 | 2024-05-06 05:53:09 |
合計ジャッジ時間 | 11,949 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 12 ms
39,380 KB |
testcase_01 | AC | 13 ms
39,424 KB |
testcase_02 | AC | 40 ms
39,296 KB |
testcase_03 | AC | 495 ms
39,264 KB |
testcase_04 | AC | 484 ms
39,424 KB |
testcase_05 | AC | 513 ms
39,420 KB |
testcase_06 | AC | 516 ms
39,408 KB |
testcase_07 | AC | 518 ms
39,244 KB |
testcase_08 | AC | 512 ms
39,416 KB |
testcase_09 | AC | 508 ms
39,368 KB |
testcase_10 | AC | 514 ms
39,348 KB |
testcase_11 | AC | 514 ms
39,276 KB |
testcase_12 | AC | 517 ms
39,340 KB |
testcase_13 | AC | 518 ms
39,296 KB |
testcase_14 | AC | 511 ms
39,224 KB |
testcase_15 | AC | 12 ms
39,328 KB |
testcase_16 | AC | 12 ms
39,424 KB |
testcase_17 | AC | 13 ms
39,424 KB |
testcase_18 | AC | 13 ms
39,424 KB |
testcase_19 | AC | 13 ms
39,248 KB |
testcase_20 | AC | 13 ms
39,296 KB |
testcase_21 | AC | 13 ms
39,240 KB |
testcase_22 | AC | 13 ms
39,424 KB |
testcase_23 | AC | 12 ms
39,236 KB |
testcase_24 | AC | 97 ms
39,296 KB |
testcase_25 | AC | 41 ms
39,288 KB |
testcase_26 | AC | 35 ms
39,360 KB |
testcase_27 | AC | 92 ms
39,296 KB |
testcase_28 | AC | 489 ms
39,420 KB |
testcase_29 | AC | 430 ms
39,424 KB |
testcase_30 | AC | 428 ms
39,424 KB |
testcase_31 | AC | 381 ms
39,420 KB |
testcase_32 | AC | 305 ms
39,424 KB |
testcase_33 | AC | 93 ms
39,292 KB |
ソースコード
#include <bits/stdc++.h> #ifdef LOCAL #include <debug.hpp> #else #define debug(...) void(0) #endif #include "atcoder/modint" using namespace std; typedef long long ll; #define all(x) begin(x), end(x) constexpr int INF = (1 << 30) - 1; constexpr long long IINF = (1LL << 60) - 1; constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { auto sep = ""; for (const auto& x : v) os << exchange(sep, " ") << x; return os; } template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); } template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); } template <class T> void mkuni(vector<T>& v) { sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); } template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); } using mint = atcoder::modint998244353; const int MAX_N = 102, D = 11; mint dp[MAX_N][1 << D][D][2][2]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; string X; cin >> N >> X; dp[0][0][0][1][0] = 1; for (int i = 0; i < N; i++) { int x = X[i] - '0'; for (int mask = 0; mask < 1 << D; mask++) { for (int j = 0; j < D; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { mint& val = dp[i][mask][j][k][l]; if (val == 0) continue; for (int d = 0; d < 10; d++) { if (k == 1 and x < d) continue; int nmask = 0, nj = (j + (i & 1 ? d : D - d)) % D, nk = k, nl = l; if (k == 1 and d < x) nk = 0; if (l == 0 and d > 0) nl = 1; for (int m = 0; m < D; m++) { if (mask >> m & 1) { int nm = (m + (i & 1 ? D - d : d)) % D; nmask |= 1 << nm; } } if (nl == 1) nmask |= 1 << j; dp[i + 1][nmask][nj][nk][nl] += val; } } } } } } mint ans = 0; for (int mask = 0; mask < 1 << D; mask++) { for (int k = 0; k < 2; k++) { if (~mask & 1) { ans += dp[N][mask][0][k][1]; } } } cout << ans.val() << '\n'; return 0; }