結果

問題 No.2867 NOT FOUND 404 Again
ユーザー haihamabossu
提出日時 2024-08-30 22:35:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 291 ms / 3,000 ms
コード長 1,160 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 199,780 KB
最終ジャッジ日時 2025-02-24 03:13:30
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using mint = atcoder::modint998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void solve() {
  string n;
  cin >> n;
  vector dp(2, vector<mint>(3, 0));
  dp[1][0] = 1;
  rep(ni, n.size()) {
    vector nex(2, vector<mint>(3, 0));
    ll d = n[ni] - '0';
    rep(di, 10) {
      rep(ps, 3) {
        ll ns = 0;
        if (di == 4) {
          if (ps <= 1) {
            ns = 1;
          } else {
            ns = 3;
          }
        } else if (di == 0) {
          if (ps == 1) {
            ns = 2;
          } else {
            ns = 0;
          }
        }
        if (ns >= 3) {
          continue;
        }
        if (di <= d) {
          ll upper = di == d;
          nex[upper][ns] += dp[1][ps];
        }
        nex[0][ns] += dp[0][ps];
      }
    }
    swap(dp, nex);
  }
  mint ans = 0;
  rep(upper, 2) rep(s, 3) ans += dp[upper][s];
  ans -= 1;
  cout << ans.val() << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0