結果

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

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/modint.hpp>
using namespace std;
 
using i32 = int;
using i64 = long long;
using i128 = __int128_t;
using f64 = double;
using p2 = pair<i64, i64>;
using p3 = tuple<i64, i64, i64>;
using mint = atcoder::modint998244353;
constexpr i64 inf = 1e18;
 
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  _main();
}

i64 solve(i64 n) {
  if (n == 0) return 0;
  vector<i64> v;
  while (n > 0) v.push_back(n % 10), n /= 10;
  reverse(v.begin(), v.end());
  vector<i64> dp(10, 0);
  i64 mx = 0;
  for (i64 i = 0; i < v.size(); i++) {
    vector<i64> ndp(10, 0);
    for (i64 j = 0; j < 10; j++) for (i64 k = 0; k < 10; k++) {
      ndp[max(j, k)] += dp[j];
    }
    // for (i64 x : ndp) cout << x << " ";
    // cout << "!\n";

    if (i != 0) {
      for (i64 j = 0; j < v[i]; j++) ndp[max(j, mx)]++;
      for (i64 j = 1; j < 10; j++) ndp[j]++;
    } else {
      for (i64 j = 1; j < v[i]; j++) ndp[max(j, mx)]++;
    }
    mx = max(mx, v[i]);
    swap(dp, ndp);
    // for (i64 x : dp) cout << x << " ";
    // cout << "!\n";
  }
  i64 ans = 0;
  for (i64 i = 0; i < 10; i++) ans += dp[i] * i;
  // for (i64 x : v) cout << x;
  // cout << ": " << ans << "\n";
  return ans;
}
void _main() {
  i64 tt;
  cin >> tt;
  for (;tt--;) {
    i64 l, r;
    cin >> l >> r;
    r++;
    i64 ans = solve(r) - solve(l);
    cout << ans << "\n";
  }
}
0