QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#829617#8932. BingolinweitongWA 6ms3588kbC++142.2kb2024-12-24 11:32:342024-12-24 11:32:35

Judging History

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

  • [2024-12-24 11:32:35]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3588kb
  • [2024-12-24 11:32:34]
  • 提交

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 ((int)S.size()>5){
	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();
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3588kb

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: 6ms
memory: 3588kb

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:

6085907239 3
6085907240

result:

wrong answer 1st lines differ - expected: '3196282244', found: '6085907239 3'