QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#785307#6812. Draw a triangleMartian148#WA 74ms3600kbC++202.1kb2024-11-26 17:28:102024-11-26 17:28:11

Judging History

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

  • [2024-11-26 17:28:11]
  • 评测
  • 测评结果:WA
  • 用时:74ms
  • 内存:3600kb
  • [2024-11-26 17:28:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
typedef i64 ll;
using i128 = __int128;

constexpr int flg[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

std::istream &operator >> (std::istream &is, i128 &n) {
    std::string s; is >> s;
    n = 0;
    for (char c : s) n = n * 10 + c - '0';
    return is;
}

std::ostream &operator << (std::ostream &os, i128 n) {
    std::string s;
    while (n) {
        s += '0' + n % 10;
        n /= 10;
    }
    std::reverse(s.begin(), s.end());
    return os << s;
}

struct Point {
    i128 x, y;
    Point(i128 x = 0, i128 y = 0) : x(x), y(y) {}
    bool operator == (Point &ohs) {
        return (x == ohs.x && y == ohs.y);
    }
};

typedef Point Vector;
Vector operator + (Vector A, Vector B) {return Vector(A.x + B.x, A.y + B.y);}
Vector operator - (Vector A, Vector B) {return Vector(A.x - B.x, A.y - B.y);}

i128 cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;}
i128 area2(Point A, Point B, Point C) {return cross(B - A, C - A);}

void print(i128 x) {
    if (x < 0) putchar('-'); x = -x;
    stack<int> st;
    do {
        st.push(x % 10);
        x /= 10;
    }while (x);
    while (!st.empty()) putchar(st.top() + '0'), st.pop();
}

void solve() {
    i64 x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    Point A(x1, y1), B(x2, y2);
    
    i128 max_area2 = -1;
    Point C;

    auto calc = [&] (Point P) -> void {
        if (P == A || P == B) return ;
        i128 now_area = area2(A, B, P);
        if (now_area < 0) now_area = -now_area;
        if (max_area2 == -1 || now_area > max_area2) {
            max_area2 = now_area;
            C = P;
        }
    };
    
    for (int k = 0; k < 4; k++) {
        calc(Point(A.x + flg[k][0], A.y + flg[k][1]));
        calc(Point(B.x + flg[k][0], B.y + flg[k][1]));
    }

    i64 Cx = C.x, Cy = C.y;
    cout << Cx << " " << Cy << '\n';
}

int main() {
    // freopen ("E.in", "r", stdin);
    // ios::sync_with_stdio(false);
    // cin.tie(0); cout.tie(0);
    int T; 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: 3600kb

input:

3
1 0 1 4
0 1 0 9
0 0 2 2

output:

0 0
-1 1
-1 0

result:

ok T=3 (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 74ms
memory: 3580kb

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
43307886 98029244
-88895230 -3180781
-90319745 20018596
-56783257 84789687
-81798038 90629148
98942945 -939145
-42532151 -57203474
53500207 -30665604
27115054 46989135
-2657412 26865464
40614182 17923421
-47649904 96037712
92954295 -64534917
86508865 -51415165
-82017700 17392575
7...

result:

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