QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#184620#6741. Digitbulijiojiodibuliduo#AC ✓1528ms17972kbC++1.8kb2023-09-20 23:44:102023-09-20 23:44:11

Judging History

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

  • [2023-09-20 23:44:11]
  • 评测
  • 测评结果:AC
  • 用时:1528ms
  • 内存:17972kb
  • [2023-09-20 23:44:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

struct Hash_table {
	static const int V=1000003;
	int fst[V],nxt[V];
	int ctm,ptm[V],T;
	int val[V];
	ll key[V];
	void init() { T=0; ctm++;}
	void insert(ll s,int v) {
		int S=s%V;
		if (ptm[S]!=ctm) ptm[S]=ctm,fst[S]=-1;
		for (int j=fst[S];j!=-1;j=nxt[j]) if (key[j]==s) {
			val[j]=v;
			return;
		}
		nxt[T]=fst[S],fst[S]=T,key[T]=s,val[T]=v;
		T++;
	}
	int query(ll s) {
		int S=s%V;
		if (ptm[S]!=ctm) return -1;
		for (int j=fst[S];j!=-1;j=nxt[j]) if (key[j]==s) 
			return val[j];
		return -1;
	}
}dp;

typedef unsigned long long u64;
u64 n,N,inv[33];

int calc(u64 x) {
	if (x>N) return 0;
	int v=dp.query(x);
	if (v!=-1) return v;
	vector<int> dd;
	u64 xx=x;
	while (xx) {
		dd.pb(xx%10);
		xx/=10;
	}
	int m=SZ(dd);
	ll val=0;
	int zp=0;
	rep(i,0,m) if (dd[i]>0) {
		val=(val+calc(x*(dd[i]+1)));
	} else {
		zp++;
	}
	val%=mod;
	val=(val*inv[m-zp]+m*inv[m-zp])%mod;
	dp.insert(x,val);
	return val;
}

void solve() {
	scanf("%llu%llu",&n,&N);
	dp.init();
	printf("%d\n",calc(n));
}

int _;
int main() {
	rep(i,1,20) inv[i]=powmod(i,mod-2);
	for (scanf("%d",&_);_;_--) {
		solve();
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11932kb

input:

3
1 10
1 100
1 1000

output:

3
4
942786340

result:

ok 3 number(s): "3 4 942786340"

Test #2:

score: 0
Accepted
time: 1027ms
memory: 17972kb

input:

200
6093 473302679260560320
8548 407261659389622784
643 187875386337017408
8115 804844129595563776
3331 457909423622471360
8554 769878068775393152
2189 248771553604839360
7395 486014798136226944
8022 834223266052054400
9218 291007794161740672
8431 738787973811775616
1829 183591119896739584
816 23406...

output:

401752224
25564055
349247348
24571488
454552241
293307892
841921314
316896313
340265070
679232017
880794571
220757927
783764236
593413719
368463075
771186516
780654585
3628414
827863355
617858224
868927625
446978548
351494058
130284374
125073939
38120850
748432314
277667083
183850680
235708406
51111...

result:

ok 200 numbers

Test #3:

score: 0
Accepted
time: 151ms
memory: 16928kb

input:

200
3043059018339257 22277869996577613
9995869516 503712331451
389592 72563932968
3520234478258 476959582208156
77586585 711120211545804458
77846354 2243822883730937
9937954107 8390895135555
39032 603567
7739 4682236745217490
12277973519 7136059697857236
7264388 607094625
66205992799 4030219735546
3...

output:

108920162
651706276
549514920
440563412
796578996
851857830
191543780
540715694
549223125
380090491
553492005
247956062
582309209
67430878
174114881
1
669072219
981051601
561639793
304668111
397423058
607062211
8458982
479445466
287831358
913943402
533482140
801644611
519995972
239199505
587671914
2...

result:

ok 200 numbers

Test #4:

score: 0
Accepted
time: 1528ms
memory: 15588kb

input:

200
58 999999999999997440
75 999999999999999872
52 999999999999997696
85 999999999999999360
12 999999999999999488
77 999999999999999232
80 999999999999999232
36 999999999999997184
51 999999999999998720
79 999999999999997440
76 999999999999998592
90 999999999999997696
32 999999999999998336
67 9999999...

output:

603520497
574767370
222266238
241598642
627473669
958322466
776467011
836867165
317725053
772230956
80008248
170
205889745
956913345
252066713
183389093
251365357
387390363
836867165
660512518
265265911
574767370
317725053
620530996
15655429
247241569
103698881
940321220
960908253
960908253
66051251...

result:

ok 200 numbers

Test #5:

score: 0
Accepted
time: 485ms
memory: 16716kb

input:

200
509411 999999999999999232
33801448 999999999999998720
65 999999999999998208
6 999999999999997184
404287 999999999999999360
800418816395 999999999999999232
44589090134507 999999999999997312
2008080 999999999999999360
13 999999999999998976
87 999999999999999872
206327851576605 999999999999999744
3...

output:

883813861
221710219
620530996
252066714
168038945
932330901
77414612
443356611
1883978
608670663
568648025
891202485
151357997
793825022
180372901
749235099
391331669
890726608
103698881
258627374
738512765
18273750
771644777
916674174
110687232
890972839
85823452
799141196
739829892
675630993
44879...

result:

ok 200 numbers

Test #6:

score: 0
Accepted
time: 1495ms
memory: 17856kb

input:

200
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 1000000000000000000
1 10000000...

output:

252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
252066716
...

result:

ok 200 numbers