結果

問題 No.2867 NOT FOUND 404 Again
ユーザー NachiaNachia
提出日時 2024-08-30 22:07:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 392 ms / 3,000 ms
コード長 1,957 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 88,976 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-30 22:07:21
合計ジャッジ時間 8,022 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 348 ms
6,944 KB
testcase_04 AC 343 ms
6,940 KB
testcase_05 AC 345 ms
6,944 KB
testcase_06 AC 346 ms
6,944 KB
testcase_07 AC 343 ms
6,940 KB
testcase_08 AC 341 ms
6,944 KB
testcase_09 AC 337 ms
6,940 KB
testcase_10 AC 349 ms
6,944 KB
testcase_11 AC 343 ms
6,944 KB
testcase_12 AC 341 ms
6,940 KB
testcase_13 AC 347 ms
6,940 KB
testcase_14 AC 345 ms
6,940 KB
testcase_15 AC 344 ms
6,944 KB
testcase_16 AC 347 ms
6,940 KB
testcase_17 AC 347 ms
6,940 KB
testcase_18 AC 266 ms
6,940 KB
testcase_19 AC 392 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
    vector<Modint> ex(3);

    bool beg = true;
    string N; cin >> N;
    for(char c : N){
        i64 d = c - '0';
        if(beg){
            ex = proc(st, d);
            dp.assign(3, 0);
            rep(e,d) if(e != 0) vadd(dp, proc(st, e), 1);
            beg = false;
        } else {
            vector<Modint> nx(3);
            i64 igcnt = d;
            if(0 < d){
                igcnt--;
                vadd(nx, proc(ex, 0), 1);
            }
            if(4 < d){
                igcnt--;
                vadd(nx, proc(ex, 4), 1);
            }
            vadd(nx, proc(ex, 1), igcnt);
            vadd(nx, proc(dp, 0), 1);
            vadd(nx, proc(dp, 4), 1);
            vadd(nx, proc(dp, 1), 8);
            nx[1] += 1;
            nx[0] += 8;
            ex = proc(ex, d);
            swap(dp, nx);
        }
    }
    vadd(dp, ex, 1);
    Modint ans = dp[0] + dp[1] + dp[2];
    cout << ans.val() << endl;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}
0