Submission #1172352
Source Code Expand
import java.io.*; import java.util.*; public class Main { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); int[] a = new int[n]; int[] cnt = new int[n]; int d = 0; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); cnt[a[i]]++; d = Math.max(d, a[i]); } if (d % 2 == 0) { for (int i = d; i > d / 2; i--) { if (cnt[i] < 2) { pr.println("Impossible"); return; } cnt[i] -= 2; } if (cnt[d / 2] < 1) { pr.println("Impossible"); return; } cnt[d / 2]--; for (int i = 0; i < d / 2 + 1; i++) { if (cnt[i] > 0) { pr.println("Impossible"); return; } } } else { for (int i = d; i >= (d + 1) / 2; i--) { if (cnt[i] < 2) { pr.println("Impossible"); return; } cnt[i] -= 2; } for (int i = 0; i < (d + 1) / 2 + 1; i++) { if (cnt[i] > 0) { pr.println("Impossible"); return; } } } pr.println("Possible"); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } private boolean isPrintable(int ch) { return ch >= '!' && ch <= '~'; } private boolean isCRLF(int ch) { return ch == '\n' || ch == '\r' || ch == -1; } private int nextPrintable() { try { int ch; while (!isPrintable(ch = br.read())) { if (ch == -1) { throw new NoSuchElementException(); } } return ch; } catch (IOException e) { throw new NoSuchElementException(); } } String next() { try { int ch = nextPrintable(); StringBuilder sb = new StringBuilder(); do { sb.appendCodePoint(ch); } while (isPrintable(ch = br.read())); return sb.toString(); } catch (IOException e) { throw new NoSuchElementException(); } } int nextInt() { try { // parseInt from Integer.parseInt() boolean negative = false; int res = 0; int limit = -Integer.MAX_VALUE; int radix = 10; int fc = nextPrintable(); if (fc < '0') { if (fc == '-') { negative = true; limit = Integer.MIN_VALUE; } else if (fc != '+') { throw new NumberFormatException(); } fc = br.read(); } int multmin = limit / radix; int ch = fc; do { int digit = ch - '0'; if (digit < 0 || digit >= radix) { throw new NumberFormatException(); } if (res < multmin) { throw new NumberFormatException(); } res *= radix; if (res < limit + digit) { throw new NumberFormatException(); } res -= digit; } while (isPrintable(ch = br.read())); return negative ? res : -res; } catch (IOException e) { throw new NoSuchElementException(); } } long nextLong() { try { // parseLong from Long.parseLong() boolean negative = false; long res = 0; long limit = -Long.MAX_VALUE; int radix = 10; int fc = nextPrintable(); if (fc < '0') { if (fc == '-') { negative = true; limit = Long.MIN_VALUE; } else if (fc != '+') { throw new NumberFormatException(); } fc = br.read(); } long multmin = limit / radix; int ch = fc; do { int digit = ch - '0'; if (digit < 0 || digit >= radix) { throw new NumberFormatException(); } if (res < multmin) { throw new NumberFormatException(); } res *= radix; if (res < limit + digit) { throw new NumberFormatException(); } res -= digit; } while (isPrintable(ch = br.read())); return negative ? res : -res; } catch (IOException e) { throw new NoSuchElementException(); } } float nextFloat() { return Float.parseFloat(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { try { int ch; while (isCRLF(ch = br.read())) { if (ch == -1) { throw new NoSuchElementException(); } } StringBuilder sb = new StringBuilder(); do { sb.appendCodePoint(ch); } while (!isCRLF(ch = br.read())); return sb.toString(); } catch (IOException e) { throw new NoSuchElementException(); } } void close() { try { br.close(); } catch (IOException e) { // throw new NoSuchElementException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }
Submission Info
Submission Time | |
---|---|
Task | C - Tree Restoring |
User | garnacha |
Language | Java8 (OpenJDK 1.8.0) |
Score | 700 |
Code Size | 4955 Byte |
Status | AC |
Exec Time | 85 ms |
Memory | 23636 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
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 | 71 ms | 19668 KB |
almostline1 | AC | 71 ms | 20564 KB |
almostline2 | AC | 69 ms | 20308 KB |
almostline3 | AC | 72 ms | 19284 KB |
can0 | AC | 72 ms | 21332 KB |
can1 | AC | 71 ms | 21588 KB |
can2 | AC | 71 ms | 21460 KB |
can3 | AC | 70 ms | 17876 KB |
can4 | AC | 69 ms | 19668 KB |
can5 | AC | 71 ms | 18260 KB |
can6 | AC | 70 ms | 20052 KB |
deg0 | AC | 85 ms | 19284 KB |
deg1 | AC | 71 ms | 18388 KB |
deg2 | AC | 72 ms | 21328 KB |
deg3 | AC | 70 ms | 19540 KB |
example0 | AC | 69 ms | 19668 KB |
example1 | AC | 76 ms | 21332 KB |
example2 | AC | 71 ms | 18772 KB |
example3 | AC | 71 ms | 18260 KB |
example4 | AC | 69 ms | 18644 KB |
example5 | AC | 71 ms | 20180 KB |
handmade0 | AC | 70 ms | 20052 KB |
line0 | AC | 71 ms | 21076 KB |
line1 | AC | 72 ms | 19408 KB |
line2 | AC | 70 ms | 18004 KB |
line3 | AC | 81 ms | 17236 KB |
ng10 | AC | 71 ms | 19540 KB |
ng11 | AC | 69 ms | 20180 KB |
ng12 | AC | 71 ms | 23636 KB |
ng13 | AC | 71 ms | 21332 KB |
ng20 | AC | 72 ms | 22740 KB |
ng21 | AC | 84 ms | 19156 KB |
ng22 | AC | 70 ms | 20820 KB |
ng23 | AC | 72 ms | 16468 KB |
plus0 | AC | 70 ms | 19796 KB |
plus1 | AC | 73 ms | 21460 KB |
plus2 | AC | 80 ms | 21204 KB |
plus3 | AC | 75 ms | 21332 KB |
rand0 | AC | 73 ms | 20564 KB |
rand1 | AC | 71 ms | 18132 KB |
rand2 | AC | 71 ms | 20948 KB |
star0 | AC | 71 ms | 21204 KB |
star1 | AC | 70 ms | 21460 KB |
star2 | AC | 83 ms | 21460 KB |
star3 | AC | 72 ms | 21588 KB |