Submission #905783


Source Code Expand

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

public class Main {

    final static boolean DEBUG = false;

    final void solve() throws Exception {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = nextInt();
        }

        Map<Integer, Integer> count = new HashMap<>();
        for (int i : a) {
            count.put(i, 0);
        }
        for (int i : a) {
            count.put(i, count.get(i) + 1);
        }


        Arrays.sort(a);

        boolean ok = true;
        int max = a[a.length - 1];

        for (int x = 0, y = max; x < y; ++x, --y) {
            if (!count.containsKey(y) || count.get(y) < 2) {
                ok = false;
                break;
            }
        }

        if (max % 2 == 0) {
            if (!count.containsKey(max / 2) || count.get(max / 2) != 1) {
                ok = false;
            }
        }

        for (int i = 1; i < max / 2; ++i) {
            if (count.containsKey(i)) {
                ok = false;
                break;
            }
        }

        print(ok ? "Possible" : "Impossible");
        println();
    }

    final static BufferedReader in;
    final static PrintWriter out;

    static final boolean isWhiteSpace(final int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == -1;
    }

    static final int read() throws Exception {
        return in.read();
    }

    static final int nextInt() throws Exception {
        int result = 0;
        boolean negative = false;
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        if (c == '-') {
            negative = true;
            c = read();
        }
        while (!isWhiteSpace(c)) {
            result = result * 10 + (c - '0');
            c = read();
        }
        return negative ? -result : result;
    }

    static final long nextLong() throws Exception {
        long result = 0;
        boolean negative = false;
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        if (c == '-') {
            negative = true;
            c = read();
        }
        while (!isWhiteSpace(c)) {
            result = result * 10 + (c - '0');
            c = read();
        }
        return negative ? -result : result;
    }

    static final StringBuilder tmpString = new StringBuilder(1 << 20);

    static final String nextString() throws Exception {
        tmpString.setLength(0);
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        while (!isWhiteSpace(c)) {
            tmpString.append((char) c);
            c = read();
        }
        return tmpString.toString();
    }

    static final char nextChar() throws Exception {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        while (!isWhiteSpace(c)) {
            return (char) c;
        }
        return (char) 0;
    }

    static final String readLine() throws Exception {
        return in.readLine();
    }

    static final void print(final int i) {
        out.print(i);
    }

    static final void print(final long l) {
        out.print(l);
    }

    static final void print(final String s) {
        out.print(s);
    }

    static final void println() {
        out.println();
    }

    static {
        try {
            if (DEBUG) {
                String fileName = Main.class.getSimpleName();
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(new BufferedWriter(new FileWriter(fileName + ".out")));
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    static final AtomicReference<Exception> exs = new AtomicReference<Exception>();

    public static void main(String[] args) throws Exception {
        Thread th = new Thread(null, new Runnable() {
            @Override
            public void run() {
                try {
                    new Main().solve();
                    out.close();
                    return;
                } catch (Exception ex) {
                    exs.set(ex);
                }
            }
        }, "Test", 64 << 20);
        th.start();
        th.join();
        Exception ex = exs.get();
        if (ex != null) {
            throw ex;
        }
    }
}

Submission Info

Submission Time
Task C - Tree Restoring
User Lgsmitty
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 4884 Byte
Status WA
Exec Time 101 ms
Memory 10484 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 6
AC × 43
WA × 2
Set Name Test Cases
Sample example0, example1, example2, example3, example4, example5
All almostline0, almostline1, almostline2, almostline3, can0, can1, can2, can3, can4, can5, can6, deg0, deg1, deg2, deg3, example0, example1, example2, example3, example4, example5, handmade0, line0, line1, line2, line3, ng10, ng11, ng12, ng13, ng20, ng21, ng22, ng23, plus0, plus1, plus2, plus3, rand0, rand1, rand2, star0, star1, star2, star3
Case Name Status Exec Time Memory
almostline0 AC 98 ms 10356 KB
almostline1 AC 100 ms 10232 KB
almostline2 AC 99 ms 10360 KB
almostline3 AC 98 ms 10356 KB
can0 AC 94 ms 10360 KB
can1 AC 96 ms 10228 KB
can2 AC 94 ms 10452 KB
can3 AC 98 ms 10360 KB
can4 AC 97 ms 10352 KB
can5 AC 94 ms 10228 KB
can6 AC 92 ms 10360 KB
deg0 AC 96 ms 10452 KB
deg1 AC 96 ms 10320 KB
deg2 AC 98 ms 10360 KB
deg3 AC 99 ms 10228 KB
example0 AC 94 ms 10352 KB
example1 AC 95 ms 10320 KB
example2 AC 94 ms 10232 KB
example3 AC 98 ms 10320 KB
example4 AC 95 ms 10232 KB
example5 AC 99 ms 10232 KB
handmade0 AC 94 ms 10356 KB
line0 AC 99 ms 10356 KB
line1 AC 96 ms 10324 KB
line2 AC 101 ms 10360 KB
line3 AC 100 ms 10232 KB
ng10 WA 95 ms 10228 KB
ng11 AC 93 ms 10352 KB
ng12 WA 98 ms 10356 KB
ng13 AC 99 ms 10232 KB
ng20 AC 95 ms 10320 KB
ng21 AC 95 ms 10380 KB
ng22 AC 98 ms 10372 KB
ng23 AC 96 ms 10228 KB
plus0 AC 97 ms 10356 KB
plus1 AC 97 ms 10356 KB
plus2 AC 96 ms 10320 KB
plus3 AC 95 ms 10356 KB
rand0 AC 99 ms 10360 KB
rand1 AC 95 ms 10356 KB
rand2 AC 95 ms 10484 KB
star0 AC 100 ms 10232 KB
star1 AC 93 ms 10320 KB
star2 AC 95 ms 10360 KB
star3 AC 98 ms 10356 KB