結果
問題 |
No.2772 Appearing Even Times
|
ユーザー |
👑 |
提出日時 | 2024-05-27 20:21:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 281 ms / 4,000 ms |
コード長 | 1,265 bytes |
コンパイル時間 | 4,176 ms |
コンパイル使用メモリ | 253,316 KB |
最終ジャッジ日時 | 2025-02-21 16:55:54 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using mint = atcoder::modint998244353; mint solve(string s){ int n = s.size(); // 0th to i-th number are all the same as s[0:i] vector<mint> equal(1 << 10); // less than s[0:i] vector<mint> small(1 << 10); { // init int num = s[0] - '0'; for(int x = 1; x < num; x++) small[1 << x]++; equal[1 << num]++; } for(int i = 1; i < n; i++){ vector<mint> equal_old(1 << 10); vector<mint> small_old(1 << 10); swap(equal, equal_old); swap(small, small_old); // num: i-th number int num = s[i] - '0'; rep(bit, 1 << 10){ // equal -> small // x s.t. 0 <= x < num is acceptable for(int x = 0; x < num; x++) small[bit ^ (1 << x)] += equal_old[bit]; // equal -> equal // x s.t. x = num is acceptable equal[bit ^ (1 << num)] += equal_old[bit]; // small -> small // x s.t. 0 <= x <= 9 is acceptable for(int x = 0; x <= 9; x++) small[bit ^ (1 << x)] += small_old[bit]; } // nothing -> small // 0th to (i-1)-th are all 0. i-th number is not 0. for(int x = 1; x <= 9; x++) small[(1 << x)]++; } return equal[0] + small[0]; } int main(){ string s; cin >> s; cout << solve(s).val() << "\n"; return 0; }