CSES - Aalto Competitive Programming 2024 - wk10 - Mon - Results
Submission details
Task:Polygon area
Sender:Nallue
Submission time:2024-11-11 16:28:00 +0200
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#20.00 sdetails
#3ACCEPTED0.00 sdetails

Code

#include <iostream>
#include <vector>

using namespace std;


long long polygonArea(vector<long long> X, vector<long long> Y, int n)
{
    long long a = 0;

    int prev = n - 1;
    for (int i=0; i<n; i++){
        a += (X[prev] + X[i]) * (Y[prev] - Y[i]);
        prev = i;
    }
 
    return abs(a / 2.0);
}

int main(){

    int n;
    cin >> n;

    vector<long long> X(n);
    vector<long long> Y(n);

    for(int i=0; i<n; i++)cin >> X[i] >> Y[i];

    cout << 2*polygonArea(X,Y,n) << endl;


}

Test details

Test 1

Verdict: ACCEPTED

input
100
-7 -19
91 77
100 100
64 60
...

correct output
43582

user output
43582

Test 2

Verdict:

input
1000
365625896 -113418831
278762563 38777445
250367343 -96991975
175866909 -129766978
...

correct output
4053466653883387139

user output
4053466653883387392

Test 3

Verdict: ACCEPTED

input
4
-1000000000 -1000000000
-1000000000 1000000000
1000000000 1000000000
1000000000 -1000000000

correct output
8000000000000000000

user output
8000000000000000000