QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#513304 | #9168. Square Locator | ucup-team956# | TL | 0ms | 1664kb | C++14 | 1.9kb | 2024-08-10 17:27:46 | 2024-08-10 17:27:53 |
Judging History
answer
#include<stdio.h>
#include<string.h>
#include<algorithm>
typedef long long ll;
struct READ{//快读
char c,w;
inline READ(){c=getchar();}
template<typename type>
inline READ& operator >>(type& num){
for(w=1;'0'>c||c>'9';c=getchar())
w=c=='-'? -1:1;
for(num=0;'0'<=c&&c<='9';c=getchar())
num=num*10+(c-'0');
return num*=w,*this;
}
}cin;
ll a,b,c,d;
inline ll sqrt(__int128_t a){
if(a<=0) return 0;
ll x=0x7fff'ffff'ffff'ffff;
for(int i=256;i;--i)
x=(__int128_t(x)*x+a)/(x*2);
while(__int128_t(x)*x<a) ++x;
while(__int128_t(x)*x>a) --x;
return x;
}
int main(){
cin>>a>>b>>c>>d;
const ll ya=sqrt(a);
ll x=d-b-a*2,y=b-d-a*2;
__int128_t dd=__int128_t(a)*b*8-__int128_t(a*2+b-d)*(a*2+b-d);
ll dis=sqrt(dd);
if(__int128_t(dis)*dis==dd){
if(std::abs(x+dis)%(ya*4)==0&&std::abs(y+dis)%(ya*4)==0){
const ll ansx=(x+dis)/(ya*4),ansy=(y+dis)/(ya*4);
printf("%lld %lld %lld %lld %lld %lld %lld",ya,
ansx,ansy+ya,ansx-ansy,ansx+ansy+ya,-ansy,ansx+ya);
return 0;
}else if(std::abs(x-dis)%(ya*4)==0&&std::abs(y-dis)%(ya*4)==0){
const ll ansx=(x-dis)/(ya*4),ansy=(y-dis)/(ya*4);
printf("%lld %lld %lld %lld %lld %lld %lld",ya,
ansx,ansy+ya,ansx-ansy,ansx+ansy+ya,-ansy,ansx+ya);
return 0;
}
}
std::swap(b,d);
x=d-b-a*2,y=b-d-a*2;
dd=__int128_t(a)*b*8-__int128_t(a*2+b-d)*(a*2+b-d);
dis=sqrt(dd);
if(__int128_t(dis)*dis==dd){
if(std::abs(x+dis)%(ya*4)==0&&std::abs(y+dis)%(ya*4)==0){
const ll ansx=(x+dis)/(ya*4),ansy=(y+dis)/(ya*4);
printf("%lld %lld %lld %lld %lld %lld %lld",ya,
-ansy,ansx+ya,ansx-ansy,ansx+ansy+ya,ansx,ansy+ya);
return 0;
}else if(std::abs(x-dis)%(ya*4)==0&&std::abs(y-dis)%(ya*4)==0){
const ll ansx=(x-dis)/(ya*4),ansy=(y-dis)/(ya*4);
printf("%lld %lld %lld %lld %lld %lld %lld",ya,
-ansy,ansx+ya,ansx-ansy,ansx+ansy+ya,ansx,ansy+ya);
return 0;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 1664kb
input:
36 5 10 41
output:
6 -1 2 3 1 4 5
result:
ok Answer is correct
Test #2:
score: -100
Time Limit Exceeded
input:
1 1 1 1