QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#183622#6300. Best Carry Player 2sheriyuoWA 10ms3952kbC++142.6kb2023-09-19 18:26:192023-09-19 18:26:19

Judging History

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

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

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--;
		//dfs(l,r);
		//cout<<l<<":"<<r<<"!\n";
		while(k)
		{
			int i=r-k+1;
			if(s[i-1]^'9') {upd(i,r);continue;}
			while(s[i-1]=='9') i--;
			int j=i+1;
			while(s[j]=='9'||s[j]=='0'&&j<r) j++;
			//cout<<i<<":"<<j<<" "<<k<<"!\n";
			if(j-i+1<=k) upd(i,j),i=j;
			else
			{
				int to=i+k-1;
				//cout<<i<<"::"<<to<<endl;
				while(s[to]=='0') to--;
				//cout<<i<<"::"<<to<<endl;
				if(i>to) continue;
				upd(i,to),i=to;
			}
		}
		output(l,r);
	}
    return 0;
}
/*
2
999901 5
919991 6

1
999990000099999 10
---
10000000001
---
10999910000
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9910

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3760kb

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
10000000001
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
1000000000000000000

result:

ok 21 lines

Test #3:

score: -100
Wrong Answer
time: 10ms
memory: 3800kb

input:

100000
119111011091190000 10
1911011191011999 16
110099199000119 0
19009911191091011 13
199090909919000900 17
19009010011919110 5
90910190019900091 18
10911100000101111 1
110090011101119990 4
100909999119090000 12
90901119109011100 2
111010119991090101 4
900991019109199009 5
100919919990991119 8
911...

output:

88988908810000
8088988808988001
10
88808908989
9800909090080999100
80890
909089809980099909
9
80010
9090000880910000
8900
9909
991
9009001
9080880081
8080090801
8009900808909899
80880898981
909
8800909
99988889901
89908888089
980908890980099000
100
9889801
81
908890008099900891
880990801
9998099
890...

result:

wrong answer 14th lines differ - expected: '9008900', found: '9009001'