Submission details
Task:Polygon area
Sender:aalto26jm_019
Submission time:2026-11-09 16:41:44 +0200
Language:Java
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.08 sdetails
#3ACCEPTED0.05 sdetails

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class PolygonArea {
    public static void main(String[] args) {
        FastScanner input = new FastScanner(System.in);
        int n = input.nextInt();

        Long[][] points = new Long[n][2];

        for (int i = 0; i < n; i++){
            points[i][0] = input.nextLong();
            points[i][1] = input.nextLong();
        }
        Long area = 0L;
        for (int i = 0; i < n-1; i++){
            Long height = points[i][1] + points[i+1][1];
            Long width = points[i+1][0] - points[i][0];

            area += height * width;
        }

        Long height = points[n-1][1] + points[0][1];
        Long width = points[0][0] - points[n-1][0];
        area += height*width;
        area = Math.abs(area);

        System.out.println(area);
    }


    static class FastScanner { //static class fastScanner
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
    	 return Double.parseDouble(next());
	 }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}
}

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