QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#347141#8337. Counter Reset Problemucup-team266#RE 142ms3992kbC++202.4kb2024-03-09 11:30:252024-03-09 11:30:28

Judging History

你现在查看的是最新测评结果

  • [2024-03-09 11:30:28]
  • 评测
  • 测评结果:RE
  • 用时:142ms
  • 内存:3992kb
  • [2024-03-09 11:30:25]
  • 提交

answer

/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
 
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts 
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest

9. module on time 
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<long long,long long>
#define mp make_pair
#define pb push_back
const int mod=1e9+9;
const int inf=0x3f3f3f3f;
const int INF=1e18;
int f[2][1<<10][2],g[2][1<<10][2];
int to[1<<10][10];
int n;
void add(int &x,int y)
{
	x+=y;
	if(x>=mod) x-=mod;
}
int calc(string lim)
{
	memset(f,0,sizeof(f)),memset(g,0,sizeof(g));
	for(int i=0;i+'0'<=lim[0];i++)
	{
		int tp=(i+'0'<lim[0]?1:0);
		g[0][(i==0?0:(1<<i))][tp]++,f[0][(i==0?0:(1<<i))][tp]+=(10-i)%10;
	}
	int nw=0;
	for(int i=1;i<n;i++)
	{
		nw^=1;
		memset(f[nw],0,sizeof(f[nw])),memset(g[nw],0,sizeof(g[nw]));
		for(int mask=0;mask<(1<<10);mask++) for(int tp=0;tp<2;tp++) if(f[nw^1][mask][tp]||g[nw^1][mask][tp])
		{
			for(int d=0;d<10;d++)
			{
				if(tp==0&&d+'0'>lim[i]) continue;
				int tp2=tp;
				if(d+'0'<lim[i]) tp2=1;
				if(to[mask][d]!=-1) add(f[nw][to[mask][d]][tp2],f[nw^1][mask][tp]),add(g[nw][to[mask][d]][tp2],g[nw^1][mask][tp]);
				else
				{
					add(f[nw][mask^(1<<d)][tp2],(f[nw^1][mask][tp]+10LL*g[nw^1][mask][tp])%mod),add(g[nw][mask^(1<<d)][tp2],g[nw^1][mask][tp]);
				}
			}
		}
	}
	int ans=0;
	for(int mask=0;mask<(1<<10);mask++) for(int tp=0;tp<2;tp++) add(ans,f[nw][mask][tp]);
	return ans;
}
string L,R;
void solve()
{
	cin>>n;
	cin>>L>>R;
	L[L.size()-1]--;
	for(int i=L.size()-1;i>=0;i--)
	{
		if(L[i]<'0') L[i]+=10,L[i-1]--;
		else break;
	}
	memset(to,-1,sizeof(to));
	for(int mask=0;mask<(1<<10);mask++) for(int i=0;i<10;i++) 
	{
		if(!i)
		{
			to[mask][i]=mask;
			continue;
		}
		for(int j=i;j>=0;j--) if(mask&(1<<j))
	{
		to[mask][i]=(mask^(1<<j)^(1<<i));
		break;
	}
	}
//	cout<<L<<" "<<R<<" "<<calc(L)<<" "<<calc(R)<<"\n";
	cout<<(calc(R)-calc(L)+mod)%mod;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _=1;
//	cin>>_;
	while(_--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3712kb

input:

2
19 23

output:

51

result:

ok 1 number(s): "51"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

6
100084 518118

output:

9159739

result:

ok 1 number(s): "9159739"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

12
040139021316 234700825190

output:

771011551

result:

ok 1 number(s): "771011551"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

1
5 6

output:

9

result:

ok 1 number(s): "9"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

2
06 72

output:

609

result:

ok 1 number(s): "609"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3964kb

input:

3
418 639

output:

2912

result:

ok 1 number(s): "2912"

Test #7:

score: 0
Accepted
time: 120ms
memory: 3660kb

input:

5000
0517031462295902016787205636287842713710486158285091634061538907131690102542613263904109051429895599547551249682345434244517372300211330243052548402051817254239088411128320032011447373157210750522722463984933692575118884942425236057310901139962840332684448050855646476051878413350560455871387882...

output:

107583434

result:

ok 1 number(s): "107583434"

Test #8:

score: 0
Accepted
time: 123ms
memory: 3704kb

input:

5000
2839631722409885676641854449409094340492285620998199901290315528351589154393629439187822315178094894928108915180727622985054953310653613329475433266861767377091508110388139487587162480394472451041742086595826537286229012805321959193382957731290351060584443229684181235109638118508206073343246746...

output:

675394398

result:

ok 1 number(s): "675394398"

Test #9:

score: 0
Accepted
time: 142ms
memory: 3800kb

input:

5000
0121086815228520611727091239718315691985426539178955693257347642954702438161323478758508490896602335048895013843711247876462745921412007803120100676220049634783076688779134708737789972863426435630047856085762842025741483042162463573248808646044510524282002015852558702184741741663627502716091539...

output:

578074633

result:

ok 1 number(s): "578074633"

Test #10:

score: 0
Accepted
time: 124ms
memory: 3992kb

input:

5000
4009315923866078525437170431271052539467314353326632440452295409898108927334934001515186676883568587509019024813648111170281871732854866326020722523420074725860024843129825137935119924032162976610499681775742229100481059217175250566980703955103400572138763397380102014106688956905053311588400020...

output:

819323161

result:

ok 1 number(s): "819323161"

Test #11:

score: -100
Runtime Error

input:

5000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:


result: