結果

問題 No.2455 Numbers Dictionary
ユーザー SSRSSSRS
提出日時 2023-09-01 21:37:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 940 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 203,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-01 21:37:29
合計ジャッジ時間 5,224 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 33 ms
4,376 KB
testcase_03 AC 34 ms
4,376 KB
testcase_04 AC 39 ms
4,376 KB
testcase_05 AC 34 ms
4,376 KB
testcase_06 AC 44 ms
4,380 KB
testcase_07 AC 54 ms
4,380 KB
testcase_08 AC 28 ms
4,376 KB
testcase_09 AC 44 ms
4,380 KB
testcase_10 AC 43 ms
4,380 KB
testcase_11 AC 46 ms
4,380 KB
testcase_12 AC 33 ms
4,380 KB
testcase_13 AC 44 ms
4,376 KB
testcase_14 AC 38 ms
4,376 KB
testcase_15 AC 43 ms
4,380 KB
testcase_16 AC 23 ms
4,380 KB
testcase_17 AC 45 ms
4,376 KB
testcase_18 AC 20 ms
4,376 KB
testcase_19 AC 36 ms
4,380 KB
testcase_20 AC 44 ms
4,376 KB
testcase_21 AC 45 ms
4,376 KB
testcase_22 AC 37 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    long long N, K;
    cin >> N >> K;
    string S = to_string(K);
    int L = S.size();
    string T = to_string(N);
    int L2 = T.size();
    vector<long long> TEN(L2);
    TEN[0] = 1;
    for (int j = 0; j < L2 - 1; j++){
      TEN[j + 1] = TEN[j] * 10;
    }
    long long ans = 0;
    long long x = 0;
    for (int j = 0; j < L; j++){
      if (j > 0){
        ans++;
      }
      for (int k = 0; k < S[j] - '0'; k++){
        if (!(j == 0 && k == 0)){
          long long y = x * 10 + k;
          for (int l = 0; j + 1 + l <= L2; l++){
            long long mn = y * TEN[l];
            long long mx = (y + 1) * TEN[l] - 1;
            mx = min(mx, N);
            ans += max(mx - mn + 1, (long long) 0);
          }
        }
      }
      x *= 10;
      x += S[j] - '0';
    }
    ans++;
    cout << ans << endl;
  }
}
0