結果
問題 | No.2032 Let's Write Multiples!! |
ユーザー | SSRS |
提出日時 | 2022-08-05 21:59:02 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,457 bytes |
コンパイル時間 | 1,677 ms |
コンパイル使用メモリ | 173,416 KB |
実行使用メモリ | 13,724 KB |
最終ジャッジ日時 | 2023-10-13 22:47:01 |
合計ジャッジ時間 | 7,745 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,724 KB |
testcase_01 | AC | 107 ms
4,352 KB |
testcase_02 | AC | 99 ms
4,348 KB |
testcase_03 | AC | 99 ms
4,352 KB |
testcase_04 | AC | 128 ms
4,352 KB |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; long long solve(int N, int K, int C){ string S = to_string(N); int L = S.size(); vector<vector<vector<long long>>> cnt(L + 1, vector<vector<long long>>(2, vector<long long>(K, 0))); vector<vector<vector<long long>>> sum(L + 1, vector<vector<long long>>(2, vector<long long>(K, 0))); cnt[0][0][0] = 1; for (int i = 0; i < L; i++){ for (int j = 0; j < 2; j++){ for (int k = 0; k < K; k++){ if (cnt[i][j][k] > 0){ for (int l = 0; l < 10; l++){ if (j == 0 && l > S[i] - '0'){ continue; } int j2 = j; if (l < S[i] - '0'){ j2 = 1; } int k2 = (k * 10 + l) % K; cnt[i + 1][j2][k2] += cnt[i][j][k]; sum[i + 1][j2][k2] += sum[i][j][k]; if (l == C){ sum[i + 1][j2][k2] += cnt[i][j][k]; } } } } } } return sum[L][1][0]; } int main(){ int T; cin >> T; for (int i = 0; i < T; i++){ int L, R, K, C; cin >> L >> R >> K >> C; if ((R - L) / K < 50000){ int ans = 0; for (int j = (L + K - 1) / K * K; j <= R; j += K){ int k = j; while (k > 0){ if (k % 10 == C){ ans++; } k /= 10; } } cout << ans << endl; } else { cout << solve(R + 1, K, C) - solve(L, K, C) << endl; } } }