QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#829613#8932. BingolinweitongWA 0ms3656kbC++142.1kb2024-12-24 11:31:502024-12-24 11:31:51

Judging History

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

  • [2024-12-24 11:31:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-12-24 11:31:50]
  • 提交

answer

#include<bits/stdc++.h>
#define eb emplace_back
#define mk(x,y) make_pair(x,y)
#define fi first
#define se second
#define I __int128
using namespace std;
typedef long long ll;
const int N=15;
string S;
int m,a[N],ti,b[2000000],len;
I pw[50];
const I INF=1000000000000000000;
void solve(){
	++ti;
	len=0;
	cin>>S>>m;
	if (ti!=50)return;
	else{
		cout<<S<<" "<<m<<"\n";
	}
	ll s=0,ans=m;
	for (int i=0;i<(int)S.size();++i)s=(s*10+S[i]-48)%m;
	ans=min(ans,m-s);
	int o=m;
	while (o){
		a[++len]=o%10;
		o/=10;
	}
	reverse(a+1,a+len+1);
	int lim=max((int)S.size()-len-20,0);
	I lst=1;
	for (int i=max(0,(int)S.size()-len);i>=0;--i){
		int oo=0;
		for (int j=i;j<=i+len-1;++j){
			oo=oo*10+S[j]-48;
		}
		if (oo>m){
			if (i<lim)continue;
			I x=0,y=0;
			for (int j=i;j<(int)S.size();++j){
				x=x*10+S[j]-48;
				if (j<=i+len-1)y=y*10+a[j-i+1];
				else y=y*10;
			}
			I z=x-y+pw[(int)S.size()-i];
			if (z<ans)ans=z;
		}
		else if (oo==m){
			ans=1;
		}
		else if (oo<m){
			if (oo<m-1){
				if (i<lim)continue;
				I x=0,y=0;
				for (int j=i;j<(int)S.size();++j){
					x=x*10+S[j]-48;
					if (j<=i+len-1)y=y*10+a[j-i+1];
					else y=y*10;
				}
				if (y-x<ans)ans=y-x;
			}
			else{
				if (i>=lim){
					I x=0,y=0;
					for (int j=i;j<(int)S.size();++j){
						x=x*10+S[j]-48;
						if (j<=i+len-1)y=y*10+a[j-i+1];
						else y=y*10;
					}
					if (y-x<ans)ans=y-x;
				}
				else{
					int ooo=S[i+len]-48;
					if (9==ooo)continue;
					if (lst>=INF)continue;
					lst+=(9-ooo)*pw[(int)S.size()-1-(i+len)];
					if (lst>INF)lst=INF;
					if (lst<ans)ans=lst;
				}
			}
		}
	}
	int cnt=0;
	for (int i=0;i<(int)S.size();++i)b[++cnt]=S[i]-48;
	reverse(b+1,b+cnt+1);
	b[1]+=ans;
	for (int i=1;i<=cnt+20;++i){
		b[i+1]+=b[i]/10;
		b[i]%=10;
	}
	cnt+=20;
	while ((!b[cnt])&&cnt>1)--cnt;
	for (int i=cnt;i;--i)cout<<b[i];cout<<"\n";
	for (int i=1;i<=cnt;++i)b[i]=0;
}int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T;
	pw[0]=1;
	for (int i=1;i<=49;++i)pw[i]=pw[i-1]*10;
	cin>>T;
	while (T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3656kb

input:

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

output:


result:

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