Submission #1611762
Source Code Expand
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; //using System.Numerics; //using static System.Math; class Program { static void Main() { //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int N; int R, C; List<Edge>[] G; long[] W; const long inf = long.MaxValue / 3; bool[] B; bool ok = true; void solve() { R = cin.nextint; C = cin.nextint; N = cin.nextint; G = Enumerable.Range(0, R + C).Select(i => new List<Edge>()).ToArray(); for (int i = 0; i < N; i++) { int r = cin.nextint - 1; int c = cin.nextint - 1; int a = cin.nextint; G[r].Add(new Edge(R + c, a)); G[R + c].Add(new Edge(r, a)); } W = Enumerable.Repeat(inf, R + C).ToArray(); B = new bool[R + C]; for (int i = 0; i < R + C; i++) { dfs(i, 0, -1); } //WriteLine(string.Join(" ", W)); if (ok && W.Take(R).Min() + W.Skip(R).Min() >= 0) { WriteLine("Yes"); } else { WriteLine("No"); } } void dfs(int u, long value, int before) { //WriteLine(u + 1); if (B[u]) { if (before == 0 && W[u] != value) { ok = false; } return; } B[u] = true; W[u] = value; foreach (var v in G[u]) { dfs(v.to, v.cost - value, 0); } } struct Edge : IComparable<Edge> { public int to; public long cost; public Edge(int to, long cost) { this.to = to; this.cost = cost; } public int CompareTo(Edge e) { return cost.CompareTo(e.cost); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
Submission Info
Submission Time | |
---|---|
Task | D - Grid and Integers |
User | claw88 |
Language | C# (Mono 4.6.2.0) |
Score | 0 |
Code Size | 3333 Byte |
Status | WA |
Exec Time | 344 ms |
Memory | 56716 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 | 30 ms | 9556 KB |
0_01.txt | AC | 28 ms | 13524 KB |
0_02.txt | AC | 30 ms | 11476 KB |
0_03.txt | AC | 30 ms | 13524 KB |
0_04.txt | AC | 28 ms | 13524 KB |
1_00.txt | AC | 72 ms | 32368 KB |
1_01.txt | AC | 72 ms | 32368 KB |
1_02.txt | AC | 72 ms | 30320 KB |
1_03.txt | AC | 74 ms | 30320 KB |
1_04.txt | AC | 72 ms | 28272 KB |
1_05.txt | AC | 64 ms | 30192 KB |
1_06.txt | AC | 310 ms | 50956 KB |
1_07.txt | AC | 344 ms | 50824 KB |
1_08.txt | AC | 300 ms | 42644 KB |
1_09.txt | AC | 299 ms | 42644 KB |
1_10.txt | AC | 315 ms | 42128 KB |
1_11.txt | AC | 302 ms | 41996 KB |
1_12.txt | AC | 337 ms | 56716 KB |
1_13.txt | AC | 328 ms | 50444 KB |
1_14.txt | AC | 343 ms | 52620 KB |
1_15.txt | AC | 331 ms | 50444 KB |
1_16.txt | AC | 314 ms | 48408 KB |
1_17.txt | AC | 317 ms | 49944 KB |
1_18.txt | AC | 319 ms | 52500 KB |
1_19.txt | AC | 325 ms | 50836 KB |
1_20.txt | AC | 167 ms | 30548 KB |
1_21.txt | WA | 115 ms | 28160 KB |
1_22.txt | WA | 56 ms | 25008 KB |
1_23.txt | WA | 211 ms | 37308 KB |
1_24.txt | AC | 206 ms | 28364 KB |
1_25.txt | AC | 176 ms | 28352 KB |
1_26.txt | WA | 42 ms | 12640 KB |
1_27.txt | WA | 77 ms | 24812 KB |
1_28.txt | AC | 282 ms | 36140 KB |
1_29.txt | WA | 119 ms | 26980 KB |
1_30.txt | AC | 272 ms | 35372 KB |
1_31.txt | WA | 160 ms | 32984 KB |
1_32.txt | AC | 188 ms | 28212 KB |
1_33.txt | AC | 267 ms | 39468 KB |
1_34.txt | WA | 74 ms | 25260 KB |
1_35.txt | AC | 198 ms | 25508 KB |
1_36.txt | WA | 83 ms | 29864 KB |
1_37.txt | AC | 111 ms | 24108 KB |
1_38.txt | WA | 236 ms | 36068 KB |
1_39.txt | WA | 105 ms | 29368 KB |
1_40.txt | WA | 233 ms | 38248 KB |
1_41.txt | WA | 157 ms | 36840 KB |
1_42.txt | AC | 193 ms | 30312 KB |
1_43.txt | AC | 226 ms | 32060 KB |
1_44.txt | AC | 230 ms | 36532 KB |
1_45.txt | AC | 92 ms | 25332 KB |
1_46.txt | AC | 264 ms | 34860 KB |
1_47.txt | WA | 113 ms | 25600 KB |
1_48.txt | AC | 95 ms | 23360 KB |
1_49.txt | WA | 65 ms | 21424 KB |
1_50.txt | AC | 161 ms | 32076 KB |
1_51.txt | AC | 242 ms | 32092 KB |
1_52.txt | WA | 86 ms | 32168 KB |
1_53.txt | WA | 103 ms | 31368 KB |
1_54.txt | WA | 110 ms | 25980 KB |
1_55.txt | AC | 113 ms | 22996 KB |
1_56.txt | AC | 197 ms | 35028 KB |
1_57.txt | AC | 253 ms | 32712 KB |
1_58.txt | AC | 243 ms | 34420 KB |
1_59.txt | WA | 65 ms | 27504 KB |
1_60.txt | AC | 30 ms | 11476 KB |
1_61.txt | AC | 29 ms | 9428 KB |
1_62.txt | AC | 30 ms | 11604 KB |
1_63.txt | AC | 27 ms | 9428 KB |