結果
問題 | No.2455 Numbers Dictionary |
ユーザー |
![]() |
提出日時 | 2023-08-16 18:49:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 816 bytes |
コンパイル時間 | 1,830 ms |
コンパイル使用メモリ | 194,160 KB |
最終ジャッジ日時 | 2025-02-16 08:49:06 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 1 |
other | AC * 4 WA * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; //Kを接頭辞としてもつ数字のうち、N以下であるものの数 ll f(ll K, ll N){ if (K > N) return 0; ll res = 1, Z=K; while(Z<=N && K<=N/10){ Z = Z*10+9; K *= 10; res += min(Z, N)-K+1; } return res; } //辞書順でK以下、数字でN以下であるものの数 string K; ll N; ll g(ll idx=0, ll num=0){ num *= 10; ll c = K[idx]-'0', res = 0; if (idx != 0 && c != 0) res += f(num, N); if (num+c <= N) res++; for (int i=1; i<c; i++) res += f(num+i, N); if (idx < K.size()-1) res += g(idx+1, num+c); return res; } int main(){ int T; cin >> T; while(T){ T--; cin >> K >> N; cout << g() << endl; } return 0; }