QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#457053#3224. DirectionspropaneWA 25ms3868kbC++202.6kb2024-06-28 23:00:332024-06-28 23:00:33

Judging History

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

  • [2024-06-28 23:00:33]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:3868kb
  • [2024-06-28 23:00:33]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<numeric>
#include<map>
#include<algorithm>
using namespace std;
using LL = long long;

struct Point{
    LL x, y;

    LL operator*(const Point &t) const {
        return x * t.x + y * t.y;
    }

    LL operator^(const Point &t) const {
        return x * t.y - y * t.x;
    }

    int quad() const {
        if (y < 0) return 1;
        if (y > 0) return 4;
        if (x < 0) return 5;
        if (x > 0) return 2;
        return 3;
    }

    bool operator<(const Point &t) const {
        int q1 = quad(), q2 = t.quad();
        if (q1 != q2) return q1 < q2;
        return (*this ^ t) > 0;
    }

};

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    const LL INF = 1e18;
    int n;
    cin >> n;
    map<Point, int> mp;
    for(int i = 0; i < n; i++){
        LL x, y; int p;
        cin >> x >> y >> p;
        if (x == 0 and y == 0) continue;
        LL g = abs(gcd(x, y));
        x /= g, y /= g;
        if (!mp.contains({x, y})){
            mp[{x, y}] = p;
        }
        else{
            mp[{x, y}] = max(mp[{x, y}], p);
        }
    }
    vector<Point> pt;
    vector<int> p;
    for(auto [x, y] : mp){
        pt.push_back(x);
        p.push_back(y);
    }

    if (pt.empty()){
        cout << -1 << '\n';
        return 0;
    }

    auto rot = [&](Point &s){
        swap(s.x, s.y);
        s.x = -s.x;
    };

    LL ans = INF;

    for(auto s : pt){
        LL sum = mp[s];
        rot(s);
        if (mp.contains(s)){
            sum += mp[s];
        }
        else continue;
        rot(s);
        if (mp.contains(s)){
            sum += mp[s];
        }
        else continue;
        rot(s);
        if (mp.contains(s)){
            sum += mp[s];
        }
        else continue;
        ans = min(ans, sum);
    }

    int mnpos = min_element(p.begin(), p.end()) - p.begin();
    rotate(pt.begin(), pt.begin() + mnpos, pt.end());
    rotate(p.begin(), p.begin() + mnpos, p.end());

    int j = 1;
    while(j < n and (pt[0] ^ pt[j]) >= 0) j++;

    int ed = 1;
    while(ed < n and (pt[0] ^ pt[ed]) > 0) ed++;

    j--;
    LL mn = INF;
    for(int i = 1; i < ed; i++){
        while(j + 1 < n and (pt[i] ^ pt[j + 1]) > 0){
            mn = min(mn, 1LL * p[++j]);
        }
        ans = min(ans, p[0] + p[i] + mn);
    }

    if (ans > INF / 2) ans = -1;
    cout << ans << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 25ms
memory: 3868kb

input:

200000
-1 -1 1
1 1 1
0 1 1
1 0 1
1 -1 1
1 1 1
1 1 1
-1 1 1
1 -1 1
0 1 1
0 0 1
0 0 1
1 -1 1
-1 -1 1
0 0 1
1 0 1
-1 1 1
-1 1 1
1 1 1
1 1 1
-1 1 1
0 -1 1
1 -1 1
-1 0 1
1 0 1
1 -1 1
0 -1 1
1 0 1
-1 1 1
1 0 1
-1 0 1
1 1 1
1 0 1
-1 -1 1
-1 1 1
-1 -1 1
0 -1 1
0 -1 1
1 1 1
1 -1 1
0 1 1
1 1 1
-1 1 1
1 -1 1
0...

output:

3

result:

ok single line: '3'

Test #2:

score: -100
Wrong Answer
time: 25ms
memory: 3860kb

input:

200000
-1 -1 2
1 0 1
1 0 2
1 -1 2
1 0 1
-1 1 1
-1 -1 2
1 1 1
0 -1 2
-1 -1 1
0 1 2
0 -1 2
-1 0 2
0 0 2
-1 1 1
1 1 1
-1 0 1
1 -1 2
1 0 1
0 0 1
1 0 2
0 -1 1
0 1 1
0 -1 2
-1 1 2
0 1 2
-1 1 2
0 1 1
0 1 1
1 1 2
1 1 1
1 0 2
1 1 2
-1 1 2
-1 1 1
0 1 2
0 -1 2
1 0 2
0 1 1
0 -1 1
1 -1 1
1 0 2
0 -1 1
-1 0 1
0 -1...

output:

6

result:

wrong answer 1st lines differ - expected: '3', found: '6'