結果

問題 No.2455 Numbers Dictionary
ユーザー AerenAeren
提出日時 2023-09-01 23:06:37
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,429 bytes
コンパイル時間 5,656 ms
コンパイル使用メモリ 357,756 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-01 23:06:57
合計ジャッジ時間 7,533 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 14 ms
4,380 KB
testcase_03 AC 19 ms
4,376 KB
testcase_04 AC 31 ms
4,380 KB
testcase_05 AC 16 ms
4,380 KB
testcase_06 AC 60 ms
4,380 KB
testcase_07 AC 104 ms
4,384 KB
testcase_08 AC 22 ms
4,380 KB
testcase_09 AC 58 ms
4,380 KB
testcase_10 AC 52 ms
4,376 KB
testcase_11 AC 62 ms
4,376 KB
testcase_12 AC 17 ms
4,376 KB
testcase_13 AC 59 ms
4,380 KB
testcase_14 AC 28 ms
4,380 KB
testcase_15 AC 48 ms
4,380 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 60 ms
4,376 KB
testcase_18 AC 10 ms
4,380 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 59 ms
4,384 KB
testcase_21 AC 61 ms
4,376 KB
testcase_22 AC 32 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////
0