結果
問題 | No.2455 Numbers Dictionary |
ユーザー |
|
提出日時 | 2023-09-01 23:06:37 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 131 ms / 2,000 ms |
コード長 | 1,429 bytes |
コンパイル時間 | 5,246 ms |
コンパイル使用メモリ | 402,500 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-03 11:11:46 |
合計ジャッジ時間 | 7,813 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> #include <x86intrin.h> using namespace std; using namespace numbers; int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); auto __solve_tc = [&](auto __tc_num)->int{ string ns, k; cin >> ns >> k; long long n = stoll(ns); auto count = [&](string prefix)->long long{ long long x = stoll(prefix), low = 1; long long res = 0; for(auto len = (int)prefix.size(); len < (int)ns.size(); ++ len){ res += low; x *= 10; low *= 10; } { res += clamp(x + low, 1LL, n + 1) - clamp(x, 1LL, n + 1); } return res; }; long long res = (int)k.size() - 1; for(auto i = 0; i < (int)k.size(); ++ i){ for(auto x = i ? 0 : 1; x < k[i] - '0'; ++ x){ res += count(k.substr(0, i) + char(x + '0')); } } cout << res + 1 << "\n"; return 0; }; int __tc_cnt; cin >> __tc_cnt; for(auto __tc_num = 0; __tc_num < __tc_cnt; ++ __tc_num){ __solve_tc(__tc_num); } return 0; } /* */ //////////////////////////////////////////////////////////////////////////////////////// // // // Coded by Aeren // // // ////////////////////////////////////////////////////////////////////////////////////////