QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625727#6812. Draw a triangleSound_MediumWA 44ms3600kbC++232.1kb2024-10-09 20:43:302024-10-09 20:43:31

Judging History

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

  • [2024-10-09 20:43:31]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:3600kb
  • [2024-10-09 20:43:30]
  • 提交

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 (a.y*(b.x-a.x)-a.x*(b.y-a.y)+x*(b.y-a.y))/(b.x-a.x);
    };
    if(a.y>b.y){
        int gc=gcd((b.x-a.x),(a.y-b.y));
        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{
            {}
            int yy=fy(x)-b.y;
            return x+yy-a.x;
        };
        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<<" "<<fy(l)<<endl;
    } 
    else{
        int gc=gcd(abs(b.x-a.x),abs(a.y-b.y));

        if(gc==abs(b.x-a.x)){
            cout<<a.x+1<<" "<<a.y<<endl;return ;
        }
        int l = a.x, r = a.x+(b.x-a.x)/(gc)-1;
        int ans1, ans2;
        auto f=[&](int x)->int{
            {}
            int yy=fy(x)-b.y;
            return b.x-x+yy;
        };
        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<<" "<<fy(l)<<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: 3592kb

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: 44ms
memory: 3600kb

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
43307636 98028994
-88895480 -3181030
-90319995 20018348
-56783507 84789440
-81798288 90628902
98942695 -939390
-42532401 -57203718
53499957 -30665847
27114804 46988893
-2657662 26865223
40613932 17923181
-47650154 96037473
92954045 -64535155
86508615 -51415402
-82017950 17392339
7...

result:

wrong answer wa on query #2 (test case 2)