QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#302221 | #7954. Special Numbers | Yarema# | WA | 0ms | 3776kb | C++20 | 1.8kb | 2024-01-10 17:41:51 | 2024-01-10 17:41:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 47;
const int mod = 1e9 + 7;
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
int sub(int a, int b)
{
return a - b >= 0 ? a - b : a - b + mod;
}
LL k;
map<LL, int> dp[N][3];
int f(string s)
{
FOR (i, 0, N)
{
FOR (j, 0, 3)
dp[i][j].clear();
}
int n = SZ(s);
FOR (i, 0, n)
s[i] -= '0';
FOR (i, 1, s[0])
dp[0][1][i % k] += 1;
dp[0][0][s[0] % k] += 1;
if (SZ(s) != 1)
{
FOR (i, s[0] + 1, 10)
dp[0][2][i % k] += 1;
}
int ans = dp[0][0][0] + dp[0][1][0] + dp[0][2][0];
//cerr << ans << '\n';
FOR (i, 1, n)
{
FOR (j, 0, 3)
{
FOR (d, 0, 10)
{
for (auto [rem, w] : dp[i - 1][j])
{
int j2 = 1;
if (j == 2 || (j == 0 && d > s[i]))
j2 = 2;
else if (j == 0 && d == s[i])
j2 = 0;
LL r = rem * d % k;
dp[i][j2][r] = add(dp[i][j2][r], w);
}
}
}
ans = add(ans, add(dp[i][0][0], dp[i][1][0]));
if (i != n - 1)
ans = add(ans, dp[i][2][0]);
//cerr << i << ' ' << ans << '\n';
}
if (s[0] != 0)
ans++;
FOR (i, 0, n)
s[i] += '0';
//cerr << s << ' ' << ans << '\n';
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
string l, r;
cin >> k >> l >> r;
int j = SZ(l) - 1;
while (l[j] == '0')
{
l[j] = '9';
j--;
}
l[j]--;
cout << sub(f(r), f(l)) << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
input:
5 1 20
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
5 50 100
output:
19
result:
ok single line: '19'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
15 11 19
output:
0
result:
ok single line: '0'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3600kb
input:
1 100 100000
output:
99791
result:
wrong answer 1st lines differ - expected: '99901', found: '99791'