Submission details
Task:Polygon area
Sender:Giaco
Submission time:2025-11-10 16:49:33 +0200
Language:Rust (2021)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails

Code

use std::io::{self, Read};

macro_rules! input {
    ($it: expr) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: expr, $T: ty) => {
        $it.next().unwrap().parse::<$T>().unwrap()
    };
}
/*
mod classes;
mod homework;

fn main() {
    // println!("{}", "-".repeat(20));
    classes::c20::task1();
    // homework::hw9::task1();
    // println!("{}", "-".repeat(20));
}
// */

fn cross_product(a: (i128, i128), b: (i128, i128)) -> i128 {
    a.0*b.1 - b.0*a.1
}

fn main() {
    let mut buf = String::new();
    io::stdin().read_to_string(&mut buf).unwrap();

    let mut it = buf.split_whitespace();

    let n: usize = input!(it);

    let v: Vec<(i128, i128)> = (0..n).into_iter().map(|_| (input!(it), input!(it))).collect();

    let mut rtn = 0;

    for i in 0..n-1 {
        rtn += cross_product(v[i], v[i+1]);
    }
    rtn += cross_product(v[n-1], v[0]);

    if rtn < 0 {
        println!("{}", -rtn);
    } else {
        println!("{}", rtn);
    }

}

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