QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625870 | #6812. Draw a triangle | Sound_Medium | WA | 36ms | 3620kb | C++23 | 2.5kb | 2024-10-09 21:31:17 | 2024-10-09 21:31:18 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define PII pair<int,int>
#define x first
#define y second
int n, m;
void solve () {
vector<pair<int,int>>p(2);
for(int i=0;i<2;i++){
cin>>p[i].first>>p[i].second;
}
sort(p.begin(),p.end(),[](PII a,PII b){
return a.x<b.x||a.x==b.x&&a.y<b.y;
});
PII a=p[0],b=p[1];
if(a.x==b.x){
cout<<a.x+1<<" "<<a.y<<endl;
return ;
}
else if(a.y==b.y){
cout<<a.x<<" "<<a.y+1<<endl;
return ;
}
auto fy=[&](int x)->int{
{}
return (int)(a.y*(b.x-a.x)-a.x*(b.y-a.y)+x*(b.y-a.y))/(b.x-a.x);
};
auto area=[&](PII a,PII b,PII c){
return abs((a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y));
};
if(a.y>b.y){
int gc=gcd((b.x-a.x),(a.y-b.y));
// cerr<<gc<<endl;
if(gc==(b.x-a.x)){
cout<<a.x<<" "<<a.y-1<<endl;return ;
}
int l = a.x, r = a.x+(b.x-a.x)/(gc)-1;
int ans1, ans2;
auto f=[&](int x)->int{
{}
PII c={x,fy(x)};
return area(a,b,c);
};
// for(int i=l;i<=r;i++){
// cout<<f(i)<<" ";
// }
while (l < r)
{
int mid1 = l + (r - l) / 3;
int mid2 = r - (r - l) / 3;
ans1 = f(mid1), ans2 = f(mid2);
if (ans1 >= ans2)r = mid2 - 1; // 极大值
else l = mid1 + 1;
}
cout<<l<<" "<<min(a.x-1,fy(l))<<endl;
}
else{
int gc=gcd(abs(b.x-a.x),abs(a.y-b.y));
// cerr<<gc<<endl;
if(gc==abs(b.x-a.x)){
// cerr<<"*";
cout<<a.x+1<<" "<<a.y<<endl;return ;
}
int l = a.x+1, r = a.x+(b.x-a.x)/(gc);
int ans1, ans2;
auto f=[&](int x)->int{
{}
PII c={x,fy(x)};
return area(a,b,c);
};
// for(int i=l;i<=r;i++){
// cout<<f(i)<<" "<<fy(i)-a.y<<" "<<i-a.x<<"\n";
// }
while (l < r)
{
int mid1 = l + (r - l) / 3;
int mid2 = r - (r - l) / 3;
ans1 = f(mid1), ans2 = f(mid2);
if (ans1 <= ans2)r = mid2 - 1; // 极小值
else l = mid1 + 1;
}
cout<<l<<" "<<min(fy(l),b.y-1)<<endl;
}
}
signed main () {
int T = 1;
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin>>T;
while (T --) solve ();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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: 36ms
memory: 3532kb
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:
66620224 -33485265 43307886 98029242 -88895479 -3181029 -90319912 20018430 -56783445 84789501 -81798238 90628951 98942737 -939349 -42532329 -57203648 53500020 -30665786 27114915 46989000 -2657637 26865247 40614068 17923311 -47650071 96037552 92954161 -64535045 86508651 -51415368 -82017917 17392370 7...
result:
wrong answer wa on query #2 (test case 2)