Submission #896426
Source Code Expand
import java.io.IOException; import java.util.InputMismatchException; import java.util.LinkedList; import java.util.List; import java.util.TreeMap; public class Main { int w, h; TreeMap<Integer, List<C>> mapX, mapY; TreeMap<Pair, Integer> map; class C implements Comparable<C> { Pair p; long value; C(int x, int y, long value) { this.p = new Pair(x, y); this.value = value; } @Override public int compareTo(C o) { return this.p.compareTo(o.p); } } class Pair implements Comparable<Pair> { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { if (this.x != o.x) { return this.x - o.x; } return this.y - o.y; } } void run() { MyScanner sc = new MyScanner(); w = sc.nextInt(); h = sc.nextInt(); int n = sc.nextInt(); C[] c = new C[n]; mapX = new TreeMap<Integer, List<C>>(); mapY = new TreeMap<Integer, List<C>>(); map = new TreeMap<Pair, Integer>(); for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); int v = sc.nextInt(); C tmp = new C(x, y, v); c[i] = tmp; if (mapX.containsKey(x)) { mapX.get(x).add(tmp); } else { List<C> xlist = new LinkedList<C>(); xlist.add(tmp); mapX.put(x, xlist); } if (mapY.containsKey(y)) { mapY.get(y).add(tmp); } else { List<C> ylist = new LinkedList<C>(); ylist.add(tmp); mapY.put(y, ylist); } map.put(new Pair(x, y), v); } for (int i = 0; i < n; i++) { int x = c[i].p.x; int y = c[i].p.y; List<C> listX = mapX.get(x); List<C> listY = mapY.get(y); if (listX == null || listY == null) { continue; } for (C tmpX : listX) { for (C tmpY : listY) { int nx = tmpY.p.x; int ny = tmpX.p.y; long k = tmpX.value + tmpY.value - c[i].value; Integer tmpC = map.get(new Pair(nx, ny)); if ((tmpC != null && tmpC != k) || (k < 0)) { System.out.println("No"); return; } } } } System.out.println("Yes"); } public static void main(String[] args) { new Main().run(); } class MyScanner { int read() { try { return System.in.read(); } catch (IOException e) { throw new InputMismatchException(); } } boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) array[i] = nextInt(); return array; } long nextLong() { return Long.parseLong(next()); } long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) array[i] = nextLong(); return array; } double nextDouble() { return Double.parseDouble(next()); } double[] nextDoubleArray(int n) { double[] array = new double[n]; for (int i = 0; i < n; i++) array[i] = nextDouble(); return array; } String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } String[] nextStringArray(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) array[i] = next(); return array; } String nextLine() { int c = read(); while (isEndline(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndline(c)); return res.toString(); } } }
Submission Info
Submission Time | |
---|---|
Task | D - Grid and Integers |
User | fujisu |
Language | Java7 (OpenJDK 1.7.0) |
Score | 0 |
Code Size | 3862 Byte |
Status | WA |
Exec Time | 2105 ms |
Memory | 80836 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 800 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 106 ms | 8016 KB |
0_01.txt | AC | 102 ms | 8020 KB |
0_02.txt | AC | 102 ms | 8020 KB |
0_03.txt | AC | 108 ms | 8016 KB |
0_04.txt | AC | 102 ms | 8020 KB |
1_00.txt | AC | 101 ms | 8020 KB |
1_01.txt | AC | 102 ms | 8020 KB |
1_02.txt | AC | 104 ms | 8020 KB |
1_03.txt | AC | 102 ms | 8020 KB |
1_04.txt | AC | 104 ms | 8020 KB |
1_05.txt | AC | 109 ms | 8020 KB |
1_06.txt | AC | 1275 ms | 80836 KB |
1_07.txt | AC | 1357 ms | 80492 KB |
1_08.txt | AC | 1263 ms | 77396 KB |
1_09.txt | AC | 1140 ms | 77344 KB |
1_10.txt | AC | 855 ms | 72544 KB |
1_11.txt | AC | 646 ms | 72880 KB |
1_12.txt | AC | 795 ms | 72672 KB |
1_13.txt | WA | 803 ms | 73116 KB |
1_14.txt | AC | 800 ms | 72716 KB |
1_15.txt | WA | 816 ms | 72668 KB |
1_16.txt | AC | 783 ms | 71856 KB |
1_17.txt | AC | 484 ms | 56264 KB |
1_18.txt | AC | 475 ms | 56360 KB |
1_19.txt | AC | 476 ms | 56328 KB |
1_20.txt | WA | 731 ms | 47524 KB |
1_21.txt | AC | 395 ms | 34956 KB |
1_22.txt | AC | 223 ms | 13872 KB |
1_23.txt | AC | 563 ms | 44732 KB |
1_24.txt | WA | 787 ms | 64980 KB |
1_25.txt | WA | 621 ms | 44072 KB |
1_26.txt | AC | 249 ms | 15536 KB |
1_27.txt | AC | 274 ms | 19896 KB |
1_28.txt | WA | 865 ms | 71796 KB |
1_29.txt | AC | 398 ms | 34884 KB |
1_30.txt | WA | 803 ms | 70944 KB |
1_31.txt | AC | 427 ms | 35044 KB |
1_32.txt | WA | 1211 ms | 64168 KB |
1_33.txt | WA | 831 ms | 71304 KB |
1_34.txt | AC | 292 ms | 20280 KB |
1_35.txt | TLE | 2105 ms | 47664 KB |
1_36.txt | AC | 321 ms | 22360 KB |
1_37.txt | WA | 488 ms | 40120 KB |
1_38.txt | AC | 598 ms | 50644 KB |
1_39.txt | AC | 378 ms | 34432 KB |
1_40.txt | AC | 650 ms | 48560 KB |
1_41.txt | AC | 427 ms | 34900 KB |
1_42.txt | AC | 516 ms | 47740 KB |
1_43.txt | AC | 424 ms | 43924 KB |
1_44.txt | WA | 1043 ms | 56952 KB |
1_45.txt | WA | 498 ms | 36688 KB |
1_46.txt | WA | 741 ms | 70204 KB |
1_47.txt | AC | 507 ms | 38768 KB |
1_48.txt | WA | 399 ms | 34712 KB |
1_49.txt | AC | 272 ms | 18136 KB |
1_50.txt | WA | 533 ms | 44000 KB |
1_51.txt | WA | 875 ms | 68704 KB |
1_52.txt | AC | 254 ms | 15608 KB |
1_53.txt | AC | 308 ms | 22284 KB |
1_54.txt | AC | 395 ms | 35332 KB |
1_55.txt | AC | 1108 ms | 39904 KB |
1_56.txt | WA | 612 ms | 44032 KB |
1_57.txt | WA | 902 ms | 69628 KB |
1_58.txt | WA | 737 ms | 67196 KB |
1_59.txt | AC | 229 ms | 14020 KB |
1_60.txt | AC | 103 ms | 8020 KB |
1_61.txt | AC | 105 ms | 8020 KB |
1_62.txt | AC | 103 ms | 8020 KB |
1_63.txt | AC | 104 ms | 8016 KB |