QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282432#5500. Barstkrawczyk#WA 186ms3808kbC++231.1kb2023-12-12 00:33:562023-12-12 00:33:57

Judging History

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

  • [2023-12-12 00:33:57]
  • 评测
  • 测评结果:WA
  • 用时:186ms
  • 内存:3808kb
  • [2023-12-12 00:33:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

struct P {
    int x, y;
    P operator-(const P& he) const {
        return {x - he.x, y - he.y};
    }
    long long operator*(const P& he) const {
        return (long long)x * he.y - (long long)he.x * y;
    }
    long long triangle(const P& a, const P& b) {
        return (a - *this) * (b - *this);
    }
};

void solve() {
    int n; cin >> n;
    vector<P> hull;
    for(int i = 1; i <= n; i++) {
        int pi; cin >> pi;
        P c{i, pi};
        while((int)hull.size() >= 2) {
            P a = hull.end()[-2];
            P b = hull.end()[-1];
            if(a.triangle(b, c) >= 0) hull.pop_back();
            else break;
        }
        hull.push_back(c);
    }
    long long ans = 0;
    for(int i = 0; i < (int)hull.size(); i++) {
        ans += (hull[i].x - (i == 0 ? 1 : hull[i - 1].x)) * (hull[i].y + (i == 0 ? 0 : hull[i - 1].y));
    }
    cout << ans << '\n';
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    int t; cin >> t;
    while(t--) solve();
}

详细

Test #1:

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

input:

2
4
5 2 2 6
5
1 5 4 4 1

output:

33
29

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 186ms
memory: 3564kb

input:

10000
4
5 2 2 6
5
1 5 4 4 1
197
763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...

output:

33
29
213549221
-2078600878
532859273
458946673513
292125782659
-413229227
1494651374
-2101356450
40554579962
-369157937
-1507408135
37604494
585094154153
-156064150
1541383052
2263935434
792582237
3353846914
-3796556
2714099932
419516009
-2592897088
259793094831
702147234976
200762466
2462509035
16...

result:

wrong answer 3rd lines differ - expected: '382465638565', found: '213549221'