QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#183599#6300. Best Carry Player 2sheriyuoWA 0ms3832kbC++142.6kb2023-09-19 18:10:312023-09-19 18:10:31

Judging History

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

  • [2023-09-19 18:10:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2023-09-19 18:10:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
#define ld long db
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in ll read()
	{
		ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
}
using namespace fast_io;
const int N=1e5+5;
int T,n,k;
ll pw[20];
char s[20],t[20];
void upd(int l,int r)
{
	//cout<<"updated "<<l<<" "<<r<<endl;
	t[r]='9'-s[r]+'0'+1,k--;
	for(int i=l;i<r;i++)
	t[i]='9'-s[i]+'0',k--;
	if(l>1&&t[l-1]>'0') t[l-1]--;
	//puts(t+1);
}
void output(int l,int r)
{
	for(int i=l;i<=n;i++) if(!t[i]) t[i]='0';
	while(t[l]=='0') l++;
	puts(t+l);
}
int main()
{
	pw[0]=1;for(int i=1;i<20;i++) pw[i]=pw[i-1]*10;
	T=read();
	while(T--)
	{
		memset(s,0,sizeof(s)),memset(t,0,sizeof(t));
		n=gs(s+1),k=read();
		if(!k)
		{
			int op=0;
			for(int i=n;i;i--) if(s[i]^'9')
			{
				printf("%lld\n",pw[n-i]);
				op=1;break;
			}
			if(!op) printf("%lld\n",pw[n]);
			continue;
		}
		int r=n;while(s[r]=='0') r--;
		int l=r-k+1;
		if(l<1)
		{
			for(int i=r+1;i<=n;i++) t[i]='0';
			upd(1,r);
			while(k--) putchar('9');
			puts(t+1);
			continue;
		}
		if(l==1||s[l-1]^'9')
		{
			upd(l,r);output(l,r);
			continue;
		}
		while(l>1&&s[l-1]=='9') l--;
		//cout<<l<<":"<<r<<"!\n";
		for(int i=l;i<=r;i++)
		{
			//cout<<i<<":::"<<k<<endl;
			if(s[i]=='0'||s[i]=='9')
			{
				int j=i+1;
				while(s[j]=='9'||s[j]=='0'&&j<r) j++;
				//cout<<i<<":"<<j<<"!\n";
				if(j-i+1<=k) upd(i,j),i=j;
				else
				{
					int to=i+k-1;
					while(s[to]=='0') to--;
					if(i>to) continue;
					//cout<<i<<"::"<<to<<endl;
					upd(i,to),i=to;
				}
			}
			if(!k) break;
		}
		//cout<<k<<"!\n";
		for(int i=r;i&&k;i--)
		{
			if(!t[i]) upd(i,i);
		}
		output(l,r);
	}
    return 0;
}
/*
2
999901 5
919991 6

1
999901 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9910

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3832kb

input:

21
999990000099999 0
999990000099999 1
999990000099999 2
999990000099999 3
999990000099999 4
999990000099999 5
999990000099999 6
999990000099999 7
999990000099999 8
999990000099999 9
999990000099999 10
999990000099999 11
999990000099999 12
999990000099999 13
999990000099999 14
999990000099999 15
999...

output:

100000
10000
1000
100
10
1
900001
9900001
99900001
999900001
10999910000
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
1000000000000000000

result:

wrong answer 11th lines differ - expected: '10000000001', found: '10999910000'