private void SolveOneTestCase() { int n = In.NextInt(), m = In.NextInt(); List <string> dirs = new List <string>(); List <string> need = new List <string>(); for (int i = 0; i < n; ++i) { dirs.Add(In.NextLine()); } for (int i = 0; i < m; ++i) { need.Add(In.NextLine()); } System.Collections.Generic.Dictionary <string, bool> h = new System.Collections.Generic.Dictionary <string, bool>(); for (int i = 0; i < n; ++i) { var data = dirs[i].Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string path = "/"; foreach (var s in data) { path += s; if (!h.ContainsKey(path)) { h.Add(path, true); } } } int res = 0; for (int i = 0; i < m; i++) { var data = need[i].Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string path = "/"; foreach (var s in data) { path += s; if (!h.ContainsKey(path)) { h.Add(path, true); ++res; } } } Out.WriteLine(res); }
private void SolveOneTestCase() { p = In.NextInt(); dp = new long[1 << (p + 1), p + 1]; was = new bool[1 << (p + 1), p + 1]; m = new long[1 << (p + 1)]; sz = 1 << (p + 1); for (int i = p; i >= 0; --i) { int shift = (1 << i) - 1; for (int j = 0; j < (1 << i); ++j) { m[j + shift] = In.NextInt(); } } Out.WriteLine(go(0, 0, 0)); }
private void Solve() { var path = Path.Combine(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), @"..\..\..\gcj\solutions\" + PROBLEM_ALIAS), OUT_FILE); if (File.Exists(path)) { File.Delete(path); } int tests = In.NextInt(); for (int i = 0; i < tests; ++i) { using (Out = new StreamWriter(path, true)) { Out.Write(string.Format("Case #{0}: ", i + 1)); var timer = new Stopwatch(); timer.Start(); SolveOneTestCase(); Console.WriteLine(string.Format("Done test {1} in {0} seconds.", timer.ElapsedMilliseconds / 1000.0, i + 1)); } } }
private void SolveOneTestCase() { int n = In.NextInt(), k = In.NextInt(); N = n; K = k; b = In.NextInt(); t = In.NextInt(); x = new int[n]; v = new int[n]; for (int i = 0; i < n; i++) { x[i] = In.NextInt(); } for (int i = 0; i < n; i++) { v[i] = In.NextInt(); } dp = new int[n + 1, n + 1]; was = new bool[n + 1, n + 1]; int res = go(n, k); Out.WriteLine(res == INF ? "IMPOSSIBLE" : res.ToString()); }
private void SolveOneTestCase() { int n = In.NextInt(); C = new long[n + 1, n + 1]; for (int i = 0; i < n; ++i) { C[i, 0] = C[i, i] = 1; for (int j = 1; j < i; j++) { C[i, j] = (C[i - 1, j] + C[i - 1, j - 1]) % MOD; } } dp = new int[n, n + 1]; was = new bool[n, n + 1]; int res = 0; for (int len = 1; len < n; ++len) { res = (res + go(len, n)) % MOD; } Out.WriteLine(res); }
private void SolveOneTestCase() { int d = In.NextInt(), k = In.NextInt(); int[] a = new int[k]; int[] ten = new int[10]; ten[0] = 1; for (int i = 1; i < 10; ++i) { ten[i] = 10 * ten[i - 1]; } for (int i = 0; i < k; i++) { a[i] = In.NextInt(); } if (k == 1) { Out.WriteLine("I don't know."); return; } int[] p = new int[ten[d]]; p[0] = p[1] = 1; for (int i = 2; i *i < ten[d]; ++i) { if (p[i] == 0) { for (int j = i * i; j < ten[d]; j += i) { p[j] = 1; } } } int nnn = -1; bool many = false; int mx = -1; for (int i = 0; i < k; ++i) { mx = Math.Max(mx, a[i]); } for (int i = mx + 1; i < ten[d]; ++i) { if (p[i] == 0) { if (many) { break; } for (int A = 0; A < i; ++A) { if (many) { break; } int B = ((a[1] - (a[0] * A) % i) % i + i) % i; bool ok = true; for (int j = 2; j < k; ++j) { int next = (A * a[j - 1] + B) % i; if (next != a[j]) { ok = false; break; } } if (ok) { int nn = (A * a[k - 1] + B) % i; if (nnn == -1) { nnn = nn; } else if (nnn != nn) { many = true; break; } } } } } if (!many && nnn != -1) { Out.WriteLine(nnn); } else { Out.WriteLine("I don't know."); } }
private void SolveOneTestCase() { int r = In.NextInt(), k = In.NextInt(), n = In.NextInt(); int[] g = new int[n]; for (int i = 0; i < n; ++i) { g[i] = In.NextInt(); } var next = new int[n]; var cnt = new long[n]; for (int i = 0; i < n; ++i) { long sum = 0; next[i] = i; for (int j = 0; j < n; ++j) { int cur = j + i; if (cur >= n) { cur -= n; } sum += (long)g[cur]; if (sum > k) { sum -= (long)g[cur]; next[i] = cur; break; } } cnt[i] = sum; } int pos = 0; long res = 0; var was = new int[n]; for (int i = 0; i < n; ++i) { was[i] = -1; } for (int i = 0; i < r; ++i) { if (was[pos] != -1) { int periodLen = i - was[pos]; int left = r - i; long periodSum = 0; for (int j = 0, p = pos; j < periodLen; ++j) { periodSum += cnt[p]; p = next[p]; } res += (long)left / periodLen * periodSum; int after = left % periodLen; for (int j = 0, p = pos; j < after; ++j) { res += cnt[p]; p = next[p]; } break; } was[pos] = i; res += cnt[pos]; pos = next[pos]; } Out.WriteLine(res); }
private void SolveOneTestCase() { int R = In.NextInt(); int[,] a = new int[200, 200]; for (int z = 0; z < R; ++z) { int x1 = In.NextInt(), y1 = In.NextInt(), x2 = In.NextInt(), y2 = In.NextInt(); for (int i = Math.Min(y1, y2); i <= Math.Max(y1, y2); ++i) { for (int j = Math.Min(x1, x2); j <= Math.Max(x1, x2); ++j) { a[i, j] = 1; } } } Queue <int> delete = new Queue <int>(), add = new Queue <int>(); for (int i = 1; i <= 100; ++i) { for (int j = 1; j <= 100; ++j) { if (a[i, j] == 0) { if (a[i - 1, j] + a[i, j - 1] == 2) { add.Enqueue(i); add.Enqueue(j); } } else { if (a[i - 1, j] + a[i, j - 1] == 0) { delete.Enqueue(i); delete.Enqueue(j); } } } } int res = 0; while (add.Count > 0 || delete.Count > 0) { ++res; Queue <int> check = new Queue <int>(); while (delete.Count > 0) { int r = delete.Dequeue(); int c = delete.Dequeue(); if (a[r, c] == 0) { continue; } a[r, c] = 0; if (a[r + 1, c] == 1) { check.Enqueue(r + 1); check.Enqueue(c); } if (a[r, c + 1] == 1) { check.Enqueue(r); check.Enqueue(c + 1); } } while (check.Count > 0) { int r = check.Dequeue(); int c = check.Dequeue(); if (a[r, c] == 1 && a[r - 1, c] + a[r, c - 1] == 0) { delete.Enqueue(r); delete.Enqueue(c); } } while (add.Count > 0) { int r = add.Dequeue(); int c = add.Dequeue(); if (a[r, c] == 1) { continue; } a[r, c] = 1; if (a[r + 1, c] == 0) { check.Enqueue(r + 1); check.Enqueue(c); } if (a[r, c + 1] == 0) { check.Enqueue(r); check.Enqueue(c + 1); } } while (check.Count > 0) { int r = check.Dequeue(); int c = check.Dequeue(); if (a[r, c] == 0 && a[r - 1, c] + a[r, c - 1] == 2) { add.Enqueue(r); add.Enqueue(c); } } } Out.WriteLine(res); }
private void SolveOneTestCase() { int n = In.NextInt(), k = In.NextInt(); Out.WriteLine((k % (1 << n)) == (1 << n) - 1 ? "ON" : "OFF"); }
private void SolveOneTestCase() { int k = In.NextInt(); int[,] a = new int[k, k]; for (int i = 0; i < 2 * k - 1; ++i) { int cnt = i < k ? i + 1 : 2 * k - i - 1; for (int j = 0; j < cnt; ++j) { if (i < k) { a[i - j, j] = In.NextInt(); } else { a[k - j - 1, j + i - k + 1] = In.NextInt(); } } } for (int sz = k; sz <= 3 * k; ++sz) { bool ex = false; for (int i = 0; i + k - 1 < sz; ++i) { for (int j = 0; j + k - 1 < sz; ++j) { int[,] b = new int[sz, sz]; for (int ii = 0; ii < sz; ++ii) { for (int jj = 0; jj < sz; ++jj) { b[ii, jj] = -1; } } for (int ii = 0; ii < k; ++ii) { for (int jj = 0; jj < k; ++jj) { b[i + ii, j + jj] = a[ii, jj]; } } bool ok = true; for (int ii = 0; ii < sz; ++ii) { for (int jj = 0; jj < sz; ++jj) { if (b[ii, jj] == -1) { continue; } if (b[jj, ii] == -1) { b[jj, ii] = b[ii, jj]; } else if (b[ii, jj] != b[jj, ii]) { ok = false; break; } if (b[sz - jj - 1, sz - ii - 1] == -1) { b[sz - jj - 1, sz - ii - 1] = b[ii, jj]; } else if (b[ii, jj] != b[sz - jj - 1, sz - ii - 1]) { ok = false; break; } } if (!ok) { break; } } if (ok) { ex = true; break; } } } if (ex) { Out.WriteLine(sz * sz - k * k); break; } } }