QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#644514 | #6812. Draw a triangle | Ynoiynoi# | WA | 76ms | 3664kb | C++20 | 1.2kb | 2024-10-16 14:23:05 | 2024-10-16 14:23:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
int exgcd(int a,int b,int &x,int &y) {
if(!b) {
x = 1; y = 0;
return a;
} else {
int d = exgcd(b,a%b,y,x); y -= x*(a/b);
return d;
}
}
signed main() {
int T;
cin >> T;
while(T --) {
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
n = abs(x2-x1); m = abs(y2-y1);
int d = __gcd(n,m);
n /= d; m /= d;
bool r = 0;
int u,v;
int x,y;
if(n > 1 || m > 1) {
if(n < m) {
r = 1;
swap(n,m);
}
exgcd(n,m,u,v);
if(v < 0) v = v%n+n;
x = v;y = m*v/n;
if(r) swap(x,y);
x *= d; y *= d;
// cout<<x<<" "<<y<<" "<<d<<"\n";
}
if(n == 1 && m == 1) {
x = 1; y = 0;
}
if(n == 1 && m == 0) {
x = 0; y = 1;
}
if(n == 0 && m == 1) {
x = 1; y = 0;
}
if(x1 > x2) x = -x;
if(y1 > y2) y = -y;
cout<<x1+x<<" "<<y1+y<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
input:
3 1 0 1 4 0 1 0 9 0 0 2 2
output:
2 0 1 1 1 0
result:
ok T=3 (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 76ms
memory: 3664kb
input:
50000 66620473 -33485015 66620223 -33485265 43307886 98029243 43307636 98028994 -88895230 -3180782 -88895480 -3181030 -90319745 20018595 -90319995 20018348 -56783257 84789686 -56783507 84789440 -81798038 90629147 -81798288 90628902 98942945 -939146 98942695 -939390 -42532151 -57203475 -42532401 -572...
output:
66620472 -33485015 43307637 98028995 -88895478 -3181028 -90319828 20018513 -56783381 84789564 -81798283 90628907 98942779 -939308 -42532258 -57203579 53500145 -30665665 27114943 46989027 -2657652 26865233 40614023 17923268 -47650112 96037513 92954122 -64535082 86508651 -51415368 -82017865 17392419 7...
result:
wrong answer wa on query #3 (test case 3)