結果
| 問題 |
No.2867 NOT FOUND 404 Again
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2024-08-30 22:55:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 3,000 ms |
| コード長 | 2,707 bytes |
| コンパイル時間 | 918 ms |
| コンパイル使用メモリ | 82,836 KB |
| 最終ジャッジ日時 | 2025-02-24 03:18:45 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
#include <atcoder/modint>
using Modint = atcoder::static_modint<998244353>;
using namespace std;
void testcase(){
auto proc = [&](vector<Modint> f, Modint d) -> vector<Modint> {
if(d == 4) return { 0, f[0] + f[1], 0 };
if(d == 0) return { f[0] + f[2], 0, f[1] };
return { f[0] + f[1] + f[2], 0, 0 };
};
auto vadd = [&](vector<Modint>& f, vector<Modint> s, Modint t){
rep(x,3) f[x] += s[x] * t;
};
vector<Modint> st = { 1, 0, 0 };
vector<Modint> dp(3);
int ex = 0;
bool beg = true;
string N; cin >> N;
for(char c : N){
i64 d = c - '0';
if(beg){
dp.assign(3, 0);
rep(e,d) if(e != 0) vadd(dp, proc(st, e), 1);
beg = false;
} else {
vector<Modint> nx(3);
nx[0] = (dp[0] + dp[1] + dp[2]) * Modint::raw(9) - dp[1];
nx[1] = dp[0] + dp[1];
nx[2] = dp[1];
i64 igcnt = d;
if(4 < d){
igcnt--;
if(ex == 0){
nx[0] += Modint::raw(d-1);
nx[1] += Modint::raw(1);
} else if(ex == 1){
nx[0] += Modint::raw(d-2);
nx[1] += Modint::raw(1);
nx[2] += Modint::raw(1);
} else if(ex == 2){
nx[0] += Modint::raw(d-1);
}
} else if(0 < d){
igcnt--;
if(ex == 0){
nx[0] += Modint::raw(d);
} else if(ex == 1){
nx[0] += Modint::raw(d-1);
nx[2] += Modint::raw(1);
} else if(ex == 2){
nx[0] += Modint::raw(d);
}
}
nx[1] += Modint::raw(1);
nx[0] += Modint::raw(8);
swap(dp, nx);
}
if(ex < 3){
if(d == 4){
if(ex == 2) ex = 3; else ex = 1;
} else if(d == 0){
if(ex == 1) ex = 2; else ex = 0;
} else ex = 0;
}
}
Modint ans = dp[0] + dp[1] + dp[2];
if(ex < 3) ans += 1;
cout << ans.val() << endl;
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
testcase();
return 0;
}
Nachia