結果

問題 No.2455 Numbers Dictionary
ユーザー kotatsugamekotatsugame
提出日時 2023-09-01 21:50:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 850 ms
コンパイル使用メモリ 68,760 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-01 21:50:46
合計ジャッジ時間 4,041 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 23 ms
4,380 KB
testcase_03 AC 38 ms
4,380 KB
testcase_04 AC 63 ms
4,380 KB
testcase_05 AC 29 ms
4,380 KB
testcase_06 AC 121 ms
4,376 KB
testcase_07 AC 217 ms
4,380 KB
testcase_08 AC 27 ms
4,380 KB
testcase_09 AC 116 ms
4,380 KB
testcase_10 AC 106 ms
4,380 KB
testcase_11 AC 131 ms
4,380 KB
testcase_12 AC 36 ms
4,384 KB
testcase_13 AC 124 ms
4,380 KB
testcase_14 AC 57 ms
4,376 KB
testcase_15 AC 102 ms
4,380 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 124 ms
4,380 KB
testcase_18 AC 10 ms
4,376 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 121 ms
4,380 KB
testcase_21 AC 122 ms
4,376 KB
testcase_22 AC 64 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cassert>
using namespace std;
string N,K;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T;cin>>T;
	for(;T--;)
	{
		cin>>N>>K;
		long ans=K.size();
		for(int i=0;i<K.size();i++)
		{//diff on i
			for(int c=i==0?1:0;c<K[i]-'0';c++)
			{//i-th digit = c
				long p=1;
				for(int j=0;i+1+j<N.size();j++)
				{
					ans+=p;
					p*=10;
				}
				if(i+1<=N.size())
				{
					string L=K.substr(0,i);
					L+=c+'0';
					string R0=string(N.size()-i-1,'0'),R9=string(N.size()-i-1,'9');
					if(L+R0>N);
					else if(L+R9<=N)ans+=p;
					else
					{
						long t=0;
						for(int j=i+1;j<N.size();j++)t=t*10+(N[j]-'0');
						ans+=t+1;
					}
				}
			}
		}
		cout<<ans<<"\n";
	}
}
0