QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#485506#5500. BarswiktorzogaWA 200ms3824kbC++201.4kb2024-07-20 18:57:162024-07-20 18:57:18

Judging History

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

  • [2024-07-20 18:57:18]
  • 评测
  • 测评结果:WA
  • 用时:200ms
  • 内存:3824kb
  • [2024-07-20 18:57:16]
  • 提交

answer

#include "bits/stdc++.h"
 
using namespace std;
 
#define sz(s)   int32_t(s.size())
#define all(x)  begin(x), end(x)
 
using ll = long long;
using ld = long double;

const int N = 5e5 + 5;

int p[N];

struct Point {
    int x, y;
    Point (int _x, int _y) : x(_x), y(_y) {}
    Point () : x(0), y(0) {}
};

void operator -= (Point& a, Point b) {
    a.x -= b.x, a.y -= b.y;
}

int cross(Point a, Point b) {
    return a.x * b.y - a.y * b.x;
}

int orientation(Point o, Point a, Point b) {
    a -= o, b -= o;
    int det = cross(a, b);
    if (det < 0)    return -1;
    else return +1;
}

void solve() {
    int n;  cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    p[0] = p[n + 1] = 0;
    vector<Point> pts;
    for (int i = 1; i <= n; i++) {
        Point P(i, p[i]);
        while (sz(pts) >= 2 && orientation(pts[sz(pts) - 2], pts[sz(pts) - 1], P) != -1) {
            pts.pop_back();
        }
        pts.push_back(P);
    }
    int res = 0;
    for (int i = 0; i + 1 < sz(pts); i++) {
        Point a = pts[i], b = pts[i + 1];
        res += (a.y + b.y) * (b.x - a.x);
    }
    cout << res << "\n";
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tests = 1;  cin >> tests;
    for (int test_case = 1; test_case <= tests; test_case++) {
        solve();
    }
}   

詳細信息

Test #1:

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

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: 200ms
memory: 3668kb

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
324658624
793445285
135701300
-614827159
68006531
1041472957
-2079769354
1622454214
1899874298
577398246
1052188061
286602769
978601897
52009853
1541383052
-1036447661
1284911644
1810264968
103497341
-1288589731
-1016875005
842520498
2095057071
2067565728
-1218375174
1025155419
-1009738986
-29...

result:

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