QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#539312#8932. Bingoucup-team4717#WA 18ms14744kbC++172.6kb2024-08-31 14:29:182024-08-31 14:29:18

Judging History

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

  • [2024-08-31 14:29:18]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:14744kb
  • [2024-08-31 14:29:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x);write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=2e6+6;
int n,m,mod;
char sa[N],sb[N];
int a[N],b[N],c[N];
void sol(){
	fill(a+1,a+n+1,0),fill(b+1,b+m+1,0),fill(c+1,c+n+1,0);
	n=0,m=0,mod=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getch();
	while(isdigit(ch))sa[++n]=ch,ch=getch();
	while(!isdigit(ch))ch=getch();
	while(isdigit(ch))sb[++m]=ch,ch=getch();
	for(int i=1;i<=n;i++)c[n-i+1]=a[n-i+1]=sa[i]-'0';
	for(int i=1;i<=m;i++)b[m-i+1]=sb[i]-'0';
	for(int i=m;i>=1;i--)mod=10*mod+b[i];
	int cnt=0;for(int i=n;i>=1;i--)cnt=(10ll*cnt+a[i])%mod;cnt=mod-cnt;
	a[1]+=cnt;n=0;while(a[n+1]){n++;a[n+1]+=a[n]/10;a[n]%=10;}
	c[1]+=1;for(int i=1;i<=n;i++)c[i+1]+=c[i]/10,c[i]%=10;
//	for(int i=n;i>=1;i--)cout<<a[i];cout<<'\n';
//	for(int i=n;i>=1;i--)cout<<c[i];cout<<'\n';
//	for(int i=m;i>=1;i--)cout<<b[i];cout<<'\n';
	for(int i=n;i>=m;i--){
		int flag=1;
		for(int j=m;j>=1;j--){
			if(c[i-(m-j)]<b[j])break;
			if(c[i-(m-j)]>b[j]){flag=0;break;}
		}
		for(int j=m;j>=1;j--){
			if(a[i-(m-j)]>b[j])break;
			if(a[i-(m-j)]<b[j]){flag=0;break;}
		}
		if(flag){
			for(int j=n;j>i;j--)write(a[j]);
			int ops=1;
			for(int j=m;j>=1;j--){
				if(b[j]>c[i-(m-j)])ops=0;
				write(b[j]);
			}
			for(int j=i-m;j>=1;j--){
				if(ops==0)write(0);
				else write(c[j]);
			}
			putch('\n');
			return;
		}
	}
	for(int i=n;i>=1;i--)write(a[i]);putch('\n');
	return;
}
signed main(){
	int T;
	read(T);
	while(T--)sol();
	flush();
	return 0;
}/*
1
1369 37
*/

详细

Test #1:

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

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: 18ms
memory: 14744kb

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
7614814251
2814581100
75124424
7822266300
1767317769
9850
61337569
6552679238
82160
92
365
767316
4811342000
3265496131
62
2845521810
1114254674
13673
46880
3289624425
6477935360
1292587551
4674742
2898829200
25
33436
9231995142
680
645000
27
640
517
7289111245
8781738838
9964674538
95899...

result:

wrong answer 3rd lines differ - expected: '2814581097', found: '2814581100'