結果

問題 No.2455 Numbers Dictionary
ユーザー 沙耶花沙耶花
提出日時 2023-09-02 21:03:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 755 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 4,450 ms
コンパイル使用メモリ 261,244 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 21:03:16
合計ジャッジ時間 12,155 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 92 ms
4,372 KB
testcase_03 AC 175 ms
4,372 KB
testcase_04 AC 291 ms
4,368 KB
testcase_05 AC 114 ms
4,372 KB
testcase_06 AC 423 ms
4,368 KB
testcase_07 AC 755 ms
4,368 KB
testcase_08 AC 89 ms
4,372 KB
testcase_09 AC 412 ms
4,368 KB
testcase_10 AC 363 ms
4,372 KB
testcase_11 AC 441 ms
4,368 KB
testcase_12 AC 160 ms
4,372 KB
testcase_13 AC 427 ms
4,368 KB
testcase_14 AC 264 ms
4,372 KB
testcase_15 AC 413 ms
4,368 KB
testcase_16 AC 41 ms
4,372 KB
testcase_17 AC 418 ms
4,372 KB
testcase_18 AC 31 ms
4,368 KB
testcase_19 AC 30 ms
4,372 KB
testcase_20 AC 429 ms
4,368 KB
testcase_21 AC 426 ms
4,372 KB
testcase_22 AC 272 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
long long n;

long long Get(string s){
	if(s=="0")return 0;
	long long cv = stoll(s);
	long long ret = 0;
	long long t = 1;
	string y = to_string(n);
	while(true){
		string x = to_string(cv);
		if(x.size()!=y.size()){
			ret += t;
			t *= 10;
			cv *= 10;
		}
		else{
			string z = y.substr(0,s.size());
			if(z<s)break;
			if(z>s){
				ret += t;
				break;
			}
			ret += n-cv+1;
			break;
			
		}
	}
	//out<<s<<' '<<ret<<endl;
	return ret;
	
}

long long get(string s){
	long long ret = s.size()-1;
	while(s.size()>0){
		while(s.back()!='0'){
			s.back()--;
			ret += Get(s);
		}
		s.pop_back();
	}
	return ret;
}

int main(){
	
	int _t;
	cin>>_t;
	
	rep(_,_t){
		
		long long k;
		cin>>n>>k;
		cout<<get(to_string(k))+1<<endl;
	}
		
	return 0;
}
0