QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625738#6812. Draw a triangleSound_MediumWA 34ms3804kbC++232.1kb2024-10-09 20:47:082024-10-09 20:47:09

Judging History

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

  • [2024-10-09 20:47:09]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:3804kb
  • [2024-10-09 20:47:08]
  • 提交

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+1, r = a.x+(b.x-a.x)/(gc);
        int ans1, ans2;
        auto f=[&](int x)->int{
            {}
            int yy=fy(x)-a.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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3804kb

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: 34ms
memory: 3616kb

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
43307637 98028994
-88895479 -3181029
-90319994 20018348
-56783506 84789440
-81798287 90628902
98942696 -939389
-42532400 -57203717
53499958 -30665846
27114805 46988893
-2657661 26865223
40613933 17923181
-47650153 96037473
92954046 -64535154
86508616 -51415401
-82017949 17392339
7...

result:

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