QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#610815#8932. Bingoucup-team4975#WA 51ms11928kbC++172.0kb2024-10-04 17:32:372024-10-04 17:33:06

Judging History

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

  • [2024-10-04 17:33:06]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:11928kb
  • [2024-10-04 17:32:37]
  • 提交

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]=0;
	nmd10i[1]=n[0];
	for(int i=2;i<=17;i++) nmd10i[i]=nmd10i[i-1]+pow10i[i-1]*n[i-1];
	
	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++) {
		//cout<<i<<" "<<f[i]<<" "<<h[i]<<endl; 
		ans=min(ans,f[i]);
	}
	
	//cout<<ans<<endl;
	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;
}

詳細信息

Test #1:

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

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: 51ms
memory: 11928kb

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
7614814239
2814581086
1075124403
7822266216
1767317769
7189709843
9061337540
6552679233
9946082150
5497675063
7787300353
4310767263
4811341955
3265496131
8294404056
2845521746
1114254674
6442013673
3744046867
3289624369
6477935357
1292587534
5504674680
2898829149
7882736014
2846033370
923...

result:

wrong answer 2nd lines differ - expected: '7614814251', found: '7614814239'