| Task: | Polygon area |
| Sender: | aalto26jm_012 |
| Submission time: | 2026-11-09 16:26:40 +0200 |
| Language: | Rust (2021) |
| 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
#![allow(unused)]
use std::collections::*;
use std::io;
fn take_int() -> usize {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
return input.trim().parse::<usize>().unwrap();
}
fn take_tuple() -> (i64, i64) {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let mut it = input
.trim()
.split_whitespace()
.map(|x| x.parse::<i64>().unwrap());
(it.next().unwrap(), it.next().unwrap())
}
fn polygon_area(ps: &[(i64, i64)]) -> i64 {
let n = ps.len();
let mut area = 0;
for i in 0..n {
let (a, b) = (ps[i], ps[(i + 1) % n]);
area += a.0 * b.1 - a.1 * b.0;
}
area.abs()
}
fn main() {
let mut n = take_int();
let mut ps: Vec<(i64, i64)> = Vec::with_capacity(n);
for _ in 0..n {
ps.push(take_tuple());
}
let mut res = polygon_area(&ps);
println!("{}", res);
}
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 |
