結果

問題 No.3549 SigMax Digits (Judge ver.)
コンテスト
ユーザー K2
提出日時 2026-05-23 00:04:46
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 923 ms / 3,000 ms
コード長 1,659 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,380 ms
コンパイル使用メモリ 375,256 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-23 00:04:58
合計ジャッジ時間 8,917 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using mint = modint998244353;
// using mint = modint1000000007;

template <typename T> using vec = vector<T>;
template <typename T> using pr = pair<T, T>;
template <typename T> using mipq = priority_queue<T, vec<T>, greater<T>>;

#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(i, n) for (auto i = decay_t<decltype(n)>{}; (i) < (n); ++i)
#define rep2(i, l, r) for (auto i = (l); (i) < (r); ++i)
#define rep3(i, l, r, d) for (auto i = (l); (i) < (r); i += (d))
#define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(i, r, l) for (auto i = (r); i >= (l); --i)
template <class T> bool chmax(T &a, const T &b) { return (a < b ? a = b, true : false); }
template <class T> bool chmin(T &a, const T &b) { return (a > b ? a = b, true : false); }

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int T = 1;
    cin >> T;
    while (T--) solve();
}

ll calc(ll n) {
    ll dp[10][2] = {};
    dp[0][0] = 1;
    for (auto s : to_string(n)) {
        int v = s - '0';
        ll ndp[10][2] = {};
        rep(j, 10) rep(x, 10) {
            ndp[max(j, x)][1] += dp[j][1];
            if (x <= v) ndp[max(j, x)][x < v] += dp[j][0];
        }
        rep(j, 10) rep(k, 2) dp[j][k] = ndp[j][k];
    }
    ll res = 0;
    rep(j, 10) rep(k, 2) res += dp[j][k] * j;
    return res;
}

void solve() {
    ll L, R;
    cin >> L >> R;
    cout << calc(R) - calc(L - 1) << '\n';
}
0