QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#456332 | #8337. Counter Reset Problem | HuTao | WA | 20ms | 14048kb | C++14 | 1.9kb | 2024-06-27 18:35:40 | 2024-06-27 18:35:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5005, S = 10, M = 1 << 9 | 5, P = 1e9 + 9;
int n;
char a[N], b[N];
int go[M][S], f[N][M];
#define Add(x, y) (((x) += (y)) >= P && ((x) -= P))
inline void Read(char a[])
{
scanf("%s", a + 1);
int i;
for(i = 1; a[i]; i ++ ) a[i] -= '0';
reverse(a + 1, a + i);
}
inline void Del(char a[])
{
int t = 0;
for(int i = 1; i <= n; i ++ ) t |= a[i];
if(t)
{
for(int i = 1; i <= n; i ++ )
{
a[i] -- ;
if(a[i] != 9) break ;
}
}
}
inline LL Sum(char a[])
{
LL s = 1, t = 0;
for(int i = 1; i < n; i ++ )
{
t = (t + s * a[i]) % P;
s = s * 10 % P;
}
// printf("!%lld\n", t);
return (s * a[n] * (a[n] - 1) / 2 + (t + 1) * a[n]) % P;
}
inline void Init()
{
for(int i = 0; i < 1 << 9; i ++ )
{
go[i][0] = i;
for(int j = 0; j < 9; j ++ )
{
int t = j;
while(!((i >> t) & 1) && t >= 0) t -- ;
go[i][j + 1] = i ^ (1 << j);
if(t >= 0) go[i][j + 1] ^= 1 << t;
}
}
for(int i = 1; i < 1 << 9; i ++ )
f[0][i] = f[0][i & (i - 1)] + 1;
for(int i = 1; i <= n; i ++ )
for(int j = 0; j < 1 << 9; j ++ )
for(int k = 0; k <= 9; k ++ )
Add(f[i][j], f[i - 1][go[j][k]]);
}
inline LL DP(char a[])
{
int s = 0, ans = 0;
for(int i = n; i >= 1; i -- )
{
for(int j = 0; j < a[i]; j ++ )
Add(ans, f[i - 1][go[s][j]]);
s = go[s][int(a[i])];
}
ans += f[0][s];
// printf("!%d\n", ans);
return ans;
}
int main()
{
scanf("%d", &n);
Read(a), Read(b), Del(a);
Init();
LL s0 = (Sum(b) - Sum(a) + P) % P;
LL s1 = (DP(b) - DP(a) + P) % P;
LL ans = (s1 * 10 - s0 + P) % P;
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3868kb
input:
2 19 23
output:
51
result:
ok 1 number(s): "51"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3996kb
input:
6 100084 518118
output:
9159739
result:
ok 1 number(s): "9159739"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3952kb
input:
12 040139021316 234700825190
output:
771011551
result:
ok 1 number(s): "771011551"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3888kb
input:
1 5 6
output:
9
result:
ok 1 number(s): "9"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
2 06 72
output:
609
result:
ok 1 number(s): "609"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
3 418 639
output:
2912
result:
ok 1 number(s): "2912"
Test #7:
score: -100
Wrong Answer
time: 20ms
memory: 14048kb
input:
5000 0517031462295902016787205636287842713710486158285091634061538907131690102542613263904109051429895599547551249682345434244517372300211330243052548402051817254239088411128320032011447373157210750522722463984933692575118884942425236057310901139962840332684448050855646476051878413350560455871387882...
output:
107583354
result:
wrong answer 1st numbers differ - expected: '107583434', found: '107583354'