結果

問題 No.2867 NOT FOUND 404 Again
ユーザー NachiaNachia
提出日時 2024-08-30 22:59:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 3,000 ms
コード長 2,175 bytes
コンパイル時間 641 ms
コンパイル使用メモリ 70,768 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-30 22:59:54
合計ジャッジ時間 2,181 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 33 ms
6,940 KB
testcase_04 AC 33 ms
6,940 KB
testcase_05 AC 32 ms
6,940 KB
testcase_06 AC 49 ms
6,944 KB
testcase_07 AC 34 ms
6,940 KB
testcase_08 AC 35 ms
6,944 KB
testcase_09 AC 33 ms
6,944 KB
testcase_10 AC 33 ms
6,940 KB
testcase_11 AC 32 ms
6,944 KB
testcase_12 AC 32 ms
6,944 KB
testcase_13 AC 33 ms
6,940 KB
testcase_14 AC 33 ms
6,944 KB
testcase_15 AC 32 ms
6,940 KB
testcase_16 AC 33 ms
6,940 KB
testcase_17 AC 33 ms
6,940 KB
testcase_18 AC 27 ms
6,940 KB
testcase_19 AC 29 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
using namespace std;

char buffer[1000010] = {};

int main(){
    fread(buffer, 1, 1000010, stdin);
    auto proc = [&](vector<i64> f, i64 d) -> vector<i64> {
        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<i64>& f, vector<i64> s, i64 t){
        rep(x,3) f[x] += s[x] * t;
    };
    vector<i64> st = { 1, 0, 0 };
    vector<i64> dp(3);
    int ex = 0;
    bool beg = true;
    for(int i=0; buffer[i] != '\n'; i++){
        i64 d = buffer[i] - '0';
        if(beg){
            dp.assign(3, 0);
            rep(e,d) if(e != 0) vadd(dp, proc(st, e), 1);
            beg = false;
        } else {
            vector<i64> nx(3);
            nx[0] = ((dp[0] + dp[1] + dp[2]) * 9 - dp[1]) % 998244353;
            nx[1] = dp[0] + dp[1];
            nx[2] = dp[1];
            i64 igcnt = d;
            if(4 < d){
                igcnt--;
                if(ex == 0){
                    nx[0] += d-1;
                    nx[1] += 1;
                } else if(ex == 1){
                    nx[0] += d-2;
                    nx[1] += 1;
                    nx[2] += 1;
                } else if(ex == 2){
                    nx[0] += d-1;
                }
            } else if(0 < d){
                igcnt--;
                if(ex == 0){
                    nx[0] += d;
                } else if(ex == 1){
                    nx[0] += d-1;
                    nx[2] += 1;
                } else if(ex == 2){
                    nx[0] += d;
                }
            }
            nx[1] += 1;
            nx[0] += 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;
        }
    }
    i64 ans = dp[0] + dp[1] + dp[2];
    if(ex < 3) ans += 1;
    ans %= 998244353;
    printf("%d\n", int(ans));
    return 0;
}
0