結果
| 問題 |
No.2867 NOT FOUND 404 Again
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-09-12 10:25:37 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 549 ms / 3,000 ms |
| コード長 | 1,287 bytes |
| コンパイル時間 | 3,044 ms |
| コンパイル使用メモリ | 248,356 KB |
| 実行使用メモリ | 39,484 KB |
| 最終ジャッジ日時 | 2024-09-12 10:25:51 |
| 合計ジャッジ時間 | 14,007 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int mod = 998244353;
int n, a[N], dp[N][2][2][2];
string s;
void ps(int &a, int b){
a += b;
while(a >= mod) a -= mod;
}
void transfer(int x, int opa, int opb, int limit){
for(int i = 0; i <= (limit ? a[x + 1] : 9); i++){
if(opb && i == 4) continue;
if(i == 4) ps(dp[x + 1][1][0][(limit && i == a[x + 1])], dp[x][opa][opb][limit]);
else if(!i) ps(dp[x + 1][0][opa][(limit && i == a[x + 1])], dp[x][opa][opb][limit]);
else ps(dp[x + 1][0][0][(limit && i == a[x + 1])], dp[x][opa][opb][limit]);
}
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> s;
n = s.size();
s = ' ' + s;
for(int i = 1; i <= n; i++) a[i] = int(s[i] - '0');
for(int i = 1; i <= n; i++){
for(int j = 1; j <= (i == 1 ? a[i] : 9); j++){
if(j == 4) ps(dp[i][1][0][(i == 1 && j == a[i])], 1);
else ps(dp[i][0][0][(i == 1 && j == a[i])], 1);
}
}
for(int i = 1; i < n; i++){
for(int state = 0; state < 8; state++){
transfer(i, ((state >> 2) & 1), ((state >> 1) & 1), ((state >> 0) & 1));
}
}
int ans = 0;
for(int state = 0; state < 7; state++){
ps(ans, dp[n][((state >> 2) & 1)][((state >> 1) & 1)][((state >> 0) & 1)]);
}
cout << ans;
return 0;
}
vjudge1