結果
| 問題 | No.3549 SigMax Digits (Judge ver.) |
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2026-05-22 22:53:58 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 712 ms / 3,000 ms |
| コード長 | 1,550 bytes |
| 記録 | |
| コンパイル時間 | 3,215 ms |
| コンパイル使用メモリ | 338,600 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-22 22:54:08 |
| 合計ジャッジ時間 | 6,516 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge1_0 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
// using mint = modint1000000007;
// const int mod = 1000000007;
// using mint = modint998244353;
// const int mod = 998244353;
// const int INF = 1e9;
// const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, l, r) for (int i = (l); i < (r); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, l, r) for (int i = (r)-1; i >= (l); --i)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
#define P pair<int, int>
template<typename A, typename B> inline bool chmax(A &a, const B &b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A &a, const B &b) { if (a > b) { a = b; return true; } return false; }
long long f(long long n) {
if (n == 0)return 0;
vector dp(2, vector<long long>(10));
dp[0][0] = 1;
string s = to_string(n);
bool init = false;
for (auto c : s) {
vector ndp(2, vector<long long>(10));
int x = c - '0';
rep(i, 10) {
// 0->0
ndp[0][max(i, x)] += dp[0][i];
// 0->1
rep(j, x)ndp[1][max(i, j)] += dp[0][i];
// 1->1
rep(j, 10)ndp[1][max(i, j)] += dp[1][i];
}
dp.swap(ndp);
}
long long ret = 0;
rep(i, 2)rep(j, 10)ret += j * dp[i][j];
return ret;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t; cin >> t;
while (t--) {
long long l, r; cin >> l >> r;
long long ans = f(r) - f(l - 1);
cout << ans << endl;
}
return 0;
}
kwm_t