QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610766#8932. Bingoucup-team4975#WA 53ms11948kbC++171.9kb2024-10-04 17:19:472024-10-04 17:19:52

Judging History

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

  • [2024-10-04 17:19:52]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:11948kb
  • [2024-10-04 17:19:47]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000100;
const int M=105;
int n[N],m,nlen,mlen;
const int inf=0x3f3f3f3f3f3f3f3fll;
char tmp[N];
int pow10i[N],lst[M],h[N],g[N],f[N],nmd10i[M];
void add(int k) {
	for(int i=0;i<=nlen+20;i++) {
		int _k=k/10+((n[i]+k%10)>9);
		n[i]=(n[i]+k)%10;
		k=_k;
	}
	nlen=nlen+20;
	while(n[nlen-1]==0) {
		nlen--;
	}
}
void solve() {
	scanf("%s",tmp);
	nlen=strlen(tmp);
	scanf("%lld",&m);
	for(int i=0;i<nlen;i++) n[i]=tmp[nlen-i-1]-'0';
	for(int i=nlen;i<=nlen+30;i++) n[i]=0;
	add(1);
	//cout<<nlen<<endl;
	//for(int i=0;i<nlen;i++) cout<<n[i]<<endl; 
	
	lst[0]=0;
	for(int i=1;i<=nlen;i++) {
		lst[i]=((n[i-1]==9)?lst[i-1]:i);
	}
	
	pow10i[0]=1;
	for(int i=1;i<=18;i++) pow10i[i]=pow10i[i-1]*10;
	
	mlen=0;int _m=m;
	while(_m) {mlen++;_m/=10;}//cout<<mlen<<endl;
	
	g[0]=0;
	for(int k=0;k<mlen;k++) g[0]=g[0]+pow10i[k]*n[k];
	for(int i=1;i<=nlen;i++) g[i]=g[i-1]/10+n[i+mlen-1]*pow10i[mlen-1];
	
	nmd10i[0]=n[0];
	for(int i=1;i<=17;i++) nmd10i[i]=nmd10i[i-1]+pow10i[i]*n[i];
	
	for(int i=0;i<=nlen;i++) {
		if(lst[i]<=mlen)
		h[i]=pow10i[lst[i]]-nmd10i[lst[i]];
	} 
		
	
	
	//for(int i=0;i<=nlen;i++) cout<<g[i]<<endl;
	
	for(int i=0;i<=nlen;i++) f[i]=inf;
	for(int i=0;i<=nlen;i++) {
		if(g[i]==m) {
			f[i]=0;
		}
		else if(lst[i]<=mlen) {
			if(g[i]==m-1) {
				f[i]=h[i];
			}
			else if(i<=mlen+1) {
				if(g[i]<m-1) {
					f[i]=h[i]+nmd10i[i]*(m-g[i]-1);
				}
				else if(g[i]>m) {
					f[i]=h[i]+nmd10i[i]*(pow10i[mlen]+m-g[i]-1);
				}
			}
		}
	}
	int ans=0;
	for(int j=nlen-1;j>=0;j--) {
		ans=ans*10+n[j];
		ans%=m;
	}
	ans=(m-ans)%m;
	for(int i=0;i<=nlen;i++) {
		ans=min(ans,f[i]);
	}
	add(ans);
	for(int i=nlen-1;i>=0;i--) {
		putchar('0'+n[i]);
	}
	putchar('\n');
	
}
signed main() {
	int t;
	cin>>t;
	while(t--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
7 3
12 3
9 10
249 51
1369 37
2 1

output:

9
13
10
251
1370
3

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 53ms
memory: 11912kb

input:

100000
3196282243 28
7614814237 33
2814581084 97
1075124401 58
7822266214 100
1767317768 31
7189709841 75
9061337538 69
6552679231 38
9946082148 18
5497675062 54
7787300351 65
4310767261 68
4811341953 100
3265496130 31
8294404054 62
2845521744 90
1114254672 26
6442013672 13
3744046866 40
3289624367 ...

output:

3196282244
7614814251
2814581100
1075124424
7822266300
1767317769
7189709850
9061337577
6552679241
9946082160
5497675063
7787300365
4310767271
4811342000
3265496131
8294404081
2845521810
1114254674
6442013673
3744046867
3289624409
6477935360
1292587554
5504674742
2898829200
7882736025
2846033436
923...

result:

wrong answer 3rd lines differ - expected: '2814581097', found: '2814581100'