結果

問題 No.2867 NOT FOUND 404 Again
ユーザー GOTKAKOGOTKAKO
提出日時 2024-08-30 22:29:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 386 ms / 3,000 ms
コード長 3,630 bytes
コンパイル時間 2,228 ms
コンパイル使用メモリ 207,688 KB
実行使用メモリ 12,264 KB
最終ジャッジ日時 2024-08-30 22:29:18
合計ジャッジ時間 4,985 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 90 ms
12,148 KB
testcase_04 AC 92 ms
12,184 KB
testcase_05 AC 94 ms
12,120 KB
testcase_06 AC 92 ms
12,092 KB
testcase_07 AC 91 ms
12,196 KB
testcase_08 AC 92 ms
12,120 KB
testcase_09 AC 92 ms
12,104 KB
testcase_10 AC 93 ms
12,000 KB
testcase_11 AC 92 ms
12,120 KB
testcase_12 AC 91 ms
12,264 KB
testcase_13 AC 92 ms
12,244 KB
testcase_14 AC 92 ms
12,168 KB
testcase_15 AC 92 ms
12,108 KB
testcase_16 AC 92 ms
12,192 KB
testcase_17 AC 92 ms
12,156 KB
testcase_18 AC 94 ms
12,184 KB
testcase_19 AC 386 ms
12,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long mod = 998244353;
//入力が必ず-mod<a<modの時.
struct mint{
    long long v = 0;
    mint(){} mint(int a){v = a<0?a+mod:a;} mint(long long a){v = a<0?a+mod:a;}
    mint(unsigned long long a){v = a;}
    long long val(){return v;}
    void modu(){v %= mod;}
 
    mint repeat2mint(const long long a,long long b){
        mint ret = 1,p = a;
        while(b){
            if(b&1) ret *= p;
            p *= p; b >>= 1;
        }
        return ret;
    };
 
    mint &operator=(const mint &b) = default;
    mint operator-() const {return mint(0)-(*this);}
    mint operator+(const mint b){return mint(v)+=b;}
    mint operator-(const mint b){return mint(v)-=b;}
    mint operator*(const mint b){return mint(v)*=b;}
    mint operator/(const mint b){return mint(v)/=b;}
 
    mint operator+=(const mint b){
        v += b.v; if(v >= mod) v -= mod;
        return *this;
    }
    mint operator-=(const mint b){
        v -= b.v; if(v < 0) v += mod; 
        return *this;
    }   
    mint operator*=(const mint b){v = v*b.v%mod; return *this;}
    mint operator/=(mint b){
        if(b == 0) assert(false);
        int left = mod-2;
        while(left){if(left&1) *this *= b; b *= b; left >>= 1;}
        return *this;
    }
 
    mint operator++(int){*this += 1; return *this;}
    mint operator--(int){*this -= 1; return *this;}
    bool operator==(const mint b){return v == b.v;}
    bool operator!=(const mint b){return v != b.v;}
    bool operator>(const mint b){return v > b.v;}
    bool operator>=(const mint b){return v >= b.v;}
    bool operator<(const mint b){return v < b.v;}
    bool operator<=(const mint b){return v <= b.v;}
 
    mint pow(const long long x){return repeat2mint(v,x);}
    mint inv(){return mint(1)/v;}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    string s; cin >> s;
    int N = s.size();
    if(N < 3){cout << s << endl; return 0;}

    bool Nng = false;
    vector<mint> p10(N,1);
    for(int i=1; i<N; i++) p10.at(i) = p10.at(i-1)*10;

    vector<mint> alive(3);
    for(int i=0; i<N-1; i++){
        vector<mint> next(3);
        next.at(0) = alive.at(0)*9+alive.at(1)*8+alive.at(2)*9;
        next.at(1) = alive.at(0)+alive.at(1);
        next.at(2) = alive.at(1);
        swap(alive,next);
        if(i >= 3 && s.at(i-3) == '4' && s.at(i-2) == '0' && s.at(i-1) == '4') Nng = true;
        if(Nng) continue;
        int limit = (s.at(i)-'0')*10;
        bool four = false,zerofour = false;
        if(i >= 2 && s.at(i-2) == '4' && s.at(i-1) == '0') four = true;
        if(i >= 1 && s.at(i-1) == '4') zerofour = true;
        for(int k=0; k<limit; k++){
            if(four && 40 <= k && k <= 49) continue;
            if(zerofour && k == 4) continue;
            if(k == 40) alive.at(2)++;
            else if(k%10 == 4) alive.at(1)++;
            else alive.at(0)++;
        }
    }

    if(N > 3 && s.at(N-4) == '4' && s.at(N-3) == '0' && s.at(N-2) == '4') Nng = true; 
    mint answer = 0;
    if(Nng == false){
        for(char i='0'; i<=s.at(N-1); i++){
            if(s.at(N-3) == '4' && s.at(N-2) == '0' && i == '4') continue;
            answer++;
        }
    }
    for(auto &a : alive) answer += a;
    answer--;
    cout << answer.v << endl;
	return 0;

    int answer2 = 0;
    long long n = stoll(s);
    for(int i=1; i<=n; i++){
        string S = to_string(i);
        int add = 1;
        for(int k=0; k<(int)S.size()-2; k++){
            string t = S.substr(k,3);
            if(t == "404"){add = 0; break;}
        }
        answer2 += add;
    }
    cout << answer2 << endl;
}
0