結果

問題 No.2455 Numbers Dictionary
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-09-01 22:40:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 973 bytes
コンパイル時間 1,994 ms
コンパイル使用メモリ 196,048 KB
最終ジャッジ日時 2025-02-16 17:01:56
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
	string s;
	string t;
	cin >> s >> t;
	ll ans = 0;
	int n = s.size(), nk = t.size();
	ll val[20];
	for (int i = 0; i < n - 1; i ++) {
		val[i] = stoll(s.substr(i + 1, n - i - 1)) + 1;
	}
	val[n - 1] = 0;
	ll tm[20];
	tm[0] = 1;
	for (int i = 1; i < 18; i ++) {
		tm[i] = tm[i - 1] * 10;
	}
	bool eq = true;
	for (int pkj = 0; pkj < nk; pkj ++) {
		// ll sm = 0;
		int i = (pkj == 0);
		for (; i < t[pkj] - '0'; i ++) {
			ll nm = 0;
			for (int x = 0; x < n - pkj; x ++) {
				if (!eq) {
					nm += tm[x];
					continue;
				}
				if (i == s[pkj] - '0' && x == n - pkj - 1) {
					nm += val[pkj];
				} else if (i > s[pkj] - '0' && x == n - pkj - 1) {
                    break;
                } else {
					nm += tm[x];
				}
			}
			ans += nm;
		}
		eq = eq && (s[pkj] == t[pkj]);
        ans ++;
	}
	cout << ans << endl;
}
int main () {
	int T;
	cin >> T;
	while (T--) {
		solve();
	}
}
0