buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { private const int INF = 1000000007; public static void Main() { long N = long.Parse(Console.ReadLine()); long ans = (long)(N / 11.0 * 2); if (N % 11 != 0) ans += 1; Console.WriteLine(ans); } } public class Factorization { private static long N; public Factorization(long n) { N = n; } //最大公約数を返す public static long GCD(long a, long b) { if (a < b) return GCD(b, a); long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } //素数判定 public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; double root = Math.Sqrt(n); for (int i = 3; i <= root; i += 2) { if (n % i == 0) return false; } return true; } //試し割り private static int[] TryPrimes = new int[] { 2, 3, 5, 7, 11 }; public long TryAllocation(long p) { long count = 0; while (N % p == 0) { count++; N /= p; } return count; } private int[] xi = new int[] { 13, 17, 19, 23, 29 }; private long f(long x, int suffix) { return (xi[suffix % xi.Count()] * x + suffix) % N; } // nを分解 public long PollardsRho(long n, int suffix = 0) { //素数を渡すと失敗するらしい if (IsPrime(n)) return n; //もう素数 long x = 2, y = 2, d = 1; while (d == 1) { x = f(x, suffix); y = f(f(y, suffix), suffix); d = GCD(Math.Abs(x - y), n); } if (d == n) { // f(x)を変えて試す return PollardsRho(n, suffix + 1); } return d; } public IEnumerable<long> Calc() { //小さな素因数の計算 foreach (var prime in TryPrimes) { var box = TryAllocation(prime); for (int i = 0; i < box; i++) yield return prime; } //残りをRhoで解く while (true) { if (N == 1) break; var ret = PollardsRho(N); yield return ret; N /= ret; } } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string StrReverce(string s) { return new string(s.Reverse().ToArray()); } public static int IntRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } public static long[] LSRead() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static long Combination(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r), r) .ToList() .Aggregate((now, next) => now * next) / Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next); } }
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { private const int INF = 1000000007; public static void Main() { long N = long.Parse(Console.ReadLine()); long n = (long)Math.Floor(N / 11.0); long ans = n * 2; N -= n * 11; if (N > 6) ans += 2; else if (N > 0) ans += 1; Console.WriteLine(ans); } } public class Factorization { private static long N; public Factorization(long n) { N = n; } //最大公約数を返す public static long GCD(long a, long b) { if (a < b) return GCD(b, a); long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } //素数判定 public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; double root = Math.Sqrt(n); for (int i = 3; i <= root; i += 2) { if (n % i == 0) return false; } return true; } //試し割り private static int[] TryPrimes = new int[] { 2, 3, 5, 7, 11 }; public long TryAllocation(long p) { long count = 0; while (N % p == 0) { count++; N /= p; } return count; } private int[] xi = new int[] { 13, 17, 19, 23, 29 }; private long f(long x, int suffix) { return (xi[suffix % xi.Count()] * x + suffix) % N; } // nを分解 public long PollardsRho(long n, int suffix = 0) { //素数を渡すと失敗するらしい if (IsPrime(n)) return n; //もう素数 long x = 2, y = 2, d = 1; while (d == 1) { x = f(x, suffix); y = f(f(y, suffix), suffix); d = GCD(Math.Abs(x - y), n); } if (d == n) { // f(x)を変えて試す return PollardsRho(n, suffix + 1); } return d; } public IEnumerable<long> Calc() { //小さな素因数の計算 foreach (var prime in TryPrimes) { var box = TryAllocation(prime); for (int i = 0; i < box; i++) yield return prime; } //残りをRhoで解く while (true) { if (N == 1) break; var ret = PollardsRho(N); yield return ret; N /= ret; } } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string StrReverce(string s) { return new string(s.Reverse().ToArray()); } public static int IntRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } public static long[] LSRead() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static long Combination(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r), r) .ToList() .Aggregate((now, next) => now * next) / Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 74, 51, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47]]
8
913
31
using System; using System.Collections.Generic; namespace Atcoder { class Program { static List<int[]> list = new List<int[]>(); static int[] yMove = new int[] { -1, 1, 0, 0 }; static int[] xMove = new int[] { 0, 0, -1, 1 }; static bool[,] miz; static void Main(string[] args) { // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line1[0]; // var M = line1[1]; // var a = new long[M]; // var b = new long[M]; // int bridge = 0; // int[,] dag = new int[N,N]; // for (int i = 0; i < M; i++) //{ // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // a[i] = line2[0]-1; // b[i] = line2[1]-1; // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // for (int i = 0; i < M; i++) //{ // bool[] visited = new bool[N]; // dag[a[i], b[i]] = 0; // dag[b[i], a[i]] = 0; // DFS(0,visited,dag); // if (visited.Where(n => n == true).Count() != N) // { // bridge++; // } // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // Console.WriteLine(bridge); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var A = line1[0]; // var B = line1[1]; // var C = line1[2]; // var D = line1[3]; // var E = line1[4]; // var F = line1[5]; // var N = int.Parse(Console.ReadLine()); // char[] mozi = new char[N]; // long[] MARCH = new long[5]; // long cnt = 0; // for (int i = 0; i < N; i++) //{ // mozi[i] = Console.ReadLine().ToCharArray()[0]; //} // MARCH[0] = mozi.Where(n => n == 'M').Count(); // MARCH[1] = mozi.Where(n => n == 'A').Count(); // MARCH[2] = mozi.Where(n => n == 'R').Count(); // MARCH[3] = mozi.Where(n => n == 'C').Count(); // MARCH[4] = mozi.Where(n => n == 'H').Count(); // for (int i = 0; i < 3; i++) //{ // for (int j = i + 1; j < 4; j++) // { // for (int k = j + 1; k < 5; k++) // { // cnt += MARCH[i] * MARCH[j] * MARCH[k]; // } // } //} // Console.WriteLine(cnt); // var N = int.Parse(Console.ReadLine()); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int candy = 0; // int MAX = 0; // for (int i = 0; i < N; i++) //{ // for (int k = 0; k <= i; k++) // { // candy += line1[k]; // } // for (int j = N - 1; j >= i; j--) // { // candy += line2[j]; // } // MAX = Math.Max(candy,MAX); // candy = 0; //} // Console.WriteLine(MAX); // var N = int.Parse(Console.ReadLine()); // List<int[]> list = new List<int[]>(); // int t = 0; // int x = 0; // int y = 0; // for (int i = 0; i < N; i++) //{ // var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // list.Add(txy); //} // foreach (var item in list) //{ // if (item[0] - t >= Math.Abs(item[1] + item[2] - x - y)) // { // if (((item[0] - t) % 2 == 1 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 1) || // ((item[0] - t) % 2 == 0 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 0)) // { // t = item[0]; // x = item[1]; // y = item[2]; // } // else // { // Console.WriteLine("No"); // return; // } // } // else // { // Console.WriteLine("No"); // return; // } //} // Console.WriteLine("Yes"); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // if (line1[1] >= 10000) //{ // for (int i = 0; i <= line1[1]/10000; i++) // { // for (int j = 0; j <= line1[1] / 5000; j++) // { // if (10000 * i + 5000 * j + (line1[0] - i - j) * 1000 == // line1[1] && line1[0] - i - j >= 0) // { // Console.WriteLine("{0} {1} {2}",i,j,line1[0] - i - j); // return; // } // } // } //} // else //{ // for (int i = 0; i < 2; i++) // { // for (int j = 0; j <= 9; j++) // { // if (5000 * i + 1000 * j == line1[1] && i + j == line1[0]) // { // Console.WriteLine("{0} {1} {2}", 0, i, j); // return; // } // } // } //} // Console.WriteLine("{0} {1} {2}", -1, -1, -1); // var N = int.Parse(Console.ReadLine()); // int[,] station = new int[N,3]; // long sum = 0; // for (int i = 0; i < N - 1; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // station[i, 0] = line[0]; // station[i, 1] = line[1]; // station[i, 2] = line[2]; //} // for (int j = 0; j < N -1; j++) //{ // for (int i = j; i < N - 1; i++) // { // var F = station[i, 2]; // var S = station[i, 1]; // if (i == j) // { // sum += station[i, 0] + station[i, 1]; // } // else // { // if (sum < S) // { // sum = S + station[i, 0]; // } // else if (sum % F == 0) // { // sum += station[i, 0]; // } // else // { // sum += F - (sum % F) + station[i, 0]; // } // } // } // Console.WriteLine(sum); // sum = 0; //} // Console.WriteLine(sum); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long A = line[0]; // int i = 0; // while (A <= line[1]) //{ // A *=2; // i++; //} // Console.WriteLine(i); // var N = long.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // Dictionary<long, long> dic = new Dictionary<long, long>(); // long sum = 0; // for (int i = 0; i < N; i++) //{ // if (dic.ContainsKey(line[i])) // { // dic[line[i]]++; // } // else // { // dic.Add(line[i], 1); // } //} // foreach (var item in dic) //{ // if (item.Key == item.Value) // { // } // else if (item.Key < item.Value) // { // sum += item.Value - item.Key; // } // else // { // sum += item.Value; // } //} // Console.WriteLine(sum); // var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // var N = line[0]; // var K = line[1]; // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long cnt = 0; // long sum = 0; // long[] lngarray = new long[N]; // for (int i = 0; i < N; i++) //{ // lngarray[line2[i]-1]++; //} // if (lngarray.Where(n => n !=0).Count() <= K) //{ // Console.WriteLine(0); // return; //} // var orderlng = lngarray.Where(n => n != 0).OrderBy(n => n).ToArray(); // for (int i = 0; i < orderlng.Length; i++) //{ // if (cnt == orderlng.Length - K) // { // Console.WriteLine(sum); // return; // } // else // { // sum += orderlng[i]; // cnt++; // } //} // int soe = 0; // saiki(soe, new int[10]); // var N = int.Parse(Console.ReadLine()); // var F = new List<int[]>(); // var P = new List<int[]>(); // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // F.Add(line); //} // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // P.Add(line); //} // int sum = int.MinValue; // list.RemoveAt(0); // foreach (var item in list) //{ // int tmpsum = 0; // for (int i = 0; i < N; i++) // { // int c = 0; // for (int j = 0; j < 10; j++) // { // if (item[j] == 1 && F[i][j] == 1) // { // c++; // } // } // tmpsum += P[i][c]; // } // sum = Math.Max(sum, tmpsum); //} // Console.WriteLine(sum); // var line = Console.ReadLine().ToCharArray(); // int[] hai = new int[7]; // hai[0] = int.Parse(line[0].ToString()); // hai[2] = int.Parse(line[1].ToString()); // hai[4] = int.Parse(line[2].ToString()); // hai[6] = int.Parse(line[3].ToString()); // saikiseven(1,0, hai); // string ope1 = list[0][1] == 0 ? "+" : "-"; // string ope2 = list[0][3] == 0 ? "+" : "-"; // string ope3 = list[0][5] == 0 ? "+" : "-"; // Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}=7", list[0][0],ope1, list[0][2], // ope2,list[0][4], ope3,list[0][6]); // var N = long.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long[] A = new long[N]; // for (int i = 0; i < N; i++) //{ // A[i] = Math.Abs(i - (N - i -1)); //} // var tmp1 = line.OrderBy(n => n).ToArray(); // var tmp2 = A.OrderBy(n => n).ToArray(); // for (int i = 0; i < N; i++) //{ // if (tmp1[i] != tmp2[i]) // { // Console.WriteLine(0); // return; // } //} // long X = 1; // for (int i = 0; i < N/2; i++) //{ // X *= 2; // X %= 1000000007; //} // Console.WriteLine(X); // var line =Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // var sx = line[0]; // var sy = line[1]; // var tx = line[2]; // var ty = line[3]; // var path1 = new string('U', ty - sy) + new string('R',tx - sx); // var path2 = new string('D', ty - sy) + new string('L', tx - sx); // var path3 = new string('L', 1) + new string('U', ty - sy + 1) + new // string('R', tx - sx + 1) + new string('D', 1); var path4 = new string('R', // 1) + new string('D', ty - sy + 1) + new string('L', tx - sx + 1) + new // string('U', 1); Console.WriteLine(path1 + path2 + path3 + path4); int[] // sosuu = new int[1000]; // var N = int.Parse(Console.ReadLine()); // int[] sosuu = new int[1001]; // long ans = 1; // for (int i = 1; i < N + 1; i++) //{ // PrimeFactors(i, sosuu); //} // for (int i = 2; i < N + 1; i++) //{ // ans *= sosuu[i] + 1; // ans %= 1000000007; //} // Console.WriteLine(ans); var N = long.Parse(Console.ReadLine()); long X = 0; long Y = 0; X = N / 11; if (X == 0) { Y = 0; } else if ((N - (11 * X)) <= 6) { Y = 1; } else { Y = 2; } Console.WriteLine(X * 2 + Y); } public static void PrimeFactors(int n, int[] sosuu) { int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; sosuu[i]++; } else { i++; } } if (tmp != 1) sosuu[tmp]++; } public static void DFSzahyo(int x, int y, int[] s, int[] g) { if (x == g[0] && y == g[1]) { return; } miz[x, y] = true; for (int i = 0; i < 4; i++) { if (miz[x + xMove[i], y + yMove[i]] != true) { DFSzahyo(x + xMove[i], y + yMove[i], s, g); } } } public static void saikiseven(int ope, int sum, int[] hairetui) { if (ope == 1) { sum = hairetui[ope - 1]; } if (ope == 7 && sum == 7) { int[] dummy = new int[ope]; hairetui.CopyTo(dummy, 0); list.Add(dummy); return; } else if (ope == 7 && sum != 7) { return; } for (int i = 0; i < 2; i++) { if (i == 0) { sum += hairetui[ope + 1]; hairetui[ope] = i; saikiseven(ope + 2, sum, hairetui); sum -= hairetui[ope + 1]; } else { sum -= hairetui[ope + 1]; hairetui[ope] = i; saikiseven(ope + 2, sum, hairetui); } } return; } public static void saiki(int soezi, int[] hairetui) { if (soezi == 10) { int[] dummy = new int[soezi]; hairetui.CopyTo(dummy, 0); list.Add(dummy); return; } for (int j = 0; j < 2; j++) { hairetui[soezi] = j; saiki(soezi + 1, hairetui); } return; } public static void DFS(int v, bool[] visited, int[,] dag) { visited[v] = true; for (int i = 0; i < visited.Length; i++) { if (dag[v, i] == 0) continue; if (visited[i]) continue; DFS(i, visited, dag); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } /// <summary> /// Get min cost between two points /// </summary> // public class Dijkstra //{ // private int maxIndex = -1; // private const int INF = Int32.MaxValue; // private int[,] _edgeArray; // /// <summary> // /// Dijkstra, get min cost between two points // /// should not contain negatie cost path // /// </summary> // /// <param name="size">max index of vertices</param> // public Dijkstra(int size) // { // maxIndex = size + 1; // _edgeArray = new int[maxIndex, maxIndex]; // for (int i = 0; i < _edgeArray.GetLength(0); i++) // { // for (int j = 0; j < _edgeArray.GetLength(1); j++) // { // _edgeArray[i, j] = INF; // if (i == j) _edgeArray[i, j] = 0; // } // } // } // // Add a path(no direction) with its cost // public void AddPath(int s, int t, int cost) // { // _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); // _edgeArray[t, s] = _edgeArray[s, t]; // } // //Get the min cost between s and t // //return Int32.MaxValue if no path // public int GetMinCost(int s, int t) // { // int[] cost = new int[maxIndex]; // for (int i = 0; i < cost.Length; i++) cost[i] = INF; // cost[s] = 0; // var priorityQueue = new PriorityQueue<ComparablePair<int, // int>>(maxIndex); priorityQueue.Push(new ComparablePair<int, int>(0, // s)); // while (priorityQueue.Count() > 0) // { // var costDestinationPair = priorityQueue.Pop(); // if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) // continue; // for (int i = 0; i < maxIndex; i++) // { // int newCostToi = _edgeArray[costDestinationPair.Item2, i] == // INF ? INF : // costDestinationPair.Item1 + // _edgeArray[costDestinationPair.Item2, i]; // if (newCostToi < cost[i]) // { // cost[i] = newCostToi; // priorityQueue.Push(new ComparablePair<int, // int>(newCostToi, i)); // } // } // } // return cost[t]; // } //} // public class ComparablePair<T, U> : IComparable where T : IComparable<T> //{ // public readonly T Item1; // public readonly U Item2; // public int CompareTo(object obj) // { // ComparablePair<T, U> castedObj = (ComparablePair<T, U>)obj; // return this.Item1.CompareTo(castedObj.Item1); // } // public ComparablePair(T t, U u) // { // Item1 = t; // Item2 = u; // } //} }
using System; using System.Collections.Generic; namespace Atcoder { class Program { static List<int[]> list = new List<int[]>(); static int[] yMove = new int[] { -1, 1, 0, 0 }; static int[] xMove = new int[] { 0, 0, -1, 1 }; static bool[,] miz; static void Main(string[] args) { // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var N = line1[0]; // var M = line1[1]; // var a = new long[M]; // var b = new long[M]; // int bridge = 0; // int[,] dag = new int[N,N]; // for (int i = 0; i < M; i++) //{ // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // a[i] = line2[0]-1; // b[i] = line2[1]-1; // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // for (int i = 0; i < M; i++) //{ // bool[] visited = new bool[N]; // dag[a[i], b[i]] = 0; // dag[b[i], a[i]] = 0; // DFS(0,visited,dag); // if (visited.Where(n => n == true).Count() != N) // { // bridge++; // } // dag[a[i], b[i]] = 1; // dag[b[i], a[i]] = 1; //} // Console.WriteLine(bridge); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // var A = line1[0]; // var B = line1[1]; // var C = line1[2]; // var D = line1[3]; // var E = line1[4]; // var F = line1[5]; // var N = int.Parse(Console.ReadLine()); // char[] mozi = new char[N]; // long[] MARCH = new long[5]; // long cnt = 0; // for (int i = 0; i < N; i++) //{ // mozi[i] = Console.ReadLine().ToCharArray()[0]; //} // MARCH[0] = mozi.Where(n => n == 'M').Count(); // MARCH[1] = mozi.Where(n => n == 'A').Count(); // MARCH[2] = mozi.Where(n => n == 'R').Count(); // MARCH[3] = mozi.Where(n => n == 'C').Count(); // MARCH[4] = mozi.Where(n => n == 'H').Count(); // for (int i = 0; i < 3; i++) //{ // for (int j = i + 1; j < 4; j++) // { // for (int k = j + 1; k < 5; k++) // { // cnt += MARCH[i] * MARCH[j] * MARCH[k]; // } // } //} // Console.WriteLine(cnt); // var N = int.Parse(Console.ReadLine()); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // var line2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // int candy = 0; // int MAX = 0; // for (int i = 0; i < N; i++) //{ // for (int k = 0; k <= i; k++) // { // candy += line1[k]; // } // for (int j = N - 1; j >= i; j--) // { // candy += line2[j]; // } // MAX = Math.Max(candy,MAX); // candy = 0; //} // Console.WriteLine(MAX); // var N = int.Parse(Console.ReadLine()); // List<int[]> list = new List<int[]>(); // int t = 0; // int x = 0; // int y = 0; // for (int i = 0; i < N; i++) //{ // var txy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // list.Add(txy); //} // foreach (var item in list) //{ // if (item[0] - t >= Math.Abs(item[1] + item[2] - x - y)) // { // if (((item[0] - t) % 2 == 1 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 1) || // ((item[0] - t) % 2 == 0 && Math.Abs(x + y - item[1] - item[2]) // % 2 == 0)) // { // t = item[0]; // x = item[1]; // y = item[2]; // } // else // { // Console.WriteLine("No"); // return; // } // } // else // { // Console.WriteLine("No"); // return; // } //} // Console.WriteLine("Yes"); // var line1 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // if (line1[1] >= 10000) //{ // for (int i = 0; i <= line1[1]/10000; i++) // { // for (int j = 0; j <= line1[1] / 5000; j++) // { // if (10000 * i + 5000 * j + (line1[0] - i - j) * 1000 == // line1[1] && line1[0] - i - j >= 0) // { // Console.WriteLine("{0} {1} {2}",i,j,line1[0] - i - j); // return; // } // } // } //} // else //{ // for (int i = 0; i < 2; i++) // { // for (int j = 0; j <= 9; j++) // { // if (5000 * i + 1000 * j == line1[1] && i + j == line1[0]) // { // Console.WriteLine("{0} {1} {2}", 0, i, j); // return; // } // } // } //} // Console.WriteLine("{0} {1} {2}", -1, -1, -1); // var N = int.Parse(Console.ReadLine()); // int[,] station = new int[N,3]; // long sum = 0; // for (int i = 0; i < N - 1; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // station[i, 0] = line[0]; // station[i, 1] = line[1]; // station[i, 2] = line[2]; //} // for (int j = 0; j < N -1; j++) //{ // for (int i = j; i < N - 1; i++) // { // var F = station[i, 2]; // var S = station[i, 1]; // if (i == j) // { // sum += station[i, 0] + station[i, 1]; // } // else // { // if (sum < S) // { // sum = S + station[i, 0]; // } // else if (sum % F == 0) // { // sum += station[i, 0]; // } // else // { // sum += F - (sum % F) + station[i, 0]; // } // } // } // Console.WriteLine(sum); // sum = 0; //} // Console.WriteLine(sum); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long A = line[0]; // int i = 0; // while (A <= line[1]) //{ // A *=2; // i++; //} // Console.WriteLine(i); // var N = long.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // Dictionary<long, long> dic = new Dictionary<long, long>(); // long sum = 0; // for (int i = 0; i < N; i++) //{ // if (dic.ContainsKey(line[i])) // { // dic[line[i]]++; // } // else // { // dic.Add(line[i], 1); // } //} // foreach (var item in dic) //{ // if (item.Key == item.Value) // { // } // else if (item.Key < item.Value) // { // sum += item.Value - item.Key; // } // else // { // sum += item.Value; // } //} // Console.WriteLine(sum); // var line = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // var N = line[0]; // var K = line[1]; // var line2 = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long cnt = 0; // long sum = 0; // long[] lngarray = new long[N]; // for (int i = 0; i < N; i++) //{ // lngarray[line2[i]-1]++; //} // if (lngarray.Where(n => n !=0).Count() <= K) //{ // Console.WriteLine(0); // return; //} // var orderlng = lngarray.Where(n => n != 0).OrderBy(n => n).ToArray(); // for (int i = 0; i < orderlng.Length; i++) //{ // if (cnt == orderlng.Length - K) // { // Console.WriteLine(sum); // return; // } // else // { // sum += orderlng[i]; // cnt++; // } //} // int soe = 0; // saiki(soe, new int[10]); // var N = int.Parse(Console.ReadLine()); // var F = new List<int[]>(); // var P = new List<int[]>(); // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // F.Add(line); //} // for (int i = 0; i < N; i++) //{ // var line = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); // P.Add(line); //} // int sum = int.MinValue; // list.RemoveAt(0); // foreach (var item in list) //{ // int tmpsum = 0; // for (int i = 0; i < N; i++) // { // int c = 0; // for (int j = 0; j < 10; j++) // { // if (item[j] == 1 && F[i][j] == 1) // { // c++; // } // } // tmpsum += P[i][c]; // } // sum = Math.Max(sum, tmpsum); //} // Console.WriteLine(sum); // var line = Console.ReadLine().ToCharArray(); // int[] hai = new int[7]; // hai[0] = int.Parse(line[0].ToString()); // hai[2] = int.Parse(line[1].ToString()); // hai[4] = int.Parse(line[2].ToString()); // hai[6] = int.Parse(line[3].ToString()); // saikiseven(1,0, hai); // string ope1 = list[0][1] == 0 ? "+" : "-"; // string ope2 = list[0][3] == 0 ? "+" : "-"; // string ope3 = list[0][5] == 0 ? "+" : "-"; // Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}=7", list[0][0],ope1, list[0][2], // ope2,list[0][4], ope3,list[0][6]); // var N = long.Parse(Console.ReadLine()); // var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); // long[] A = new long[N]; // for (int i = 0; i < N; i++) //{ // A[i] = Math.Abs(i - (N - i -1)); //} // var tmp1 = line.OrderBy(n => n).ToArray(); // var tmp2 = A.OrderBy(n => n).ToArray(); // for (int i = 0; i < N; i++) //{ // if (tmp1[i] != tmp2[i]) // { // Console.WriteLine(0); // return; // } //} // long X = 1; // for (int i = 0; i < N/2; i++) //{ // X *= 2; // X %= 1000000007; //} // Console.WriteLine(X); // var line =Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // var sx = line[0]; // var sy = line[1]; // var tx = line[2]; // var ty = line[3]; // var path1 = new string('U', ty - sy) + new string('R',tx - sx); // var path2 = new string('D', ty - sy) + new string('L', tx - sx); // var path3 = new string('L', 1) + new string('U', ty - sy + 1) + new // string('R', tx - sx + 1) + new string('D', 1); var path4 = new string('R', // 1) + new string('D', ty - sy + 1) + new string('L', tx - sx + 1) + new // string('U', 1); Console.WriteLine(path1 + path2 + path3 + path4); int[] // sosuu = new int[1000]; // var N = int.Parse(Console.ReadLine()); // int[] sosuu = new int[1001]; // long ans = 1; // for (int i = 1; i < N + 1; i++) //{ // PrimeFactors(i, sosuu); //} // for (int i = 2; i < N + 1; i++) //{ // ans *= sosuu[i] + 1; // ans %= 1000000007; //} // Console.WriteLine(ans); var N = long.Parse(Console.ReadLine()); long X = 0; long Y = 0; X = N / 11; if ((N - (11 * X)) == 0) { Y = 0; } else if ((N - (11 * X)) <= 6) { Y = 1; } else { Y = 2; } Console.WriteLine(X * 2 + Y); } public static void PrimeFactors(int n, int[] sosuu) { int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; sosuu[i]++; } else { i++; } } if (tmp != 1) sosuu[tmp]++; } public static void DFSzahyo(int x, int y, int[] s, int[] g) { if (x == g[0] && y == g[1]) { return; } miz[x, y] = true; for (int i = 0; i < 4; i++) { if (miz[x + xMove[i], y + yMove[i]] != true) { DFSzahyo(x + xMove[i], y + yMove[i], s, g); } } } public static void saikiseven(int ope, int sum, int[] hairetui) { if (ope == 1) { sum = hairetui[ope - 1]; } if (ope == 7 && sum == 7) { int[] dummy = new int[ope]; hairetui.CopyTo(dummy, 0); list.Add(dummy); return; } else if (ope == 7 && sum != 7) { return; } for (int i = 0; i < 2; i++) { if (i == 0) { sum += hairetui[ope + 1]; hairetui[ope] = i; saikiseven(ope + 2, sum, hairetui); sum -= hairetui[ope + 1]; } else { sum -= hairetui[ope + 1]; hairetui[ope] = i; saikiseven(ope + 2, sum, hairetui); } } return; } public static void saiki(int soezi, int[] hairetui) { if (soezi == 10) { int[] dummy = new int[soezi]; hairetui.CopyTo(dummy, 0); list.Add(dummy); return; } for (int j = 0; j < 2; j++) { hairetui[soezi] = j; saiki(soezi + 1, hairetui); } return; } public static void DFS(int v, bool[] visited, int[,] dag) { visited[v] = true; for (int i = 0; i < visited.Length; i++) { if (dag[v, i] == 0) continue; if (visited[i]) continue; DFS(i, visited, dag); } } public static long LowerBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static long UpperBound<T>(T[] arr, long start, long end, T value, IComparer<T> comparer) { long low = start; long high = end; long mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static long UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } } /// <summary> /// Get min cost between two points /// </summary> // public class Dijkstra //{ // private int maxIndex = -1; // private const int INF = Int32.MaxValue; // private int[,] _edgeArray; // /// <summary> // /// Dijkstra, get min cost between two points // /// should not contain negatie cost path // /// </summary> // /// <param name="size">max index of vertices</param> // public Dijkstra(int size) // { // maxIndex = size + 1; // _edgeArray = new int[maxIndex, maxIndex]; // for (int i = 0; i < _edgeArray.GetLength(0); i++) // { // for (int j = 0; j < _edgeArray.GetLength(1); j++) // { // _edgeArray[i, j] = INF; // if (i == j) _edgeArray[i, j] = 0; // } // } // } // // Add a path(no direction) with its cost // public void AddPath(int s, int t, int cost) // { // _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); // _edgeArray[t, s] = _edgeArray[s, t]; // } // //Get the min cost between s and t // //return Int32.MaxValue if no path // public int GetMinCost(int s, int t) // { // int[] cost = new int[maxIndex]; // for (int i = 0; i < cost.Length; i++) cost[i] = INF; // cost[s] = 0; // var priorityQueue = new PriorityQueue<ComparablePair<int, // int>>(maxIndex); priorityQueue.Push(new ComparablePair<int, int>(0, // s)); // while (priorityQueue.Count() > 0) // { // var costDestinationPair = priorityQueue.Pop(); // if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) // continue; // for (int i = 0; i < maxIndex; i++) // { // int newCostToi = _edgeArray[costDestinationPair.Item2, i] == // INF ? INF : // costDestinationPair.Item1 + // _edgeArray[costDestinationPair.Item2, i]; // if (newCostToi < cost[i]) // { // cost[i] = newCostToi; // priorityQueue.Push(new ComparablePair<int, // int>(newCostToi, i)); // } // } // } // return cost[t]; // } //} // public class ComparablePair<T, U> : IComparable where T : IComparable<T> //{ // public readonly T Item1; // public readonly U Item2; // public int CompareTo(object obj) // { // ComparablePair<T, U> castedObj = (ComparablePair<T, U>)obj; // return this.Item1.CompareTo(castedObj.Item1); // } // public ComparablePair(T t, U u) // { // Item1 = t; // Item2 = u; // } //} }
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 33], ["+", 15, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 48], ["+", 15, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25]]
8
1,413
8
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace NotFounds { public class Program { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; WriteLine(Ceiling(N / 11.0 * 2)); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace NotFounds { public class Program { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; WriteLine(N / 11 * 2 + (N % 11 > 6 ? 2 : (N % 11 == 0 ? 0 : 1))); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 250], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 17, 47], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 64, 203], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 0, 102], ["+", 0, 16, 12, 23, 0, 41, 75, 23, 0, 24], ["+", 75, 23, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 75, 23, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 75, 23, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 0, 41, 75, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 41, 75, 23, 0, 41, 15, 16, 12, 203], ["+", 12, 23, 0, 41, 75, 23, 0, 41, 0, 101], ["+", 12, 23, 0, 41, 75, 23, 0, 41, 64, 203], ["+", 12, 23, 0, 41, 75, 23, 0, 41, 0, 102], ["+", 12, 23, 0, 41, 75, 23, 0, 41, 75, 203], ["+", 0, 16, 12, 23, 0, 41, 75, 23, 0, 25]]
8
547
25
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Linq.Expressions; using static System.Console; using static System.Math; class Simple { long x; void Solve() { // input x = io.Long; // cal var ans = x <= 6 ? 1 : x <= 11 ? 2 : (x / 11) * 2 + (x % 11 == 0 ? 0 : 1); // ret WriteLine(ans); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); private void Stream() { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // SetIn(exStdIn); Solve(); io.Flush(); } } class SimpleIO { string[] _nextBuffer; int _bufferCnt; char[] cs = new char[] { ' ', '"', ',' }; StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { _nextBuffer = new string[0]; _bufferCnt = 0; SetOut(sw); } string Next() { if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++]; var st = ReadLine(); while (st == "") st = ReadLine(); if (st != null) _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); else st = ""; _bufferCnt = 0; return _nextBuffer[_bufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void Flush() => Out.Flush(); }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Linq.Expressions; using static System.Console; using static System.Math; class Simple { long x; void Solve() { // input x = io.Long; // cal var ans = x <= 6 ? 1 : x <= 11 ? 2 : (x / 11) * 2 + (x % 11 == 0 ? 0 : x % 11 <= 6 ? 1 : 2); // ret WriteLine(ans); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); private void Stream() { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // SetIn(exStdIn); Solve(); io.Flush(); } } class SimpleIO { string[] _nextBuffer; int _bufferCnt; char[] cs = new char[] { ' ', '"', ',' }; StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { _nextBuffer = new string[0]; _bufferCnt = 0; SetOut(sw); } string Next() { if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++]; var st = ReadLine(); while (st == "") st = ReadLine(); if (st != null) _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); else st = ""; _bufferCnt = 0; return _nextBuffer[_bufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void Flush() => Out.Flush(); }
[["+", 0, 41, 75, 41, 15, 16, 31, 16, 31, 22], ["+", 0, 41, 75, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 41, 75, 41, 15, 16, 31, 16, 12, 203], ["+", 12, 23, 0, 41, 75, 41, 15, 16, 17, 19], ["+", 12, 23, 0, 41, 75, 41, 15, 16, 12, 203], ["+", 75, 16, 12, 23, 0, 41, 75, 41, 0, 101], ["+", 75, 16, 12, 23, 0, 41, 75, 41, 0, 102], ["+", 75, 16, 12, 23, 0, 41, 75, 41, 75, 203]]
8
373
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BeginnerContest053 { class Program { static void Main(string[] args) { var input = Console.ReadLine(); // Console.WriteLine(int.Parse(input) < 1200 ? "ABC" : "ARC"); // var first = input.IndexOf("A"); // var last = input.LastIndexOf("Z"); // Console.WriteLine(last - first +1); var max = long.Parse(input); if (max <= 6) { Console.WriteLine(1); } else if (max < 11) { Console.WriteLine(2); } else { var result = max / 11; result *= 2; if (max % 11 != 0) result += 1; Console.WriteLine(result); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BeginnerContest053 { class Program { static void Main(string[] args) { var input = Console.ReadLine(); // Console.WriteLine(int.Parse(input) < 1200 ? "ABC" : "ARC"); // var first = input.IndexOf("A"); // var last = input.LastIndexOf("Z"); // Console.WriteLine(last - first +1); var max = long.Parse(input); if (max <= 6) { Console.WriteLine(1); } else if (max < 11) { Console.WriteLine(2); } else { var result = max / 11; result *= 2; if (max % 11 != 0) { result += 1; var mod = max % 11; if (mod > 6) result += 1; } Console.WriteLine(result); } } } }
[["+", 75, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 75, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 75, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 75, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 75, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 75, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
8
133
19
using System; namespace AtCoder { class Program { static void Main(string[] args) // static void dummy() { // 入力データパース string szPoint = Console.ReadLine(); long point = long.Parse(szPoint); // 初回は絶対6だ!!その次は5にする、6、5、… // 偶数回の計算式から必要な回数を long retEven = (2L * point) / 11 + 1; // 奇数回の計算式から必要な回数を long retOdd = (2L * (point - 6) + 11) / 11 + 1; long ret = Math.Min(retEven, retOdd); Console.WriteLine(ret); } private static int EvenPoint(int x) { return 11 * (x / 2); } private static int OddPoint(int x) { return 11 * ((x - 1) / 2) + 6; } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) // static void dummy() { // 入力データパース string szPoint = Console.ReadLine(); long point = long.Parse(szPoint); // 初回は絶対6だ!!その次は5にする、6、5、… // 偶数回の計算式から必要な回数を long retEven = (long)Math.Ceiling((2d * point) / 11); // 奇数回の計算式から必要な回数を long retOdd = (long)Math.Ceiling((2d * (point - 6) + 11) / 11); long ret = Math.Min(retEven, retOdd); Console.WriteLine(ret); } private static int EvenPoint(int x) { return 11 * (x / 2); } private static int OddPoint(int x) { return 11 * ((x - 1) / 2) + 6; } } }
[["-", 0, 16, 31, 16, 31, 23, 0, 16, 31, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 74, 51, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 250], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 212, 0, 74, 51, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["-", 31, 16, 31, 23, 0, 16, 31, 16, 31, 203], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 250]]
8
141
24
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { long x = RLong(); long ans = 0; ans += (x / 11) * 2; x %= 11; var s = new List<int>() { 6, 5 }; for (int i = 0; i < 3; i++) { x -= s[i]; ans++; if (x <= 0) break; } WriteLine(ans); } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { long x = RLong(); long ans = 0; ans += (x / 11) * 2; x %= 11; var s = new List<int>() { 6, 5 }; for (int i = 0; i < 3; i++) { if (x <= 0) break; x -= s[i]; ans++; } WriteLine(ans); } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94]]
8
744
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class219 { static void Main() { long x = long.Parse(Console.ReadLine()); long x2 = x / 11 * 2; long y = x % 11; if (y > 6) y = 2; else y = 1; Console.WriteLine(x2 + y); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class219 { static void Main() { long x = long.Parse(Console.ReadLine()); long x2 = x / 11 * 2; long y = x % 11; if (y > 6) y = 2; else if (y != 0) y = 1; else y = 0; Console.WriteLine(x2 + y); } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 0, 57, 75, 57, 75, 1, 0, 11, 31, 22], ["+", 75, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 57, 75, 1, 0, 11, 12, 203]]
8
96
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_A.Lib_IO; using static Contest_A.Lib_Minifunc; public static class Contest_A { public static void Main() { checked{ long x; Lib_IO.rm(out x); long c = x/11; x -= c*11; ll ans = 2*c + (x<=6?1:2); Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_A.Lib_IO; using static Contest_A.Lib_Minifunc; public static class Contest_A { public static void Main() { checked{ long x; Lib_IO.rm(out x); long c = x/11; x -= c*11; ll ans = 2*c; if(0<x) ans += (x<=6?1:2); Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 8, 196, 0, 287, 0, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 287, 0, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 287, 0, 196, 0, 57, 0, 24], ["+", 0, 287, 0, 196, 0, 57, 15, 16, 31, 203], ["+", 0, 287, 0, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 287, 0, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 287, 0, 196, 0, 57, 0, 25], ["+", 0, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107]]
8
2,921
10
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Diagnostics; using static System.Console; using static System.Math; namespace FunProCon { class FunProConSummer { static void Main(string[] args) { long s = long.Parse(ReadLine()); // 65656565...という操作を行う long hoge = s % 11; WriteLine(((s / 11) * 2) + (hoge / 7) + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Diagnostics; using static System.Console; using static System.Math; namespace FunProCon { class FunProConSummer { static void Main(string[] args) { long s = long.Parse(ReadLine()); // 65656565...という操作を行う long hoge = s % 11; WriteLine(hoge == 0 ? ((s / 11) * 2) + (hoge / 7) : ((s / 11) * 2) + (hoge / 7) + 1); } } }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 28, 0, 41, 64, 16, 31, 23, 0, 24], ["+", 64, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 17, 85], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 64, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 41, 64, 16, 31, 23, 0, 16, 17, 48], ["+", 0, 41, 64, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 41, 64, 16, 31, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 17, 72], ["+", 0, 41, 64, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 41, 64, 16, 12, 23, 0, 16, 17, 85], ["+", 0, 41, 64, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 41, 64, 16, 12, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 41, 75, 16, 31, 16, 31, 23, 0, 24]]
8
102
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { private const int MODULO = 1000000007; private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static void Main(string[] args) { long x = ReadLong(); long y = ((x * 2 + 10) / 11); Console.WriteLine(y); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { private const int MODULO = 1000000007; private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static void Main(string[] args) { long x = ReadLong(); long q = (x - 1) / 11; long m = (x - 1) % 11; long y = (m < 6) ? q * 2 + 1 : q * 2 + 2; Console.WriteLine(y); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 212, 0, 23, 0, 16, 31, 23, 0, 24], ["-", 0, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["-", 0, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 23, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 200, 0, 212, 0, 41, 15, 23, 0, 24], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 17, 18], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 212, 0, 41, 64, 16, 31, 16, 31, 22], ["+", 0, 212, 0, 41, 64, 16, 31, 16, 17, 48], ["+", 0, 212, 0, 41, 64, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 64, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 41, 64, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 212, 0, 41, 75, 16, 31, 16, 31, 22], ["+", 0, 212, 0, 41, 75, 16, 31, 16, 17, 48], ["+", 0, 212, 0, 41, 75, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 12, 203]]
8
228
40
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace AtCoder { class MainClass { // C#7.0///////////////////////////////////////////////////// long X; void Solve() { io.i(out X); long ans = X / 11 * 2 + ((X % 11 <= 6) ? 1 : 2); io.o(ans); } //////////////////////////////////////////////////////////// public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // Hack Update // cannot use break,continue,goto void FOR(int a, int b, Action<int> act, int c = 1) { for (int i = a; i < b; i += c) act(i); } void FOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = a; i < b && con(i); i += c) act(i); } void RFOR(int a, int b, Action<int> act, int c = 1) { for (int i = a; i >= b; i -= c) act(i); } void RFOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = a; i >= b && con(i); i -= c) act(i); } void REP(int n, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = 0; i < n && con(i); i += c) act(i); } void REP(int n, Action<int> act, int c = 1) { for (int i = 0; i < n; i += c) act(i); } void RREP(int n, Action<int> act, int c = 1) { for (int i = n - 1; i >= 0; i -= c) act(i); } void RREP(int n, Action<int> act, Func<int, bool> con) { for (int i = n - 1; i >= 0 && con(i); i--) act(i); } #endregion } #region default class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string next => Next(); public char nextChar => char.Parse(next); public int nextInt => int.Parse(next); public long nextLong => long.Parse(next); public double nextDouble => double.Parse(next); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } public void i<T>(out T v) { v = suitType<T>(next); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt; } public void ini(out long[] a, int size) { a = new long[size]; for (int i = 0; i < size; i++) a[i] = nextLong; } public void ini(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt; a2[i] = nextInt; } } public void ini(out long[] a1, out long[] a2, int size) { a1 = new long[size]; a2 = new long[size]; for (int i = 0; i < size; i++) { a1[i] = nextLong; a2[i] = nextLong; } } public void ini(out int[,] g, int h, int w) { g = new int[h, w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) g[i, j] = nextInt; } public void ini(out string[] a, int size) { a = new string[size]; for (int i = 0; i < size; i++) a[i] = next; } public void inii(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt - 1; } public void inii(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt - 1; a2[i] = nextInt - 1; } } public void inii(out int[,] a, int size) { a = new int[size, size]; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) a[i, j] = nextInt - 1; } public void o<T>(T v) { Console.WriteLine(v); } public void ol<T>(T v) { Console.Write(v + " "); } public void o<T>(params T[] a) { foreach (T v in a) o(v); } public void o<T>(List<T> l) { o(l.ToArray()); } public void ol<T>(params T[] a) { foreach (T v in a) { ol(v); } br(); } public void ol<T>(List<T> l) { ol(l.ToArray()); } public void YN(bool f) { o(f ? "YES" : "NO"); } public void Yn(bool f) { o(f ? "Yes" : "No"); } public void yn(bool f) { o(f ? "yes" : "no"); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } } #endregion #region other class Mat { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long Sum(params long[] a) { return a.Aggregate((v, next) => (v % mod + next) % mod); } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public T Max<T>(params T[] v) { return v.Max(); } public T Min<T>(params T[] v) { return v.Min(); } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } // test public int DigitValue(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } /* public int[] DigVal(int n) {//桁の順番... int[] ret = new int[Digit(n)]; return ret; } */ // public int Clamp(int n, int a, int b) { return (n < a) ? a : (b < n) ? b : n; } public long Clamp(long n, long a, long b) { return (n < a) ? a : (b < n) ? b : n; } public double Clamp(double n, double a, double b) { return (n < a) ? a : (b < n) ? b : n; } public long Tousa(long a, long d, int n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, int n) { return n * (2 * a + (n - 1) * d) / 2; } } class AssociativeArray<T> { public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(params T[] a) { for (int i = 0; i < a.Length; i++) { if (!dic.ContainsKey(a[i])) dic[a[i]] = 0; dic[a[i]]++; } } public void Remove(params T[] a) { for (int i = 0; i < a.Length; i++) if (dic.ContainsKey(a[i])) dic.Remove(a[i]); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValueSum() { return dic.Values.Sum(); } public int KeyNum() { return dic.Keys.Count; } public int MaxVal() { return dic.Values.Max(); } public int MinVal() { return dic.Values.Min(); } public T MaxKey() { return dic.First(d => d.Value == MaxVal()).Key; } public T MinKey() { return dic.First(d => d.Value == MinVal()).Key; } public bool isContainsK(T k) { return dic.ContainsKey(k); } public bool anyContainsK(params T[] k) { return k.Any(key => isContainsK(key)); } public bool allContainsK(params T[] k) { return k.All(key => isContainsK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } //:sort->array } class WarshallFloyd { int INF; public WarshallFloyd() { INF = (int)(1e8); } public WarshallFloyd(int INF) { this.INF = INF; } public int[,] Run(int[,] m) { int edgeLength = m.GetLength(0); for (int i = 0; i < edgeLength; i++) for (int j = 0; j < edgeLength; j++) for (int k = 0; k < edgeLength; k++) m[j, k] = Math.Min(m[j, k], m[j, i] + m[i, k]); return m; } public int[,] Init(int n) { int[,] m = new int[n, n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) m[i, j] = INF; for (int i = 0; i < n; i++) m[i, i] = 0; return m; } } class Time { public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } class BucketSort { public int[] bucket; public void Init(int[] a) { bucket = new int[a.Max() + 1]; for (int i = 0; i < a.Length; ++i) ++bucket[a[i]]; for (int i = 0, j = 0; j < bucket.Length; ++j) for (int k = bucket[j]; k != 0; --k, ++i) a[i] = j; } } #endregion #region Ex static class StringEX { //文字 public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } } static class NumericEx { //数値 public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static void Set<T>(this T[] a, T v) { for (int i = 0; i < a.Length; i++) { a[i] = v; } } public static void Set<T>(this T[,] a, T v) { for (int i = 0; i < a.GetLength(0); i++) for (int j = 0; j < a.GetLength(1); j++) a[i, j] = v; } } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace AtCoder { class MainClass { // C#7.0///////////////////////////////////////////////////// long X; void Solve() { io.i(out X); long ans = X / 11 * 2 + ((X % 11 != 0) ? ((X % 11 <= 6) ? 1 : 2) : 0); io.o(ans); } //////////////////////////////////////////////////////////// public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // Hack Update // cannot use break,continue,goto void FOR(int a, int b, Action<int> act, int c = 1) { for (int i = a; i < b; i += c) act(i); } void FOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = a; i < b && con(i); i += c) act(i); } void RFOR(int a, int b, Action<int> act, int c = 1) { for (int i = a; i >= b; i -= c) act(i); } void RFOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = a; i >= b && con(i); i -= c) act(i); } void REP(int n, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = 0; i < n && con(i); i += c) act(i); } void REP(int n, Action<int> act, int c = 1) { for (int i = 0; i < n; i += c) act(i); } void RREP(int n, Action<int> act, int c = 1) { for (int i = n - 1; i >= 0; i -= c) act(i); } void RREP(int n, Action<int> act, Func<int, bool> con) { for (int i = n - 1; i >= 0 && con(i); i--) act(i); } #endregion } #region default class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string next => Next(); public char nextChar => char.Parse(next); public int nextInt => int.Parse(next); public long nextLong => long.Parse(next); public double nextDouble => double.Parse(next); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } public void i<T>(out T v) { v = suitType<T>(next); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt; } public void ini(out long[] a, int size) { a = new long[size]; for (int i = 0; i < size; i++) a[i] = nextLong; } public void ini(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt; a2[i] = nextInt; } } public void ini(out long[] a1, out long[] a2, int size) { a1 = new long[size]; a2 = new long[size]; for (int i = 0; i < size; i++) { a1[i] = nextLong; a2[i] = nextLong; } } public void ini(out int[,] g, int h, int w) { g = new int[h, w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) g[i, j] = nextInt; } public void ini(out string[] a, int size) { a = new string[size]; for (int i = 0; i < size; i++) a[i] = next; } public void inii(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt - 1; } public void inii(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt - 1; a2[i] = nextInt - 1; } } public void inii(out int[,] a, int size) { a = new int[size, size]; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) a[i, j] = nextInt - 1; } public void o<T>(T v) { Console.WriteLine(v); } public void ol<T>(T v) { Console.Write(v + " "); } public void o<T>(params T[] a) { foreach (T v in a) o(v); } public void o<T>(List<T> l) { o(l.ToArray()); } public void ol<T>(params T[] a) { foreach (T v in a) { ol(v); } br(); } public void ol<T>(List<T> l) { ol(l.ToArray()); } public void YN(bool f) { o(f ? "YES" : "NO"); } public void Yn(bool f) { o(f ? "Yes" : "No"); } public void yn(bool f) { o(f ? "yes" : "no"); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } } #endregion #region other class Mat { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long Sum(params long[] a) { return a.Aggregate((v, next) => (v % mod + next) % mod); } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public T Max<T>(params T[] v) { return v.Max(); } public T Min<T>(params T[] v) { return v.Min(); } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } // test public int DigitValue(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } /* public int[] DigVal(int n) {//桁の順番... int[] ret = new int[Digit(n)]; return ret; } */ // public int Clamp(int n, int a, int b) { return (n < a) ? a : (b < n) ? b : n; } public long Clamp(long n, long a, long b) { return (n < a) ? a : (b < n) ? b : n; } public double Clamp(double n, double a, double b) { return (n < a) ? a : (b < n) ? b : n; } public long Tousa(long a, long d, int n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, int n) { return n * (2 * a + (n - 1) * d) / 2; } } class AssociativeArray<T> { public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(params T[] a) { for (int i = 0; i < a.Length; i++) { if (!dic.ContainsKey(a[i])) dic[a[i]] = 0; dic[a[i]]++; } } public void Remove(params T[] a) { for (int i = 0; i < a.Length; i++) if (dic.ContainsKey(a[i])) dic.Remove(a[i]); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValueSum() { return dic.Values.Sum(); } public int KeyNum() { return dic.Keys.Count; } public int MaxVal() { return dic.Values.Max(); } public int MinVal() { return dic.Values.Min(); } public T MaxKey() { return dic.First(d => d.Value == MaxVal()).Key; } public T MinKey() { return dic.First(d => d.Value == MinVal()).Key; } public bool isContainsK(T k) { return dic.ContainsKey(k); } public bool anyContainsK(params T[] k) { return k.Any(key => isContainsK(key)); } public bool allContainsK(params T[] k) { return k.All(key => isContainsK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } //:sort->array } class WarshallFloyd { int INF; public WarshallFloyd() { INF = (int)(1e8); } public WarshallFloyd(int INF) { this.INF = INF; } public int[,] Run(int[,] m) { int edgeLength = m.GetLength(0); for (int i = 0; i < edgeLength; i++) for (int j = 0; j < edgeLength; j++) for (int k = 0; k < edgeLength; k++) m[j, k] = Math.Min(m[j, k], m[j, i] + m[i, k]); return m; } public int[,] Init(int n) { int[,] m = new int[n, n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) m[i, j] = INF; for (int i = 0; i < n; i++) m[i, i] = 0; return m; } } class Time { public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } class BucketSort { public int[] bucket; public void Init(int[] a) { bucket = new int[a.Max() + 1]; for (int i = 0; i < a.Length; ++i) ++bucket[a[i]]; for (int i = 0, j = 0; j < bucket.Length; ++j) for (int k = bucket[j]; k != 0; --k, ++i) a[i] = j; } } #endregion #region Ex static class StringEX { //文字 public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } } static class NumericEx { //数値 public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static void Set<T>(this T[] a, T v) { for (int i = 0; i < a.Length; i++) { a[i] = v; } } public static void Set<T>(this T[,] a, T v) { for (int i = 0; i < a.GetLength(0); i++) for (int j = 0; j < a.GetLength(1); j++) a[i, j] = v; } } #endregion }
[["+", 12, 23, 0, 41, 15, 23, 0, 16, 17, 79], ["+", 12, 23, 0, 41, 15, 23, 0, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 41, 15, 23, 0, 25], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 16, 12, 23, 0, 41, 64, 23, 0, 24], ["+", 0, 41, 64, 23, 0, 41, 15, 23, 0, 24], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 109], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 41, 64, 23, 0, 25], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 0, 102], ["+", 0, 212, 0, 16, 12, 23, 0, 41, 75, 203]]
8
3,880
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var b = new int[100001]; for (int i = 0; i < n; i++) { b[a[i]]++; } int count = b.Where(x => x > 1).Sum(); int ans = n - count - (count % 2); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var b = new int[100001]; for (int i = 0; i < n; i++) { b[a[i]]++; } int count = b.Where(x => x > 1).Select(x => x - 1).Sum(); int ans = n - count - (count % 2); Console.WriteLine(ans); } } }
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131]]
8
160
9
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace MSL001 { // public class A //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // var S = c.Read; // var A = c.ReadLong; // var B = c.ReadLong; // var C = c.ReadLong; // var D = c.ReadLong; // var sb = new StringBuilder(S.Length + 10); // for (int i = 0; i < S.Length; i++) // { // if(i == A || i == B || i == C || i == D) // { // sb.Append("\""); // } // sb.Append(S[i]); // } // if (D == S.Length) sb.Append("\""); // Console.WriteLine(sb.ToString()); // } //} // public class B //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // Dictionary<string, long> dic = new Dictionary<string, long>(); // var N = c.ReadLong; // for (int i = 0; i < N; i++) // { // string k = c.Read; // if(dic.TryGetValue(k,out long value)) // { // dic[k] = value + 1; // } // else{ // dic.Add(k, 1); // } // } // var M = c.ReadLong; // for (int i = 0; i < M; i++) // { // string k = c.Read; // if(dic.TryGetValue(k,out long value)) // { // dic[k] = value - 1; // } // } // long max = dic.Values.Max(); // Console.WriteLine(max > 0 ? max : 0); // } //} public class C { public static void Main(string[] args) { var c = new ConsoleInput(Console.In); var N = c.ReadInt; var A = new long[N]; var B = new long[N]; for (int i = 0; i < N; i++) { A[i] = c.ReadLong; B[i] = c.ReadLong; } long count = 0; for (int i = N - 1; i >= 0; i--) { long diff = B[i] - ((A[i] + count) % B[i]); if (diff == B[i]) diff = 0; Console.WriteLine(diff); count += diff; } Console.WriteLine(count); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Trim().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i].Trim()); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace MSL001 { // public class A //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // var S = c.Read; // var A = c.ReadLong; // var B = c.ReadLong; // var C = c.ReadLong; // var D = c.ReadLong; // var sb = new StringBuilder(S.Length + 10); // for (int i = 0; i < S.Length; i++) // { // if(i == A || i == B || i == C || i == D) // { // sb.Append("\""); // } // sb.Append(S[i]); // } // if (D == S.Length) sb.Append("\""); // Console.WriteLine(sb.ToString()); // } //} // public class B //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // Dictionary<string, long> dic = new Dictionary<string, long>(); // var N = c.ReadLong; // for (int i = 0; i < N; i++) // { // string k = c.Read; // if(dic.TryGetValue(k,out long value)) // { // dic[k] = value + 1; // } // else{ // dic.Add(k, 1); // } // } // var M = c.ReadLong; // for (int i = 0; i < M; i++) // { // string k = c.Read; // if(dic.TryGetValue(k,out long value)) // { // dic[k] = value - 1; // } // } // long max = dic.Values.Max(); // Console.WriteLine(max > 0 ? max : 0); // } //} public class C { public static void Main(string[] args) { var c = new ConsoleInput(Console.In); var N = c.ReadInt; var A = new long[N]; var B = new long[N]; for (int i = 0; i < N; i++) { A[i] = c.ReadLong; B[i] = c.ReadLong; } long count = 0; for (int i = N - 1; i >= 0; i--) { long diff = B[i] - ((A[i] + count) % B[i]); if (diff == B[i]) diff = 0; count += diff; } Console.WriteLine(count); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Trim().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i].Trim()); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
588
7
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 998244353; public static void Main() { // 方針 // int n = rint(); long[,] li = new long[n, 2]; for (int i = 0; i < n; i++) { long[] a = longa(); li[i, 0] = a[0]; li[i, 1] = a[1]; } long ans = 0; for (int i = n - 1; i >= 0; i--) { long temp = (li[i, 0] + ans) % li[i, 1]; ans += li[i, 1] - temp; } WriteLine(ans); } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { var temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 998244353; public static void Main() { // 方針 // int n = rint(); long[,] li = new long[n, 2]; for (int i = 0; i < n; i++) { long[] a = longa(); li[i, 0] = a[0]; li[i, 1] = a[1]; } long ans = 0; for (int i = n - 1; i >= 0; i--) { long temp = (li[i, 0] + ans) % li[i, 1]; if (temp == 0) continue; ans += li[i, 1] - temp; // WriteLine(ans); } WriteLine(ans); } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { var temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } // static int square2(long a,long b,long m){var list = new List<int>();int // temp = 1;long n2 = a;list.Add(1);int count = 1;while(temp < // b){list.Add((int)n2);temp*=2;count++;n2 = n2*n2%m;}long ret = 1;while(b > // 0){if(temp <= b){b -= temp;ret = // ret*list[count]%1000000007;}count--;temp/=2;}return(int)ret;} 各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
1,428
8
using System; using System.Collections.Generic; using System.Text; namespace AtTest.AGC_Challenge { class _009_A { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int n = ReadInt(); var aArray = new long[n]; var bArray = new long[n]; for (int i = 0; i < n; i++) { int[] ab = ReadInts(); aArray[i] = ab[0]; bArray[i] = ab[1]; } Array.Reverse(aArray); Array.Reverse(bArray); long cnt = 0; for (int i = 0; i < n; i++) { if (aArray[i] % bArray[i] == 0) continue; long aNow = aArray[i] + cnt; long dest = (aNow / bArray[i] + 1) * bArray[i]; cnt += dest - aNow; } Console.WriteLine(cnt); } private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Text; namespace AtTest.AGC_Challenge { class _009_A { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int n = ReadInt(); var aArray = new long[n]; var bArray = new long[n]; for (int i = 0; i < n; i++) { int[] ab = ReadInts(); aArray[i] = ab[0]; bArray[i] = ab[1]; } Array.Reverse(aArray); Array.Reverse(bArray); long cnt = 0; for (int i = 0; i < n; i++) { long aNow = aArray[i] + cnt; if (aNow % bArray[i] == 0) continue; long dest = (aNow / bArray[i] + 1) * bArray[i]; cnt += dest - aNow; } Console.WriteLine(cnt); } private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
374
21
using System; using System.Linq; namespace AGC009_A { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var A = new long[N]; var B = new long[N]; for (long i = 0; i < N; i++) { var l = Console.ReadLine().Split().Select(long.Parse).ToArray(); A[i] = l[0]; B[i] = l[1]; } long c = 0; for (long i = N; i > 0; i--) { var t = (A[i] + c) % B[i]; if (t != 0) c += t; } } } }
using System; using System.Linq; namespace AGC009_A { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var A = new long[N]; var B = new long[N]; for (long i = 0; i < N; i++) { var l = Console.ReadLine().Split().Select(long.Parse).ToArray(); A[i] = l[0]; B[i] = l[1]; } long c = 0; for (long i = N - 1; i >= 0; i--) { var t = (A[i] + c) % B[i]; if (t != 0) c += B[i] - t; } Console.WriteLine(c); } } }
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 64, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
167
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC009MultipleArray { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] A = new long[N]; long[] B = new long[N]; string[] vals; for (int i = 0; i < N; i++) { vals = Console.ReadLine().Split(' '); A[i] = long.Parse(vals[0]); B[i] = long.Parse(vals[1]); } long push = 0; int t; for (int i = N - 1; i >= 0; i--) { t = 1; A[i] += push; while (t * B[i] < A[i]) t++; push += t * B[i] - A[i]; } Console.WriteLine(push); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC009MultipleArray { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] A = new long[N]; long[] B = new long[N]; string[] vals; for (int i = 0; i < N; i++) { vals = Console.ReadLine().Split(' '); A[i] = long.Parse(vals[0]); B[i] = long.Parse(vals[1]); } long push = 0; long t; for (int i = N - 1; i >= 0; i--) { A[i] += push; t = (A[i] / B[i]); if (A[i] % B[i] != 0) t++; push += t * B[i] - A[i]; } Console.WriteLine(push); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["-", 8, 196, 0, 7, 8, 196, 0, 52, 0, 24], ["-", 8, 196, 0, 52, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 0, 11, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 17, 85], ["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
8
223
28
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); // static Scan sc = new ScanCHK(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n = sc.Int; var a = new long[n]; var b = new long[n]; for (int i = 0; i < n; i++) { sc.Multi(out a[i], out b[i]); } long ans = 0; for (int i = n - 1; i >= 0; i--) { ans = (ans - (b[i] - a[i] % b[i]) + b[i] - 1) / b[i] * b[i] + b[i] - a[i] % b[i]; } Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { Console.WriteLine(string.Join(" ", a)); } static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); } static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } } } 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 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(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } 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 { public static long Mod = 1000000007; public static 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 static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static 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 static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static 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; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); // static Scan sc = new ScanCHK(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n = sc.Int; var a = new long[n]; var b = new long[n]; for (int i = 0; i < n; i++) { sc.Multi(out a[i], out b[i]); } long ans = 0; for (int i = n - 1; i >= 0; i--) { long k = (b[i] - a[i] % b[i]) % b[i]; ans = (ans - k + b[i] - 1) / b[i] * b[i] + k; } Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { Console.WriteLine(string.Join(" ", a)); } static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); } static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } } } 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 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(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } 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 { public static long Mod = 1000000007; public static 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 static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static 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 static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static 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; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 31, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 17, 33], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 11, 12, 16, 31, 16, 12, 204, 205, 22], ["-", 12, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 11, 12, 16, 12, 16, 31, 204, 205, 22], ["-", 12, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 17, 109], ["-", 0, 11, 12, 16, 12, 16, 12, 204, 205, 22], ["-", 12, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
3,051
33
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class _Class { void _() { var N = _Ns()[0]; var a = new ulong[N]; var b = new ulong[N]; for (int i = 0; i < N; i++) { var AB = _Ns(); a[i] = (ulong)AB[0]; b[i] = (ulong)AB[1]; } ulong s = 0; for (int i = N - 1; i >= 0; i--) { ulong v = a[i] + s; if (v <= b[i]) { s += (b[i] - v); } else { ulong d = v % b[i]; if (d == 0) { } else { ulong dd = b[i] - d; s += dd; } } } Console.WriteLine(s); } static void Main(string[] args) { new _Class()._(); } #region string _S() { return Console.ReadLine(); } string[] _Ss() { return Console.ReadLine().Split(); } int[] _N(int n) { var x = new int[n]; for (var i = 0; i < n; i++) { x[i] = int.Parse(Console.ReadLine()); } return x; } int[] _Ns() { var ss = Console.ReadLine().Split(); var x = new int[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = int.Parse(ss[i]); return x; } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class _Class { void _() { var N = _Ns()[0]; var a = new ulong[N]; var b = new ulong[N]; for (int i = 0; i < N; i++) { var AB = _Ns(); a[i] = (ulong)AB[0]; b[i] = (ulong)AB[1]; } ulong s = 0; for (int i = N - 1; i >= 0; i--) { ulong v = a[i] + s; /* if (v <= b[i]) { s += (b[i] - v); } else */ { ulong d = v % b[i]; if (d == 0) { } else { ulong dd = b[i] - d; s += dd; } } } Console.WriteLine(s); } static void Main(string[] args) { new _Class()._(); } #region string _S() { return Console.ReadLine(); } string[] _Ss() { return Console.ReadLine().Split(); } int[] _N(int n) { var x = new int[n]; for (var i = 0; i < n; i++) { x[i] = int.Parse(Console.ReadLine()); } return x; } int[] _Ns() { var ss = Console.ReadLine().Split(); var x = new int[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = int.Parse(ss[i]); return x; } #endregion }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 64, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["-", 0, 11, 12, 23, 0, 16, 31, 204, 205, 22], ["-", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45]]
8
390
23
using System; using System.Collections.Generic; public class AtCoder { public static void Main() { Tree tree = new Tree(); Console.WriteLine(tree.Calc(1)); } public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); } } class Tree { int n; int[] a; List<int>[] list; List<int>[] m; public Tree() { n = int.Parse(Console.ReadLine()); a = new int[n + 1]; for (int i = 2; i <= n; i++) { a[i] = int.Parse(Console.ReadLine()); } list = new List<int>[n + 1]; m = new List<int>[n + 1]; for (int i = 1; i <= n; i++) { list[i] = new List<int>(); m[i] = new List<int>(); } for (int i = 2; i <= n; i++) { list[a[i]].Add(i); } } public int Calc(int x) { int c = 0; int max = -1; foreach (int i in list[x]) { m[x].Add(Calc(i)); c++; } m[x].Sort(); for (int i = 0; i < c; i++) { m[x][i] += c - 1 - i; if (m[x][i] > max) max = m[x][i]; } Console.WriteLine(x + " " + (max + 1)); if (c == 0) return 0; else return max + 1; } }
using System; using System.Collections.Generic; public class AtCoder { public static void Main() { Tree tree = new Tree(); Console.WriteLine(tree.Calc(1)); } public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); } } class Tree { int n; int[] a; List<int>[] list; List<int>[] m; public Tree() { n = int.Parse(Console.ReadLine()); a = new int[n + 1]; for (int i = 2; i <= n; i++) { a[i] = int.Parse(Console.ReadLine()); } list = new List<int>[n + 1]; m = new List<int>[n + 1]; for (int i = 1; i <= n; i++) { list[i] = new List<int>(); m[i] = new List<int>(); } for (int i = 2; i <= n; i++) { list[a[i]].Add(i); } } public int Calc(int x) { int c = 0; int max = -1; foreach (int i in list[x]) { m[x].Add(Calc(i)); c++; } m[x].Sort(); for (int i = 0; i < c; i++) { m[x][i] += c - 1 - i; if (m[x][i] > max) max = m[x][i]; } if (c == 0) return 0; else return max + 1; } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
391
17
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Globalization; using System.Diagnostics; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().Solve(); Out.Flush(); } Scanner cin = new Scanner(); Random rnd = new Random(); Stopwatch sw = new Stopwatch(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; //浅いのと先に戦う。 void Solve() { int N = cin.Nextint; var G = Enumerable.Range(0, N).Select(i => new List<int>()).ToArray(); for (int i = 1; i < N; i++) { G[cin.Nextint - 1].Add(i); } sw.Start(); var B = new bool[N]; var dp = new int[N]; var S = new Stack<int>(); S.Push(0); while (S.Any()) { int u = S.Pop(); if (B[u]) { if (G[u].Count == 0) { dp[u] = 0; continue; } var L = new List<int>(); foreach (var v in G[u]) { L.Add(dp[v]); } dp[u] = L.OrderBy(k => rnd.Next()) .OrderByDescending(k => k) .Select((v, i) => new { v, i }) .Max(k => k.v + k.i) + 1; } else { B[u] = true; S.Push(u); foreach (var v in G[u]) { S.Push(v); } } } WriteLine(dp[0]); WriteLine(sw.Elapsed); } } 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); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Globalization; using System.Diagnostics; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().Solve(); Out.Flush(); } Scanner cin = new Scanner(); Random rnd = new Random(); Stopwatch sw = new Stopwatch(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; //浅いのと先に戦う。 void Solve() { int N = cin.Nextint; var G = Enumerable.Range(0, N).Select(i => new List<int>()).ToArray(); for (int i = 1; i < N; i++) { G[cin.Nextint - 1].Add(i); } // sw.Start(); var B = new bool[N]; var dp = new int[N]; var S = new Stack<int>(); S.Push(0); while (S.Any()) { int u = S.Pop(); if (B[u]) { if (G[u].Count == 0) { dp[u] = 0; continue; } var L = new List<int>(); foreach (var v in G[u]) { L.Add(dp[v]); } dp[u] = L.OrderBy(k => rnd.Next()) .OrderByDescending(k => k) .Select((v, i) => new { v, i }) .Max(k => k.v + k.i) + 1; } else { B[u] = true; S.Push(u); foreach (var v in G[u]) { S.Push(v); } } } WriteLine(dp[0]); // WriteLine(sw.Elapsed); } } 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); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
8
697
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC052A { class Program { static void Main(string[] args) { int s, S, A, B, C, D; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); C = int.Parse(word[2]); D = int.Parse(word[3]); s = A * B; S = C * D; if (s < S) { Console.WriteLine(S); } else if (A * B > C * D) { Console.WriteLine(s); } else if (A * B == C * D) { Console.WriteLine(s); Console.WriteLine(S); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC052A { class Program { static void Main(string[] args) { int s, S, A, B, C, D; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); C = int.Parse(word[2]); D = int.Parse(word[3]); s = A * B; S = C * D; if (s < S) { Console.WriteLine(S); } else if (A * B > C * D) { Console.WriteLine(s); } else if (A * B == C * D) { Console.WriteLine(s); } Console.ReadKey(); } } }
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35]]
8
203
7
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { B(); } static void B() { var KS = ReadSplitInt(); var ans = 0; for (var X = 0; X <= KS[0]; X++) { for (var Y = 0; Y <= KS[0]; Y++) { var Z = KS[1] - X - Y; if (X + Y + Z == KS[1]) ans++; } } Println(ans); } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int DigitsSum(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static IList<string> ReadSplit() => Read().Split().ToList(); static IList<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static void Print(object value = null) => Console.Write(value.ToString()); static void Println(object value = null) => Console.WriteLine(value.ToString()); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { B(); } static void B() { var KS = ReadSplitInt(); var ans = 0; for (var X = 0; X <= KS[0]; X++) { for (var Y = 0; Y <= KS[0]; Y++) { var Z = KS[1] - (X + Y); if (Z >= 0 && Z <= KS[0] && X + Y + Z == KS[1]) ans++; } } Println(ans); } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int DigitsSum(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static IList<string> ReadSplit() => Read().Split().ToList(); static IList<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static void Print(object value = null) => Console.Write(value.ToString()); static void Println(object value = null) => Console.WriteLine(value.ToString()); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
[["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["+", 15, 16, 31, 16, 12, 16, 12, 204, 205, 22], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
493
15
using static System.Console; using static System.Convert; class Program { static void Main(string[] args) { var input = ReadLine().Split(' '); var max = ToInt32(input[0]); var num = ToInt32(input[1]); var result = 0; for (var i = 0; i <= max; i++) { if (i > num) break; for (var j = 0; j <= i; j++) { if (i + j > num || max - (i + j) > j) break; var h = max - (i + j); if (i == j && j == h && h == i) result++; else if (i == j || j == h || h == i) result += 3; else result += 6; } } WriteLine(result); } }
using static System.Console; using static System.Convert; class Program { static void Main(string[] args) { var input = ReadLine().Split(' '); var max = ToInt32(input[0]); var num = ToInt32(input[1]); var result = 0; for (var i = 0; i <= max; i++) { if (i > num) break; for (var j = 0; j <= i; j++) { if (i + j > num) break; if (num - (i + j) > j) continue; var h = num - (i + j); if (i == j && j == h && h == i) result++; else if (i == j || j == h || h == i) result += 3; else result += 6; } } WriteLine(result); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22]]
8
185
12
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Program { static void Main(string[] args) { int[] inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int K = inp[0]; int S = inp[1]; int res = 0; for (int x = 0; x <= K; x++) { for (int y = 0; y <= K; y++) { if (S - (x + y) <= K) { res++; } } } WriteLine(res); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Program { static void Main(string[] args) { int[] inp = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int K = inp[0]; int S = inp[1]; int res = 0; for (int x = 0; x <= K; x++) { for (int y = 0; y <= K; y++) { int z = S - (x + y); if (0 <= z && z <= K) { res++; } } } WriteLine(res); } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
143
13
using System; using System.Linq; namespace AtCoder_Beginner_Contest_051_B { class Program { static void Main(string[] args) { int[] kj = Console.ReadLine().Split().Select(int.Parse).ToArray(); int K = kj[0], S = kj[1]; int answer = 0; for (int i = 0; i <= K; i++) { if (i <= K) { for (int k = 0; k <= S - i; k++) { if (k <= K) { answer++; } } } } Console.WriteLine(answer); Console.ReadLine(); } } }
using System; using System.Linq; namespace AtCoder_Beginner_Contest_051_B { class Program { static void Main(string[] args) { int[] kj = Console.ReadLine().Split().Select(int.Parse).ToArray(); int K = kj[0], S = kj[1]; int answer = 0; for (int i = 0; i <= S; i++) { if (i <= K) { for (int k = 0; k <= S - i; k++) { if (k <= K) { if (S - i - k <= K) { answer++; } } } } } Console.WriteLine(answer); Console.ReadLine(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 25], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 45], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
139
14
using System; using System.Linq; namespace abc051_b { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int K = x[0]; if (K > x[1]) { K = x[1]; } int S = x[1]; int a = 0; for (int i = 0; i <= K; i++) { for (int j = i; j <= K; j++) { for (int k = j; k <= K; k++) { if (i + j + k == S) { if (i == j && j == k) { a++; } else { a += 3; } } } } } Console.WriteLine(a); } } }
using System; using System.Linq; namespace abc051_b { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int K = x[0]; if (K > x[1]) { K = x[1]; } int S = x[1]; int a = 0; for (int i = 0; i <= K; i++) { for (int j = i; j <= K; j++) { for (int k = j; k <= K; k++) { if (i + j + k == S) { if (i == j && j == k) { a++; } else if (i == j || j == k) { a += 3; } else { a += 6; } } } } } Console.WriteLine(a); } } }
[["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 17, 106], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 95], ["+", 64, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
8
181
17
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.ItemMax = inpt[0]; this.Total = inpt[1]; long ans = 0; for (int i = 0; i <= ItemMax; i++) { if (Total - i > ItemMax * 2) { continue; } int min = Math.Max(0, Total - i - ItemMax); int max = Math.Min(this.ItemMax, Total - i); ans += max - min + 1; } Console.WriteLine(ans); } private int ItemMax; private int Total; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 2 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.ItemMax = inpt[0]; this.Total = inpt[1]; long ans = 0; for (int i = 0; i <= ItemMax; i++) { if (Total - i > ItemMax * 2) { continue; } if (Total - i < 0) { continue; } int min = Math.Max(0, Total - i - ItemMax); int max = Math.Min(this.ItemMax, Total - i); ans += max - min + 1; } Console.WriteLine(ans); } private int ItemMax; private int Total; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 2 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
285
12
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var M = sc.ReadInt(); var A = new int[N]; var B = new int[N]; var C = new int[N]; var dist = new long[N, N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dist[i, j] = long.MaxValue; } } for (int i = 0; i < M; i++) { A[i] = sc.ReadInt() - 1; B[i] = sc.ReadInt() - 1; C[i] = sc.ReadInt(); dist[A[i], B[i]] = C[i]; dist[B[i], A[i]] = C[i]; } for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (dist[i, k] == long.MaxValue || dist[k, j] == long.MaxValue) continue; dist[i, j] = Math.Min(dist[i, j], dist[i, k] + dist[k, j]); } } } var ans = 0; for (int i = 0; i < M; i++) { if (dist[A[i], B[i]] != C[i]) ans++; } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var M = sc.ReadInt(); var A = new int[M]; var B = new int[M]; var C = new int[M]; var dist = new long[N, N]; var INF = long.MaxValue / 4; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dist[i, j] = INF; } } for (int i = 0; i < M; i++) { A[i] = sc.ReadInt() - 1; B[i] = sc.ReadInt() - 1; C[i] = sc.ReadInt(); dist[A[i], B[i]] = C[i]; dist[B[i], A[i]] = C[i]; } for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (dist[i, k] == INF || dist[k, j] == INF) continue; dist[i, j] = Math.Min(dist[i, j], dist[i, k] + dist[k, j]); } } } var ans = 0; for (int i = 0; i < M; i++) { if (dist[A[i], B[i]] != C[i]) ans++; } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 12, 214, 205, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 214, 205, 199], ["-", 0, 57, 15, 16, 31, 16, 12, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 16, 12, 16, 12, 214, 205, 199], ["-", 0, 57, 15, 16, 12, 16, 12, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
1,401
27
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { int N, M; sc.Make(out N, out M); var edge = new Pair<int, int, int>[M]; var dist = Create(N, () => new int[N]); for (int i = 0; i < M; i++) { int a, b, c; sc.Make(out a, out b, out c); a--; b--; dist[a][b] = dist[b][a] = c; edge[i] = new Pair<int, int, int>(a, b, c); } for (var k = 0; k < N; k++) for (var i = 0; i < N; i++) for (var j = 0; j < N; j++) chmin(ref dist[i][j], dist[i][k] + dist[k][j]); var res = 0; foreach (var e in edge) { if (dist[e.v1][e.v2] != e.v3) res++; } WriteLine(res); } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { int N, M; sc.Make(out N, out M); var edge = new Pair<int, int, int>[M]; var dist = Create(N, () => Create(N, () => int.MaxValue / 2)); for (int i = 0; i < M; i++) { int a, b, c; sc.Make(out a, out b, out c); a--; b--; dist[a][b] = dist[b][a] = c; edge[i] = new Pair<int, int, int>(a, b, c); } for (var k = 0; k < N; k++) for (var i = 0; i < N; i++) for (var j = 0; j < N; j++) chmin(ref dist[i][j], dist[i][k] + dist[k][j]); var res = 0; foreach (var e in edge) { if (dist[e.v1][e.v2] != e.v3) res++; } WriteLine(res); } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
[["-", 3, 4, 0, 28, 0, 218, 8, 227, 0, 228], ["-", 0, 28, 0, 218, 8, 227, 39, 224, 39, 199], ["-", 0, 218, 8, 227, 39, 224, 225, 226, 0, 70], ["+", 3, 4, 0, 28, 0, 218, 8, 213, 63, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["-", 0, 218, 8, 227, 39, 224, 225, 226, 0, 73], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["+", 8, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 85], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25]]
8
1,795
16
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } public static void WarshallFloyd(int[,] d, int v) { for (int k = 0; k < v; k++) for (int i = 0; i < v; i++) for (int j = 0; j < v; j++) d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]); } } class Program { public static void Main() { int M = 1000000; var tmp = ReadIntArray(); int n = tmp[0], m = tmp[1]; int[,] d = new int[n, n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i, j] = M; List<Tuple<int, int, int>> e = new List<Tuple<int, int, int>>(); for (int i = 0; i < m; i++) { tmp = ReadIntArray(); int a = tmp[0], b = tmp[1], c = tmp[2]; e.Add(Tuple.Create(a - 1, b - 1, c)); d[a - 1, b - 1] = c; d[b - 1, a - 1] = c; } WarshallFloyd(d, n); int ans = m; foreach (Tuple<int, int, int> t in e) { int a = t.Item1, b = t.Item2, c = t.Item3; for (int j = 0; j < n; j++) { if (d[j, a] + c == d[j, b]) { ans--; break; } } } WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } public static void WarshallFloyd(int[,] d, int v) { for (int k = 0; k < v; k++) for (int i = 0; i < v; i++) for (int j = 0; j < v; j++) d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]); } } class Program { public static void Main() { int M = 1000000; var tmp = ReadIntArray(); int n = tmp[0], m = tmp[1]; int[,] d = new int[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) d[i, j] = 0; else d[i, j] = M; } } List<Tuple<int, int, int>> e = new List<Tuple<int, int, int>>(); for (int i = 0; i < m; i++) { tmp = ReadIntArray(); int a = tmp[0], b = tmp[1], c = tmp[2]; e.Add(Tuple.Create(a - 1, b - 1, c)); d[a - 1, b - 1] = c; d[b - 1, a - 1] = c; } WarshallFloyd(d, n); int ans = m; foreach (Tuple<int, int, int> t in e) { int a = t.Item1, b = t.Item2, c = t.Item3; for (int j = 0; j < n; j++) { if (d[j, a] + c == d[j, b]) { ans--; break; } } } WriteLine(ans); } }
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
463
20
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; public static void Main() { int N = NextInt(); int M = NextInt(); List<int>[] wf = new List<int>[N]; for (int i = 0; i < N; i++) wf[i] = Enumerable.Repeat(INF, N).ToList(); for (int i = 0; i < N; i++) wf[i][i] = 0; List<int>[] e = new List<int>[N]; List<bool>[] e_b = new List<bool>[N]; for (int i = 0; i < N; i++) e[i] = Enumerable.Repeat(-INF, N).ToList(); for (int i = 0; i < N; i++) e_b[i] = Enumerable.Repeat(false, N).ToList(); for (int i = 0; i < M; i++) { int A = NextInt() - 1; int B = NextInt() - 1; int Cost = NextInt(); wf[A][B] = Cost; wf[B][A] = Cost; e[A][B] = Cost; e[B][A] = Cost; e_b[A][B] = true; e_b[B][A] = true; } for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int k = 0; k < N; k++) wf[j][k] = Math.Min(wf[j][k], wf[j][i] + wf[i][k]); for (int s = 0; s < N; s++) { //始点 for (int i = 0; i < N; i++) { if (s == i) continue; //中継 for (int j = 0; j < N; j++) { if (i == j || s == j || !e_b[i][j]) continue; //終点 if (wf[s][i] + e[i][j] == wf[s][j]) { e_b[i][j] = false; e_b[j][i] = false; } } } } int ans = 0; for (int i = 0; i < N; i++) ans += e_b[i].Count(v => v == true); Console.WriteLine(ans / 2); } } public class PriorityQueue<Tkey, Tvalue> where Tkey : IComparable { private static List<Tkey> list = new List<Tkey>(); private static List<Tvalue> value = new List<Tvalue>(); public int Count { get; private set; } = 0; private static bool Descending; public PriorityQueue(bool b = true) { Descending = b; } private static int Compare(Tkey a, Tkey b) { if (Descending) return a.CompareTo(b); else return b.CompareTo(a); } public void Enqueue(Tkey e, Tvalue n) { Count++; int now = Count - 1; list.Add(e); value.Add(n); while (now != 0) { int par = (now - 1) / 2; if (Compare(list[par], e) <= 0) break; Tkey a = list[now]; list[now] = list[par]; list[par] = a; Tvalue b = value[now]; value[now] = value[par]; value[par] = b; now = par; } } public Tvalue Dequeue() { if (Count == 0) return (Tvalue)(object)(-1); Tvalue e = value.First(); if (Count == 1) { list = new List<Tkey>(); value = new List<Tvalue>(); Count--; return e; } Tkey x = list[Count - 1]; Tvalue y = value[Count - 1]; int i = 0; while (i * 2 + 1 < Count) { int l = i * 2 + 1; int r = i * 2 + 2; if (r < Count && Compare(list[r], list[l]) < 0) l = r; if (Compare(list[l], x) >= 0) break; list[i] = list[l]; value[i] = value[l]; i = l; } list[i] = x; value[i] = y; Count--; return e; } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; public static void Main() { int N = NextInt(); int M = NextInt(); List<int>[] wf = new List<int>[N]; for (int i = 0; i < N; i++) wf[i] = Enumerable.Repeat(INF, N).ToList(); for (int i = 0; i < N; i++) wf[i][i] = 0; List<int>[] e = new List<int>[N]; List<bool>[] e_b = new List<bool>[N]; for (int i = 0; i < N; i++) e[i] = Enumerable.Repeat(-INF, N).ToList(); for (int i = 0; i < N; i++) e_b[i] = Enumerable.Repeat(false, N).ToList(); for (int i = 0; i < M; i++) { int A = NextInt() - 1; int B = NextInt() - 1; int Cost = NextInt(); wf[A][B] = Cost; wf[B][A] = Cost; e[A][B] = Cost; e[B][A] = Cost; e_b[A][B] = true; e_b[B][A] = true; } for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int k = 0; k < N; k++) wf[j][k] = Math.Min(wf[j][k], wf[j][i] + wf[i][k]); for (int s = 0; s < N; s++) { //始点 for (int i = 0; i < N; i++) { //中継 for (int j = 0; j < N; j++) { if (!e_b[i][j]) continue; //終点 if (wf[s][i] + e[i][j] == wf[s][j]) { e_b[i][j] = false; e_b[j][i] = false; } } } } int ans = 0; for (int i = 0; i < N; i++) ans += e_b[i].Count(v => v == true); Console.WriteLine(ans / 2); } } public class PriorityQueue<Tkey, Tvalue> where Tkey : IComparable { private static List<Tkey> list = new List<Tkey>(); private static List<Tvalue> value = new List<Tvalue>(); public int Count { get; private set; } = 0; private static bool Descending; public PriorityQueue(bool b = true) { Descending = b; } private static int Compare(Tkey a, Tkey b) { if (Descending) return a.CompareTo(b); else return b.CompareTo(a); } public void Enqueue(Tkey e, Tvalue n) { Count++; int now = Count - 1; list.Add(e); value.Add(n); while (now != 0) { int par = (now - 1) / 2; if (Compare(list[par], e) <= 0) break; Tkey a = list[now]; list[now] = list[par]; list[par] = a; Tvalue b = value[now]; value[now] = value[par]; value[par] = b; now = par; } } public Tvalue Dequeue() { if (Count == 0) return (Tvalue)(object)(-1); Tvalue e = value.First(); if (Count == 1) { list = new List<Tkey>(); value = new List<Tvalue>(); Count--; return e; } Tkey x = list[Count - 1]; Tvalue y = value[Count - 1]; int i = 0; while (i * 2 + 1 < Count) { int l = i * 2 + 1; int r = i * 2 + 2; if (r < Count && Compare(list[r], list[l]) < 0) l = r; if (Compare(list[l], x) >= 0) break; list[i] = list[l]; value[i] = value[l]; i = l; } list[i] = x; value[i] = y; Count--; return e; } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106]]
8
1,308
16
using System; namespace D___Candidates_of_No_Shortest_Paths { class Program { static void Main(string[] args) { var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = read[0]; var M = read[1]; // 2次元配列に辺と重さを記録 var edges = new int[M, 3]; for (int i = 0; i < M; i++) { read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); edges[i, 0] = read[0]; edges[i, 1] = read[1]; edges[i, 2] = read[2]; } // 2次元配列に各頂点間の最短距離を記録 var costs = new int[N + 1, N + 1]; for (int i = 1; i < N + 1; i++) for (int j = 1; j < N + 1; j++) costs[i, j] = 10000000; for (int i = 1; i < N + 1; i++) costs[i, i] = 0; for (int i = 0; i < M; i++) { costs[edges[i, 0], edges[i, 1]] = edges[i, 2]; costs[edges[i, 1], edges[i, 0]] = edges[i, 2]; } // Warshall-Floyd法で全ての頂点間の最短距離求める for (int from = 1; from < N + 1; from++) for (int via = 1; via < N + 1; via++) for (int to = 1; to < N + 1; to++) costs[from, to] = Math.Min(costs[from, to], costs[from, via] + costs[via, to]); //各辺の距離と両端の頂点間の最短距離を比較し、辺の距離のほうが長いものの数を出力 var result = 0; for (int i = 0; i < M; i++) if (costs[edges[i, 0], edges[i, 1]] != edges[i, 2]) result++; Console.WriteLine(result); } } }
using System; namespace D___Candidates_of_No_Shortest_Paths { class Program { static void Main(string[] args) { var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = read[0]; var M = read[1]; // 2次元配列に辺と重さを記録 var edges = new int[M, 3]; for (int i = 0; i < M; i++) { read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); edges[i, 0] = read[0]; edges[i, 1] = read[1]; edges[i, 2] = read[2]; } // 2次元配列に各頂点間の最短距離を記録 var costs = new int[N + 1, N + 1]; for (int i = 1; i < N + 1; i++) for (int j = 1; j < N + 1; j++) costs[i, j] = 1000000000; for (int i = 1; i < N + 1; i++) costs[i, i] = 0; for (int i = 0; i < M; i++) { costs[edges[i, 0], edges[i, 1]] = edges[i, 2]; costs[edges[i, 1], edges[i, 0]] = edges[i, 2]; } // Warshall-Floyd法で全ての頂点間の最短距離求める for (int via = 1; via < N + 1; via++) for (int from = 1; from < N + 1; from++) for (int to = 1; to < N + 1; to++) costs[from, to] = Math.Min(costs[from, to], costs[from, via] + costs[via, to]); //各辺の距離と両端の頂点間の最短距離を比較し、辺の距離のほうが長いものの数を出力 var result = 0; for (int i = 0; i < M; i++) if (costs[edges[i, 0], edges[i, 1]] != edges[i, 2]) result++; Console.WriteLine(result); } } }
[["-", 0, 7, 8, 7, 8, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 7, 8, 1, 0, 11, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 141, 22, 0, 314], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 7, 15, 16, 31, 22, 0, 314], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 8, 196, 0, 7, 26, 223, 0, 22, 0, 314], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 7, 10, 198, 0, 200, 141, 22, 0, 314], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 7, 15, 16, 31, 22, 0, 314], ["-", 8, 196, 0, 7, 8, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 7, 26, 223, 0, 22, 0, 314]]
8
435
14
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 static long n = long.Parse(input[0]); static long m = long.Parse(input[1]); static List<long[]>[] nextList = new List<long[]>[n]; //頂点番号ごとの隣接リスト。距離、隣接頂点番号 static long[] colors = new long[n]; //最短距離未確定の頂点が0、確定で2 static long[] distances = new long[n]; //各頂点への最短距離 static long[] distanceMemos = new long[2]; //キューから捨てた最短距離と頂点番号 static long answer = 0; static void Main() { for (long i = 0; i < n; i++) nextList[i] = new List<long[]>(); //リストの宣言が必要 for (long j = 0; j < m; j++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long[] nextMemo = new long[2]; nextMemo[1] = nums[1] - 1; //隣接頂点番号 nextMemo[0] = nums[2]; //距離 nextList[nums[0] - 1].Add(nextMemo); //隣接リストの作成 long[] nextMemoSub = new long[2]; nextMemoSub[1] = nums[0] - 1; //隣接頂点番号 nextMemoSub[0] = nums[2]; //距離 nextList[nums[1] - 1].Add(nextMemoSub); } for (int i = 0; i < n; i++) Dijkstra(i); answer /= 2; Console.WriteLine(answer); } static void Dijkstra( int startVertexNum) // O((|頂点数|+|辺数|)log頂点数)で各頂点への最短距離を求める { // Console.WriteLine(startVertexNum); List<long[]> distanceList = new List<long[]>(); //優先度付きキュー for (long i = 0; i < n; i++) { distances[i] = long.MaxValue; //最短距離を無限とおく } long[] newDistance = new long[2]; //スタート地点を決める newDistance[1] = startVertexNum; //スタート地点番号 distances[startVertexNum] = 0; colors[startVertexNum] = 1; newDistance[0] = 0; //スタートからスタートまでの距離0 distanceList.Add(newDistance); // Console.WriteLine(distanceList.Count()); while (distanceList.Count() != 0) { distanceList = PopHeap(distanceList); long minVertex = distanceMemos[1]; //最短頂点の番号 colors[minVertex] = 2; if (distances[minVertex] < distanceMemos[0]) continue; //最小値が最短でないなら無視 for (long i = 0; i < nextList[minVertex].Count(); i++) { long v = nextList[minVertex][(int)i][1]; if (colors[v] == 2) continue; if (distances[v] > distances[minVertex] + nextList[minVertex][(int)i][0]) { distances[v] = distances[minVertex] + nextList[minVertex][(int)i][0]; long[] newDistanceSub = new long[2]; newDistanceSub[0] = distances[v]; newDistanceSub[1] = v; distanceList = PushHeap(distanceList, newDistanceSub); colors[v] = 1; } } } for (int i = 0; i < nextList[startVertexNum].Count(); i++) { if (distances[nextList[startVertexNum][i][1]] < nextList[startVertexNum][i][0]) answer++; // Console.WriteLine(distances[nextList[startVertexNum][i][1]] +" "+ // nextList[startVertexNum][i][0]); } } //引数は、昇順にソート済みのリスト static List<long[]> PushHeap(List<long[]> nums, long[] addNums) //現在のヒープnumsにaddNumを追加 { int n = nums.Count; nums.Add(addNums); while (n > 0) { int i = (n - 1) / 2; if (nums[n][0] < nums[i][0]) //親のほうが大きいなら入れ替え。 { long tmp = nums[n][0]; long tmpSub = nums[n][1]; nums[n][0] = nums[i][0]; nums[n][1] = nums[i][1]; nums[i][0] = tmp; nums[i][1] = tmpSub; } n = i; } return nums; } static List<long[]> PopHeap(List<long[]> nums) //ヒープnumsからポップ { int n = nums.Count - 1; distanceMemos[0] = nums[0][0]; //捨てる値の保存 distanceMemos[1] = nums[0][1]; nums[0][0] = nums[n][0]; //最小値である根を削除してリストの最後を持ってくる nums[0][1] = nums[n][1]; nums.RemoveAt(n); for (int i = 0, j; (j = 2 * i + 1) < n;) { if ((j != n - 1) && (nums[j][0] > nums[j + 1][0])) // 2つの子のうち、値の小さい方を選ぶ j++; if (nums[i][0] > nums[j][0]) //子が親より小さいなら入れ替え { long tmp = nums[j][0]; long tmpSub = nums[j][1]; nums[j][0] = nums[i][0]; nums[j][1] = nums[i][1]; nums[i][0] = tmp; nums[i][1] = tmpSub; } i = j; } return nums; } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 static long n = long.Parse(input[0]); static long m = long.Parse(input[1]); static List<long[]>[] nextList = new List<long[]>[n]; //頂点番号ごとの隣接リスト。距離、隣接頂点番号 static long[] colors = new long[n]; //最短距離未確定の頂点が0、確定で2 static long[] distances = new long[n]; //各頂点への最短距離 static long[] distanceMemos = new long[2]; //キューから捨てた最短距離と頂点番号 static long answer = 0; static void Main() { for (long i = 0; i < n; i++) nextList[i] = new List<long[]>(); //リストの宣言が必要 for (long j = 0; j < m; j++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long[] nextMemo = new long[2]; nextMemo[1] = nums[1] - 1; //隣接頂点番号 nextMemo[0] = nums[2]; //距離 nextList[nums[0] - 1].Add(nextMemo); //隣接リストの作成 long[] nextMemoSub = new long[2]; nextMemoSub[1] = nums[0] - 1; //隣接頂点番号 nextMemoSub[0] = nums[2]; //距離 nextList[nums[1] - 1].Add(nextMemoSub); } for (int i = 0; i < n; i++) Dijkstra(i); answer /= 2; Console.WriteLine(answer); } static void Dijkstra( int startVertexNum) // O((|頂点数|+|辺数|)log頂点数)で各頂点への最短距離を求める { // Console.WriteLine(startVertexNum); List<long[]> distanceList = new List<long[]>(); //優先度付きキュー for (long i = 0; i < n; i++) { distances[i] = long.MaxValue; //最短距離を無限とおく colors[i] = 0; } long[] newDistance = new long[2]; //スタート地点を決める newDistance[1] = startVertexNum; //スタート地点番号 distances[startVertexNum] = 0; colors[startVertexNum] = 1; newDistance[0] = 0; //スタートからスタートまでの距離0 distanceList.Add(newDistance); distanceMemos[0] = 0; // Console.WriteLine(distanceList.Count()); while (distanceList.Count() != 0) { distanceList = PopHeap(distanceList); long minVertex = distanceMemos[1]; //最短頂点の番号 colors[minVertex] = 2; // Console.WriteLine(distances[minVertex] +"&"+ distanceMemos[0]); if (distances[minVertex] < distanceMemos[0]) continue; //最小値が最短でないなら無視 // Console.WriteLine(nextList[minVertex].Count()+"a"); for (long i = 0; i < nextList[minVertex].Count(); i++) { long v = nextList[minVertex][(int)i][1]; if (colors[v] == 2) continue; if (distances[v] > distances[minVertex] + nextList[minVertex][(int)i][0]) { distances[v] = distances[minVertex] + nextList[minVertex][(int)i][0]; long[] newDistanceSub = new long[2]; newDistanceSub[0] = distances[v]; newDistanceSub[1] = v; distanceList = PushHeap(distanceList, newDistanceSub); colors[v] = 1; } } } for (int i = 0; i < nextList[startVertexNum].Count(); i++) { if (distances[nextList[startVertexNum][i][1]] < nextList[startVertexNum][i][0]) answer++; // Console.WriteLine(distances[nextList[startVertexNum][i][1]] +" "+ // nextList[startVertexNum][i][0]); } } //引数は、昇順にソート済みのリスト static List<long[]> PushHeap(List<long[]> nums, long[] addNums) //現在のヒープnumsにaddNumを追加 { int n = nums.Count; nums.Add(addNums); while (n > 0) { int i = (n - 1) / 2; if (nums[n][0] < nums[i][0]) //親のほうが大きいなら入れ替え。 { long tmp = nums[n][0]; long tmpSub = nums[n][1]; nums[n][0] = nums[i][0]; nums[n][1] = nums[i][1]; nums[i][0] = tmp; nums[i][1] = tmpSub; } n = i; } return nums; } static List<long[]> PopHeap(List<long[]> nums) //ヒープnumsからポップ { int n = nums.Count - 1; distanceMemos[0] = nums[0][0]; //捨てる値の保存 distanceMemos[1] = nums[0][1]; nums[0][0] = nums[n][0]; //最小値である根を削除してリストの最後を持ってくる nums[0][1] = nums[n][1]; nums.RemoveAt(n); for (int i = 0, j; (j = 2 * i + 1) < n;) { if ((j != n - 1) && (nums[j][0] > nums[j + 1][0])) // 2つの子のうち、値の小さい方を選ぶ j++; if (nums[i][0] > nums[j][0]) //子が親より小さいなら入れ替え { long tmp = nums[j][0]; long tmpSub = nums[j][1]; nums[j][0] = nums[i][0]; nums[j][1] = nums[i][1]; nums[i][0] = tmp; nums[i][1] = tmpSub; } i = j; } return nums; } }
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203]]
8
1,128
14
using System; using System.Collections.Generic; using System.Linq; namespace AtTest.Dijkstra { class ABC_051 { static Node[] nodes; static Dictionary<int, bool> usedDict; static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); nodes = new Node[n]; for (int i = 0; i < n; i++) { nodes[i] = new Node(n); nodes[i].distances[i] = 0; nodes[i].isMin[i] = true; } for (int i = 0; i < m; i++) { string[] nodeInput = Console.ReadLine().Split(' '); int n1 = int.Parse(nodeInput[0]) - 1; int n2 = int.Parse(nodeInput[1]) - 1; int t = int.Parse(nodeInput[2]); nodes[n1].edges.Add(new Edge(n2, t, i)); nodes[n2].edges.Add(new Edge(n1, t, i)); } usedDict = new Dictionary<int, bool>(); for (int i = 0; i < n; i++) { Dijkstra(i); /*for(int j = 0; j < n; j++) { Console.Write(nodes[i].distances[j] + " "); } Console.WriteLine();*/ } /*for(int i = 0; i < n-1; i++) { for (int j = i + 1; j < n; j++) { int now = j; while (now != i) { int next = now; int edgeId = -1; for (int k = 0; k < nodes[now].edges.Count; k++) { int index = nodes[now].edges[k].toIndex; if (nodes[i].distances[index] < nodes[i].distances[next]) { next = k; edgeId = nodes[now].edges[k].id; } } if (!usedDict.ContainsKey(edgeId)) { usedDict.Add(edgeId, true); } Console.WriteLine(edgeId); now = next; } } }*/ Console.WriteLine(m - usedDict.Count); } //最大距離を帰す static long Dijkstra(int start) { Node startNode = nodes[start]; int cnt = 1; int nowIndex = start; while (cnt < nodes.Length) { Node nowNode = nodes[nowIndex]; for (int i = 0; i < nowNode.edges.Count; i++) { int destIndex = nowNode.edges[i].toIndex; if (startNode.isMin[destIndex]) continue; //確定ノードは無視 long distance = startNode.distances[nowIndex] + nowNode.edges[i].distance; if (distance < startNode.distances[destIndex] || startNode.distances[destIndex] == -1) { startNode.distances[destIndex] = distance; } } int settleIndex = -1; for (int i = 0; i < startNode.distances.Length; i++) { if (startNode.isMin[i] || startNode.distances[i] == -1) continue; if (settleIndex == -1 || startNode.distances[i] < startNode.distances[settleIndex]) { settleIndex = i; } } if (settleIndex == -1) break; startNode.isMin[settleIndex] = true; nowIndex = settleIndex; cnt++; for (int i = 0; i < nodes[nowIndex].edges.Count; i++) { int pair = nodes[nowIndex].edges[i].toIndex; if (!usedDict.ContainsKey(nodes[nowIndex].edges[i].id) && startNode.distances[nowIndex] == startNode.distances[pair] + nodes[nowIndex].edges[i].distance) { usedDict.Add(nodes[nowIndex].edges[i].id, true); break; } } } return startNode.distances[nowIndex]; } class Node { public long[] distances; public bool[] isMin; public List<Edge> edges; public Node(int length) { distances = new long[length]; isMin = new bool[length]; for (int i = 0; i < length; i++) { distances[i] = -1; } edges = new List<Edge>(); } } class Edge { public int toIndex; public int distance; public int id; public Edge(int toIndex, int distance, int id) { this.toIndex = toIndex; this.distance = distance; this.id = id; } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtTest.Dijkstra { class ABC_051 { static Node[] nodes; static Dictionary<int, bool> usedDict; static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); nodes = new Node[n]; for (int i = 0; i < n; i++) { nodes[i] = new Node(n); nodes[i].distances[i] = 0; nodes[i].isMin[i] = true; } for (int i = 0; i < m; i++) { string[] nodeInput = Console.ReadLine().Split(' '); int n1 = int.Parse(nodeInput[0]) - 1; int n2 = int.Parse(nodeInput[1]) - 1; int t = int.Parse(nodeInput[2]); nodes[n1].edges.Add(new Edge(n2, t, i)); nodes[n2].edges.Add(new Edge(n1, t, i)); } usedDict = new Dictionary<int, bool>(); for (int i = 0; i < n; i++) { Dijkstra(i); /*for(int j = 0; j < n; j++) { Console.Write(nodes[i].distances[j] + " "); } Console.WriteLine();*/ } /*for(int i = 0; i < n-1; i++) { for (int j = i + 1; j < n; j++) { int now = j; while (now != i) { int next = now; int edgeId = -1; for (int k = 0; k < nodes[now].edges.Count; k++) { int index = nodes[now].edges[k].toIndex; if (nodes[i].distances[index] < nodes[i].distances[next]) { next = k; edgeId = nodes[now].edges[k].id; } } if (!usedDict.ContainsKey(edgeId)) { usedDict.Add(edgeId, true); } Console.WriteLine(edgeId); now = next; } } }*/ Console.WriteLine(m - usedDict.Count); } //最大距離を帰す static long Dijkstra(int start) { Node startNode = nodes[start]; int cnt = 1; int nowIndex = start; while (cnt < nodes.Length) { Node nowNode = nodes[nowIndex]; for (int i = 0; i < nowNode.edges.Count; i++) { int destIndex = nowNode.edges[i].toIndex; if (startNode.isMin[destIndex]) continue; //確定ノードは無視 long distance = startNode.distances[nowIndex] + nowNode.edges[i].distance; if (distance < startNode.distances[destIndex] || startNode.distances[destIndex] == -1) { startNode.distances[destIndex] = distance; } } int settleIndex = -1; for (int i = 0; i < startNode.distances.Length; i++) { if (startNode.isMin[i] || startNode.distances[i] == -1) continue; if (settleIndex == -1 || startNode.distances[i] < startNode.distances[settleIndex]) { settleIndex = i; } } if (settleIndex == -1) break; startNode.isMin[settleIndex] = true; nowIndex = settleIndex; cnt++; for (int i = 0; i < nodes[nowIndex].edges.Count; i++) { int pair = nodes[nowIndex].edges[i].toIndex; if (!usedDict.ContainsKey(nodes[nowIndex].edges[i].id) && startNode.isMin[pair] && startNode.distances[nowIndex] == startNode.distances[pair] + nodes[nowIndex].edges[i].distance) { usedDict.Add(nodes[nowIndex].edges[i].id, true); break; } } } return startNode.distances[nowIndex]; } class Node { public long[] distances; public bool[] isMin; public List<Edge> edges; public Node(int length) { distances = new long[length]; isMin = new bool[length]; for (int i = 0; i < length; i++) { distances[i] = -1; } edges = new List<Edge>(); } } class Edge { public int toIndex; public int distance; public int id; public Edge(int toIndex, int distance, int id) { this.toIndex = toIndex; this.distance = distance; this.id = id; } } } }
[["+", 15, 16, 31, 16, 12, 204, 205, 214, 141, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 204, 205, 214, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 205, 214, 0, 131]]
8
823
7
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; class Magatro { static int N, M; const int INF = 100000000; static void Main() { string[] s = Console.ReadLine().Split(' '); N = int.Parse(s[0]); M = int.Parse(s[1]); int[,] Dist = new int[N, N]; int[,] Root = new int[N, N]; bool[,,] P = new bool[N, N, M]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { Root[i, j] = INF; } } for (int i = 0; i < M; i++) { string[] ss = Console.ReadLine().Split(' '); int a = int.Parse(ss[0]); int b = int.Parse(ss[1]); int c = int.Parse(ss[2]); Root[a - 1, b - 1] = c; Root[b - 1, a - 1] = c; P[a - 1, b - 1, i] = true; P[b - 1, a - 1, i] = true; } for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { if (i == j) Dist[i, j] = 0; if (Root[i, j] != INF) { Dist[i, j] = Root[i, j]; Dist[j, i] = Root[i, j]; } else { Dist[i, j] = INF; Dist[j, i] = INF; } } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { if (Dist[i, j] > Dist[i, k] + Dist[k, j]) { Dist[i, j] = Dist[i, k] + Dist[k, j]; for (int l = 0; l < M; l++) { P[i, j, l] = P[i, k, l] || P[k, j, l]; } } } } } bool[] ans = new bool[M]; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { for (int k = 0; k < M; k++) { ans[k] |= P[i, j, k]; } } } int cnt = 0; for (int i = 0; i < M; i++) { if (!ans[i]) cnt++; } Console.WriteLine(cnt); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; class Magatro { static int N, M; const int INF = 100000000; static void Main() { string[] s = Console.ReadLine().Split(' '); N = int.Parse(s[0]); M = int.Parse(s[1]); int[,] Dist = new int[N, N]; int[,] Root = new int[N, N]; bool[,,] P = new bool[N, N, M]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { Root[i, j] = INF; } } for (int i = 0; i < M; i++) { string[] ss = Console.ReadLine().Split(' '); int a = int.Parse(ss[0]); int b = int.Parse(ss[1]); int c = int.Parse(ss[2]); Root[a - 1, b - 1] = c; Root[b - 1, a - 1] = c; P[a - 1, b - 1, i] = true; P[b - 1, a - 1, i] = true; } for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { if (i == j) Dist[i, j] = 0; if (Root[i, j] != INF) { Dist[i, j] = Root[i, j]; Dist[j, i] = Root[i, j]; } else { Dist[i, j] = INF; Dist[j, i] = INF; } } } for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (Dist[i, j] > Dist[i, k] + Dist[k, j]) { Dist[i, j] = Dist[i, k] + Dist[k, j]; for (int l = 0; l < M; l++) { P[i, j, l] = P[i, k, l] || P[k, j, l]; } } } } } bool[] ans = new bool[M]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < M; k++) { ans[k] |= P[i, j, k]; } } } int cnt = 0; for (int i = 0; i < M; i++) { if (!ans[i]) cnt++; } Console.WriteLine(cnt); } }
[["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
681
24
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using System.Numerics; // using Point = System.Numerics.Complex; using Number = System.Int64; namespace Program { public class Solver { public void Solve() { var n = sc.Integer(); var m = sc.Integer(); var a = new int[m]; var b = new int[m]; var c = new int[m]; var g = Enumerate(n, x => new int[n]); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) g[i][j] = 1000000000; for (int i = 0; i < m; i++) { a[i] = sc.Integer() - 1; b[i] = sc.Integer() - 1; c[i] = sc.Integer(); g[a[i]][b[i]] = g[b[i]][a[i]] = c[i]; } for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) g[i][j] = Math.Min(g[i][j], g[i][k] + g[k][j]); var ans = 0; for (int i = 0; i < m; i++) if (g[a[i]][b[i]] != c[i]) ans++; IO.Printer.Out.WriteLine(ans); } ModInteger f(long k) { var mat = new Matrix(2, 2); mat[0, 0] = mat[0, 1] = 1; mat[1, 0] = 1; var ret = Matrix.Pow(mat, k); return ret[0, 0] + ret[0, 1]; } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { // static public string AsString(this IEnumerable<char> ie) { return new // string(System.Linq.Enumerable.ToArray(ie)); } static public string // AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return // string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion #region Matrix public class Matrix { int row, col; public Number[] mat; public Number this[int r, int c] { get { return mat[r * col + c]; } set { mat[r * col + c] = value; } } public Matrix(int r, int c) { row = r; col = c; mat = new Number[row * col]; } public static Matrix operator +(Matrix l, Matrix r) { check(l, r); var ret = new Matrix(l.row, l.col); for (int i = 0; i < l.row; i++) for (int j = 0; j < l.col; j++) ret.mat[i * ret.col + j] = l.mat[i * l.col + j] + r.mat[i * r.col + j]; return ret; } public static Matrix operator *(Matrix l, Matrix r) { checkMul(l, r); var ret = new Matrix(l.row, r.col); for (int i = 0; i < l.row; i++) for (int k = 0; k < l.col; k++) for (int j = 0; j < r.col; j++) ret.mat[i * r.col + j] = (ret.mat[i * r.col + j] + l.mat[i * l.col + k] * r.mat[k * r.col + j]); return ret; } public static Matrix Pow(Matrix m, long n) { var ret = new Matrix(m.row, m.col); for (int i = 0; i < m.row; i++) ret.mat[i * m.col + i] = 1; for (; n > 0; m *= m, n >>= 1) if ((n & 1) == 1) ret = ret * m; return ret; } public static Matrix[] PowTable(Matrix m, int k) { var ret = new Matrix[k]; ret[0] = m; for (int i = 1; i < k; i++) ret[i] = ret[i - 1] * ret[i - 1]; return ret; } public static Matrix PowWithTable(Matrix m, long n, Matrix[] table) { var ret = new Matrix(m.row, m.col); for (int i = 0; i < m.row; i++) ret.mat[i * m.col + i] = 1; for (int i = 0; i < table.Length; i++) { if ((n & 1) == 1) ret = ret * table[i]; } return ret; } public static Matrix Trans(Matrix m) { var ret = new Matrix(m.col, m.row); for (int i = 0; i < m.row; i++) for (int j = 0; j < m.col; j++) ret.mat[j * m.col + i] = m.mat[i * m.col + j]; return ret; } [System.Diagnostics.Conditional("DEBUG")] static private void check(Matrix a, Matrix b) { if (a.row != b.row || a.col != b.col) throw new Exception("row and col have to be same."); } [System.Diagnostics.Conditional("DEBUG")] static private void checkMul(Matrix a, Matrix b) { if (a.col != b.row) throw new Exception("row and col have to be same."); } public Number[][] Items { get { var a = new Number[row][]; for (int i = 0; i < row; i++) { a[i] = new Number[col]; for (int j = 0; j < col; j++) a[i][j] = mat[i * col + j]; } return a; } } public override string ToString() { return string.Format("{0}*{1}", row, col); } } #endregion #region ModNumber public partial struct ModInteger { public const long Mod = (long)1e9 + 7; public long num; public ModInteger(long n) : this() { num = n % Mod; if (num < 0) num += Mod; } public override string ToString() { return num.ToString(); } public static ModInteger operator +(ModInteger l, ModInteger r) { var n = l.num + r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; } public static ModInteger operator -(ModInteger l, ModInteger r) { var n = l.num + Mod - r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; } public static ModInteger operator *(ModInteger l, ModInteger r) { return new ModInteger(l.num * r.num); } public static ModInteger operator ^(ModInteger l, long r) { return ModInteger.Pow(l, r); } public static implicit operator ModInteger(long n) { return new ModInteger() { num = n }; } public static ModInteger Pow(ModInteger v, long k) { ModInteger ret = 1; var n = k; for (; n > 0; n >>= 1, v *= v) { if ((n & 1) == 1) ret = ret * v; } return ret; } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using System.Numerics; // using Point = System.Numerics.Complex; using Number = System.Int64; namespace Program { public class Solver { public void Solve() { var n = sc.Integer(); var m = sc.Integer(); var a = new int[m]; var b = new int[m]; var c = new int[m]; var g = Enumerate(n, x => new int[n]); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) g[i][j] = g[j][i] = 1000000000; for (int i = 0; i < m; i++) { a[i] = sc.Integer() - 1; b[i] = sc.Integer() - 1; c[i] = sc.Integer(); g[a[i]][b[i]] = g[b[i]][a[i]] = c[i]; } for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) g[i][j] = Math.Min(g[i][j], g[i][k] + g[k][j]); var ans = 0; for (int i = 0; i < m; i++) if (g[a[i]][b[i]] != c[i]) ans++; IO.Printer.Out.WriteLine(ans); } ModInteger f(long k) { var mat = new Matrix(2, 2); mat[0, 0] = mat[0, 1] = 1; mat[1, 0] = 1; var ret = Matrix.Pow(mat, k); return ret[0, 0] + ret[0, 1]; } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { // static public string AsString(this IEnumerable<char> ie) { return new // string(System.Linq.Enumerable.ToArray(ie)); } static public string // AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return // string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion #region Matrix public class Matrix { int row, col; public Number[] mat; public Number this[int r, int c] { get { return mat[r * col + c]; } set { mat[r * col + c] = value; } } public Matrix(int r, int c) { row = r; col = c; mat = new Number[row * col]; } public static Matrix operator +(Matrix l, Matrix r) { check(l, r); var ret = new Matrix(l.row, l.col); for (int i = 0; i < l.row; i++) for (int j = 0; j < l.col; j++) ret.mat[i * ret.col + j] = l.mat[i * l.col + j] + r.mat[i * r.col + j]; return ret; } public static Matrix operator *(Matrix l, Matrix r) { checkMul(l, r); var ret = new Matrix(l.row, r.col); for (int i = 0; i < l.row; i++) for (int k = 0; k < l.col; k++) for (int j = 0; j < r.col; j++) ret.mat[i * r.col + j] = (ret.mat[i * r.col + j] + l.mat[i * l.col + k] * r.mat[k * r.col + j]); return ret; } public static Matrix Pow(Matrix m, long n) { var ret = new Matrix(m.row, m.col); for (int i = 0; i < m.row; i++) ret.mat[i * m.col + i] = 1; for (; n > 0; m *= m, n >>= 1) if ((n & 1) == 1) ret = ret * m; return ret; } public static Matrix[] PowTable(Matrix m, int k) { var ret = new Matrix[k]; ret[0] = m; for (int i = 1; i < k; i++) ret[i] = ret[i - 1] * ret[i - 1]; return ret; } public static Matrix PowWithTable(Matrix m, long n, Matrix[] table) { var ret = new Matrix(m.row, m.col); for (int i = 0; i < m.row; i++) ret.mat[i * m.col + i] = 1; for (int i = 0; i < table.Length; i++) { if ((n & 1) == 1) ret = ret * table[i]; } return ret; } public static Matrix Trans(Matrix m) { var ret = new Matrix(m.col, m.row); for (int i = 0; i < m.row; i++) for (int j = 0; j < m.col; j++) ret.mat[j * m.col + i] = m.mat[i * m.col + j]; return ret; } [System.Diagnostics.Conditional("DEBUG")] static private void check(Matrix a, Matrix b) { if (a.row != b.row || a.col != b.col) throw new Exception("row and col have to be same."); } [System.Diagnostics.Conditional("DEBUG")] static private void checkMul(Matrix a, Matrix b) { if (a.col != b.row) throw new Exception("row and col have to be same."); } public Number[][] Items { get { var a = new Number[row][]; for (int i = 0; i < row; i++) { a[i] = new Number[col]; for (int j = 0; j < col; j++) a[i][j] = mat[i * col + j]; } return a; } } public override string ToString() { return string.Format("{0}*{1}", row, col); } } #endregion #region ModNumber public partial struct ModInteger { public const long Mod = (long)1e9 + 7; public long num; public ModInteger(long n) : this() { num = n % Mod; if (num < 0) num += Mod; } public override string ToString() { return num.ToString(); } public static ModInteger operator +(ModInteger l, ModInteger r) { var n = l.num + r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; } public static ModInteger operator -(ModInteger l, ModInteger r) { var n = l.num + Mod - r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; } public static ModInteger operator *(ModInteger l, ModInteger r) { return new ModInteger(l.num * r.num); } public static ModInteger operator ^(ModInteger l, long r) { return ModInteger.Pow(l, r); } public static implicit operator ModInteger(long n) { return new ModInteger() { num = n }; } public static ModInteger Pow(ModInteger v, long k) { ModInteger ret = 1; var n = k; for (; n > 0; n >>= 1, v *= v) { if ((n & 1) == 1) ret = ret * v; } return ret; } } #endregion
[["+", 0, 11, 12, 11, 31, 204, 205, 204, 205, 22], ["+", 12, 11, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 11, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 11, 31, 204, 206, 207, 0, 70], ["+", 12, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 1, 0, 11, 12, 11, 0, 202, 0, 32]]
8
2,636
8
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var x = input[0]; var y = input[1]; long ans = 0; if (x < y) { if (x >= 0 && y > 0) ans = Math.Abs(y - x); if (x < 0 && y > 0) { if (Math.Abs(x) > Math.Abs(y)) ans = y - x; else ans = x + y + 1; } if (x < 0 && y <= 0) ans = Math.Abs(y - x); } else { if (x > 0 && y > 0) ans = Math.Abs(y - x) + 2; if (x >= 0 && y <= 0) ans = Math.Abs(x + y) + 1; if (x < 0 && y < 0) ans = Math.Abs(y - x) + 2; } Console.WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var x = input[0]; var y = input[1]; long ans = 0; if (x < y) { if (x >= 0 && y > 0) ans = Math.Abs(y - x); if (x < 0 && y > 0) ans = Math.Abs(x + y) + 1; if (x < 0 && y <= 0) ans = Math.Abs(y - x); } else { if (x > 0 && y > 0) ans = Math.Abs(y - x) + 2; if (x >= 0 && y <= 0) ans = Math.Abs(x + y) + 1; if (x < 0 && y < 0) ans = Math.Abs(y - x) + 2; } Console.WriteLine(ans); Console.Out.Flush(); } } }
[["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["-", 64, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["-", 64, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
324
26
using System; namespace kekW { internal static class Program { private static void Main() { var nbrs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var x = nbrs[0]; var y = nbrs[1]; int res = 0; while (x != y) { if (x < y) { if (-x - y > x - y && -x <= y) { x = -x; res++; } else if (x < 0 && y > 0) { int temp = y - x - y * 2; x += temp; res += temp; } else { int temp = y - x; x += temp; res += temp; } } else { if (Math.Abs(y) - x > 0) { int temp = Math.Abs(y) - x; x += temp; res += temp; } else { x = -x; res++; } } } Console.WriteLine(res); } } }
using System; namespace kekW { internal static class Program { private static void Main() { var nbrs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var x = nbrs[0]; var y = nbrs[1]; int res = 0; while (x != y) { if (x < y) { if (-x - y > x - y && -x <= y) { x = -x; res++; } else if (x < 0 && y > 0) { int temp = y - x - y * 2; x += temp; res += temp; } else { int temp = y - x; x += temp; res += temp; } } else { if (-x >= y && x < 0 || -x == y || Math.Abs(y) - x <= 0) { x = -x; res++; } else { int temp = Math.Abs(y) - x; x += temp; res += temp; } } } Console.WriteLine(res); } } }
[["+", 31, 16, 31, 16, 31, 16, 31, 241, 0, 33], ["+", 31, 16, 31, 16, 31, 16, 31, 241, 0, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 20], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 203], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 15, 16, 31, 16, 12, 16, 31, 241, 0, 33], ["+", 15, 16, 31, 16, 12, 16, 31, 241, 0, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 22], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["-", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["-", 0, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["-", 75, 196, 0, 1, 0, 11, 12, 241, 0, 22], ["-", 75, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29]]
8
212
38
using System; namespace kekW { internal static class Program { private static void Main() { var nbrs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var x = nbrs[0]; var y = nbrs[1]; int res = 0; while (x != y) { if (x < y) { if (-x - y > x - y && -x <= y) { x = -x; res++; } else { int temp = y - x; x += temp; res += temp; } } else { if (-x >= y && x < 0 || -x == y) { x = -x; res++; } else if (Math.Abs(y) - x > 0) { int temp = Math.Abs(y) - x; x += temp; res += temp; } else { x = -x; res++; } } } Console.WriteLine(res); } } }
using System; namespace kekW { internal static class Program { private static void Main() { var nbrs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var x = nbrs[0]; var y = nbrs[1]; int res = 0; while (x != y) { if (x < y) { if (-x - y > x - y && -x <= y) { x = -x; res++; } else if (x < 0 && y > 0) { int temp = y - x - y * 2; x += temp; res += temp; } else { int temp = y - x; x += temp; res += temp; } } else { if (-x >= y && x < 0 || -x == y) { x = -x; res++; } else if (Math.Abs(y) - x > 0) { int temp = Math.Abs(y) - x; x += temp; res += temp; } else { x = -x; res++; } } } Console.WriteLine(res); } } }
[["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 64, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 47], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 25], ["+", 64, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 57, 64, 196, 0, 197, 0, 35], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 95]]
8
207
32
using System; using CompLib.Util; public class Program { private int N; private int[] A; public void Solve() { var sc = new Scanner(); int x = sc.NextInt(); int y = sc.NextInt(); int ans = int.MaxValue; if (x < y) ans = Math.Min(ans, y - x); if (x < -y) ans = Math.Min(ans, -y - x + 1); if (-x < y) ans = Math.Min(ans, y - (-x) + 1); if (-x < -y) ans = Math.Min(ans, -y - (-x) + 2); Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s = Console.ReadLine(); while (s.Length == 0) { s = Console.ReadLine(); } _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using CompLib.Util; public class Program { private int N; private int[] A; public void Solve() { var sc = new Scanner(); int x = sc.NextInt(); int y = sc.NextInt(); int ans = int.MaxValue; if (x <= y) ans = Math.Min(ans, y - x); if (x <= (-y)) ans = Math.Min(ans, (-y) - x + 1); if ((-x) <= y) ans = Math.Min(ans, y - (-x) + 1); if ((-x) <= -y) ans = Math.Min(ans, (-y) - (-x) + 2); Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s = Console.ReadLine(); while (s.Length == 0) { s = Console.ReadLine(); } _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25]]
8
532
18
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { long x, y; ReadMulti(out x, out y); long dif = Math.Abs(Math.Abs(x) - Math.Abs(y)); if (x < y) { if (x < 0 && 0 < y) { WriteAnswer(dif + 1); } else { WriteAnswer(dif); } } else { if (x < 0 && y < 0) { WriteAnswer(dif + 2); } else { WriteAnswer(dif + 1); } } } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む global::Common.ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); static bool IsOdd(long num) { return (num & 1) == 1; } static bool IsEven(long num) { return (num & 1) == 0; } static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { long x, y; ReadMulti(out x, out y); long dif = Math.Abs(Math.Abs(x) - Math.Abs(y)); if (x < y) { if (x < 0 && 0 < y) { WriteAnswer(dif + 1); } else { WriteAnswer(dif); } } else { if (x < 0 && y < 0) { WriteAnswer(dif + 2); } else if (0 < x && 0 < y) { WriteAnswer(dif + 2); } else { WriteAnswer(dif + 1); } } } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む global::Common.ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); static bool IsOdd(long num) { return (num & 1) == 1; } static bool IsEven(long num) { return (num & 1) == 0; } static long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } } }
[["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 203], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 75, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 203], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 95]]
8
793
20
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long x = long.Parse(input[0]); long y = long.Parse(input[1]); long answer = Math.Abs(Math.Abs(x) - Math.Abs(y)); if (x < y && y < 0 || 0 <= x && x < y) answer += 0; else if (y < x && x < 0 || 0 < y && y < x) answer += 2; else answer += 1; Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); long x = long.Parse(input[0]); long y = long.Parse(input[1]); long a = Math.Abs(Math.Abs(x) - Math.Abs(y)); if (x < y && y <= 0 || 0 <= x && x < y) a += 0; else if (y < x && x < 0 || 0 < y && y < x) a += 2; else a += 1; Console.WriteLine(a); } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 57, 75, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
158
2
using System.Linq; using System; public class Hello { public const long INF = 99999999999999; public static void Main() { var ret = new long[4]; for (int i = 0; i < 4; i++) ret[i] = INF; string[] line = Console.ReadLine().Trim().Split(' '); var x = long.Parse(line[0]); var y = long.Parse(line[1]); ret[0] = getAns(x, y); ret[1] = getAns(x, -y) + 1; ret[2] = getAns(-x, y) + 1; ret[3] = getAns(-x, -y) + 2; Console.WriteLine(ret.Min()); } public static long getAns(long a, long b) { return a < b ? b - a : INF; } }
using System.Linq; using System; public class Hello { public const long INF = 99999999999; public static void Main() { var ret = new long[4]; string[] line = Console.ReadLine().Trim().Split(' '); var x = long.Parse(line[0]); var y = long.Parse(line[1]); ret[0] = getAns(x, y); ret[1] = getAns(x, -y) + 1; ret[2] = getAns(-x, y) + 1; ret[3] = getAns(-x, -y) + 2; Console.WriteLine(ret.Min()); } public static long getAns(long a, long b) { return a <= b ? b - a : INF; } }
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 7, 8, 1, 0, 11, 31, 204, 205, 22], ["-", 8, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 7, 8, 1, 0, 11, 12, 22], ["-", 0, 195, 8, 196, 0, 7, 8, 1, 0, 35], ["-", 8, 196, 0, 37, 0, 41, 15, 16, 17, 18], ["+", 8, 196, 0, 37, 0, 41, 15, 16, 17, 19]]
8
199
4
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("10 20"); // 10 } else if (InputPattern == "Input2") { WillReturn.Add("10 -10"); // 1 } else if (InputPattern == "Input3") { WillReturn.Add("-10 -20"); // 12 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); long[] wkArr = InputList[0].Split(' ').Select(A => long.Parse(A)).ToArray(); long X = wkArr[0], Y = wkArr[1]; Console.WriteLine(Solve(X, Y)); } static long Solve(long pX, long pY) { if (pX == 0) { if (0 < pY) return pY; return -pY + 1; } if (pY == 0) { if (0 < pX) return 1 + pX; else return -pX; } long AbsSum = Math.Abs(pX) + Math.Abs(pY); long AbsDiff = Math.Abs(Math.Abs(pX) - Math.Abs(pY)); if (0 < pX && 0 < pY) { //場合01 if (pX < pY) return AbsDiff; //場合02 else return 1 + AbsDiff + 1; } if (pX < 0 && pY < 0) { //場合03 if (pX < pY) return AbsDiff; //場合04 else return 1 + AbsDiff + 1; } if (0 < pX && pY < 0) { //場合05 if (Math.Abs(pX) < Math.Abs(pY)) return AbsDiff + 1; //場合06 else return 1 + AbsDiff; } if (pX < 0 && 0 < pY) { //場合07 if (Math.Abs(pX) < Math.Abs(pY)) return 1 + AbsDiff; //場合08 else return AbsSum; } return -1; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("10 20"); // 10 } else if (InputPattern == "Input2") { WillReturn.Add("10 -10"); // 1 } else if (InputPattern == "Input3") { WillReturn.Add("-10 -20"); // 12 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int[] wkArr = InputList[0].Split(' ').Select(A => int.Parse(A)).ToArray(); int X = wkArr[0], Y = wkArr[1]; Console.WriteLine(Solve(X, Y)); } static int Solve(int pX, int pY) { if (pX == 0) { if (0 < pY) return pY; return -pY + 1; } if (pY == 0) { if (0 < pX) return 1 + pX; else return -pX; } int AbsDiff = Math.Abs(Math.Abs(pX) - Math.Abs(pY)); if (0 < pX && 0 < pY) { //場合01 if (pX < pY) return AbsDiff; //場合02 else return 1 + AbsDiff + 1; } if (pX < 0 && pY < 0) { //場合03 if (pX < pY) return AbsDiff; //場合04 else return 1 + AbsDiff + 1; } if (0 < pX && pY < 0) { //場合05 if (Math.Abs(pX) < Math.Abs(pY)) return AbsDiff + 1; //場合06 else return 1 + AbsDiff; } if (pX < 0 && 0 < pY) { //場合07 if (Math.Abs(pX) < Math.Abs(pY)) return 1 + AbsDiff; //場合08 else return AbsDiff + 1; } return -1; } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 212, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 212, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 212, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 212, 0, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 75, 37, 0, 22], ["+", 64, 196, 0, 57, 75, 37, 0, 16, 31, 22], ["+", 64, 196, 0, 57, 75, 37, 0, 16, 17, 72], ["+", 64, 196, 0, 57, 75, 37, 0, 16, 12, 203]]
8
461
35
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { new Program().SolveA(); Console.ReadKey(); } Scanner sc = new Scanner(); void SolveA() { int x = sc.NextInt(); int y = sc.NextInt(); int res = 0; if (x <= y) { res = Math.Abs(x - y); if (-x <= y) { res = Min(res, 1 + Math.Abs(-x - y)); } } else { res = Min(Math.Abs(x - y) + 2, Math.Abs(-x - y) + 1); } Console.WriteLine(res); } void SolveB() {} // ------------------------------------- // int Max(int v1, int v2) { return Math.Max(v1, v2); } int Min(int v1, int v2) { return Math.Min(v1, v2); } int[][] CreateArray2D(int n1, int n2) { int[][] ary = new int [n1][]; for (int i = 0; i < n1; i++) ary[i] = new int[n2]; return ary; } } class Scanner { public Scanner() {} private string[] buff = null; private int bIndex = 0; public string Next() { if (buff == null || bIndex >= buff.Length) { buff = Console.ReadLine().Split(' '); bIndex = 0; } return buff[bIndex++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } } class Pair<T, K> { public Pair() {} public Pair(T f, K s) { first = f; second = s; } public T first { get; set; } public K second { get; set; } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { new Program().SolveA(); Console.ReadKey(); } Scanner sc = new Scanner(); void SolveA() { int x = sc.NextInt(); int y = sc.NextInt(); int res = 0; if (x <= y) { res = Min(Math.Abs(x - y), 1 + Math.Abs(-x - y)); } else { res = Min(Math.Abs(x - y) + 2, Math.Abs(-x - y) + 1); } Console.WriteLine(res); } void SolveB() {} // ------------------------------------- // int Max(int v1, int v2) { return Math.Max(v1, v2); } int Min(int v1, int v2) { return Math.Min(v1, v2); } int[][] CreateArray2D(int n1, int n2) { int[][] ary = new int [n1][]; for (int i = 0; i < n1; i++) ary[i] = new int[n2]; return ary; } } class Scanner { public Scanner() {} private string[] buff = null; private int bIndex = 0; public string Next() { if (buff == null || bIndex >= buff.Length) { buff = Console.ReadLine().Split(' '); bIndex = 0; } return buff[bIndex++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } } class Pair<T, K> { public Pair() {} public Pair(T f, K s) { first = f; second = s; } public T first { get; set; } public K second { get; set; } }
[["+", 64, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 64, 196, 0, 57, 15, 16, 31, 241, 0, 33], ["-", 64, 196, 0, 57, 15, 16, 31, 241, 0, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
426
17
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; class Prog { public Prog() {} public static int Main() { new Prog().calc(); return 0; } Scanner cin; public void calc() { cin = new Scanner(); int x = cin.nextInt(); int y = cin.nextInt(); if (x == 0) { if (y > 0) Console.WriteLine(y); else Console.WriteLine(y + 1); return; } if (y == 0) { if (x > 0) Console.WriteLine(x); else Console.WriteLine(x + 1); return; } if (large(x, y) && ((sei(x) && sei(y)) || (!sei(x) && !sei(y)))) { Console.WriteLine(y - x); return; } if (!large(x, y) && ((sei(x) && sei(y)) || (!sei(x) && !sei(y)))) { Console.WriteLine(x - y + 2); return; } int absmax = Math.Max(Math.Abs(x), Math.Abs(y)); int absmin = Math.Min(Math.Abs(x), Math.Abs(y)); Console.WriteLine(absmax - absmin + 1); } bool large(int x, int y) { return x < y; } bool sei(int x) { return x > 0; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; class Prog { public Prog() {} public static int Main() { new Prog().calc(); return 0; } Scanner cin; public void calc() { cin = new Scanner(); int x = cin.nextInt(); int y = cin.nextInt(); if (x == 0) { if (y > 0) Console.WriteLine(y); else Console.WriteLine(Math.Abs(y) + 1); return; } if (y == 0) { if (x > 0) Console.WriteLine(x + 1); else Console.WriteLine(Math.Abs(x)); return; } if (large(x, y) && ((sei(x) && sei(y)) || (!sei(x) && !sei(y)))) { Console.WriteLine(y - x); return; } if (!large(x, y) && ((sei(x) && sei(y)) || (!sei(x) && !sei(y)))) { Console.WriteLine(x - y + 2); return; } int absmax = Math.Max(Math.Abs(x), Math.Abs(y)); int absmin = Math.Min(Math.Abs(x), Math.Abs(y)); Console.WriteLine(absmax - absmin + 1); } bool large(int x, int y) { return x < y; } bool sei(int x) { return x > 0; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
[["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
514
14
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int x = sc.nextInt(); int y = sc.nextInt(); int ans = Math.Abs(Math.Abs(x) - Math.Abs(y)); if (x > 0 && y > 0) { if (x > y) ans += 2; } else if (x < 0 && y < 0) { if (x > y) ans += 2; } else if (x <= 0 && y == 0) { } else { ans++; } Console.WriteLine(ans); } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int x = sc.nextInt(); int y = sc.nextInt(); int ans = Math.Abs(Math.Abs(x) - Math.Abs(y)); if (x > 0 && y > 0) { if (x > y) ans += 2; } else if (x < 0 && y < 0) { if (x > y) ans += 2; } else if (x <= 0 && y == 0) { } else if (x == 0 && y > 0) { } else { ans++; } Console.WriteLine(ans); } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
[["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 17, 47], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 95]]
8
1,275
13
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); long X = int.Parse(str[0]); long Y = int.Parse(str[1]); long count = 0; if (X < Y) { count = Y - X; } else { count = X - Y + 2; } if (-X <= Y) { count = Math.Min(Y + X + 1, count); } sb.Append(count + "\n"); } }
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); long X = int.Parse(str[0]); long Y = int.Parse(str[1]); long count = 0; if (X < Y) { count = Y - X; } else { count = X - Y + 2; } if (-X <= Y) { count = Math.Min(Y + X + 1, count); } else { count = Math.Min(-Y - X + 1, count); } sb.Append(count + "\n"); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 31, 241, 0, 33], ["+", 0, 28, 0, 16, 31, 16, 31, 241, 0, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
191
19
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int K = cin.nextInt(); long[] A = cin.ArrayLong(N); long[] sumA = new long[N + 1]; long[] sumB = new long[N + 1]; for (int i = 0; i < N; i++) { sumA[i + 1] = sumA[i] + A[i]; sumB[i + 1] = sumB[i] + Math.Max(A[i], 0); } long ans = 0; for (int i = K; i <= N; i++) { ans = Math.Max(ans, sumA[N] - (sumA[i] - sumA[i - K]) + (sumB[i] - sumB[i - K])); ans = Math.Max(ans, sumA[N] - (sumA[i] - sumA[i - K])); } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int K = cin.nextInt(); long[] A = cin.ArrayLong(N); long[] sumA = new long[N + 1]; long[] sumB = new long[N + 1]; for (int i = 0; i < N; i++) { sumA[i + 1] = sumA[i] + A[i]; sumB[i + 1] = sumB[i] + Math.Max(A[i], 0); } long ans = 0; for (int i = K; i <= N; i++) { ans = Math.Max(ans, sumB[N] - (sumB[i] - sumB[i - K]) + (sumA[i] - sumA[i - K])); ans = Math.Max(ans, sumB[N] - (sumB[i] - sumB[i - K])); } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 0, 28, 0, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 204, 205, 22], ["-", 31, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 31, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["-", 31, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["-", 0, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["-", 0, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22]]
8
647
16
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { AGC008.C(); } class AGC008 { public static void A() { var X = Read.Int(); var Y = Read.Int(); var AX = Math.Abs(X); var AY = Math.Abs(Y); if (AX == AY) { Console.WriteLine(1); } else if (AX < AY) { Console.WriteLine(AY - AX + (X < 0 ? 1 : 0) + (Y < 0 ? 1 : 0)); } else { Console.WriteLine(AX - AY + (X > 0 ? 1 : 0) + (Y > 0 ? 1 : 0)); } } public static void B() { var N = Read.Int(); var K = Read.Long(); var A = Read.LongN(); var Asum = new long[N + 1]; var Bsum = new long[N + 1]; for (int i = 0; i < N; ++i) { Asum[i + 1] = Asum[i] + A[i]; Bsum[i + 1] = Bsum[i] + Math.Max(0, A[i]); } long max = 0; for (int i = 0; i < N - K + 1; ++i) { long score = Bsum[i] - Bsum[0] + Math.Max(0, Asum[i + K] - Asum[i + 1]) + Bsum[N] - Bsum[K + i]; max = Math.Max(max, score); } Console.WriteLine(max); } public static void C() { var A = Read.LongN(); var AI = A[0]; var AO = A[1]; var AJ = A[3]; var AL = A[4]; var K1 = AI / 2 * 2 + AO + AJ / 2 * 2 + AL / 2 * 2; var K2 = AI > 0 && AJ > 0 && AL > 0 ? (AI - 1) / 2 * 2 + AO + (AJ - 1) / 2 * 2 + (AL - 1) / 2 * 2 + 2 : 0; Console.WriteLine(Math.Max(K1, K2)); } } class Util {} static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { AGC008.C(); } class AGC008 { public static void A() { var X = Read.Int(); var Y = Read.Int(); var AX = Math.Abs(X); var AY = Math.Abs(Y); if (AX == AY) { Console.WriteLine(1); } else if (AX < AY) { Console.WriteLine(AY - AX + (X < 0 ? 1 : 0) + (Y < 0 ? 1 : 0)); } else { Console.WriteLine(AX - AY + (X > 0 ? 1 : 0) + (Y > 0 ? 1 : 0)); } } public static void B() { var N = Read.Int(); var K = Read.Long(); var A = Read.LongN(); var Asum = new long[N + 1]; var Bsum = new long[N + 1]; for (int i = 0; i < N; ++i) { Asum[i + 1] = Asum[i] + A[i]; Bsum[i + 1] = Bsum[i] + Math.Max(0, A[i]); } long max = 0; for (int i = 0; i < N - K + 1; ++i) { long score = Bsum[i] - Bsum[0] + Math.Max(0, Asum[i + K] - Asum[i]) + Bsum[N] - Bsum[i + K]; max = Math.Max(max, score); } Console.WriteLine(max); } public static void C() { var A = Read.LongN(); var AI = A[0]; var AO = A[1]; var AJ = A[3]; var AL = A[4]; var K1 = AI / 2 * 2 + AO + AJ / 2 * 2 + AL / 2 * 2; var K2 = AI > 0 && AJ > 0 && AL > 0 ? (AI - 1) / 2 * 2 + AO + (AJ - 1) / 2 * 2 + (AL - 1) / 2 * 2 + 3 : 0; Console.WriteLine(Math.Max(K1, K2)); } } class Util {} static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 41, 64, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 64, 16, 12, 203]]
8
1,540
8
using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); long ret = 0; ret += x[1]; int[] a = new int[] { x[0], x[3], x[4] }; long aret = 0; aret += a[0] / 2 * 2; aret += a[1] / 2 * 2; aret += a[2] / 2 * 2; int[] b = new int[] { x[0] - 1, x[3] - 1, x[4] - 1 }; long bret = 0; bret += b[0] / 2 * 2; bret += b[1] / 2 * 2; bret += b[2] / 2 * 2; Console.WriteLine(ret + Math.Max(aret, bret + 1)); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); long ret = 0; ret += x[1]; int[] a = new int[] { x[0], x[3], x[4] }; long aret = 0; aret += a[0] / 2 * 2; aret += a[1] / 2 * 2; aret += a[2] / 2 * 2; int[] b = new int[] { x[0] - 1, x[3] - 1, x[4] - 1 }; long bret = 0; bret += b[0] / 2 * 2; bret += b[1] / 2 * 2; bret += b[2] / 2 * 2; Console.WriteLine(ret + Math.Max(aret, b.Min() >= 0 ? bret + 3 : 0)); } } }
[["+", 0, 41, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 41, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 41, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 41, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 41, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 12, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
224
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { Solve(); } private const long MOD = 1000000007; static void Solve() { var o = ReadAndParseIntArr(); int a = o[0]; char op = (char)o[1]; int b = o[2]; int ans = 0; if (op == '+') { ans = a + b; } else { ans = a - b; } Console.WriteLine(ans); } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { Solve(); } private const long MOD = 1000000007; static void Solve() { var o = Console.ReadLine(); var arr = o.Split(' '); int a = int.Parse(arr[0]); string op = arr[1]; int b = int.Parse(arr[2]); int ans = 0; if (op == "+") { ans = a + b; } else { ans = a - b; } Console.WriteLine(ans); } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 200, 0, 212, 0, 74, 51, 204, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 57, 15, 16, 12, 5, 0, 62]]
8
429
41
using System; public class Aprob { public static void Main() { string[] read = new string[3]; read = Console.ReadLine().Split(' '); int A = int.Parse(read[0]); // int B = int.Parse(read[1]); int C = int.Parse(read[2]); if (read[1] == "+") { Console.WriteLine(A + C); } else { Console.WriteLine(A - C); } Console.WriteLine("A" + read[1].Substring(0, 1) + "C"); } }
using System; public class Aprob { public static void Main() { string[] read = new string[3]; read = Console.ReadLine().Split(' '); int A = int.Parse(read[0]); // int B = int.Parse(read[1]); int C = int.Parse(read[2]); if (read[1] == "+") { Console.WriteLine(A + C); } else { Console.WriteLine(A - C); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 16, 31, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 31, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 31, 16, 12, 213, 63, 214, 205, 204, 205, 22], ["-", 12, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["-", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["-", 12, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["-", 0, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["-", 31, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["-", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
128
25
using System; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] t1 = Console.ReadLine().Split(); int[] t = new int[t1.Length]; for (int i = 0; i < t1.Length; i++) { t[i] = int.Parse(t1[i]); } int m = int.Parse(Console.ReadLine()); int[][] px = new int [m][]; for (int i = 0; i < m; i++) { string[] px1 = Console.ReadLine().Split(); px[i] = new int[2]; px[i][0] = int.Parse(px1[0]); } for (int i = 0; i < m; i++) { int ans = 0; for (int j = 0; j < t.Length; j++) { if (j == px[i][0]) { ans += px[i][1]; } else { ans += t[j]; } } Console.WriteLine(ans); } } }
using System; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] t1 = Console.ReadLine().Split(' '); int[] t = new int[t1.Length]; for (int i = 0; i < t1.Length; i++) { t[i] = int.Parse(t1[i]); } int m = int.Parse(Console.ReadLine()); int[][] px = new int [m][]; for (int i = 0; i < m; i++) { string[] px1 = Console.ReadLine().Split(' '); px[i] = new int[2]; px[i][0] = int.Parse(px1[0]); px[i][1] = int.Parse(px1[1]); } for (int i = 0; i < m; i++) { int ans = 0; for (int j = 0; j < n; j++) { if (j == px[i][0] - 1) { ans += px[i][1]; } else { ans += t[j]; } } Console.WriteLine(ans); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 11, 31, 204, 205, 204, 205, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
262
30
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Linq.Expressions; using static System.Console; using static System.Math; class Simple { int N; int[] A; const int mod = (int)1e9 + 7; void Solve() { // input N = io.Int; A = new int[N]; for (int i = 0; i < N; ++i) A[i] = io.Int; // cal var dic = new Dictionary<int, int>(); foreach (var v in A) { if (!dic.ContainsKey(v)) dic[v] = 0; dic[v]++; } var isOdd = N % 2 != 0; var isValid = isOdd ? dic.Count(v => v.Value != 2) == 1 : dic.All(v => v.Value == 2); var ans = 1L; if (isValid) { var n = isOdd ? dic.Keys.Count - 1 : dic.Keys.Count; for (int i = 0; i < n; ++i) { ans = (ans * 2) % mod; } } else { ans = 0; } // ret WriteLine(ans); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); private void Stream() { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // SetIn(exStdIn); Solve(); io.Flush(); } } class SimpleIO { string[] _nextBuffer; int _bufferCnt; char[] cs = new char[] { ' ', '"', ',' }; StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { _nextBuffer = new string[0]; _bufferCnt = 0; SetOut(sw); } string Next() { if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++]; var st = ReadLine(); while (st == "") st = ReadLine(); if (st != null) _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); else st = ""; _bufferCnt = 0; return _nextBuffer[_bufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void Flush() => Out.Flush(); }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Linq.Expressions; using static System.Console; using static System.Math; class Simple { int N; int[] A; const int mod = (int)1e9 + 7; void Solve() { // input N = io.Int; A = new int[N]; for (int i = 0; i < N; ++i) A[i] = io.Int; // cal var dic = new Dictionary<int, int>(); foreach (var v in A) { if (!dic.ContainsKey(v)) dic[v] = 0; dic[v]++; } var isOdd = N % 2 != 0; var isValid = isOdd ? dic.Count(v => v.Value != 2) == 1 && dic.Where(v => v.Value == 1).All(v => v.Key == 0) : dic.All(v => v.Value == 2); var ans = 1L; if (isValid) { var n = isOdd ? dic.Keys.Count - 1 : dic.Keys.Count; for (int i = 0; i < n; ++i) { ans = (ans * 2) % mod; } } else { ans = 0; } // ret WriteLine(ans); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); private void Stream() { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // SetIn(exStdIn); Solve(); io.Flush(); } } class SimpleIO { string[] _nextBuffer; int _bufferCnt; char[] cs = new char[] { ' ', '"', ',' }; StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { _nextBuffer = new string[0]; _bufferCnt = 0; SetOut(sw); } string Next() { if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++]; var st = ReadLine(); while (st == "") st = ReadLine(); if (st != null) _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); else st = ""; _bufferCnt = 0; return _nextBuffer[_bufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void Flush() => Out.Flush(); }
[["+", 0, 200, 0, 212, 0, 41, 64, 16, 17, 98], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 41, 64, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 41, 64, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 41, 64, 16, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 41, 64, 16, 12, 213, 3, 4, 0, 25]]
8
535
24
using System; using System.Collections.Generic; namespace ConsoleApp_CS { class Program { static void Main(string[] args) { var n = CIn.ReadLong(); var a = CIn.ReadLongArray(n); var ans = (long)1; Array.Sort(a); if (a.Length > 1) { var tmp = a[1] - 2; for (var i = a.Length % 2; i < n; i += 2) { if (a[i] == a[i + 1] && a[i] - tmp == 2 && false) { tmp = a[i]; ans *= 2; } else { ans = 0; } } } Console.WriteLine(ans); } } class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(long n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(long n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(long n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(long n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } } }
using System; using System.Collections.Generic; namespace ConsoleApp_CS { class Program { static void Main(string[] args) { var n = CIn.ReadLong(); var a = CIn.ReadLongArray(n); var ans = (long)1; var mod = (long)1000000007; Array.Sort(a); if (a.Length > 1) { var tmp = a[1] - 2; for (var i = a.Length % 2; i < n; i += 2) { if (a[i] == a[i + 1] && a[i] - tmp == 2) { tmp = a[i]; ans *= 2; if (ans >= mod) { ans %= mod; } } else { ans = 0; } } } Console.WriteLine(ans); } } class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(long n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(long n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(long n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(long n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 51, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
470
22
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int count = int.Parse(Reader.ReadLine()); int[] list = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); Dictionary<int, int> dic = new Dictionary<int, int>(); list.ToList().ForEach(a => { if (dic.ContainsKey(a)) { dic[a]++; } else { dic[a] = 1; } }); bool isCorrect = true; if (count % 2 == 0) { if (dic.Keys.Any(a => a == 0 || a > count - 1)) { isCorrect = false; } else { for (int i = 1; i <= count - 1; i += 2) { if (!dic.ContainsKey(i)) { isCorrect = false; break; } if (dic[i] != 2) { isCorrect = false; break; } } } } else { if (dic.Keys.Any(a => a > count - 1)) { isCorrect = false; } else { for (int i = 0; i <= count - 1; i += 2) { if (!dic.ContainsKey(i)) { isCorrect = false; break; } if (dic[i] != 2) { isCorrect = false; break; } } } } if (isCorrect) { long ans = 1; long mod = 1000000000 + 7; for (int i = 0; i < count / 2; i++) { ans *= 2; ans = ans % mod; } Console.WriteLine(ans); } else { Console.WriteLine(0); } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 8 7 5 1 1 7 3 5 3 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int count = int.Parse(Reader.ReadLine()); int[] list = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); Dictionary<int, int> dic = new Dictionary<int, int>(); list.ToList().ForEach(a => { if (dic.ContainsKey(a)) { dic[a]++; } else { dic[a] = 1; } }); bool isCorrect = true; if (count % 2 == 0) { if (dic.Keys.Any(a => a == 0 || a > count - 1)) { isCorrect = false; } else { for (int i = 1; i <= count - 1; i += 2) { if (!dic.ContainsKey(i)) { isCorrect = false; break; } if (dic[i] != 2) { isCorrect = false; break; } } } } else { if (dic.Keys.Any(a => a > count - 1)) { isCorrect = false; } else { for (int i = 0; i <= count - 1; i += 2) { if (!dic.ContainsKey(i)) { isCorrect = false; break; } if (i == 0) { if (dic[i] != 1) { isCorrect = false; break; } } else { if (dic[i] != 2) { isCorrect = false; break; } } } } } if (isCorrect) { long ans = 1; long mod = 1000000000 + 7; for (int i = 0; i < count / 2; i++) { ans *= 2; ans = ans % mod; } Console.WriteLine(ans); } else { Console.WriteLine(0); } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 7 6 4 0 2 4 0 2 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
8
495
30
using System; using System.Collections.Generic; namespace cswork { class Program { static void Main(string[] args) { string s = ReadStr(); if (s.Equals("a") || s.Equals("b") || s.Equals("c") || s.Equals("d") || s.Equals("e")) { Write("vowel"); } else { Write("consonant"); } Exit(); } public static void Write(string str) { Console.WriteLine(str); } public static void Write(int i) { Console.WriteLine(i); } public static void Write(double d) { Console.WriteLine(d); } public static string ReadStr() { return Console.ReadLine(); } public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long Read() { return long.Parse(Console.ReadLine()); } public static double ReadDouble() { return double.Parse(Console.ReadLine()); } public static void Exit() {} public static List<string> ReadListStr() { return new List<string>(ReadStr().Split(" ")); } public static List<long> ReadList() { return ReadListStr().ConvertAll(x => long.Parse(x)); } public static List<int> ReadListInt() { return ReadListStr().ConvertAll(x => int.Parse(x)); } } }
using System; using System.Collections.Generic; namespace cswork { class Program { static void Main(string[] args) { string s = ReadStr(); if (s.Equals("a") || s.Equals("i") || s.Equals("u") || s.Equals("e") || s.Equals("o")) { Write("vowel"); } else { Write("consonant"); } Exit(); } public static void Write(string str) { Console.WriteLine(str); } public static void Write(int i) { Console.WriteLine(i); } public static void Write(double d) { Console.WriteLine(d); } public static string ReadStr() { return Console.ReadLine(); } public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long Read() { return long.Parse(Console.ReadLine()); } public static double ReadDouble() { return double.Parse(Console.ReadLine()); } public static void Exit() {} public static List<string> ReadListStr() { return new List<string>(ReadStr().Split(" ")); } public static List<long> ReadList() { return ReadListStr().ConvertAll(x => long.Parse(x)); } public static List<int> ReadListInt() { return ReadListStr().ConvertAll(x => int.Parse(x)); } } }
[["-", 12, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 12, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
326
8
using System; using static System.Console; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var x = ReadLine(); if (x == "a" || x == "b" || x == "c" || x == "d" || x == "e") { WriteLine("vowel"); } else { WriteLine("consonant"); } } static int InputNum() { return int.Parse(ReadLine()); } static List<int> InputNumList() { return ReadLine().Split(' ').Select(int.Parse).ToList(); } } }
using System; using static System.Console; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { var x = ReadLine(); if (x == "a" || x == "i" || x == "u" || x == "o" || x == "e") { WriteLine("vowel"); } else { WriteLine("consonant"); } } static int InputNum() { return int.Parse(ReadLine()); } static List<int> InputNumList() { return ReadLine().Split(' ').Select(int.Parse).ToList(); } } }
[["-", 31, 16, 31, 16, 12, 16, 12, 5, 0, 222], ["+", 31, 16, 31, 16, 12, 16, 12, 5, 0, 222], ["-", 15, 16, 31, 16, 12, 16, 12, 5, 0, 222], ["+", 15, 16, 31, 16, 12, 16, 12, 5, 0, 222]]
8
148
6
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var str = Console.ReadLine(); if (str == "a" || str == "b" || str == "c" || str == "d" || str == "e") { Console.WriteLine("vowel"); } else { Console.WriteLine("consonant"); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var str = Console.ReadLine(); if (str == "a" || str == "i" || str == "u" || str == "o" || str == "e") { Console.WriteLine("vowel"); } else { Console.WriteLine("consonant"); } } } }
[["-", 31, 16, 31, 16, 12, 16, 12, 5, 0, 222], ["+", 31, 16, 31, 16, 12, 16, 12, 5, 0, 222], ["-", 15, 16, 31, 16, 12, 16, 12, 5, 0, 222], ["+", 15, 16, 31, 16, 12, 16, 12, 5, 0, 222]]
8
98
6
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input = Console.ReadLine(); string boin = "aiueo"; Console.WriteLine(boin.Contains(input)); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input = Console.ReadLine(); string boin = "aiueo"; Console.WriteLine(boin.Contains(input) ? "vowel" : "consonant"); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
77
8
using System; using System.Linq; namespace ABC049_B { class Program { static void Main(string[] args) { var sss = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var H = sss[0]; var W = sss[1]; var C = new string[H].Select(x => Console.ReadLine()).ToArray(); for (var i = 0; i < 2 * (H - 1); i++) { for (var j = 0; j < W; j++) { Console.Write(C[(i + 1) / 2][j]); } Console.WriteLine(); } } } }
using System; using System.Linq; namespace ABC049_B { class Program { static void Main(string[] args) { var sss = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var H = sss[0]; var W = sss[1]; var C = new string[H].Select(x => Console.ReadLine()).ToArray(); for (var i = 0; i <= 2 * H - 1; i++) { for (var j = 0; j < W; j++) { Console.Write(C[i / 2][j]); } Console.WriteLine(); } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 15, 16, 12, 16, 12, 23, 0, 24], ["-", 0, 7, 15, 16, 12, 16, 12, 23, 0, 25], ["-", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 206, 207, 0, 28, 0, 16, 31, 23, 0, 25]]
8
155
8
using System; class Program { static void Main(string[] args) { string str = Console.ReadLine(); int h = int.Parse(str[0].ToString()); int w = int.Parse(str[1].ToString()); string[] c = new string[h]; for (int i = 0; i < h; i++) { c[i] = Console.ReadLine(); } for (int i = 0; i < h; i++) { Console.WriteLine(c[i]); Console.WriteLine(c[i]); } } }
using System; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int h = int.Parse(str[0].ToString()); int w = int.Parse(str[1].ToString()); string[] c = new string[h]; for (int i = 0; i < h; i++) { c[i] = Console.ReadLine(); } for (int i = 0; i < h; i++) { Console.WriteLine(c[i]); Console.WriteLine(c[i]); } } }
[["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
135
9
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int[] Cnt = new int[M]; int[] Same = new int[M]; Dictionary<int, int> D = new Dictionary<int, int>(); for (int i = 0; i < N; i++) { if (D.ContainsKey(A[i]) == false) D.Add(A[i], 0); D[A[i]]++; } foreach (var k in D.Keys) { Cnt[k % M] += D[k]; Same[k % M] += D[k] / 2; } int ans = 0; for (int i = 0; i < M; i++) { int j = M - i; if (j < i) continue; j %= M; if (i == j) { ans += Cnt[i] / 2; } else { int ma = Cnt[i] > Cnt[j] ? i : j; int mi = ma == i ? j : i; ans += Cnt[mi]; int rest = Cnt[ma] - Cnt[mi]; int add = Math.Min(rest / 2, Same[ma] * 2); ans += add; } } Console.WriteLine(ans); } int N, M; int[] A; public Sol() { var d = ria(); N = d[0]; M = d[1]; A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int[] Cnt = new int[M]; int[] Same = new int[M]; Dictionary<int, int> D = new Dictionary<int, int>(); for (int i = 0; i < N; i++) { if (D.ContainsKey(A[i]) == false) D.Add(A[i], 0); D[A[i]]++; } foreach (var k in D.Keys) { Cnt[k % M] += D[k]; Same[k % M] += D[k] / 2; } int ans = 0; for (int i = 0; i < M; i++) { int j = M - i; if (j < i) continue; j %= M; if (i == j) { ans += Cnt[i] / 2; } else { int ma = Cnt[i] > Cnt[j] ? i : j; int mi = ma == i ? j : i; ans += Cnt[mi]; int rest = Cnt[ma] - Cnt[mi]; int add = rest >= Same[ma] * 2 ? Same[ma] : rest / 2; ans += add; } } Console.WriteLine(ans); } int N, M; int[] A; public Sol() { var d = ria(); N = d[0]; M = d[1]; A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 20], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 200, 0, 212, 0, 41, 64, 204, 205, 22], ["+", 0, 212, 0, 41, 64, 204, 206, 207, 0, 70], ["+", 0, 41, 64, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 41, 64, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 12, 203]]
8
591
18
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray(); var h = hw[0]; var w = hw[1]; char[][] jag = new char [h][]; for (int i = 0; i < h; i++) { jag[i] = Console.ReadLine().ToCharArray(); } char[][] visited = new char [h][]; for (int i = 0; i < h; i++) { visited[i] = new char[w]; for (int k = 0; k < w; k++) { visited[i][k] = '.'; } } var que1 = new Queue<int>(); var que2 = new Queue<int>(); visited[0][0] = '#'; if (jag[0][1] == '#') { que1.Enqueue(0); que2.Enqueue(1); } else if (jag[1][0] == '#') { que1.Enqueue(0); que2.Enqueue(1); } while (que1.Count > 0) { var x = que1.Dequeue(); var y = que2.Dequeue(); visited[x][y] = '#'; if (y + 1 < w && jag[x][y + 1] == '#') { que1.Enqueue(x); que2.Enqueue(y + 1); } else if (x + 1 < h && jag[x + 1][y] == '#') { que1.Enqueue(x + 1); que2.Enqueue(y); } } var ans = "Possible"; for (int i = 0; i < h; i++) { for (int k = 0; k < w; k++) { if (jag[i][k] != visited[i][k]) { ans = "Impossible"; break; } } } // 出力 Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); int[] hw = Console.ReadLine().Split().Select(int.Parse).ToArray(); var h = hw[0]; var w = hw[1]; char[][] jag = new char [h][]; for (int i = 0; i < h; i++) { jag[i] = Console.ReadLine().ToCharArray(); } char[][] visited = new char [h][]; for (int i = 0; i < h; i++) { visited[i] = new char[w]; for (int k = 0; k < w; k++) { visited[i][k] = '.'; } } var que1 = new Queue<int>(); var que2 = new Queue<int>(); visited[0][0] = '#'; if (jag[0][1] == '#') { que1.Enqueue(0); que2.Enqueue(1); } else if (jag[1][0] == '#') { que1.Enqueue(1); que2.Enqueue(0); } while (que1.Count > 0) { var x = que1.Dequeue(); var y = que2.Dequeue(); visited[x][y] = '#'; if (y + 1 < w && jag[x][y + 1] == '#') { que1.Enqueue(x); que2.Enqueue(y + 1); } else if (x + 1 < h && jag[x + 1][y] == '#') { que1.Enqueue(x + 1); que2.Enqueue(y); } } var ans = "Possible"; for (int i = 0; i < h; i++) { for (int k = 0; k < w; k++) { if (jag[i][k] != visited[i][k]) { ans = "Impossible"; break; } } } // 出力 Console.WriteLine(ans); } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
492
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AGC007A { class Program { public static void Solve(Input input) { var h = input.NextInt(); var w = input.NextInt(); var map = new string[h]; for (int i = 0; i < h; i++) { map[i] = input.Next(); } if (bfs(map, h, w)) { Console.WriteLine("Possible"); } else { Console.WriteLine("Impossible"); } } static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; // D/Rだけで終点に到達できて、分岐路がない static bool bfs(string[] map, int h, int w) { bool reached = false; var q = new Queue<Tuple<int, int, int, int>>(); q.Enqueue(new Tuple<int, int, int, int>(-10, -10, 0, 0)); while (q.Any()) { var v = q.Dequeue(); reached = reached || (v.Item3 == w - 1 && v.Item4 == h - 1); int path = 0; for (int i = 0; i < 4; i++) { var tx = v.Item3 + dx[i]; var ty = v.Item4 + dy[i]; if (tx < 0 || tx >= w || ty < 0 || ty >= h) continue; if (map[ty][tx] == '.') continue; // 来た道を戻る経路は探索しない if (tx == v.Item1 && ty == v.Item2) continue; path++; if (i < 2) q.Enqueue(new Tuple<int, int, int, int>(v.Item3, v.Item4, tx, ty)); } if (path > 1) { return false; } } return reached; } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AGC007A { class Program { public static void Solve(Input input) { var h = input.NextInt(); var w = input.NextInt(); var map = new string[h]; for (int i = 0; i < h; i++) { map[i] = input.Next(); } if (bfs(map, h, w)) { Console.WriteLine("Possible"); } else { Console.WriteLine("Impossible"); } } static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; // D/Rだけで終点に到達できて、分岐路がない static bool bfs(string[] map, int h, int w) { bool reached = false; var q = new Queue<Tuple<int, int, int, int>>(); q.Enqueue(new Tuple<int, int, int, int>(-10, -10, 0, 0)); while (q.Any()) { var v = q.Dequeue(); reached = reached || (v.Item3 == w - 1 && v.Item4 == h - 1); int path = 0; for (int i = 0; i < 4; i++) { var tx = v.Item3 + dx[i]; var ty = v.Item4 + dy[i]; if (tx < 0 || tx >= w || ty < 0 || ty >= h) continue; if (map[ty][tx] == '.') continue; // 来た道を戻る経路は探索しない if (tx == v.Item1 && ty == v.Item2) continue; // 来た道以外でULに経路があったらだめ if (i >= 2) return false; path++; if (i < 2) q.Enqueue(new Tuple<int, int, int, int>(v.Item3, v.Item4, tx, ty)); } if (path > 1) { return false; } } return reached; } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 37, 0, 211, 0, 147], ["+", 0, 7, 8, 196, 0, 57, 64, 37, 0, 35]]
8
1,986
9
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; namespace AtCoder { class Program { static void Main() { var h = ReadInt(); var w = ReadInt(); var a = ReadString(h); var current = 0; foreach (var l in a) { var b = l.Take(current - 1).All(x => x == '.'); b &= l[current] == '#'; current += l.Skip(current).TakeWhile(x => x == '#').Count() - 1; b &= l.Skip(current + 1).All(x => x == '.'); if (!b) { WriteLine("Impossible"); return; } } WriteLine("Possible"); } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class MyMath { public static long ToNearestInt(this double d) { var l = (long)Math.Floor(d); var r = l + 1; return r - d < d - l ? r : l; } public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Multiply); public static long nPr(int n, int r) => r < 0 || r > n? 0 : FromTo(n - r + 1, n) .Select(x => (long)x) .Aggregate(1L, Multiply); public static long nCr(int n, int r) => nPr(n, r) / Factorial(r); public static long Inc(long i) => i + 1; public static long Dec(long i) => i - 1; public static long Plus(long i, long j) => i + j; public static Func<long, long> Plus(long j) => i => i + j; public static long Minus(long i, long j) => i - j; public static Func<long, long> Minus(long j) => i => i - j; public static long Multiply(long i, long j) => i * j; public static Func<long, long> Multiply(long j) => i => i * j; public static long Divide(long i, long j) => j / j; public static Func<long, long> Divide(long j) => i => i * j; public static long Mod(long i, long j) => i % j; public static Func<long, long> Mod(long j) => i => i % j; public static long Max(params long[] ns) => ns.Max(); public static bool InRange(this long x, long min, long max) => min <= x && x <= max; public static bool IsEven(this int x) => x % 2 == 0; public static bool IsOdd(this int x) => x % 2 != 1; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 1; } static class Util { public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> Factors(this int n) { for (int i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<int> Natural() { for (int i = 0;; i++) yield return i; } public static IEnumerable<int> Positive() => Natural().Skip(1); public static long Pow(long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t); public static int Max(this int i, int j) => i > j? i : j; public static bool IsPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } public readonly static VectorInt2[] Dir8 = { new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1), new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1), new VectorInt2(1, 0), new VectorInt2(1, 1) }; public const long MODCONST = 1000000007; public static T debug<T>(this T value) { Console.Error.WriteLine($"debug:{value}"); return value; } public static T Id<T>(T t) => t; public static long ToLong(this String s) => long.Parse(s); public static long ToLong(this char c) => c - '0'; public static int ToInt(this String s) => int.Parse(s); public static int ToInt(this char c) => c - '0'; public static void Times(this int n, Action action) { for (int i = 0; i < n; i++) action(); } public static void Times(this long n, Action action) { for (long i = 0; i < n; i++) action(); } public static IEnumerable<T> Times<T>(this int n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Times<T>(this long n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static Func<S, U> Then<S, T, U>(this Func<S, T> f, Func<T, U> g) => x => g(f(x)); public static Func<S, U> Compose<S, T, U>(this Func<T, U> f, Func<S, T> g) => x => f(g(x)); public static void Call<T>(this T t, Action<T> action) => action(t); public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); public static void WriteLine<T>(this T t) => Console.WriteLine(t); public static T Call<S, T>(this S s, Func<S, T> func) => func(s); public static void Each<T>(this IEnumerable<T> e, Action<T> action) { foreach (var v in e) action(v); } public static long Prod(this IEnumerable<long> source) => source.Aggregate(Multiply); public static IEnumerable<int> FromTo(int a, int b) => Range(a, Max(b - a + 1, 0)); public static IEnumerable<T> Repeat<T>(T t) { while (true) yield return t; } public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n); public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) { while (true) foreach (var v in e) yield return v; } public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { var result = init; foreach (var item in source) { result = accumulator(result, item); yield return result; } } public static T[] ToArray<T>(params T[] ns) => ns; public static List<T> ToList<T>(params T[] ns) => ns.ToList(); public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { yield return init; foreach (var item in Scan(source, init, accumulator)) yield return item; } public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source, int length) { while (source.Any()) { yield return source.Take(length).ToList(); source = source.Skip(length); } } public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static string ReplaceX(this string input, string pattern, string replace) => Regex.Replace(input, pattern, replace); public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j); public static IEnumerable<long> Range(long i, long j) { for (long k = i; k < i + j; k++) yield return k; } public static void Swap<T>(this IList<T> enumerable, int i, int j) { var buf = enumerable[i]; enumerable[i] = enumerable[j]; enumerable[j] = buf; } public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) { int half = (j - i) / 2; for (int k = 0; k <= half; k++) enumerable.Swap(i + k, j - k); } public static bool isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any(); } static class Cin { private static Queue<string> tokens; static Cin() { string line; tokens = new Queue<string>(); while ((line = Console.ReadLine()) != null) { foreach (var token in line.Split(' ')) { tokens.Enqueue(token); } } } static public int ReadInt() => int.Parse(tokens.Dequeue()); static public List<int> ReadInt(long n) { var list = new List<int>(); n.Times(() => list.Add(ReadInt())); return list; } static public long ReadLong() => long.Parse(tokens.Dequeue()); static public List<long> ReadLong(long n) { var list = new List<long>(); n.Times(() => list.Add(ReadLong())); return list; } static public string ReadString() => tokens.Dequeue(); static public List<string> ReadString(long n) { var list = new List<string>(); n.Times(() => list.Add(ReadString())); return list; } static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine(); } struct VectorInt2 { public int X { get; set; } public int Y { get; set; } public VectorInt2(int x, int y) { X = x; Y = y; } static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X + v2.X, v1.Y + v2.Y); static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X - v2.X, v1.Y - v2.Y); static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X * v2.X, v1.Y *v2.Y); static public VectorInt2 operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i); static public VectorInt2 operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y); static public VectorInt2 operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i); } class Maxer<T> where T : IComparable<T> { public T Value; public Maxer(T t) { Value = t; } public void Max(T other) { if (Value.CompareTo(other) < 0) Value = other; } } class MultiSet<T> : IEnumerable<KeyValuePair<T, int>> { Dictionary<T, int> dictionary = new Dictionary<T, int>(); public MultiSet(IEnumerable<T> data) { foreach (var datum in data) { if (dictionary.ContainsKey(datum)) { dictionary[datum]++; } else { dictionary[datum] = 1; } } } public int this[T key] { get { return dictionary.ContainsKey(key) ? dictionary[key] : 0; } } public MultiSet() {} public static MultiSet<S> ToMultiSet<S>(IEnumerable<S> source) => new MultiSet<S>(source); public Dictionary<T, int> AsDict() => dictionary; public IEnumerator<KeyValuePair<T, int>> GetEnumerator() => dictionary.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; namespace AtCoder { class Program { static void Main() { var h = ReadInt(); var w = ReadInt(); var a = ReadString(h); var current = 0; foreach (var l in a) { var left = l.Take(current).All(x => x == '.'); var start = l[current] == '#'; current += l.Skip(current).TakeWhile(x => x == '#').Count() - 1; var right = l.Skip(current + 1).All(x => x == '.'); // WriteLine($"{current} left:{left} start:{start}: right:{right}"); if (!(left && start && right)) { WriteLine("Impossible"); return; } } WriteLine("Possible"); } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class MyMath { public static long ToNearestInt(this double d) { var l = (long)Math.Floor(d); var r = l + 1; return r - d < d - l ? r : l; } public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Multiply); public static long nPr(int n, int r) => r < 0 || r > n? 0 : FromTo(n - r + 1, n) .Select(x => (long)x) .Aggregate(1L, Multiply); public static long nCr(int n, int r) => nPr(n, r) / Factorial(r); public static long Inc(long i) => i + 1; public static long Dec(long i) => i - 1; public static long Plus(long i, long j) => i + j; public static Func<long, long> Plus(long j) => i => i + j; public static long Minus(long i, long j) => i - j; public static Func<long, long> Minus(long j) => i => i - j; public static long Multiply(long i, long j) => i * j; public static Func<long, long> Multiply(long j) => i => i * j; public static long Divide(long i, long j) => j / j; public static Func<long, long> Divide(long j) => i => i * j; public static long Mod(long i, long j) => i % j; public static Func<long, long> Mod(long j) => i => i % j; public static long Max(params long[] ns) => ns.Max(); public static bool InRange(this long x, long min, long max) => min <= x && x <= max; public static bool IsEven(this int x) => x % 2 == 0; public static bool IsOdd(this int x) => x % 2 != 1; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 1; } static class Util { public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> Factors(this int n) { for (int i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<int> Natural() { for (int i = 0;; i++) yield return i; } public static IEnumerable<int> Positive() => Natural().Skip(1); public static long Pow(long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t); public static int Max(this int i, int j) => i > j? i : j; public static bool IsPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } public readonly static VectorInt2[] Dir8 = { new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1), new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1), new VectorInt2(1, 0), new VectorInt2(1, 1) }; public const long MODCONST = 1000000007; public static T debug<T>(this T value) { Console.Error.WriteLine($"debug:{value}"); return value; } public static T Id<T>(T t) => t; public static long ToLong(this String s) => long.Parse(s); public static long ToLong(this char c) => c - '0'; public static int ToInt(this String s) => int.Parse(s); public static int ToInt(this char c) => c - '0'; public static void Times(this int n, Action action) { for (int i = 0; i < n; i++) action(); } public static void Times(this long n, Action action) { for (long i = 0; i < n; i++) action(); } public static IEnumerable<T> Times<T>(this int n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Times<T>(this long n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static Func<S, U> Then<S, T, U>(this Func<S, T> f, Func<T, U> g) => x => g(f(x)); public static Func<S, U> Compose<S, T, U>(this Func<T, U> f, Func<S, T> g) => x => f(g(x)); public static void Call<T>(this T t, Action<T> action) => action(t); public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); public static void WriteLine<T>(this T t) => Console.WriteLine(t); public static T Call<S, T>(this S s, Func<S, T> func) => func(s); public static void Each<T>(this IEnumerable<T> e, Action<T> action) { foreach (var v in e) action(v); } public static long Prod(this IEnumerable<long> source) => source.Aggregate(Multiply); public static IEnumerable<int> FromTo(int a, int b) => Range(a, Max(b - a + 1, 0)); public static IEnumerable<T> Repeat<T>(T t) { while (true) yield return t; } public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n); public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) { while (true) foreach (var v in e) yield return v; } public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { var result = init; foreach (var item in source) { result = accumulator(result, item); yield return result; } } public static T[] ToArray<T>(params T[] ns) => ns; public static List<T> ToList<T>(params T[] ns) => ns.ToList(); public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { yield return init; foreach (var item in Scan(source, init, accumulator)) yield return item; } public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source, int length) { while (source.Any()) { yield return source.Take(length).ToList(); source = source.Skip(length); } } public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static string ReplaceX(this string input, string pattern, string replace) => Regex.Replace(input, pattern, replace); public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j); public static IEnumerable<long> Range(long i, long j) { for (long k = i; k < i + j; k++) yield return k; } public static void Swap<T>(this IList<T> enumerable, int i, int j) { var buf = enumerable[i]; enumerable[i] = enumerable[j]; enumerable[j] = buf; } public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) { int half = (j - i) / 2; for (int k = 0; k <= half; k++) enumerable.Swap(i + k, j - k); } public static bool isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any(); } static class Cin { private static Queue<string> tokens; static Cin() { string line; tokens = new Queue<string>(); while ((line = Console.ReadLine()) != null) { foreach (var token in line.Split(' ')) { tokens.Enqueue(token); } } } static public int ReadInt() => int.Parse(tokens.Dequeue()); static public List<int> ReadInt(long n) { var list = new List<int>(); n.Times(() => list.Add(ReadInt())); return list; } static public long ReadLong() => long.Parse(tokens.Dequeue()); static public List<long> ReadLong(long n) { var list = new List<long>(); n.Times(() => list.Add(ReadLong())); return list; } static public string ReadString() => tokens.Dequeue(); static public List<string> ReadString(long n) { var list = new List<string>(); n.Times(() => list.Add(ReadString())); return list; } static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine(); } struct VectorInt2 { public int X { get; set; } public int Y { get; set; } public VectorInt2(int x, int y) { X = x; Y = y; } static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X + v2.X, v1.Y + v2.Y); static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X - v2.X, v1.Y - v2.Y); static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X * v2.X, v1.Y *v2.Y); static public VectorInt2 operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i); static public VectorInt2 operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y); static public VectorInt2 operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i); } class Maxer<T> where T : IComparable<T> { public T Value; public Maxer(T t) { Value = t; } public void Max(T other) { if (Value.CompareTo(other) < 0) Value = other; } } class MultiSet<T> : IEnumerable<KeyValuePair<T, int>> { Dictionary<T, int> dictionary = new Dictionary<T, int>(); public MultiSet(IEnumerable<T> data) { foreach (var datum in data) { if (dictionary.ContainsKey(datum)) { dictionary[datum]++; } else { dictionary[datum] = 1; } } } public int this[T key] { get { return dictionary.ContainsKey(key) ? dictionary[key] : 0; } } public MultiSet() {} public static MultiSet<S> ToMultiSet<S>(IEnumerable<S> source) => new MultiSet<S>(source); public Dictionary<T, int> AsDict() => dictionary; public IEnumerator<KeyValuePair<T, int>> GetEnumerator() => dictionary.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 205, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 161], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 210, 8, 196, 0, 57, 15, 241, 0, 22], ["+", 8, 196, 0, 57, 15, 241, 0, 23, 0, 24], ["+", 15, 241, 0, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 241, 0, 23, 0, 16, 31, 16, 17, 98], ["+", 15, 241, 0, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 241, 0, 23, 0, 16, 17, 98], ["+", 0, 57, 15, 241, 0, 23, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 241, 0, 23, 0, 25]]
8
2,896
22
using System; namespace abc047A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = int.Parse(str[2]); int d = (a + b + c) / 2; if (a == d || b == d || c == d) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; namespace abc047A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = int.Parse(str[2]); int d = (a + b + c) / 2; int e = (a + b + c) % 2; if ((a == d || b == d || c == d) && e == 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
123
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC037A { class Program { static void Main(string[] args) { string[] n = Console.ReadLine().Split(' '); int a = int.Parse(n[0]); int b = int.Parse(n[1]); int c = int.Parse(n[1]); if (a == (b + c)) Console.WriteLine("Yes"); else if (b == (a + c)) Console.WriteLine("Yes"); else if (c == (a + b)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC037A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a == (b + c)) Console.WriteLine("Yes"); else if (b == (a + c)) Console.WriteLine("Yes"); else if (c == (a + b)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
172
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC047A___キャンディーと2人の子供 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string[] candyPacks = input.Split(' '); List<int> candyPackList = ParseInValueToInteger(candyPacks).ToList(); int maxValue = candyPackList.Max(); List<int> exeptMaxValueList = candyPackList.Except(candyPackList.Where(x => x == maxValue)).ToList(); bool canEqual = (maxValue == exeptMaxValueList.Sum()); string output = "No"; if (canEqual) { output = "Yes"; } Console.WriteLine(output); } private static IEnumerable<int> ParseInValueToInteger<T>(IEnumerable<T> enumerable) { IList<int> list = new List<int>(); foreach (var value in enumerable) { list.Add(int.Parse(value.ToString())); } return list; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC047A___キャンディーと2人の子供 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string[] candyPacks = input.Split(' '); List<int> candyPackList = ParseInValueToInteger(candyPacks).ToList(); int maxValue = candyPackList.Max(); int maxValueIndex = candyPackList.IndexOf(maxValue); candyPackList.Remove(maxValue); bool canEqual = (maxValue == candyPackList.Sum()); string output = "No"; if (canEqual) { output = "Yes"; } Console.WriteLine(output); } private static IEnumerable<int> ParseInValueToInteger<T>(IEnumerable<T> enumerable) { IList<int> list = new List<int>(); foreach (var value in enumerable) { list.Add(int.Parse(value.ToString())); } return list; } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 18], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 47], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 23, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 23, 0, 16, 12, 213, 63, 214, 205, 22]]
8
222
23
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); Console.WriteLine(Math.Max(input[0], Math.Max(input[1], input[2])) == (double)input.Sum() / 2); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); Console.WriteLine(Math.Max(input[0], Math.Max(input[1], input[2])) == (double)input.Sum() / 2 ? "Yes" : "No"); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
119
8
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] num = ReadLine().Split(' '); int n = int.Parse(num[0]); int k = int.Parse(num[1]); int m = int.Parse(num[2]); int a = (n + k + m) / 2; if (a == n || a == m || a == k) { WriteLine("Yes"); } else { WriteLine("No"); } } }
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] num = ReadLine().Split(' '); int n = int.Parse(num[0]); int k = int.Parse(num[1]); int m = int.Parse(num[2]); int d = n + m + k; int a = (n + k + m) / 2; if ((a == n || a == m || a == k) && d % 2 == 0) { WriteLine("Yes"); } else { WriteLine("No"); } } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
129
17
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { Console.WriteLine(A.Contains(A.Sum() / 2) ? "Yes" : "No"); } int[] A; public Sol() { A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { Console.WriteLine(A.Contains(A.Sum() / 2) && A.Sum() % 2 == 0 ? "Yes" : "No"); } int[] A; public Sol() { A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98], ["+", 12, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 12, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 12, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 12, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 12, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 41, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 41, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 60], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 203]]
8
325
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Trim().Split(' '); Array.Sort(line); int a = int.Parse(line[0]); int b = int.Parse(line[1]); int c = int.Parse(line[2]); if (c == b + a) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Trim().Split(' '); int a = int.Parse(line[0]); int b = int.Parse(line[1]); int c = int.Parse(line[2]); if (c == b + a || b == a + c || a == b + c) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 15, 16, 31, 16, 12, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 16, 12, 16, 17, 72], ["+", 15, 16, 31, 16, 12, 16, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 22]]
8
145
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); if ((a + b + c) % 3 == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } #if DEBUG Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); if ((a + b) == c || (a + c) == b || (b + c) == a) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } #if DEBUG Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } }
[["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 15, 16, 31, 16, 12, 16, 31, 23, 0, 24], ["+", 31, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
156
18
using System; using System.Collections.Generic; using System.Linq; namespace abc047 { public class Program { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); List<int> list = new List<int>(); list.Add(Convert.ToInt32(str[0])); list.Add(Convert.ToInt32(str[1])); list.Add(Convert.ToInt32(str[2])); int avg = (from item in list select item).Sum() / 2; if ((from item in list where item == avg select item).Count() > 0) { Console.WriteLine("Yes"); } else if ((from item in list where item < avg select item).Sum() == avg) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace abc047 { public class Program { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); List<int> list = new List<int>(); list.Add(Convert.ToInt32(str[0])); list.Add(Convert.ToInt32(str[1])); list.Add(Convert.ToInt32(str[2])); int avg = (from item in list select item).Sum() / 2; int mod = (from item in list select item).Sum() % 2; if (mod == 0) { if ((from item in list where item == avg select item).Count() > 0) { Console.WriteLine("Yes"); } else if ((from item in list where item < avg select item).Sum() == avg) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); } } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 16, 31, 213, 63, 214, 205, 23, 0, 24], ["+", 63, 214, 205, 23, 0, 242, 0, 257, 0, 314], ["+", 63, 214, 205, 23, 0, 242, 0, 257, 141, 22], ["+", 63, 214, 205, 23, 0, 242, 0, 257, 0, 267], ["+", 63, 214, 205, 23, 0, 242, 0, 257, 0, 22], ["+", 63, 214, 205, 23, 0, 242, 0, 244, 0, 245], ["+", 63, 214, 205, 23, 0, 242, 0, 244, 0, 22], ["+", 0, 16, 31, 213, 63, 214, 205, 23, 0, 25], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 95], ["+", 64, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 57, 75, 57, 75, 196, 0, 46]]
8
208
38
using LIB; using System; using System.Linq; using System.Text; using System.Collections.Generic; class Program { public static IO IO = new IO(); static void Main(string[] args) { int[] m = IO.INT(' '); if (m[0] == m[1] + m[2] || m[0] + m[1] == m[2]) { IO.WRITE("Yes"); } else { IO.WRITE("No"); } IO.FLUSH(); } } namespace LIB { public class IO { private const int WMAX = 1000; private StringBuilder S = new StringBuilder(); private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); } private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); } private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; } private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; } private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } } public string STRING() { return R(s => s); } public string[] STRING(char c) { return R(s => s, c); } public string[] STRING(int l) { return R(s => s, l); } public string[][] STRING(int l, char c) { return R(s => s, l, c); } public int INT() { return R(int.Parse); } public int[] INT(char c) { return R(int.Parse, c); } public int[] INT(int l) { return R(int.Parse, l); } public int[][] INT(int l, char c) { return R(int.Parse, l, c); } public long LONG() { return R(long.Parse); } public long[] LONG(char c) { return R(long.Parse, c); } public long[] LONG(int l) { return R(long.Parse, l); } public long[][] LONG(int l, char c) { return R(long.Parse, l, c); } public double DOUBLE() { return R(double.Parse); } public double[] DOUBLE(char c) { return R(double.Parse, c); } public double[] DOUBLE(int l) { return R(double.Parse, l); } public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); } public void WRITE(object s, bool lf = true) { W(v => v.ToString(), s, lf); } public void FLUSH() { Console.Write(S); S.Length = 0; } } }
using LIB; using System; using System.Linq; using System.Text; using System.Collections.Generic; class Program { public static IO IO = new IO(); static void Main(string[] args) { int[] m = IO.INT(' '); if (m[0] == m[1] + m[2] || m[0] + m[1] == m[2] || m[0] + m[2] == m[1]) { IO.WRITE("Yes"); } else { IO.WRITE("No"); } IO.FLUSH(); } } namespace LIB { public class IO { private const int WMAX = 1000; private StringBuilder S = new StringBuilder(); private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); } private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); } private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; } private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; } private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } } public string STRING() { return R(s => s); } public string[] STRING(char c) { return R(s => s, c); } public string[] STRING(int l) { return R(s => s, l); } public string[][] STRING(int l, char c) { return R(s => s, l, c); } public int INT() { return R(int.Parse); } public int[] INT(char c) { return R(int.Parse, c); } public int[] INT(int l) { return R(int.Parse, l); } public int[][] INT(int l, char c) { return R(int.Parse, l, c); } public long LONG() { return R(long.Parse); } public long[] LONG(char c) { return R(long.Parse, c); } public long[] LONG(int l) { return R(long.Parse, l); } public long[][] LONG(int l, char c) { return R(long.Parse, l, c); } public double DOUBLE() { return R(double.Parse); } public double[] DOUBLE(char c) { return R(double.Parse, c); } public double[] DOUBLE(int l) { return R(double.Parse, l); } public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); } public void WRITE(object s, bool lf = true) { W(v => v.ToString(), s, lf); } public void FLUSH() { Console.Write(S); S.Length = 0; } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["+", 15, 16, 12, 16, 31, 16, 12, 204, 205, 22], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
8
807
15
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var WHN = Sarray(); var W = WHN[0]; var H = WHN[1]; var N = WHN[2]; var xl = 0L; var xr = W; var yd = 0L; var yu = H; for (var i = 0; i < N; ++i) { var xya = Sarray(); var x = xya[0]; var y = xya[1]; var a = xya[2]; if (1 == a) xl = x; else if (2 == a) xr = x; else if (3 == a) yd = y; else if (4 == a) yu = y; } if (xr < xl || yu < yd) WriteLine(0); else WriteLine((xr - xl) * (yu - yd)); // Out.Flush(); } static long gcd(long x, long y) => y == 0 ? x : gcd(y, x % y); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var WHN = Sarray(); var W = WHN[0]; var H = WHN[1]; var N = WHN[2]; var xl = 0L; var xr = W; var yd = 0L; var yu = H; for (var i = 0; i < N; ++i) { var xya = Sarray(); var x = xya[0]; var y = xya[1]; var a = xya[2]; if (1 == a) xl = Max(xl, x); else if (2 == a) xr = Min(xr, x); else if (3 == a) yd = Max(yd, y); else if (4 == a) yu = Min(yu, y); } if (xr < xl || yu < yd) WriteLine(0); else WriteLine((xr - xl) * (yu - yd)); // Out.Flush(); } static long gcd(long x, long y) => y == 0 ? x : gcd(y, x % y); } }
[["+", 0, 57, 64, 1, 0, 11, 12, 213, 63, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 75, 57, 64, 1, 0, 11, 12, 213, 63, 22]]
8
317
20
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); int w = cin.NextInt(); int h = cin.NextInt(); int n = cin.NextInt(); int xmin = 0; int xmax = 100; int ymin = 0; int ymax = 100; for (int i = 0; i < n; i++) { var a = cin.NextInt(); var x = cin.NextInt(); var y = cin.NextInt(); switch (a) { case 1: xmin = Math.Max(xmin, x); break; case 2: xmax = Math.Min(xmax, x); break; case 3: ymin = Math.Max(ymin, y); break; case 4: ymax = Math.Min(ymax, y); break; default: break; } } Console.WriteLine(Math.Max(0, xmax - xmin) * Math.Max(0, ymax - ymin)); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); int w = cin.NextInt(); int h = cin.NextInt(); int n = cin.NextInt(); int xmin = 0; int xmax = w; int ymin = 0; int ymax = h; for (int i = 0; i < n; i++) { var x = cin.NextInt(); var y = cin.NextInt(); var a = cin.NextInt(); switch (a) { case 1: xmin = Math.Max(xmin, x); break; case 2: xmax = Math.Min(xmax, x); break; case 3: ymin = Math.Max(ymin, y); break; case 4: ymax = Math.Min(ymax, y); break; default: break; } } Console.WriteLine(Math.Max(0, xmax - xmin) * Math.Max(0, ymax - ymin)); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22]]
8
639
10
using System; namespace ABC047 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int W = int.Parse(input[0]); int H = int.Parse(input[1]); int N = int.Parse(input[2]); int x0 = 0; int y0 = 0; int x1 = W; int y1 = H; for (int i = 0; i < N; i++) { input = Console.ReadLine().Split(); int x = int.Parse(input[0]); int y = int.Parse(input[1]); int a = int.Parse(input[2]); if (a == 1) { x0 = x; } if (a == 2) { x1 = x; } if (a == 3) { y0 = y; } if (a == 4) { y1 = y; } } if ((x1 - x0) <= 0 || (y1 - y0) <= 0) Console.WriteLine(0); else Console.WriteLine((x1 - x0) * (y1 - y0)); } } }
using System; namespace ABC047 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int W = int.Parse(input[0]); int H = int.Parse(input[1]); int N = int.Parse(input[2]); int x0 = 0; int y0 = 0; int x1 = W; int y1 = H; for (int i = 0; i < N; i++) { input = Console.ReadLine().Split(); int x = int.Parse(input[0]); int y = int.Parse(input[1]); int a = int.Parse(input[2]); if (a == 1) { x0 = Math.Max(x0, x); } if (a == 2) { x1 = Math.Min(x1, x); ; } if (a == 3) { y0 = Math.Max(y0, y); } if (a == 4) { y1 = Math.Min(y1, y); } } if ((x1 - x0) < 0 || (y1 - y0) < 0) Console.WriteLine(0); else Console.WriteLine((x1 - x0) * (y1 - y0)); } } }
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 260, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18]]
8
254
33
using System; using System.Linq; namespace A { class Program { static void Main(string[] args) { var WHN = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var W = WHN[0]; var H = WHN[1]; var N = WHN[2]; var xyaList = Enumerable.Range(0, N).Select( _ => Console.ReadLine().Split(' ').Select(int.Parse).ToArray()); var minx = 0; var miny = 0; var maxx = W; var maxy = H; foreach (var xya in xyaList) { var x = xya[0]; var y = xya[1]; var a = xya[2]; switch (a) { case 1: minx = x; break; case 2: maxx = x; break; case 3: miny = y; break; case 4: maxy = y; break; } } var output = Math.Max(0, (maxx - minx)) * Math.Max(0, (maxy - miny)); Console.WriteLine(output); } static int SumOfDigits(int x) { var sum = 0; while (x > 0) { sum += x % 10; x /= 10; } return sum; } } }
using System; using System.Linq; namespace A { class Program { static void Main(string[] args) { var WHN = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var W = WHN[0]; var H = WHN[1]; var N = WHN[2]; var xyaList = Enumerable.Range(0, N).Select( _ => Console.ReadLine().Split(' ').Select(int.Parse).ToArray()); var minx = 0; var miny = 0; var maxx = W; var maxy = H; foreach (var xya in xyaList) { var x = xya[0]; var y = xya[1]; var a = xya[2]; switch (a) { case 1: minx = Math.Max(minx, x); break; case 2: maxx = Math.Min(maxx, x); break; case 3: miny = Math.Max(miny, y); break; case 4: maxy = Math.Min(maxy, y); break; } } var output = Math.Max(0, (maxx - minx)) * Math.Max(0, (maxy - miny)); Console.WriteLine(output); } static int SumOfDigits(int x) { var sum = 0; while (x > 0) { sum += x % 10; x /= 10; } return sum; } } }
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
285
28
using System; using System.Linq; class P { static void Main() { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int W = n[0]; int H = n[1]; int N = n[2]; int[] x = new int[N]; int[] y = new int[N]; int[] a = new int[N]; for (int i = 0; i < N; i++) { int[] m = Console.ReadLine().Split().Select(int.Parse).ToArray(); x[i] = m[0]; y[i] = m[1]; a[i] = m[2]; } int minX = 0, maxX = W, minY = 0, maxY = H; for (int i = 0; i < N; i++) { if (a[i] == 1) minX = x[i]; else if (a[i] == 2) maxX = x[i]; else if (a[i] == 3) minY = y[i]; else maxY = y[i]; } int ans = maxX >= minX && maxY >= minY ? (maxX - minX) * (maxY - minY) : 0; Console.WriteLine(ans); } }
using System; using System.Linq; class P { static void Main() { int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); int W = n[0]; int H = n[1]; int N = n[2]; int[] x = new int[N]; int[] y = new int[N]; int[] a = new int[N]; for (int i = 0; i < N; i++) { int[] m = Console.ReadLine().Split().Select(int.Parse).ToArray(); x[i] = m[0]; y[i] = m[1]; a[i] = m[2]; } int minX = 0, maxX = W, minY = 0, maxY = H; for (int i = 0; i < N; i++) { if (a[i] == 1) minX = Math.Max(minX, x[i]); else if (a[i] == 2) maxX = Math.Min(maxX, x[i]); else if (a[i] == 3) minY = Math.Max(minY, y[i]); else maxY = Math.Min(maxY, y[i]); } int ans = maxX >= minX && maxY >= minY ? (maxX - minX) * (maxY - minY) : 0; Console.WriteLine(ans); } }
[["+", 64, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 75, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 75, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 75, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 75, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 75, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
297
28
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int startX = 0; int startY = 0; int tempX = 0; int tempY = 0; int readCount = 0; int result = 0; int calcFLG = 0; string readValue = Console.ReadLine(); int[] tokens = readValue.Split(' ').Select(int.Parse).ToArray(); maxX = tokens[0]; maxY = tokens[1]; startX = maxX; startY = maxY; readCount = tokens[2]; for (int i = 0; i < readCount; i++) { readValue = Console.ReadLine(); tokens = readValue.Split(' ').Select(int.Parse).ToArray(); tempX = tokens[0]; tempY = tokens[1]; calcFLG = tokens[2]; switch (calcFLG) { case 1: minX = tempX; break; case 2: if (startX >= tempX) { maxX = tempX; } break; case 3: minY = tempY; break; case 4: if (startY >= tempY) { maxY = tempY; } break; default: break; } } if (maxX - minX > 0 && maxY - minY > 0) { result = (maxX - minX) * (maxY - minY); } Console.WriteLine(result.ToString()); // Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int startX = 0; int startY = 0; int tempX = 0; int tempY = 0; int readCount = 0; int result = 0; int calcFLG = 0; string readValue = Console.ReadLine(); int[] tokens = readValue.Split(' ').Select(int.Parse).ToArray(); maxX = tokens[0]; maxY = tokens[1]; startX = maxX; startY = maxY; readCount = tokens[2]; for (int i = 0; i < readCount; i++) { readValue = Console.ReadLine(); tokens = readValue.Split(' ').Select(int.Parse).ToArray(); tempX = tokens[0]; tempY = tokens[1]; calcFLG = tokens[2]; switch (calcFLG) { case 1: if (minX < tempX) { minX = tempX; } break; case 2: if (startX > tempX && maxX > tempX) { maxX = tempX; } break; case 3: if (minY < tempY) { minY = tempY; } break; case 4: if (startY > tempY && maxY > tempY) { maxY = tempY; } break; default: break; } } if (maxX - minX > 0 && maxY - minY > 0) { result = (maxX - minX) * (maxY - minY); } Console.WriteLine(result.ToString()); // Console.ReadLine(); } } }
[["+", 0, 99, 8, 254, 0, 239, 0, 57, 0, 121], ["+", 0, 99, 8, 254, 0, 239, 0, 57, 0, 24], ["+", 8, 254, 0, 239, 0, 57, 15, 16, 31, 22], ["+", 8, 254, 0, 239, 0, 57, 15, 16, 17, 18], ["+", 8, 254, 0, 239, 0, 57, 15, 16, 12, 22], ["+", 0, 99, 8, 254, 0, 239, 0, 57, 0, 25], ["+", 8, 254, 0, 239, 0, 57, 64, 196, 0, 45], ["+", 8, 254, 0, 239, 0, 57, 64, 196, 0, 46], ["-", 8, 254, 0, 239, 0, 57, 15, 16, 17, 20], ["+", 0, 239, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 0, 239, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 254, 0, 239, 0, 57, 15, 16, 17, 98], ["+", 0, 239, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 239, 0, 57, 15, 16, 12, 16, 17, 47]]
8
340
28
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Globalization; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { static void Main() { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; int W, H, N; void solve() { W = cin.nextint; H = cin.nextint; N = cin.nextint; int WW = 0, HH = 0; for (int i = 0; i < N; i++) { var t = cin.scanint; if (t[2] == 1) WW = t[0]; else if (t[2] == 2) W = t[0]; else if (t[2] == 3) HH = t[1]; else if (t[2] == 4) H = t[1]; } if (W - WW <= 0 || H - HH <= 0) { WriteLine(0); } else { WriteLine((W - WW) * (H - HH)); } } } 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); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Globalization; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { static void Main() { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; int W, H, N; void solve() { W = cin.nextint; H = cin.nextint; N = cin.nextint; int WW = 0, HH = 0; for (int i = 0; i < N; i++) { var t = cin.scanint; if (t[2] == 1) WW = Math.Max(WW, t[0]); else if (t[2] == 2) W = Math.Min(W, t[0]); else if (t[2] == 3) HH = Math.Max(HH, t[1]); else if (t[2] == 4) H = Math.Min(H, t[1]); } if (W - WW <= 0 || H - HH <= 0) { WriteLine(0); } else { WriteLine((W - WW) * (H - HH)); } } } 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); } } }
[["+", 64, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
542
28
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var n = input[0]; var k = input[1]; long anwer = k; int i = 1; while (true) { anwer *= k - 1; i++; if (i == n) break; } Console.WriteLine(anwer); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var n = input[0]; var k = input[1]; long anwer = k; int i = 1; while (i < n) { anwer *= k - 1; i++; } Console.WriteLine(anwer); Console.Out.Flush(); } } }
[["-", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94]]
8
187
12
using System; namespace ABC046B_PaintingBallswithAtCoDeer { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); int result = k * (k - 1) ^ (n - 1); Console.WriteLine(result); } } }
using System; namespace ABC046B_PaintingBallswithAtCoDeer { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); double result = k * Math.Pow(k - 1, n - 1); Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 16, 31, 16, 12, 23, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 140], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 21]]
8
90
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace ABC046_B { class Program { static void Main(string[] args) { long ans = 1; var t = scan; long N = t[0]; long K = t[1]; ans = K; for (int i = 1; i < N; i++) { ans *= (K - 1); } } static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace ABC046_B { class Program { static void Main(string[] args) { long ans = 1; var t = scan; long N = t[0]; long K = t[1]; ans = K; for (int i = 1; i < N; i++) { ans *= (K - 1); } Console.WriteLine(ans); } static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
136
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_B(); } public static void Solve_A() { long n; MyIO.ReadMulti(out n); VT<ll, ll>[] atl; MyIO.ReadLines(n, out atl); ll aa = atl[0].Item1; ll bb = atl[0].Item2; for (int i = 1; i < n; i++) { ll b1 = aa / atl[i].Item1 + (aa % atl[i].Item1 == 0 ? 0 : 1); ll b2 = bb / atl[i].Item2 + (bb % atl[i].Item2 == 0 ? 0 : 1); aa = atl[i].Item1 * (b1 > b2 ? b1 : b2); bb = atl[i].Item2 * (b1 > b2 ? b1 : b2); } long ans = aa + bb; MyIO.WriteMulti(ans); } public static void Solve_B() { string s; MyIO.ReadMulti(out s); ll gc = 0; ll pc = 0; ll lc = 0; ll wc = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'p') { pc++; } else { if ((pc + 1) <= gc) { wc++; pc++; } else { gc++; } } } long ans = wc - lc; MyIO.WriteMulti(ans); } public static void Solve_C() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_B(); } public static void Solve_A() { long n; MyIO.ReadMulti(out n); VT<ll, ll>[] atl; MyIO.ReadLines(n, out atl); ll aa = atl[0].Item1; ll bb = atl[0].Item2; for (int i = 1; i < n; i++) { ll b1 = aa / atl[i].Item1 + (aa % atl[i].Item1 == 0 ? 0 : 1); ll b2 = bb / atl[i].Item2 + (bb % atl[i].Item2 == 0 ? 0 : 1); aa = atl[i].Item1 * (b1 > b2 ? b1 : b2); bb = atl[i].Item2 * (b1 > b2 ? b1 : b2); } long ans = aa + bb; MyIO.WriteMulti(ans); } public static void Solve_B() { string s; MyIO.ReadMulti(out s); ll gc = 0; ll pc = 0; ll lc = 0; ll wc = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'p') { if ((pc + 1) <= gc) { pc++; } else { lc++; gc++; } } else { if ((pc + 1) <= gc) { wc++; pc++; } else { gc++; } } } long ans = wc - lc; MyIO.WriteMulti(ans); } public static void Solve_C() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 203], ["+", 64, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
2,598
21
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { public static void Main() { int N = int.Parse(Console.ReadLine()); ulong m, n, a, b; var s = Console.ReadLine().Split(' '); a = 1; b = 1; for (int i = 0; i < N; i++) { s = Console.ReadLine().Split(' '); m = ulong.Parse(s[0]); n = ulong.Parse(s[1]); ulong pa, pb; if (a % m == 0) pa = a / m; else pa = a / m + 1; if (a % n == 0) pb = b / n; else pb = b / n + 1; if (pa > pb) { a = m * pa; b = n * pa; } else { a = m * pb; b = n * pb; } } Console.WriteLine(a + b); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { public static void Main() { int N = int.Parse(Console.ReadLine()); ulong m, n, a, b; string[] s; a = 1; b = 1; for (int i = 0; i < N; i++) { s = Console.ReadLine().Split(' '); m = ulong.Parse(s[0]); n = ulong.Parse(s[1]); ulong pa, pb; if (a % m == 0) pa = a / m; else pa = a / m + 1; if (b % n == 0) pb = b / n; else pb = b / n + 1; if (pa > pb) { a = m * pa; b = n * pa; } else { a = m * pb; b = n * pb; } } Console.WriteLine(a + b); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22]]
8
229
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); // CompLib.Collections.PriorityQueue<?> public static void Main() { string S = Console.ReadLine(); int length = S.Length; int pa = length / 2; int gu = length - pa; int point = 0; for (int i = 1; i <= length; i++) { char hand = S[i - 1]; if (i <= gu) { point += janken(i, 'g', hand); } else { point += janken(i, 'p', hand); } } } public static int janken(int i, char player, char aitehand) { if (player == aitehand) return 0; else { if (aitehand == 'p') return -1; return 1; } } public static long nibutanfirst(long first, long left, long right, long[] A, long[] F, long K) { if (solver(0, A, F, K)) { return 0; } return nibutan(0, first, A, F, K); } public static long nibutan(long left, long right, long[] A, long[] F, long K) { long aim = (left + right) / 2; if (solver(aim, A, F, K)) { if (left == aim) { return aim; } return nibutan(left, aim, A, F, K); } else { if (solver(aim + 1, A, F, K)) { return aim + 1; } else { return nibutan(aim, right, A, F, K); } } } public static bool solver(long aim, long[] A, long[] F, long K) { long used = 0; for (int i = 0; i < A.Length; i++) { long Alimit = aim / F[i]; if (A[i] <= Alimit) { } else { used += A[i] - Alimit; if (used > K) return false; } } return true; } } class readint { public readint(out int i) { i = int.Parse(Console.ReadLine()); } public readint(out int a, out int b) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readint(out int a, out int b, out int c) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readint(out int a, out int b, out int c, out int d) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class readlong { public readlong(out long i) { i = long.Parse(Console.ReadLine()); } public readlong(out long a, out long b) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readlong(out long a, out long b, out long c) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readlong(out long a, out long b, out long c, out long d) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class Util { public static long GCD(long a, long b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } public static int GCD(int a, int b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } public static void swap<T>(ref T a, ref T b) { T temp = b; b = a; a = temp; } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); } public static int M = (int)(Math.Pow(10, 9)) + 7; private static int[] factorial_modM; public static int Multiple_modM(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public static void factorial_modM_Prepare(int n) { factorial_modM = new int[n + 1]; factorial_modM[0] = 1; for (int i = 1; i <= n; ++i) { factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i); } } public static int Factorial(int n) { return factorial_modM[n]; } public static int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiple_modM(p1, p1); return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a); } } public static int Div(int a, int b) { return Multiple_modM(a, Pow(b, M - 2)); } public static int nCr_modM(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Div(res, Factorial(r)); res = Div(res, Factorial(n - r)); return res; } } class UnionFind<T> { public int tree_height; public UnionFind<T> parent; public T item { get; private set; } public UnionFind(T item) { tree_height = 0; parent = this; } public UnionFind<T> FindAdam() { if (parent == this) return this; else { UnionFind<T> ParentOfParent = parent.FindAdam(); parent = ParentOfParent; //縦長な構成をつなぎ直している return ParentOfParent; } } public static void Unite(UnionFind<T> a, UnionFind<T> b) { UnionFind<T> ParentOfA = a.FindAdam(); UnionFind<T> ParentOfB = b.FindAdam(); if (ParentOfA.tree_height < ParentOfB.tree_height) { ParentOfA.parent = ParentOfB; ParentOfB.tree_height = Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height); } else { ParentOfB.parent = ParentOfA; ParentOfA.tree_height = Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height); } } } // Treap 平衡二分木 class Treap<T> where T : IComparable { private class Node { private static Random g_rand = new Random(); private readonly int m_rank = g_rand.Next(); private readonly T m_value; private Node m_lch; private Node m_rch; private int m_count; public Node(T value) { m_value = value; m_count = 1; } private static int Count(Node node) { return (node != null) ? node.m_count : 0; } private Node Update() { m_count = Count(m_lch) + Count(m_rch) + 1; return this; } public static Node Merge(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } if (a.m_rank < b.m_rank) { a.m_rch = Merge(a.m_rch, b); return a.Update(); } else { b.m_lch = Merge(a, b.m_lch); return b.Update(); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) { return new Tuple<Node, Node>(null, null); } if (k <= Count(t.m_lch)) { var pair = Split(t.m_lch, k); t.m_lch = pair.Item2; return new Tuple<Node, Node>(pair.Item1, t.Update()); } else { var pair = Split(t.m_rch, k - Count(t.m_lch) - 1); t.m_rch = pair.Item1; return new Tuple<Node, Node>(t.Update(), pair.Item2); } } public int FindIndex(T value) { int L = Count(m_lch); if (value.CompareTo(m_value) < 0) { return (m_lch != null) ? m_lch.FindIndex(value) : 0; } else if (value.CompareTo(m_value) > 0) { return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1; } else { return L; } } public T this[int i] { get { int L = Count(m_lch); if (i < L) { return m_lch[i]; } else if (i > L) { return m_rch[i - L - 1]; } else { return m_value; } } } } private Node node; public void Insert(T value) { if (node != null) { int k = node.FindIndex(value); var pair = Node.Split(node, k); node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2); } else { node = new Node(value); } } public int FindIndex(T value) { return node.FindIndex(value); } public T this[int i] { get { return node[i]; } } } static class Permutation<T> { private static void Search(List<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) { perms.Add(stack.Reverse().ToArray()); } else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) { b[i] = a[i]; } stack.Pop(); } } } public static IEnumerable<T[]> All(IEnumerable<T> src) { var perms = new List<T[]>(); Search(perms, new Stack<T>(), src.ToArray()); return perms; } } namespace CompLib.Collections { #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } /// <summary> /// SEGTREEは1-BASE運用でございます /// よろしくおねがいします /// </summary> /// <typeparam name="T"></typeparam> class Segtree<T> { int n; //高さ T[] tree; //本体 Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか T exnum; //初期値 int count; public Segtree(int m, Func<T, T, T> f, T ex) { this.count = 0; this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { this.count = 0; for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) // j番目をxにする { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } this.count++; } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } public void delete (int j) { int i = j + n - 1; tree[i] = exnum; int moved = 0; while (true) { tree[i + 1] = tree[i]; T check = tree[i]; moved++; if (moved + j + 2 > count) { break; } } all_update(); } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); // CompLib.Collections.PriorityQueue<?> public static void Main() { string S = Console.ReadLine(); int length = S.Length; int pa = length / 2; int gu = length - pa; int point = 0; for (int i = 1; i <= length; i++) { char hand = S[i - 1]; if (i <= gu) { point += janken(i, 'g', hand); } else { point += janken(i, 'p', hand); } } Console.WriteLine(point); } public static int janken(int i, char player, char aitehand) { if (player == aitehand) return 0; else { if (aitehand == 'p') return -1; return 1; } } public static long nibutanfirst(long first, long left, long right, long[] A, long[] F, long K) { if (solver(0, A, F, K)) { return 0; } return nibutan(0, first, A, F, K); } public static long nibutan(long left, long right, long[] A, long[] F, long K) { long aim = (left + right) / 2; if (solver(aim, A, F, K)) { if (left == aim) { return aim; } return nibutan(left, aim, A, F, K); } else { if (solver(aim + 1, A, F, K)) { return aim + 1; } else { return nibutan(aim, right, A, F, K); } } } public static bool solver(long aim, long[] A, long[] F, long K) { long used = 0; for (int i = 0; i < A.Length; i++) { long Alimit = aim / F[i]; if (A[i] <= Alimit) { } else { used += A[i] - Alimit; if (used > K) return false; } } return true; } } class readint { public readint(out int i) { i = int.Parse(Console.ReadLine()); } public readint(out int a, out int b) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readint(out int a, out int b, out int c) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readint(out int a, out int b, out int c, out int d) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class readlong { public readlong(out long i) { i = long.Parse(Console.ReadLine()); } public readlong(out long a, out long b) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readlong(out long a, out long b, out long c) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readlong(out long a, out long b, out long c, out long d) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class Util { public static long GCD(long a, long b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } public static int GCD(int a, int b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } public static void swap<T>(ref T a, ref T b) { T temp = b; b = a; a = temp; } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); } public static int M = (int)(Math.Pow(10, 9)) + 7; private static int[] factorial_modM; public static int Multiple_modM(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public static void factorial_modM_Prepare(int n) { factorial_modM = new int[n + 1]; factorial_modM[0] = 1; for (int i = 1; i <= n; ++i) { factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i); } } public static int Factorial(int n) { return factorial_modM[n]; } public static int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiple_modM(p1, p1); return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a); } } public static int Div(int a, int b) { return Multiple_modM(a, Pow(b, M - 2)); } public static int nCr_modM(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Div(res, Factorial(r)); res = Div(res, Factorial(n - r)); return res; } } class UnionFind<T> { public int tree_height; public UnionFind<T> parent; public T item { get; private set; } public UnionFind(T item) { tree_height = 0; parent = this; } public UnionFind<T> FindAdam() { if (parent == this) return this; else { UnionFind<T> ParentOfParent = parent.FindAdam(); parent = ParentOfParent; //縦長な構成をつなぎ直している return ParentOfParent; } } public static void Unite(UnionFind<T> a, UnionFind<T> b) { UnionFind<T> ParentOfA = a.FindAdam(); UnionFind<T> ParentOfB = b.FindAdam(); if (ParentOfA.tree_height < ParentOfB.tree_height) { ParentOfA.parent = ParentOfB; ParentOfB.tree_height = Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height); } else { ParentOfB.parent = ParentOfA; ParentOfA.tree_height = Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height); } } } // Treap 平衡二分木 class Treap<T> where T : IComparable { private class Node { private static Random g_rand = new Random(); private readonly int m_rank = g_rand.Next(); private readonly T m_value; private Node m_lch; private Node m_rch; private int m_count; public Node(T value) { m_value = value; m_count = 1; } private static int Count(Node node) { return (node != null) ? node.m_count : 0; } private Node Update() { m_count = Count(m_lch) + Count(m_rch) + 1; return this; } public static Node Merge(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } if (a.m_rank < b.m_rank) { a.m_rch = Merge(a.m_rch, b); return a.Update(); } else { b.m_lch = Merge(a, b.m_lch); return b.Update(); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) { return new Tuple<Node, Node>(null, null); } if (k <= Count(t.m_lch)) { var pair = Split(t.m_lch, k); t.m_lch = pair.Item2; return new Tuple<Node, Node>(pair.Item1, t.Update()); } else { var pair = Split(t.m_rch, k - Count(t.m_lch) - 1); t.m_rch = pair.Item1; return new Tuple<Node, Node>(t.Update(), pair.Item2); } } public int FindIndex(T value) { int L = Count(m_lch); if (value.CompareTo(m_value) < 0) { return (m_lch != null) ? m_lch.FindIndex(value) : 0; } else if (value.CompareTo(m_value) > 0) { return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1; } else { return L; } } public T this[int i] { get { int L = Count(m_lch); if (i < L) { return m_lch[i]; } else if (i > L) { return m_rch[i - L - 1]; } else { return m_value; } } } } private Node node; public void Insert(T value) { if (node != null) { int k = node.FindIndex(value); var pair = Node.Split(node, k); node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2); } else { node = new Node(value); } } public int FindIndex(T value) { return node.FindIndex(value); } public T this[int i] { get { return node[i]; } } } static class Permutation<T> { private static void Search(List<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) { perms.Add(stack.Reverse().ToArray()); } else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) { b[i] = a[i]; } stack.Pop(); } } } public static IEnumerable<T[]> All(IEnumerable<T> src) { var perms = new List<T[]>(); Search(perms, new Stack<T>(), src.ToArray()); return perms; } } namespace CompLib.Collections { #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } /// <summary> /// SEGTREEは1-BASE運用でございます /// よろしくおねがいします /// </summary> /// <typeparam name="T"></typeparam> class Segtree<T> { int n; //高さ T[] tree; //本体 Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか T exnum; //初期値 int count; public Segtree(int m, Func<T, T, T> f, T ex) { this.count = 0; this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { this.count = 0; for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) // j番目をxにする { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } this.count++; } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } public void delete (int j) { int i = j + n - 1; tree[i] = exnum; int moved = 0; while (true) { tree[i + 1] = tree[i]; T check = tree[i]; moved++; if (moved + j + 2 > count) { break; } } all_update(); } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
3,434
7
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var s = Console.ReadLine(); var correct = "C0DEFESTIVAL2O16"; var count = 0; for (var i = 0; i < correct.Length; i++) { if (s[i] != correct[i]) { count++; } } Console.WriteLine(count); } }
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var s = Console.ReadLine(); var t = "CODEFESTIVAL2016"; var count = 0; for (var i = 0; i < s.Length; i++) { if (s[i] != t[i]) { count++; } } Console.WriteLine(count); } }
[["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22]]
8
91
16
using System; namespace Sample { class Sample { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int A = int.Parse(str[1]); int B = int.Parse(str[2]); string S = Console.ReadLine(); int count = 0; int fCount = 0; for (int i = 0; i < N; i++) { if (S.Substring(i, 1) == "c") { Console.WriteLine("No"); continue; } else if (S.Substring(i, 1) == "a") { if (count < A + B) { Console.WriteLine("Yes"); count++; } else { Console.WriteLine("No"); } } else { if ((count < A + B) && (fCount < B)) { Console.WriteLine("Yes"); count++; fCount++; } } } } } }
using System; namespace Sample { class Sample { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int A = int.Parse(str[1]); int B = int.Parse(str[2]); string S = Console.ReadLine(); int count = 0; int fCount = 0; for (int i = 0; i < N; i++) { if (S.Substring(i, 1) == "c") { Console.WriteLine("No"); continue; } else if (S.Substring(i, 1) == "a") { if (count < (A + B)) { Console.WriteLine("Yes"); count++; } else { Console.WriteLine("No"); } } else { if ((count < (A + B)) && (fCount < B)) { Console.WriteLine("Yes"); count++; fCount++; } else { Console.WriteLine("No"); } } } } } }
[["+", 64, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 15, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 75, 57, 75, 196, 0, 57, 0, 95], ["+", 75, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
230
16
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Runtime.ExceptionServices; using System.Security; using System.Threading; using System.Xml.Serialization; namespace AtCoderCs { class Program { const int mod = 1000000007; static void Main() { var args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var A = args[1]; var B = args[2]; var C = 0; var commands = Console.ReadLine(); for (int i = 0, l = commands.Length; i < l; i++) switch (commands[i]) { case 'a': if (i < A + B) Yes(); else No(); break; case 'b': if (i < A + B && C < B) { Yes(); C++; } else No(); break; default: No(); break; } } static void Yes() => Console.WriteLine("Yes"); static void No() => Console.WriteLine("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Runtime.ExceptionServices; using System.Security; using System.Threading; using System.Xml.Serialization; namespace AtCoderCs { class Program { const int mod = 1000000007; static void Main() { var args = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var A = args[1]; var B = args[2]; var C = 0; var commands = Console.ReadLine(); for (int i = 0, l = commands.Length, countAB = 0, countB = 0; i < l; i++) switch (commands[i]) { case 'a': if (countAB < A + B) { Yes(); countAB++; } else No(); break; case 'b': if (countAB < A + B && countB < B) { Yes(); countAB++; countB++; } else No(); break; default: No(); break; } } static void Yes() => Console.WriteLine("Yes"); static void No() => Console.WriteLine("No"); } }
[["+", 0, 195, 8, 196, 0, 7, 10, 198, 0, 21], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 254, 0, 239, 0, 57, 15, 16, 31, 22], ["+", 8, 254, 0, 239, 0, 57, 15, 16, 31, 22], ["+", 8, 254, 0, 239, 0, 57, 64, 196, 0, 45], ["+", 0, 239, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 254, 0, 239, 0, 57, 64, 196, 0, 46], ["-", 0, 239, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 239, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 239, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 239, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22]]
8
256
24
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var nab = Input.ar; var str = ReadLine(); var ct = 0; for (var i = 0; i < nab[0]; i++) if (str[i] == 'c' || ct >= nab[1] + nab[2]) WriteLine("No"); else if (str[i] == 'a') { WriteLine("Yes"); ct++; } else if (ct <= nab[2]) { WriteLine("Yes"); ct++; } else WriteLine("No"); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[][] ar2D(int num) => Enumerable.Repeat(0, num).Select(_ => ar).ToArray(); public static long[][] arL2D(int num) => Enumerable.Repeat(0, num).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var nab = Input.ar; var str = ReadLine(); var ct = 0; var ct2 = 0; for (var i = 0; i < nab[0]; i++) if (str[i] == 'c' || ct >= nab[1] + nab[2]) WriteLine("No"); else if (str[i] == 'a') { WriteLine("Yes"); ct++; } else if (ct2 < nab[2]) { WriteLine("Yes"); ct++; ct2++; } else WriteLine("No"); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[][] ar2D(int num) => Enumerable.Repeat(0, num).Select(_ => ar).ToArray(); public static long[][] arL2D(int num) => Enumerable.Repeat(0, num).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["-", 8, 57, 75, 57, 75, 57, 15, 16, 17, 19], ["+", 8, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 57, 75, 57, 75, 57, 15, 16, 17, 18], ["+", 75, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 64, 196, 0, 1, 0, 223, 0, 22]]
8
575
12
using System; class Program { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); int n = int.Parse(str1[0]); int a = int.Parse(str1[1]); int b = int.Parse(str1[2]); string str = Console.ReadLine(); int i; int u = 0; int v = 0; for (i = 0; i < n; i++) { if (str[i] == 'a') { u++; if (u <= a + b) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else if (str[i] == 'b') { u++; v++; if ((u <= a + b) && (v <= b)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else Console.WriteLine("No"); } } }
using System; class Program { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); int n = int.Parse(str1[0]); int a = int.Parse(str1[1]); int b = int.Parse(str1[2]); string str = Console.ReadLine(); int i; int u = 0; int v = 0; for (i = 0; i < n; i++) { if (str[i] == 'a') { if (u < a + b) { Console.WriteLine("Yes"); u++; } else Console.WriteLine("No"); } else if (str[i] == 'b') { if ((u < a + b) && (v < b)) { Console.WriteLine("Yes"); u++; v++; } else Console.WriteLine("No"); } else Console.WriteLine("No"); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 75, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 75, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 18], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 18], ["+", 75, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
220
28
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var nab = Console.ReadLine().Split(' '); var n = nab[0].ToInt(); var a = nab[1].ToInt(); var b = nab[2].ToInt(); var s = Console.ReadLine().ToArray(); var cnta = 0; var cntb = 0; var output = new string[s.Length]; for (var i = 0; i < n; ++i) { if (s[i] == 'a') { ++cnta; if (cnta + cntb <= a + b) Console.WriteLine("Yes"); else Console.Write("No"); } else if (s[i] == 'b') { ++cntb; if (cnta + cntb <= a + b && cntb <= b) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else Console.WriteLine("No"); } } } static class Ex { public static int ToInt(this string str) { return int.Parse(str); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var nab = Console.ReadLine().Split(' '); var n = nab[0].ToInt(); var a = nab[1].ToInt(); var b = nab[2].ToInt(); var s = Console.ReadLine().ToArray(); var cnta = 0; var cntb = 0; var output = new string[s.Length]; for (var i = 0; i < n; ++i) { if (s[i] == 'a') { if (cnta + cntb < a + b) { ++cnta; Console.WriteLine("Yes"); } else Console.WriteLine("No"); } else if (s[i] == 'b') { if (cnta + cntb < a + b && cntb < b) { ++cntb; Console.WriteLine("Yes"); } else Console.WriteLine("No"); } else Console.WriteLine("No"); } } } static class Ex { public static int ToInt(this string str) { return int.Parse(str); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 241, 0, 29], ["-", 0, 57, 64, 196, 0, 1, 0, 241, 0, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 241, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 241, 0, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 57, 64, 196, 0, 1, 0, 241, 0, 29], ["-", 75, 57, 64, 196, 0, 1, 0, 241, 0, 22], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 75, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
277
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CF2016B_D { class Program { static int N; static long ans; static void Main(string[] args) { N = scan; var G = new SortedSet<int>(); var nowjust = 1; // var first = scan; // ans += first - 1; for (int i = 0; i < N; i++) { var a = scan; if (a % nowjust == 0) { var d = a / nowjust; ans += d - 1; if (nowjust * nowjust == a) continue; if (a == nowjust) nowjust++; else if (nowjust == 1) nowjust++; } else { var d = a / nowjust; ans += d; } // Console.WriteLine(ans+" " +nowjust); } Console.WriteLine(ans); } static int scan { get { return int.Parse(Console.ReadLine()); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CF2016B_D { class Program { static int N; static long ans; static void Main(string[] args) { N = scan; var G = new SortedSet<int>(); var nowjust = 2; var first = scan; ans += first - 1; for (int i = 1; i < N; i++) { var a = scan; if (a % nowjust == 0) { var d = a / nowjust; ans += d - 1; if (a == nowjust) nowjust++; } else { var d = a / nowjust; ans += d; } // Console.WriteLine(ans+" " +nowjust); } Console.WriteLine(ans); } static int scan { get { return int.Parse(Console.ReadLine()); } } } }
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 57, 64, 196, 0, 57, 64, 116, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 64, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 64, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["-", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["-", 0, 57, 64, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 57, 64, 196, 0, 57, 75, 57, 0, 24], ["-", 64, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["-", 64, 196, 0, 57, 75, 57, 15, 16, 12, 203]]
8
191
33
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N; long x; Multi(out N, out x); var A = GetLongArray(); long ans = 0; for (int i = 0; i < N - 1; i++) { if (A[i] + A[i + 1] > x) { ans += A[i] + A[i + 1] - x; A[i + 1] = Math.Max(0, x - (A[i] + A[i + 1])); } } Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); 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]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N; long x; Multi(out N, out x); var A = GetLongArray(); long ans = 0; for (int i = 0; i < N - 1; i++) { if (A[i] + A[i + 1] > x) { ans += A[i] + A[i + 1] - x; A[i + 1] = Math.Max(0, A[i + 1] - (A[i] + A[i + 1] - x)); } } Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); 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]); } } }
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22]]
8
1,211
9