Submission #895510
Source Code Expand
using System; using System.Collections.Generic; using System.Linq; using System.IO; class Program { const int M = 1000000007; const double eps = 1e-9; static int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var sc = new Scan(); int r, c; sc.Multi(out r, out c); int n = sc.Int; var nodes = new SortedDictionary<int, int>[r]; for (int i = 0; i < r; i++) { nodes[i] = new SortedDictionary<int, int>(); } for (int i = 0; i < n; i++) { var a = sc.IntArr; --a[0]; --a[1]; nodes[a[0]].Add(a[1], a[2]); } var ed_to = new List<int>[c]; var ed_cost = new List<int>[c]; for (int i = 0; i < c; i++) { ed_to[i] = new List<int>(); ed_cost[i] = new List<int>(); } for (int i = 0; i < r; i++) { int prc = -1, prcost = -1; foreach (var item in nodes[i]) { if (prc > -1) { ed_to[prc].Add(item.Key); ed_to[item.Key].Add(prc); ed_cost[prc].Add(item.Value - prcost); ed_cost[item.Key].Add(prcost - item.Value); } prc = item.Key; prcost = item.Value; } } var dis = new int[c]; for (int i = 0; i < c; i++) { dis[i] = -M; } for (int i = 0; i < c; i++) { if (dis[i] == -M) { var q = new Queue<int>(); q.Enqueue(i); dis[i] = 0; while (q.Any()) { var p = q.Dequeue(); for (int j = 0; j < ed_to[p].Count; j++) { var nex = ed_to[p][j]; if (dis[nex] == -M) { dis[nex] = dis[p] + ed_cost[p][j]; q.Enqueue(nex); } else if (dis[nex] != dis[p] + ed_cost[p][j]) { DBG("No"); return; } } } } } sw.WriteLine("Yes"); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static void swap<T>(IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG<T>(params T[] a) { Console.WriteLine(string.Join(" ", a)); } static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); } static T[] copy<T>(IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public int[] IntArrWithSep(char sep) { return Str.Split(sep).Select(int.Parse).ToArray(); } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } T cv<T>(string inp) { if (typeof(T).Equals(typeof(int))) return (T)Convert.ChangeType(int.Parse(inp), typeof(T)); if (typeof(T).Equals(typeof(long))) return (T)Convert.ChangeType(long.Parse(inp), typeof(T)); if (typeof(T).Equals(typeof(double))) return (T)Convert.ChangeType(double.Parse(inp), typeof(T)); if (typeof(T).Equals(typeof(char))) return (T)Convert.ChangeType(inp[0], typeof(T)); return (T)Convert.ChangeType(inp, typeof(T)); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } class mymath { static int Mod = 1000000007; public void setMod(int m) { Mod = m; } public bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public bool[] sieve(int n) { var isp = new bool[n + 1]; for (int i = 2; i <= n; i++) isp[i] = true; for (int i = 2; i * i <= n; i++) if (isp[i]) for (int j = i * i; j <= n; j += i) isp[j] = false; return isp; } public List<int> getprimes(int n) { var prs = new List<int>(); var isp = sieve(n); for (int i = 2; i <= n; i++) if (isp[i]) prs.Add(i); return prs; } public long[][] E(int n) { var ret = new long[n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public long[][] powmat(long[][] A, long n) { if (n == 0) return E(A.Length); var t = powmat(A, n / 2); if ((n & 1) == 0) return mulmat(t, t); return mulmat(mulmat(t, t), A); } public long[] mulmat(long[][] A, long[] x) { int n = A.Length, m = x.Length; var ans = new long[n]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ans[i] = (ans[i] + x[j] * A[i][j]) % Mod; return ans; } public long[][] mulmat(long[][] A, long[][] B) { int n = A.Length, m = B[0].Length, l = B.Length; var ans = new long[n][]; for (int i = 0; i < n; i++) { ans[i] = new long[m]; for (int j = 0; j < m; j++) for (int k = 0; k < l; k++) ans[i][j] = (ans[i][j] + A[i][k] * B[k][j]) % Mod; } return ans; } public long[] addmat(long[] x, long[] y) { int n = x.Length; var ans = new long[n]; for (int i = 0; i < n; i++) ans[i] = (x[i] + y[i]) % Mod; return ans; } public long[][] addmat(long[][] A, long[][] B) { int n = A.Length, m = A[0].Length; var ans = new long[n][]; for (int i = 0; i < n; i++) ans[i] = addmat(A[i], B[i]); return ans; } public long powmod(long a, long b) { if (a >= Mod) return powmod(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = powmod(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public long inv(long a) { return powmod(a, Mod - 2); } public long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } public long lcm(long a, long b) { return a * (b / gcd(a, b)); } public long Comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; var numerator = new int[r]; var denominator = new int[r]; for (int k = 0; k < r; k++) { numerator[k] = n - r + k + 1; denominator[k] = k + 1; } for (int p = 2; p <= r; p++) { int pivot = denominator[p - 1]; if (pivot > 1) { int offset = (n - r) % p; for (int k = p - 1; k < r; k += p) { numerator[k - offset] /= pivot; denominator[k] /= pivot; } } } long result = 1; for (int k = 0; k < r; k++) if (numerator[k] > 1) result = result * numerator[k] % Mod; return result; } }
Submission Info
Submission Time | |
---|---|
Task | D - Grid and Integers |
User | riantkb |
Language | C# (Mono 4.6.2.0) |
Score | 0 |
Code Size | 8848 Byte |
Status | WA |
Exec Time | 487 ms |
Memory | 42624 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 | 37 ms | 3672 KB |
0_01.txt | AC | 34 ms | 3544 KB |
0_02.txt | WA | 33 ms | 3416 KB |
0_03.txt | AC | 33 ms | 3416 KB |
0_04.txt | AC | 35 ms | 3416 KB |
1_00.txt | AC | 145 ms | 31280 KB |
1_01.txt | AC | 147 ms | 31280 KB |
1_02.txt | AC | 145 ms | 31284 KB |
1_03.txt | WA | 149 ms | 31284 KB |
1_04.txt | AC | 144 ms | 31284 KB |
1_05.txt | AC | 134 ms | 31284 KB |
1_06.txt | AC | 326 ms | 35220 KB |
1_07.txt | AC | 383 ms | 35220 KB |
1_08.txt | AC | 439 ms | 42620 KB |
1_09.txt | WA | 487 ms | 42624 KB |
1_10.txt | AC | 405 ms | 39948 KB |
1_11.txt | AC | 457 ms | 40052 KB |
1_12.txt | AC | 451 ms | 39948 KB |
1_13.txt | AC | 392 ms | 39948 KB |
1_14.txt | AC | 407 ms | 39948 KB |
1_15.txt | WA | 407 ms | 39948 KB |
1_16.txt | AC | 388 ms | 39948 KB |
1_17.txt | WA | 441 ms | 39968 KB |
1_18.txt | WA | 397 ms | 39968 KB |
1_19.txt | WA | 393 ms | 39944 KB |
1_20.txt | WA | 232 ms | 20348 KB |
1_21.txt | AC | 144 ms | 20552 KB |
1_22.txt | AC | 79 ms | 16248 KB |
1_23.txt | AC | 275 ms | 30708 KB |
1_24.txt | WA | 262 ms | 22304 KB |
1_25.txt | WA | 207 ms | 21828 KB |
1_26.txt | AC | 57 ms | 9268 KB |
1_27.txt | AC | 119 ms | 20360 KB |
1_28.txt | WA | 390 ms | 29984 KB |
1_29.txt | AC | 170 ms | 22252 KB |
1_30.txt | WA | 401 ms | 32284 KB |
1_31.txt | AC | 217 ms | 29852 KB |
1_32.txt | WA | 243 ms | 19228 KB |
1_33.txt | WA | 366 ms | 32264 KB |
1_34.txt | AC | 100 ms | 17872 KB |
1_35.txt | AC | 251 ms | 20432 KB |
1_36.txt | AC | 115 ms | 19872 KB |
1_37.txt | WA | 135 ms | 14704 KB |
1_38.txt | AC | 294 ms | 31844 KB |
1_39.txt | AC | 161 ms | 24732 KB |
1_40.txt | AC | 301 ms | 30616 KB |
1_41.txt | AC | 215 ms | 31284 KB |
1_42.txt | AC | 250 ms | 20124 KB |
1_43.txt | WA | 263 ms | 29480 KB |
1_44.txt | WA | 299 ms | 26668 KB |
1_45.txt | AC | 117 ms | 16988 KB |
1_46.txt | WA | 372 ms | 31420 KB |
1_47.txt | AC | 156 ms | 20496 KB |
1_48.txt | WA | 121 ms | 15864 KB |
1_49.txt | AC | 92 ms | 17064 KB |
1_50.txt | WA | 199 ms | 22512 KB |
1_51.txt | AC | 291 ms | 25316 KB |
1_52.txt | AC | 132 ms | 25220 KB |
1_53.txt | AC | 131 ms | 23868 KB |
1_54.txt | AC | 148 ms | 21120 KB |
1_55.txt | AC | 148 ms | 15880 KB |
1_56.txt | AC | 247 ms | 26516 KB |
1_57.txt | AC | 305 ms | 26520 KB |
1_58.txt | WA | 308 ms | 28132 KB |
1_59.txt | AC | 101 ms | 20484 KB |
1_60.txt | WA | 34 ms | 3416 KB |
1_61.txt | WA | 34 ms | 3416 KB |
1_62.txt | AC | 34 ms | 3416 KB |
1_63.txt | AC | 34 ms | 3416 KB |