結果
問題 | No.2437 Fragile Multiples of 11 |
ユーザー | ei1333333 |
提出日時 | 2023-08-18 22:09:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 398 ms / 2,000 ms |
コード長 | 3,373 bytes |
コンパイル時間 | 4,360 ms |
コンパイル使用メモリ | 282,312 KB |
実行使用メモリ | 74,496 KB |
最終ジャッジ日時 | 2024-11-28 07:31:09 |
合計ジャッジ時間 | 11,823 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
5,248 KB |
testcase_01 | AC | 4 ms
5,888 KB |
testcase_02 | AC | 23 ms
11,392 KB |
testcase_03 | AC | 396 ms
74,368 KB |
testcase_04 | AC | 388 ms
74,496 KB |
testcase_05 | AC | 392 ms
74,496 KB |
testcase_06 | AC | 396 ms
74,368 KB |
testcase_07 | AC | 392 ms
74,496 KB |
testcase_08 | AC | 392 ms
74,368 KB |
testcase_09 | AC | 386 ms
74,496 KB |
testcase_10 | AC | 392 ms
74,496 KB |
testcase_11 | AC | 395 ms
74,368 KB |
testcase_12 | AC | 398 ms
74,496 KB |
testcase_13 | AC | 386 ms
74,368 KB |
testcase_14 | AC | 389 ms
74,368 KB |
testcase_15 | AC | 4 ms
5,248 KB |
testcase_16 | AC | 3 ms
5,248 KB |
testcase_17 | AC | 3 ms
5,248 KB |
testcase_18 | AC | 3 ms
5,248 KB |
testcase_19 | AC | 3 ms
5,248 KB |
testcase_20 | AC | 4 ms
5,248 KB |
testcase_21 | AC | 3 ms
5,248 KB |
testcase_22 | AC | 3 ms
5,248 KB |
testcase_23 | AC | 3 ms
5,248 KB |
testcase_24 | AC | 69 ms
19,200 KB |
testcase_25 | AC | 26 ms
11,392 KB |
testcase_26 | AC | 22 ms
10,624 KB |
testcase_27 | AC | 67 ms
18,560 KB |
testcase_28 | AC | 380 ms
71,552 KB |
testcase_29 | AC | 363 ms
63,744 KB |
testcase_30 | AC | 323 ms
63,744 KB |
testcase_31 | AC | 287 ms
56,832 KB |
testcase_32 | AC | 232 ms
46,720 KB |
testcase_33 | AC | 68 ms
18,432 KB |
ソースコード
#line 1 "template/template.hpp" #include<bits/stdc++.h> #include<atcoder/all> using namespace std; using int64 = long long; const int mod = 1e9 + 7; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 >& p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { explicit FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } using mint = atcoder::modint998244353; int main() { int N; string X; cin >> N >> X; auto dp = make_v< mint >(N, 2, 2, 11, 1 << 11); auto memo = make_v< int >(N, 2, 2, 11, 1 << 11); auto cash = make_v< int >(1 << 11, 10); for(int skipped = 0; skipped < (1 << 11); skipped++) { for(int i = 0; i < 10; i++) { for(int j = 0; j < 11; j++) { if((skipped >> j) & 1) { cash[skipped][i] |= 1 << ((j * 10 + i) % 11); } } } } auto dfs = MFP([&](auto dfs, int idx, bool is_free, bool is_zero, int mul, int skipped) -> mint { if(idx == N) { return not is_zero and mul == 0 and (skipped & 1) == 0; } if(memo[idx][is_free][is_zero][mul][skipped]) { return dp[idx][is_free][is_zero][mul][skipped]; } memo[idx][is_free][is_zero][mul][skipped] = 1; mint ret = 0; for(int i = 0; i <= (is_free ? 9 : int(X[idx] - '0')); i++) { int next_skipped = cash[skipped][i]; if(not is_zero or i != 0) { next_skipped |= 1 << mul; } int next_mul = (mul * 10 + i) % 11; ret += dfs(idx + 1, is_free or (X[idx] - '0' != i), is_zero and (i == 0), next_mul, next_skipped); } return dp[idx][is_free][is_zero][mul][skipped] = ret; }); cout << dfs(0, false, true, 0, 0).val() << "\n"; }