QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#408093#6519. X Equals Yx17875487211WA 2ms3904kbC++141.8kb2024-05-09 18:19:312024-05-09 18:19:33

Judging History

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

  • [2024-05-09 18:19:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3904kb
  • [2024-05-09 18:19:31]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,x,y,A,B,W[100],cntw;
bool flag,NO;
bool num_is_ok(int num,int lim){
	if(num>=2&&num<=lim) return 1;
	return 0;
}
bool check_w0(int a,int b,int w1){
	if(x-a*w1!=y-b*w1) return 0;
	int w0=x-a*w1;
	if(w1<1||w1>=min(a,b)) return 0;
	if(w0<1||w0>=min(a,b)) return 0;
	if(a*w1+w0==x&&b*w1+w0==y&&num_is_ok(a,A)&&num_is_ok(b,B)){
		if(flag) swap(a,b);
		printf("YES\n%lld %lld\n",a,b),NO=0;
		return 1;
	}
	return 0;
}
bool cal(int w1){
	int a=x/w1,b=y/w1;
	if(check_w0(a,b,w1)) return 1;
	if(check_w0(a+1,b+1,w1)) return 1;
	if(check_w0(a-1,b-1,w1)) return 1;
	return 0;
}
void DI(int Num,int bas){
	cntw=0;
	while(Num){
		W[++cntw]=Num%bas;
		Num/=bas;
	}
}
int num_base_on(int di){
	int sum=0,mi=1;
	for(int i=1;i<=cntw;i++){
		sum+=W[i]*mi;
		mi*=di;
	}
	return sum;
}
int bin_sea(){
	int l=2,r=A;
	while(l<=r){
		int mid=(l+r)>>1;
		int NUM_BASE_ON=num_base_on(mid);
		if(NUM_BASE_ON==x) return mid; 
		else if(NUM_BASE_ON<x) l=mid+1;
		else r=mid-1;
	} 
	return -1;
}
bool work_on_less_than_sqrt(int b){
	DI(y,b);
	int a=bin_sea();
	if(a!=-1){
		if(flag) swap(a,b);
		printf("YES\n%lld %lld\n",a,b),NO=0;
		return 1;
	}
	return 0;
}
signed main(){
	scanf("%lld",&T);
	while(T--){
		flag=0;
		scanf("%lld%lld%lld%lld",&x,&y,&A,&B);
		if(x<y) swap(x,y),swap(A,B),flag=1;
		NO=1;
		for(int i=1;i*i<=(x-y);i++)
			if((x-y)%i==0){
				if(cal((x-y)/i)) break;
				if(cal(i)) break;
			}
		for(int b=2;b<=B&&b*b<=y;b++)
			if(work_on_less_than_sqrt(b)) break;
		if(NO&&x==y&&A>=x&&B>=y){
			if(x==1&&num_is_ok(x+1,A)&&num_is_ok(x+1,B)) printf("YES\n%lld %lld\n",x+1,x+1),NO=0;
			else if(num_is_ok(x,A)&&num_is_ok(y,B)) printf("YES\n%lld %lld\n",x,x),NO=0;
		}
		if(NO) printf("NO\n");
	}
	return 0;
}

详细

Test #1:

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

input:

6
1 1 1000 1000
1 2 1000 1000
3 11 1000 1000
157 291 5 6
157 291 3 6
10126 114514 789 12345

output:

YES
2 2
NO
YES
2 10
YES
4 5
NO
YES
6 10

result:

ok correct (6 test cases)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3904kb

input:

1000
920 661 756 534
52 454 31 218
980 77 812 6
729 733 289 660
161 643 21 475
602 525 329 274
782 167 279 113
875 100 388 16
426 498 341 417
433 751 312 39
91 50 47 39
941 388 247 46
725 808 148 486
945 405 700 145
647 509 152 445
45 564 16 468
843 40 530 3
722 36 323 22
568 472 443 41
38 749 25 42...

output:

YES
131 94
YES
17 151
NO
YES
182 183
NO
YES
54 47
YES
260 55
YES
25 10
NO
YES
212 248
NO
NO
NO
NO
YES
314 134
YES
107 84
YES
14 187
NO
NO
YES
35 29
YES
12 249
NO
NO
YES
196 20
YES
16 5
YES
150 119
NO
YES
498 296
NO
YES
66 195
NO
YES
66 29
NO
NO
YES
94 54
YES
6 5
NO
NO
NO
NO
NO
YES
324 129
NO
YES
37 ...

result:

wrong answer wrong solution, (875 in base 25) != (100 in base 10) (test case 8)