結果

問題 No.2867 NOT FOUND 404 Again
ユーザー InTheBloomInTheBloom
提出日時 2024-08-30 22:51:14
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 444 ms / 3,000 ms
コード長 1,580 bytes
コンパイル時間 1,164 ms
コンパイル使用メモリ 98,020 KB
実行使用メモリ 162,452 KB
最終ジャッジ日時 2024-08-30 22:51:24
合計ジャッジ時間 9,339 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 403 ms
162,188 KB
testcase_04 AC 403 ms
162,412 KB
testcase_05 AC 414 ms
162,352 KB
testcase_06 AC 401 ms
162,272 KB
testcase_07 AC 402 ms
162,452 KB
testcase_08 AC 409 ms
162,272 KB
testcase_09 AC 399 ms
162,244 KB
testcase_10 AC 398 ms
162,268 KB
testcase_11 AC 409 ms
162,376 KB
testcase_12 AC 402 ms
162,212 KB
testcase_13 AC 397 ms
162,252 KB
testcase_14 AC 414 ms
162,224 KB
testcase_15 AC 403 ms
162,208 KB
testcase_16 AC 427 ms
162,216 KB
testcase_17 AC 400 ms
162,276 KB
testcase_18 AC 360 ms
162,312 KB
testcase_19 AC 444 ms
162,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <tuple>

using namespace std;
using ll = long long;

int main () {
    string n; cin >> n;
    vector<int> N(n.size());
    for (int i = 0; i < n.size(); i++) N[i] = n[i] - '0';
    const int len = static_cast<int>(n.size());

    const ll MOD = 998244353;
    const auto ban = vector<int>({4, 0, 4});
    int sz = static_cast<int> (n.size()) * 2 * 4;
    vector<ll> mp(sz + 10, -1);

    auto encode = [&] (int pos, bool less, int cur) {
        int res = 0;
        int p = 1;
        res += p * pos;
        p *= len;
        res += p * static_cast<int> (less);
        p *= 2;
        res += p * cur;
        return res;
    };

    auto dp = [&] (auto dp, int pos, bool less, int cur) {
        auto key = encode(pos, less, cur);
        if (mp[key] != -1) return mp[key];
        if (pos == len) {
            if (cur == 3) return 0LL;
            return 1LL;
        }

        ll res = 0;
        for (int nex = 0; nex < 10; nex++) {
            if (!less && N[pos] < nex) continue;
            bool nl = less || nex < N[pos];
            int nc = cur;
            if (nc < 3) {
                if (ban[nc] == nex) {
                    nc++;
                }
                else if (nex == 4) {
                    nc = 1;
                }
                else {
                    nc = 0;
                }
            }

            res += dp(dp, pos + 1, nl, nc);
            res %= MOD;
        }

        return mp[key] = res;
    };

    cout << dp(dp, 0, false, 0) - 1 << "\n";
}
0