QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377836#7996. 报数 IVDestinyAC ✓983ms60836kbC++175.3kb2024-04-05 18:35:252024-04-05 18:35:25

Judging History

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

  • [2024-04-05 18:35:25]
  • 评测
  • 测评结果:AC
  • 用时:983ms
  • 内存:60836kb
  • [2024-04-05 18:35:25]
  • 提交

answer

#include<bits/stdc++.h>
#ifndef xxx
#define dbg(...) ;
#endif
using namespace std;
template<class T> ostream &operator<<(ostream &o, const vector <T> &v) { bool f=false; for(T i:v) { f?o<<' ':o; o<<(i); f=true; } return o; }
template<class T> void sort(T &v) { std::sort(v.begin(), v.end()); }
template<class T, class C> void sort(T &v, C c) { std::sort(v.begin(), v.end(), c); }
template<class T> void reverse(T &v) { std::reverse(v.begin(), v.end()); }
template<class T> bool is_sorted(T &v) { return std::is_sorted(v.begin(), v.end()); }
template<class T> inline void _min(T &x, const T &y) { x>y?x=y:x; }
template<class T> inline void _max(T &x, const T &y) { x<y?x=y:x; }
istream &operator>>(istream &i, __int128_t &x) { x=0; short f=1; char c=0; while(!isdigit(c)) { if(c=='-')f=-1; c=i.get(); } while(isdigit(c))x=x*10+c-'0', c=i.get(); x*=f; return i; }
ostream &operator<<(ostream &o, __int128_t x) { if(x==0) { o<<0; return o; } bool f=false; string s; if(x<0)f=true, x=-x; while(x)s+=x%10+'0', x/=10; reverse(s); if(f)o<<'-'; o<<s; return o; }
mt19937 mt(time(0));
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
constexpr int maxn=1e4+5;
constexpr int mod=1e9+7;
constexpr int inf=0x3f3f3f3f;
constexpr ll INF=0x3f3f3f3f3f3f3f3fll;
constexpr double pi=acos(-1.0);
constexpr double eps=1e-9;
template <int m>
struct static_modint
{
	using mint=static_modint;

public:
	static_modint() : v(0) {}
	template <class T>
	static_modint(T x)
	{
		x=(x%(ll)(umod()));
		if(x<0)x+=umod();
		v=(unsigned int)(x);
	}

	static_modint(bool x) { v=((unsigned int)(x)%umod()); }

	unsigned int val() const { return v; }

	mint &operator++()
	{
		v++;
		if(v==umod()) v=0;
		return *this;
	}

	mint &operator--()
	{
		if(v==0) v=umod();
		v--;
		return *this;
	}

	mint operator++(int)
	{
		mint result=*this;
		++*this;
		return result;
	}

	mint operator--(int)
	{
		mint result=*this;
		--*this;
		return result;
	}

	mint &operator+=(const mint &rs)
	{
		v+=rs.v;
		if(v>=umod()) v-=umod();
		return *this;
	}

	mint &operator-=(const mint &rs)
	{
		if(v<rs.v) v+=umod();
		v-=rs.v;
		return *this;
	}

	mint &operator*=(const mint &rs)
	{
		ull z=v;
		z*=rs.v;
		v=(unsigned int)(z%umod());
		return *this;
	}

	mint &operator/=(const mint &rs) { return *this=*this*rs.inv(); }

	mint operator+() const { return *this; }
	mint operator-() const { return mint()-*this; }

	mint pow(ll n) const
	{
		assert(n>=0);
		mint x=*this, r=1;
		while(n)
		{
			if(n&1) r*=x;
			x*=x;
			n>>=1;
		}
		return r;
	}

	mint inv() const
	{
		//assert(v);
		return pow(umod()-2);
	}

	istream &operator>>(istream &in)
	{
		in>>v;
		*this=static_modint(v);
		return in;
	}

	ostream &operator<<(ostream &o)const
	{
		o<<v;
		return o;
	}

	friend mint operator+(const mint &l, const mint &r)
	{
		return mint(l)+=r;
	}

	friend mint operator-(const mint &l, const mint &r)
	{
		return mint(l)-=r;
	}

	friend mint operator*(const mint &l, const mint &r)
	{
		return mint(l)*=r;
	}

	friend mint operator/(const mint &l, const mint &r)
	{
		return mint(l)/=r;
	}

	friend bool operator==(const mint &l, const mint &r)
	{
		return l.v==r.v;
	}

	friend bool operator!=(const mint &l, const mint &r)
	{
		return l.v!=r.v;
	}

	friend bool operator<(const mint &l, const mint &r)
	{
		return l.v<r.v;
	}

	friend bool operator>(const mint &l, const mint &r)
	{
		return l.v>r.v;
	}

