QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#348657 | #8337. Counter Reset Problem | ucup-team135# | WA | 26ms | 163792kb | C++20 | 2.0kb | 2024-03-09 20:18:48 | 2024-03-09 20:18:48 |
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)
{
if(!dp[i][mask][was]) continue;
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;n=5000;
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: 0
Wrong Answer
time: 26ms
memory: 163792kb
input:
2 19 23
output:
171
result:
wrong answer 1st numbers differ - expected: '51', found: '171'