Task: | Polygon area |
Sender: | odanobunaga8199 |
Submission time: | 2024-11-11 16:32:08 +0200 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
Code
#include <bits/stdc++.h> using namespace std; string int128_to_string(__int128 n) { bool is_negative = false; if (n < 0) { is_negative = true; n = -n; } string s = ""; if (n == 0) { s = "0"; } else { while (n > 0) { char digit = '0' + (n % 10); s += digit; n /= 10; } reverse(s.begin(), s.end()); } if (is_negative) { s = "-" + s; } return s; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<long long, long long>> vertices(n); for(int i = 0; i < n; ++i){ cin >> vertices[i].first >> vertices[i].second; } __int128 twice_area = 0; for(int i = 0; i < n; ++i){ long long x_current = vertices[i].first; long long y_current = vertices[i].second; long long x_next = vertices[(i + 1) % n].first; long long y_next = vertices[(i + 1) % n].second; twice_area += (__int128)(x_current) * y_next; twice_area -= (__int128)(x_next) * y_current; } if(twice_area < 0){ twice_area = -twice_area; } string result = int128_to_string(twice_area); cout << result; }
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: ACCEPTED
input |
---|
1000 365625896 -113418831 278762563 38777445 250367343 -96991975 175866909 -129766978 ... |
correct output |
---|
4053466653883387139 |
user output |
---|
4053466653883387139 |
Test 3
Verdict: ACCEPTED
input |
---|
4 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 1000000000 -1000000000 |
correct output |
---|
8000000000000000000 |
user output |
---|
8000000000000000000 |