QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#351406 | #8337. Counter Reset Problem | ucup-team134 | RE | 1ms | 3956kb | C++17 | 1.6kb | 2024-03-11 21:39:48 | 2024-03-11 21:39:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+9;
int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
int sub(int x,int y){x-=y;return x<0?x+mod:x;}
int mul(int x,int y){return (ll)x*y%mod;}
void ckadd(int&x,int y){x=add(x,y);}
const int N=5050;
char L[N],R[N];
int n;
int Add(int mask,int x){
if(x==0)return mask;
x--;
for(int i=x;i>=0;i--){
if(mask>>i&1){
mask^=1<<i;
break;
}
}
return mask|(1<<x);
}
const int M=1<<9;
int dp[2][M];
int Calc(char*s){
int all=0;
int now=0,pre=1;
for(int mask=0;mask<M;mask++)dp[now][mask]=0;
for(int i=1;i<=n;i++){
swap(now,pre);
for(int mask=0;mask<M;mask++){
dp[now][mask]=0;
}
for(int x=0;x<s[i]-'0';x++){
ckadd(dp[now][Add(all,x)],1);
}
all=Add(all,s[i]-'0');
for(int x=0;x<10;x++){
for(int mask=0;mask<M;mask++){
ckadd(dp[now][Add(mask,x)],dp[pre][mask]);
}
}
}
ckadd(dp[now][all],1);
int ans=0;
for(int mask=0;mask<M;mask++){
ckadd(ans,mul(__builtin_popcount(mask),dp[now][mask]));
}
ans=mul(ans,10);
int po=1;
for(int i=1;i<n;i++)po=mul(po,10);
for(int fir=0;fir<s[1]-'0';fir++){
ans=sub(ans,mul(po,fir));
}
int val=0;
for(int i=2;i<=n;i++){
val=mul(val,10);
ckadd(val,s[i]-'0');
}
ckadd(val,1);
ans=sub(ans,mul(val,s[1]-'0'));
return ans;
}
int main(){
scanf("%i",&n);
scanf("%s %s",L+1,R+1);
int ans=Calc(R);
bool zero=true;
for(int i=1;i<=n;i++)if(L[i]!='0')zero=false;
if(!zero){
L[n]--;
for(int i=n;i>1;i--){
if(L[i]<0){
L[i]+=10;
L[i-1]--;
}
}
ans=sub(ans,Calc(L));
}
printf("%i\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3768kb
input:
2 19 23
output:
51
result:
ok 1 number(s): "51"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
6 100084 518118
output:
9159739
result:
ok 1 number(s): "9159739"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3956kb
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: 3808kb
input:
2 06 72
output:
609
result:
ok 1 number(s): "609"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
3 418 639
output:
2912
result:
ok 1 number(s): "2912"
Test #7:
score: -100
Runtime Error
input:
5000 0517031462295902016787205636287842713710486158285091634061538907131690102542613263904109051429895599547551249682345434244517372300211330243052548402051817254239088411128320032011447373157210750522722463984933692575118884942425236057310901139962840332684448050855646476051878413350560455871387882...