QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#539884#8932. Bingoucup-team4717#WA 27ms17244kbC++172.9kb2024-08-31 15:57:062024-08-31 15:57:07

Judging History

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

  • [2024-08-31 15:57:07]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:17244kb
  • [2024-08-31 15:57:06]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long 
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],tmp[N];
void check(){
	for(int i=n;i>=1;i--){
		if(tmp[i]>a[i])return;
		if(tmp[i]<a[i]){
			for(int j=1;j<=n;j++)a[j]=tmp[j];
			return;
		}
	}
}
void sol(){
	fill(a+1,a+n+20,0),fill(b+1,b+m+20,0),fill(c+1,c+n+20,0);
	n=0,m=0,mod=0;
	char ch=getch();
	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];
	if(n<m){
		for(int i=m;i>=1;i--)write(b[i]);putch('\n');
		return;	
	}
	int cnt=0;for(int i=n;i>=1;i--)cnt=(10ll*cnt+a[i])%mod;cnt=mod-cnt;
	a[1]+=cnt;for(int i=1;i<=n;i++)a[i+1]+=a[i]/10,a[i]%=10;if(a[n+1])n++;
	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';
	int asdasd=0;
	for(int i=m;i<=n;i++){
		int flag=1;
		for(int j=m;j>=1;j--)
			if(c[i-(m-j)]!=b[j])flag=0;
		if(flag)asdasd=1;
	}
	if(asdasd){
		if(!c[n])n--;
		for(int i=n;i>=1;i--)write(c[i]);putch('\n');
		return;
	}
	for(int i=min(n,2*m+10);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;}
		}
		if(flag){
			for(int j=n;j>i;j--)tmp[n]=c[j];
			for(int j=m;j>=1;j--)tmp[i-(m-j)]=b[j];
			for(int j=i-m;j>=1;j--)tmp[j]=0;
			check();
		}
	}
	while(!a[n])n--;
	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: 15820kb

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: 27ms
memory: 17244kb

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
4033033330
999999997
1075124424
7822266300
1767317769
7189709850
669000000
2663800338
2663180180
5497675063
663666500
1666800000
4811342000
3265496131
626666200
1999999900
1114254674
6442013673
3744046867
2750777500
6477935360
1292587554
888900000
1000080880
80225
888887000
1555405554
382...

result:

wrong answer 2nd lines differ - expected: '7614814251', found: '4033033330'