QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#348650 | #8337. Counter Reset Problem | ucup-team135# | TL | 32ms | 163940kb | C++20 | 2.0kb | 2024-03-09 20:17:05 | 2024-03-09 20:17:06 |
Judging History
answer
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx","avx2","popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define app push_back
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << endl;}(#__VA_ARGS__, ":", __VA_ARGS__)
#else
#define debug(...)
#endif
#ifdef LOCAL
#define __int128 long long
#endif // LOCAL
const int inf=1e18;
const int p=1e9+9;
int dp[5005][1024][2];
int dp2[5005][1024][2];
int f(int mask,int d)
{
for(int i=d;i>=0;--i)
{
if(mask & (1<<i)) {mask-=(1<<i);break;}
}
if(d) mask+=(1<<d);
return mask;
}
int go(string s,bool ok)
{
for(int i=0;i<5005;++i) {for(int j=0;j<1024;++j) {for(int k=0;k<2;++k) {dp[i][j][k]=0;dp2[i][j][k]=0;}}}
int n=s.size();
dp[0][0][0]=1;dp2[0][0][0]=1;
for(int i=0;i<n;++i)
{
for(int mask=0;mask<1024;++mask) {
for(int was=0;was<2;++was)
{
for(int d=0;d<=9;++d)
{
int newwas;
if(was) {newwas=1;}
else if(d<s[i]-'0') {newwas=1;}
else if(d==s[i]-'0') {newwas=0;}
else {continue;}
int newi=i+1;int newmask=f(mask,d);
dp[newi][newmask][newwas]+=dp[i][mask][was];dp[newi][newmask][newwas]%=p;
dp2[newi][newmask][newwas]+=(i!=0 ? dp2[i][mask][was] : d*dp[i][mask][was]);dp2[newi][newmask][newwas]%=p;
}
}
}
}
int res=0;
for(int mask=0;mask<1024;++mask)
{
for(int was=0;was<2;++was)
{
if(was || ok)
{
res+=dp[n][mask][was]*__builtin_popcount(mask)*10;res%=p;
res-=dp2[n][mask][was];res%=p;
}
}
}
return res;
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;cin>>n;
string l,r;cin>>l>>r;
cout<<((go(r,true)-go(l,false))%p+p)%p;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 21ms
memory: 163684kb
input:
2 19 23
output:
51
result:
ok 1 number(s): "51"
Test #2:
score: 0
Accepted
time: 32ms
memory: 163748kb
input:
6 100084 518118
output:
9159739
result:
ok 1 number(s): "9159739"
Test #3:
score: 0
Accepted
time: 23ms
memory: 163704kb
input:
12 040139021316 234700825190
output:
771011551
result:
ok 1 number(s): "771011551"
Test #4:
score: 0
Accepted
time: 15ms
memory: 163732kb
input:
1 5 6
output:
9
result:
ok 1 number(s): "9"
Test #5:
score: 0
Accepted
time: 29ms
memory: 163756kb
input:
2 06 72
output:
609
result:
ok 1 number(s): "609"
Test #6:
score: 0
Accepted
time: 24ms
memory: 163940kb
input:
3 418 639
output:
2912
result:
ok 1 number(s): "2912"
Test #7:
score: -100
Time Limit Exceeded
input:
5000 0517031462295902016787205636287842713710486158285091634061538907131690102542613263904109051429895599547551249682345434244517372300211330243052548402051817254239088411128320032011447373157210750522722463984933692575118884942425236057310901139962840332684448050855646476051878413350560455871387882...