結果
問題 | No.2437 Fragile Multiples of 11 |
ユーザー | ei1333333 |
提出日時 | 2023-08-18 22:09:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 458 ms / 2,000 ms |
コード長 | 3,373 bytes |
コンパイル時間 | 4,708 ms |
コンパイル使用メモリ | 282,828 KB |
実行使用メモリ | 74,496 KB |
最終ジャッジ日時 | 2024-05-06 04:14:28 |
合計ジャッジ時間 | 12,863 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
5,248 KB |
testcase_01 | AC | 5 ms
5,888 KB |
testcase_02 | AC | 25 ms
11,520 KB |
testcase_03 | AC | 430 ms
74,496 KB |
testcase_04 | AC | 430 ms
74,496 KB |
testcase_05 | AC | 421 ms
74,368 KB |
testcase_06 | AC | 425 ms
74,368 KB |
testcase_07 | AC | 424 ms
74,496 KB |
testcase_08 | AC | 430 ms
74,368 KB |
testcase_09 | AC | 458 ms
74,496 KB |
testcase_10 | AC | 420 ms
74,496 KB |
testcase_11 | AC | 431 ms
74,496 KB |
testcase_12 | AC | 429 ms
74,368 KB |
testcase_13 | AC | 431 ms
74,496 KB |
testcase_14 | AC | 427 ms
74,496 KB |
testcase_15 | AC | 4 ms
5,376 KB |
testcase_16 | AC | 4 ms
5,376 KB |
testcase_17 | AC | 3 ms
5,376 KB |
testcase_18 | AC | 3 ms
5,376 KB |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 3 ms
5,376 KB |
testcase_22 | AC | 3 ms
5,376 KB |
testcase_23 | AC | 3 ms
5,376 KB |
testcase_24 | AC | 74 ms
19,200 KB |
testcase_25 | AC | 29 ms
11,520 KB |
testcase_26 | AC | 23 ms
10,624 KB |
testcase_27 | AC | 70 ms
18,560 KB |
testcase_28 | AC | 410 ms
71,680 KB |
testcase_29 | AC | 363 ms
63,744 KB |
testcase_30 | AC | 357 ms
63,744 KB |
testcase_31 | AC | 309 ms
56,704 KB |
testcase_32 | AC | 246 ms
46,720 KB |
testcase_33 | AC | 70 ms
18,560 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"; }