	friend bool operator<=(const mint &l, const mint &r)
	{
		return l.v<=r.v;
	}

	friend bool operator>=(const mint &l, const mint &r)
	{
		return l.v>=r.v;
	}

	friend ostream &operator<<(ostream &o, mint u)
	{
		u.operator<<(o);
		return o;
	}

	friend istream &operator>>(istream &in, mint &u)
	{
		u.operator>>(in);
		return in;
	}

private:
	unsigned int v;
	static constexpr unsigned int umod() { return m; }
};
typedef static_modint<mod> mint;

int val[maxn][6];
void init(const int n=9000)
{
	auto f=[](int x)->int
	{
		string s=to_string(x);
		int ans=0;
		for(char c:s)
		{
			ans+=c-'0';
		}
		return ans;
	};
	for(int i=1; i<=n; i++)
		val[i][0]=i;
	for(int i=1; i<=n; i++)
	{
		for(int k=1; k<=5; k++)
		{
			val[i][k]=f(val[i][k-1]);
		}
	}
}
string N;
int k, m;
int timestamp=0;
int vis[1005][9005];
mint f[1005][9005];
const int LIMIT_TAR[]={0, 9000, 35, 11, 9, 9};
mint dfs(int pos, bool limited, bool leading_zero, int sum)
{
	if(pos==0)
	{
		return val[sum][k-1]==m;
	}
	if(!limited&&!leading_zero&&vis[pos][sum]==timestamp)return f[pos][sum];
	mint ans=0;
	int lim=limited?N[N.size()-pos]-'0':9;
	for(int i=0; i<=lim; i++)
	{
		ans+=dfs(pos-1, limited&&i==lim, leading_zero&&!i, sum+i);
	}
	if(!limited&&!leading_zero)
	{
		vis[pos][sum]=timestamp;
		return f[pos][sum]=ans;
	}
	return ans;
}
mint calc()
{
	timestamp++;
	return dfs(N.size(), true, true, 0);
}
mint getans()
{
	_min(k, 4);
	return calc();
}
int main()//MARK: main
{
#ifndef xxx
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#endif
	cout<<fixed<<setprecision(10);
	init();
	int t;
	cin>>t;
	while(t--)
	{
		cin>>N>>k>>m;
		cout<<getans()<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 39268kb

input:

2
114 1 5
514 2 10

output:

8
10

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 40044kb

input:

5
114 1 5
514 2 10
114514 3 7
1919810 2 13
1145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810114514191981011451419198101145141919810 1 79

output:

8
10
12724
504
481046284

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 951ms
memory: 60740kb

input:

5
3134666912140933323880320519044791121794814671711104987304374190280064994554822259889216567113228716903875026053927191961850586115167336109747673868148288830282192461669674173201533887392623483710043038941036243583011049049915834937139438028987629569618561762595613799223807979488245056374812076511...

output:

0
613343513
0
500149787
932367667

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 969ms
memory: 60608kb

input:

5
1139519997005658838804233882542131329603951012645222504700958241682545257324091070752720569220022637054777343187779232016568942045167801853025395316038491270541841827939668031807503056209394655628349207403327386083909984082879989255237547274110143051980886947606735206241362546384481120301780245959...

output:

0
0
983106233
842410978
351127737

result:

ok 5 lines

Test #5:

score: 0
Accepted
time: 956ms
memory: 60528kb

input:

5
8638076091316635855641492966551052879887835736093039980247820372626975300011595185556660107638347885877620156412525017113706895612406460047827904025826640853053762221239009476530804397983925491363476392003741370633988524528072186299564325622601218035310613510134479162974878452692502169127286160440...

output:

0
151494485
491996396
951216080
735591005

result:

ok 5 lines

Test #6:

score: 0
Accepted
time: 965ms
memory: 60748kb

input:

5
4594403190887655851098979323885347301970260472182981436563110607463337770897498592230279433635011809482497666151819612860549852933087582131069399973150048275594755688227873941703801791577493672811179138154635173296855021815570777969295164438906410283251071005981539590431740858876880832337309525533...

output:

452162993
993032288
529250142
0
0

result:

ok 5 lines

Test #7:

score: 0
Accepted
time: 934ms
memory: 60472kb

input:

5
7106329661074460076851813089444392472728206874451143771638786962963099120130351553150316525985245033972323999641553983578568333846746709032264525531367915930983812069660457027974526824268427908058438462283103774963889147187903776098321357665707620452891363086885353145154955480116362167820560099473...

output:

0
42143665
0
0
266635325

result:

ok 5 lines

Test #8:

score: 0
Accepted
time: 946ms
memory: 60500kb

input:

5
3197096843267069616758413776891049764649182364659681310636123435063129351340319661216252795154685419993835505771367978692486745621757064307866143997529010856187698866761085397967488612326286182291301655780420802213700700872824442868225191222911023750488609973480926167606063152176688092948837104972...

output:

447917122
738150576
134709012
571675718
0

result:

ok 5 lines

Test #9:

score: 0
Accepted
time: 928ms
memory: 60484kb

input:

5
7612942550467855237767978070830743429305395120370014044416141696259440200835613011108477499855450341979327882148431400498007877975643997499046007388707405687392636406520850657394581417406913024784851871291661719356877660941151602720564069428677800545614776632869404791295787921432277016643912651129...

output:

0
264129072
541216127
357954287
0

result:

ok 5 lines

Test #10:

score: 0
Accepted
time: 948ms
memory: 60624kb

input:

5
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

0
0
0
0
0

result:

ok 5 lines

Test #11:

score: 0
Accepted
time: 961ms
memory: 60600kb

input:

5
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

910755804
259808709
937821856
357970005
357970004

result:

ok 5 lines

Test #12:

score: 0
Accepted
time: 983ms
memory: 60648kb

input:

5
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
0
0
0
0

result:

ok 5 lines

Test #13:

score: 0
Accepted
time: 955ms
memory: 60564kb

input:

5
5493600942860040477621631776833866796633825984175588516360787148451695869301784861251377693592220895430016092915864584070561727072786074401876239679966435830840108325415158767012889770532442098922126012279790947926699687673153716303479935588263453954268774120993175103389470374955885050132475090943...

output:

0
300754613
527108222
803186040
892721871

result:

ok 5 lines

Test #14:

score: 0
Accepted
time: 956ms
memory: 60612kb

input:

5
1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

320215386
716889023
567624008
357970005
357970006

result:

ok 5 lines

Test #15:

score: 0
Accepted
time: 943ms
memory: 60576kb

input:

5
9812761167325920856130376846862436937947447230654673184010669691739766031552475237221268849030438467080297886603870858917934654394088222131015941324484064243169674411393827605062172844413306867153409653032875875932730337155928621241642891239404177544951325020506663647342309917196598863243062161544...

output:

0
469928597
497418961
0
391423761

result:

ok 5 lines

Test #16:

score: 0
Accepted
time: 956ms
memory: 60504kb

input:

5
9013501952727330363984611655757069529140061668352243348131242141715906906114807898855698384965618856928927417081394644166161162830825179502161401400642096135223979387761058683717466953382929504725324258978052930668420706866257850069631732579721803675116406468720025921542594305209295461027074284529...

output:

385295755
0
826010110
468568966
0

result:

ok 5 lines

Test #17:

score: 0
Accepted
time: 950ms
memory: 60608kb

input:

5
8299276307146554536050575918961724216373725603114732403143797725790612708959386530057274467495195402828666463169527607000394687018773329311746262289704318815996536046048237937697238691975566621555830914989783566285006290394230091450543627201211538144590398957372070315341068147825604925011592907516...

output:

0
510867977
0
343376120
214886107

result:

ok 5 lines

Test #18:

score: 0
Accepted
time: 950ms
memory: 60680kb

input:

5
5978386495534656451410085599244329473463314859713321863671010880820574367293215984254435511977274737538376669406905970846704986107233076928078383576465358933281714235428695844731759396130287355362520342786149980212289046796827813545285558877894772706667916112882424152831253823242761178245591040551...

output:

200381997
248732590
659988610
728803841
281731921

result:

ok 5 lines

Test #19:

score: 0
Accepted
time: 946ms
memory: 60636kb

input:

5
3653745784886652871154357862309923857817567252560725002381570519161248252147392315049190794174402649782040388482129025970204654043850249370372033244471538178164319261755776547097203201498608147530621634820597155316537832780268365695458704201328436275425247055333335893078213722495376788491166394840...

output:

0
827622189
909406252
224192882
472231991

result:

ok 5 lines

Test #20:

score: 0
Accepted
time: 957ms
memory: 60836kb

input:

5
8033033272391208112504025738196814953295344818136472894597554051040020955286362518341894063333412258812817219386808976514037940329057156352396807896773931916676875163079204283714827821854630201268421360605246824369120510639882686009186217462096143084170888173631995492474470043432451899005431488434...

output:

210535726
822079653
985955681
540372548
893241037

result:

ok 5 lines

Test #21:

score: 0
Accepted
time: 968ms
memory: 60624kb

input:

5
5567143473825105413062640204906776053975645715210961093621242820515284746059383788299405075430487954445602098969989027355660374546878999126847721403752212660945084700687121976823655410921184811436776882931203119629438066770465897899783553110960619700314302907304525788754873835497787674395031347966...

output:

0
0
358266018
0
50998365

result:

ok 5 lines