結果
問題 | No.2455 Numbers Dictionary |
ユーザー |
|
提出日時 | 2023-09-01 22:43:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 1,103 bytes |
コンパイル時間 | 1,701 ms |
コンパイル使用メモリ | 194,676 KB |
最終ジャッジ日時 | 2025-02-16 17:04:03 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
#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;}int cp = 0;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 (cp < 0) {nm += tm[x];continue;}if (cp > 0 && x == n - pkj - 1) {break;}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;}if (cp == 0) {if (s[pkj] < t[pkj]) {cp = 1;}if (s[pkj] > t[pkj]) {cp = -1;}}ans ++;}cout << ans << endl;}int main () {int T;cin >> T;while (T--) {solve();}}