QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#563700#7954. Special Numberssentheta#WA 1ms13852kbC++203.4kb2024-09-14 15:14:522024-09-14 15:14:53

Judging History

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

  • [2024-09-14 15:14:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:13852kb
  • [2024-09-14 15:14:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(int)a; i<(int)b; i++)
#define Int long long
#define V vector

void solve();
signed main(){
	solve();
}

const int MOD = 1e9+7;

int k;
int two, tri, fiv, svn;

V<int> fac;

int dp[22][68][43][30][25];

// #nonzero integer with nonzero digit product divisible by k
int f(string s){
	bool allZero = 1;
	for(char ch : s) allZero &= ch=='0';
	if(allZero) return 0;

	rep(i,0,s.size())
		rep(a,0,two+1) rep(b,0,tri+1) rep(c,0,fiv+1) rep(d,0,svn+1)
			dp[i][a][b][c][d] = 0;

	int sa=0, sb=0, sc=0, sd=0, zro=0;
	for(int i=0; i<s.size(); i++){
		// cerr << "i " << i << endl;
		int x = s[i]-'0';

		// prv(nonzero) + y
		// cerr << "prv + y" << endl;
		if(i>0) for(int y=1; y<=9; y++){
			rep(a,0,two+1) rep(b,0,tri+1) rep(c,0,fiv+1) rep(d,0,svn+1)
				(dp[i]
				[min(two,a+(y%2==0)+(y%4==0)+(y%8==0))]
				[min(tri,b+(y%3==0)+(y%9==0))]
				[min(fiv,c+(y%5==0))]
				[min(svn,d+(y%7==0))]
				+= dp[i-1][a][b][c][d] )%=MOD;
		}

		// pref(s) + y
		// cerr << "prefix + y" << endl;
		if(!zro) for(int y=1; y<x; y++){
			dp[i]
			[min(two,sa+(y%2==0)+(y%4==0)+(y%8==0))]
			[min(tri,sb+(y%3==0)+(y%9==0))]
			[min(fiv,sc+(y%5==0))]
			[min(svn,sd+(y%7==0))]
			+= 1;
		}
		zro |= x==0;
		sa += (x%2==0) + (x%4==0) + (x%8==0);
		sb += (x%3==0) + (x%9==0);
		sc += (x%5==0);
		sd += (x%7==0);

		// zeroes + y
		// cerr << "zeroes + y" << endl;
		if(i>0) for(int y=1; y<=9; y++){
			dp[i]
			[min(two,(int)(y%2==0)+(y%4==0)+(y%8==0))]
			[min(tri,(int)(y%3==0)+(y%9==0))]
			[min(fiv,(int)(y%5==0))]
			[min(svn,(int)(y%7==0))]
			++;
		}
	}

	// check s itself
	// cerr << "dp[last][last]... " << dp[s.size()-1][two][tri][fiv][svn] << '\n';
	int ret = dp[s.size()-1][two][tri][fiv][svn] + (!zro)*(sa>=two)*(sb>=tri)*(sc>=fiv)*(sd>=svn);
	return ret;
}

int dpg[22][2];
// #nonzero integer with zero digit product
int g(string s){
	bool allZero = 1;
	for(char ch : s) allZero &= ch=='0';
	if(allZero) return 0;

	rep(i,0,s.size())
		dpg[i][0] = dpg[i][1] = 0;

	int prod = 1;
	for(int i=0; i<s.size(); i++){
		int x = s[i]-'0';
		// cerr << "x: " << x << endl;

		// prv(nonzero) + y
		if(i>0) for(int y=0; y<=9; y++){
			(dpg[i][0] += dpg[i-1][0] )%=MOD;
			(dpg[i][(bool)(y)] += dpg[i-1][1] )%=MOD;
		}

		// pref(s) + y
		for(int y=(i==0?1:0); y<x; y++){
			dpg[i][prod&(bool)y]++;
		}
		prod &= (bool)x;

		// zeroes + y
		if(i>0) for(int y=1; y<=9; y++){
			dpg[i][1]++;
		}
	}

	// cerr << "g: dpg[last][0]: " << dpg[s.size()-1][0] << endl;
	// cerr << "prod " << prod << endl;
	int ret = dpg[s.size()-1][0] + (prod==0);
	return ret;
}


void solve(){
	string l, r;
	cin >> k >> l >> r;

	// substract 1 from l
	l.back()--;
	for(int i=l.size()-1; i>=0 && l[i]=='0'-1; i--){
		l[i] += 10;
		l[i-1]--;
	}
	// cerr << l << " " << r << endl;

	// factorize k
	while(k%2==0){
		k/=2; two++;
	}
	while(k%3==0){
		k/=3; tri++;
	}
	while(k%5==0){
		k/=5; fiv++;
	}
	while(k%7==0){
		k/=7; svn++;
	}
	// cerr << k << endl;

	int ans = 0;

	if(k==1){
		// nonzero product
		(ans += f(r) )%=MOD;
		(ans -= f(l) )%=MOD;
	}
	// cerr << "f: " << ans << '\n';
	// zero product
	(ans += g(r) )%=MOD;
	(ans -= g(l) )%=MOD;
	// cerr << "f+g: " << ans << '\n';


	ans = (ans%MOD+MOD)%MOD;
	cout << ans << '\n';
}

詳細信息

Test #1:

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

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

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

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 13852kb

input:

1 100 100000

output:

99801

result:

wrong answer 1st lines differ - expected: '99901', found: '99801'