結果
| 問題 |
No.2867 NOT FOUND 404 Again
|
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2024-08-30 23:25:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 423 ms / 3,000 ms |
| コード長 | 913 bytes |
| コンパイル時間 | 2,184 ms |
| コンパイル使用メモリ | 204,416 KB |
| 最終ジャッジ日時 | 2025-02-24 03:25:13 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
}
#include <atcoder/modint>
using mint = atcoder::modint998244353;
int main() {
fast_io();
string n;
cin >> n;
int m = n.size();
string s = "404";
vector dp(m + 1, vector(2, vector<mint>(3, 0)));
dp[0][0][0] = 1;
for (int i = 0; i < m; i++) {
for (int smaller = 0; smaller < 2; smaller++) {
for (int j = 0; j < 3; j++) {
for (int x = 0; x <= (smaller ? 9 : (n[i] - '0')); x++) {
int nj;
if (x == (s[j] - '0')) {
nj = j + 1;
} else if (x == 4) {
nj = 1;
} else {
nj = 0;
}
if (nj == 3) {
continue;
}
dp[i + 1][smaller || (x < (n[i] - '0'))][nj] +=
dp[i][smaller][j];
}
}
}
}
mint ans = 0;
for (int j = 0; j < 3; j++) {
ans += dp[m][0][j] + dp[m][1][j];
}
ans--;
cout << ans.val() << endl;
}
eve__fuyuki