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.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.CandleCount = inpt[0]; this.FireCount = inpt[1]; this.Candles = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); this.Dist = new long[this.CandleCount]; this.Dist[0] = 0; for (int i = 1; i < this.CandleCount; i++) { this.Dist[i] = this.Dist[0] + (this.Candles[i] - this.Candles[i - 1]); } long ans = long.MaxValue; for (int i = 0; i < this.CandleCount; i++) { int stIdx = i; int edIdx = i + FireCount - 1; if (edIdx >= this.CandleCount) { break; } long mv = Math.Abs(this.Candles[i]); mv += this.Candles[edIdx] - this.Candles[stIdx]; ans = Math.Min(mv, ans); } Console.WriteLine(ans); } long[] Dist; long[] Candles; int CandleCount; int FireCount; public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 3 2 10 20 30 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.CandleCount = inpt[0]; this.FireCount = inpt[1]; this.Candles = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); this.Dist = new long[this.CandleCount]; this.Dist[0] = 0; for (int i = 1; i < this.CandleCount; i++) { this.Dist[i] = this.Dist[0] + (this.Candles[i] - this.Candles[i - 1]); } long ans = long.MaxValue; for (int i = 0; i < this.CandleCount; i++) { int stIdx = i; int edIdx = i + FireCount - 1; if (edIdx >= this.CandleCount) { break; } long mv = Math.Min(Math.Abs(this.Candles[edIdx]), Math.Abs(this.Candles[stIdx])); mv += this.Candles[edIdx] - this.Candles[stIdx]; ans = Math.Min(mv, ans); } Console.WriteLine(ans); } long[] Dist; long[] Candles; int CandleCount; int FireCount; public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 5 3 -30 -10 10 20 50 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 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], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 204, 205, 214, 205, 273, 0, 274], ["+", 3, 4, 0, 28, 0, 204, 205, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 204, 205, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
8
420
21
using System; using System.Collections.Generic; using System.Text; namespace AtTest.ABC_107 { class D { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { long n = ReadLong(); int[] array = ReadInts(); int[] sorted = new int[n]; for (int i = 0; i < n; i++) sorted[i] = array[i]; Array.Sort(sorted); Dictionary<int, int> pos = new Dictionary<int, int>(); for (int i = 0; i < n; i++) { if (pos.ContainsKey(sorted[i])) continue; pos.Add(sorted[i], i); } int bottom = 0; int top = (int)n; while (bottom + 1 < top) { int mid = (bottom + top) / 2; int val = sorted[mid]; int[] sums = new int[n]; long cnt = 0; for (int i = 0; i < n; i++) { if (val <= array[i]) { sums[i] = 1; cnt++; } else sums[i] = -1; if (i > 0) sums[i] += sums[i - 1]; } SegTree<int> tree = new SegTree<int>(2 * 100000 + 5, 0, (a, b) => a + b, 0); for (int i = (int)n - 1; i >= 0; i--) { tree.Update(sums[i] + 100000, tree.Look(sums[i] + 100000) + 1); if (val <= array[i]) { cnt += tree.Scan(sums[i] - 1 + 100000, 2 * 100000 + 10); } else { cnt += tree.Scan(sums[i] + 1 + 100000, 2 * 100000 + 10); } } long thres = n * (n + 1) / 4; if ((n * (n + 1) / 2) % 2 > 0) thres++; if (cnt >= thres) bottom = mid; else top = mid; } Console.WriteLine(sorted[bottom]); } class SegTree<T> { int totalLength; T[] tree; Func<T, T, T> integrate; T exValue; public SegTree(int length, Func<T, T, T> integrate, T exValue) { this.integrate = integrate; this.exValue = exValue; totalLength = 1; while (totalLength < length) totalLength *= 2; tree = new T[2 * totalLength - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = exValue; } public SegTree(int length, T initialValue, Func<T, T, T> integrate, T exValue) : this(length, integrate, exValue) { for (int i = 0; i < length; i++) { tree[i + totalLength - 1] = initialValue; } UpdateAll(); } public void AssignWithoutUpdate(int i, T value) { tree[i + totalLength - 1] = value; } public void Update(int i, T value) { int now = i + totalLength - 1; tree[now] = value; while (now > 0) { now = (now - 1) / 2; tree[now] = integrate(tree[now * 2 + 1], tree[now * 2 + 2]); } } public void UpdateAll() { for (int i = totalLength - 2; i >= 0; i--) { tree[i] = integrate(tree[i * 2 + 1], tree[i * 2 + 2]); } } public T Look(int i) { return tree[i + totalLength - 1]; } //[top,last) public T Scan(int top, int last) { return Query(top, last, 0, 0, totalLength); } T Query(int top, int last, int i, int left, int right) { if (right <= top || last <= left) return exValue; if (top <= left && right <= last) return tree[i]; T leftValue = Query(top, last, i * 2 + 1, left, (left + right) / 2); T rightValue = Query(top, last, (i + 1) * 2, (left + right) / 2, right); return integrate(leftValue, rightValue); } } 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.ABC_107 { class D { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { long n = ReadLong(); int[] array = ReadInts(); int[] sorted = new int[n]; for (int i = 0; i < n; i++) sorted[i] = array[i]; Array.Sort(sorted); Dictionary<int, int> pos = new Dictionary<int, int>(); for (int i = 0; i < n; i++) { if (pos.ContainsKey(sorted[i])) continue; pos.Add(sorted[i], i); } int bottom = 0; int top = (int)n; while (bottom + 1 < top) { int mid = (bottom + top) / 2; int val = sorted[mid]; int[] sums = new int[n]; for (int i = 0; i < n; i++) { if (val <= array[i]) { sums[i] = 1; } else sums[i] = -1; if (i > 0) sums[i] += sums[i - 1]; } long cnt = 0; SegTree<int> tree = new SegTree<int>(2 * 100000 + 5, 0, (a, b) => a + b, 0); for (int i = (int)n - 1; i >= 0; i--) { tree.Update(sums[i] + 100000, tree.Look(sums[i] + 100000) + 1); if (val <= array[i]) { cnt += tree.Scan(sums[i] - 1 + 100000, 2 * 100000 + 10); } else { cnt += tree.Scan(sums[i] + 1 + 100000, 2 * 100000 + 10); } } long thres = n * (n + 1) / 4; if ((n * (n + 1) / 2) % 2 > 0) thres++; if (cnt >= thres) bottom = mid; else top = mid; } Console.WriteLine(sorted[bottom]); } class SegTree<T> { int totalLength; T[] tree; Func<T, T, T> integrate; T exValue; public SegTree(int length, Func<T, T, T> integrate, T exValue) { this.integrate = integrate; this.exValue = exValue; totalLength = 1; while (totalLength < length) totalLength *= 2; tree = new T[2 * totalLength - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = exValue; } public SegTree(int length, T initialValue, Func<T, T, T> integrate, T exValue) : this(length, integrate, exValue) { for (int i = 0; i < length; i++) { tree[i + totalLength - 1] = initialValue; } UpdateAll(); } public void AssignWithoutUpdate(int i, T value) { tree[i + totalLength - 1] = value; } public void Update(int i, T value) { int now = i + totalLength - 1; tree[now] = value; while (now > 0) { now = (now - 1) / 2; tree[now] = integrate(tree[now * 2 + 1], tree[now * 2 + 2]); } } public void UpdateAll() { for (int i = totalLength - 2; i >= 0; i--) { tree[i] = integrate(tree[i * 2 + 1], tree[i * 2 + 2]); } } public T Look(int i) { return tree[i + totalLength - 1]; } //[top,last) public T Scan(int top, int last) { return Query(top, last, 0, 0, totalLength); } T Query(int top, int last, int i, int left, int right) { if (right <= top || last <= left) return exValue; if (top <= left && right <= last) return tree[i]; T leftValue = Query(top, last, i * 2 + 1, left, (left + right) / 2); T rightValue = Query(top, last, (i + 1) * 2, (left + right) / 2, right); return integrate(leftValue, rightValue); } } 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); } } }
[["-", 0, 52, 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 52, 8, 196, 0, 197, 0, 35], ["-", 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, 52, 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 197, 0, 35]]
8
1,125
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C_Skip { class Program { static void Main(string[] args) { string[] NX = Console.ReadLine().Split(' '); int N = int.Parse(NX[0]); int X = int.Parse(NX[1]); List<int> num = new List<int> { X }; int x; string[] x0 = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { x = int.Parse(x0[i]); num.Add(x); } num.Sort(); List<int> sa = new List<int>(); for (int i = 0; i < N; i++) { sa.Add(num[i + 1] - num[i]); } int gcd = 0; List<int> gcdList = new List<int>(); for (int i = 0; i < N - 1; i++) { gcd = Gcd(sa[i + 1], sa[i]); gcdList.Add(gcd); } Console.WriteLine(gcdList.Min()); } // ユークリッドの互除法 public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C_Skip { class Program { static void Main(string[] args) { string[] NX = Console.ReadLine().Split(' '); int N = int.Parse(NX[0]); int X = int.Parse(NX[1]); List<int> num = new List<int> { X }; int x; string[] x0 = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { x = int.Parse(x0[i]); num.Add(x); } num.Sort(); List<int> sa = new List<int>(); for (int i = 0; i < N; i++) { sa.Add(num[i + 1] - num[i]); } int gcd = 0; List<int> gcdList = new List<int>(); if (N == 1) { Console.WriteLine(sa[0]); } else { for (int i = 0; i < N - 1; i++) { gcd = Gcd(sa[i + 1], sa[i]); gcdList.Add(gcd); } Console.WriteLine(gcdList.Min()); } } // ユークリッドの互除法 public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } } }
[["+", 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], ["+", 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, 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], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
341
21
using System; using System.Collections.Generic; public class Operation { private int sY, sX, tY, tX; public Operation(int a, int b, int c, int d) { sY = a; sX = b; tY = c; tX = d; } public void print() { Console.WriteLine("{0} {1} {2} {3}", sY, sX, tY, tX); } } public class D { public static void Main() { string[] args; args = Console.ReadLine().Split(' '); int h = Int32.Parse(args[0]); int w = Int32.Parse(args[1]); int[,] a = new int[h + 1, w + 1]; for (int i = 1; i <= h; i++) { args = Console.ReadLine().Split(' '); for (int j = 1; j <= w; j++) { a[i, j] = Int32.Parse(args[j - 1]); } } List<Operation> op = new List<Operation>(); for (int i = 1; i <= h - 1; i++) { for (int j = 1; j <= w - 1; j++) { if (a[i, j] % 2 != 0) { a[i, j + 1]++; op.Add(new Operation(i, j, i, j + 1)); } } if (a[i, w] % 2 != 0) { a[i + 1, w]++; op.Add(new Operation(i, w, i + 1, w)); } } for (int j = 1; j <= w - 1; j++) { if (a[h, j] % 2 != 0) { a[h, j + 1]++; op.Add(new Operation(h, j, h, j + 1)); } } for (int i = 0; i < op.Count; i++) (op[i]).print(); } }
using System; using System.Collections.Generic; public class Operation { private int sY, sX, tY, tX; public Operation(int a, int b, int c, int d) { sY = a; sX = b; tY = c; tX = d; } public void print() { Console.WriteLine("{0} {1} {2} {3}", sY, sX, tY, tX); } } public class D { public static void Main() { string[] args; args = Console.ReadLine().Split(' '); int h = Int32.Parse(args[0]); int w = Int32.Parse(args[1]); int[,] a = new int[h + 1, w + 1]; for (int i = 1; i <= h; i++) { args = Console.ReadLine().Split(' '); for (int j = 1; j <= w; j++) { a[i, j] = Int32.Parse(args[j - 1]); } } List<Operation> op = new List<Operation>(); for (int i = 1; i <= h - 1; i++) { for (int j = 1; j <= w - 1; j++) { if (a[i, j] % 2 != 0) { a[i, j + 1]++; op.Add(new Operation(i, j, i, j + 1)); } } if (a[i, w] % 2 != 0) { a[i + 1, w]++; op.Add(new Operation(i, w, i + 1, w)); } } for (int j = 1; j <= w - 1; j++) { if (a[h, j] % 2 != 0) { a[h, j + 1]++; op.Add(new Operation(h, j, h, j + 1)); } } Console.WriteLine(op.Count); for (int i = 0; i < op.Count; i++) (op[i]).print(); } }
[["+", 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, 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, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
452
9
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; using System.Text; namespace ABC109 { class Program { static void Main(string[] args) { var H = RInt; var W = RInt; int[,] a = new int[H, W]; for (int i = 0; i < H; i++) { var input = RInts; for (int j = 0; j < W; j++) { a[i, j] = input[j]; } } List<int> x1 = new List<int>(); List<int> y1 = new List<int>(); List<int> x2 = new List<int>(); List<int> y2 = new List<int>(); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (a[i, j] % 2 == 1) { if (j != W - 1) { a[i, j + 1]++; a[i, j]--; x1.Add(j + 1); y1.Add(i + 1); x2.Add(j + 2); y2.Add(i + 1); } else if (i != H - 1) { a[i + 1, j]++; a[i, j]--; x1.Add(j + 1); y1.Add(i + 1); x2.Add(j + 1); y2.Add(i + 2); } } } } Draw(a); StringBuilder sb = new StringBuilder(); sb.AppendLine(x1.Count.ToString()); for (int i = 0; i < x1.Count; i++) { sb.AppendLine(x1[i] + " " + y1[i] + " " + x2[i] + " " + y2[i]); } Console.Write(sb); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod || n < 0 ? (n % mod + mod) % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a % mod, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { public static void Draw<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } static public void Draw<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } } }
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; using System.Text; namespace ABC109 { class Program { static void Main(string[] args) { var H = RInt; var W = RInt; int[,] a = new int[H, W]; for (int i = 0; i < H; i++) { var input = RInts; for (int j = 0; j < W; j++) { a[i, j] = input[j]; } } List<int> x1 = new List<int>(); List<int> y1 = new List<int>(); List<int> x2 = new List<int>(); List<int> y2 = new List<int>(); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (a[i, j] % 2 == 1) { if (j != W - 1) { a[i, j + 1]++; a[i, j]--; x1.Add(j + 1); y1.Add(i + 1); x2.Add(j + 2); y2.Add(i + 1); } else if (i != H - 1) { a[i + 1, j]++; a[i, j]--; x1.Add(j + 1); y1.Add(i + 1); x2.Add(j + 1); y2.Add(i + 2); } } } } Draw(a); StringBuilder sb = new StringBuilder(); sb.AppendLine(x1.Count.ToString()); for (int i = 0; i < x1.Count; i++) { sb.AppendLine(y1[i] + " " + x1[i] + " " + y2[i] + " " + x2[i]); } Console.Write(sb); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod || n < 0 ? (n % mod + mod) % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a % mod, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { public static void Draw<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } static public void Draw<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } } }
[["-", 31, 16, 31, 16, 31, 16, 31, 204, 205, 22], ["+", 31, 16, 31, 16, 31, 16, 31, 204, 205, 22], ["-", 31, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["+", 31, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["-", 0, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22]]
8
1,517
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class ACCEPTED { public void Solve() { var o = Intm; var H = o[0]; var W = o[1]; var a = new int [H][]; for (int i = 0; i < H; ++i) a[i] = Intm; var c = new List<Tuple<int, int, int, int>>(); for (int i = 0; i < H; ++i) { if (i % 2 == 0) { for (int j = 0; j < W; ++j) { if (a[i][j] % 2 == 1) { if (i == H - 1 && j == W - 1) continue; else if (j == W - 1) { a[i + 1][W - 1]++; c.Add(new Tuple<int, int, int, int>(i + 1, j + 1, i + 2, W)); } else { a[i][j + 1]++; c.Add(new Tuple<int, int, int, int>(i + 1, j + 1, i + 1, j + 2)); } } } } else for (int j = W - 1; j >= 0; --j) { if (i == H - 1 && j == 0) continue; else if (j == 0) { a[i + 1][0]++; c.Add(new Tuple<int, int, int, int>(i + 1, j + 1, i + 2, 1)); } else { a[i][j - 1]++; c.Add(new Tuple<int, int, int, int>(i + 1, j + 1, i + 1, j)); } } } Write(c.Count); foreach (var x in c) { Write(x.Item1, x.Item2, x.Item3, x.Item4); } } } public static class Graph {} public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const int MOD = 1000000007; public const int MOD2 = 998244353; public static long Pow(long i, long N, long MOD = 1000000007) { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var ACCEPTED = new ACCEPTED(); ACCEPTED.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strm => Str.Split(' '); public static long[] Longm => Strm.Select(long.Parse).ToArray(); public static int[] Intm => Strm.Select(int.Parse).ToArray(); public static char[] Charm => Str.ToArray(); public static double[] Doublem => Strm.Select(double.Parse).ToArray(); public static long Long1 => Longm[0]; public static int Int1 => Intm[0]; public static char Char1 => Charm[0]; public static double Double1 => Doublem[0]; public static long[] HorizontalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Horizontalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class ACCEPTED { public void Solve() { var o = Intm; var H = o[0]; var W = o[1]; var a = new int [H][]; for (int i = 0; i < H; ++i) a[i] = Intm; var c = new List<Tuple<int, int, int, int>>(); for (int i = 0; i < H; ++i) { if (i % 2 == 0) { for (int j = 0; j < W; ++j) { if (a[i][j] % 2 == 1) { if (i == H - 1 && j == W - 1) continue; else if (j == W - 1) { a[i + 1][W - 1]++; c.Add(new Tuple<int, int, int, int>(i + 1, j + 1, i + 2, W)); } else { a[i][j + 1]++; c.Add(new Tuple<int, int, int, int>(i + 1, j + 1, i + 1, j + 2)); } } } } else { for (int j = W - 1; j >= 0; --j) { if (a[i][j] % 2 == 1) { if (i == H - 1 && j == 0) continue; else if (j == 0) { a[i + 1][0]++; c.Add(new Tuple<int, int, int, int>(i + 1, j + 1, i + 2, 1)); } else { a[i][j - 1]++; c.Add(new Tuple<int, int, int, int>(i + 1, j + 1, i + 1, j)); } } } } } Write(c.Count); foreach (var x in c) { Write(x.Item1, x.Item2, x.Item3, x.Item4); } } } public static class Graph {} public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const int MOD = 1000000007; public const int MOD2 = 998244353; public static long Pow(long i, long N, long MOD = 1000000007) { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var ACCEPTED = new ACCEPTED(); ACCEPTED.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strm => Str.Split(' '); public static long[] Longm => Strm.Select(long.Parse).ToArray(); public static int[] Intm => Strm.Select(int.Parse).ToArray(); public static char[] Charm => Str.ToArray(); public static double[] Doublem => Strm.Select(double.Parse).ToArray(); public static long Long1 => Longm[0]; public static int Int1 => Intm[0]; public static char Char1 => Charm[0]; public static double Double1 => Doublem[0]; public static long[] HorizontalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Horizontalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 7, 26, 241, 0, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 7, 0, 25], ["+", 0, 57, 75, 196, 0, 7, 8, 196, 0, 45], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 204, 205, 204, 205, 22], ["+", 31, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 64, 196, 0, 57, 75, 57, 75, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,450
18
using System.Linq; using System.Collections.Generic; using System; public class P { public int x { get; set; } public int nx { get; set; } public int y { get; set; } public int ny { get; set; } } public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var h = int.Parse(line[0]); var w = int.Parse(line[1]); var a = new int[h, w]; for (int i = 0; i < h; i++) { line = Console.ReadLine().Trim().Split(' '); for (int j = 0; j < w; j++) a[i, j] = int.Parse(line[j]); } var ps = new List<P>(); if (h == 1) goto h1; for (int i = 0; i * 2 < h; i++) for (int j = 0; j < w; j++) if (a[i, j] % 2 == 1) { a[i, j]--; a[i + 1, j]++; ps.Add(new P { x = i + 1, nx = i + 2, y = j + 1, ny = j + 1 }); } h1:; for (int i = 0; i * 2 < w; i++) { if (a[h - 1, i] % 2 == 1) { a[h - 1, i]--; a[h - 1, i + 1]++; ps.Add(new P { x = h, nx = h, y = i + 1, ny = i + 2 }); } } var psc = ps.Count(); Console.WriteLine(psc); for (int i = 0; i < psc; i++) { var t = ps[i]; Console.WriteLine("{0} {1} {2} {3}", t.x, t.y, t.nx, t.ny); } } }
using System.Linq; using System.Collections.Generic; using System; public class P { public int x { get; set; } public int nx { get; set; } public int y { get; set; } public int ny { get; set; } } public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var h = int.Parse(line[0]); var w = int.Parse(line[1]); var a = new int[h, w]; for (int i = 0; i < h; i++) { line = Console.ReadLine().Trim().Split(' '); for (int j = 0; j < w; j++) a[i, j] = int.Parse(line[j]); } var ps = new List<P>(); if (h == 1) goto h1; for (int i = 0; i < h - 1; i++) for (int j = 0; j < w; j++) if (a[i, j] % 2 == 1) { a[i, j]--; a[i + 1, j]++; ps.Add(new P { x = i + 1, nx = i + 2, y = j + 1, ny = j + 1 }); } h1:; for (int i = 0; i < w - 1; i++) { if (a[h - 1, i] % 2 == 1) { a[h - 1, i]--; a[h - 1, i + 1]++; ps.Add(new P { x = h, nx = h, y = i + 1, ny = i + 2 }); } } var psc = ps.Count(); Console.WriteLine(psc); for (int i = 0; i < psc; i++) { var t = ps[i]; Console.WriteLine("{0} {1} {2} {3}", t.x, t.y, t.nx, t.ny); } } }
[["-", 8, 196, 0, 7, 15, 16, 31, 16, 17, 48], ["-", 8, 196, 0, 7, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
464
8
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Myon { public Myon() {} public static int Main() { cin = new Scanner(); new Myon().calc(); return 0; } static Scanner cin; struct state { public int X; public int Y; public state(int x, int y) { X = x; Y = y; } } // メンバ変数--- int H; int W; int[,] A; // ------------- void calc() { H = cin.nextInt(); W = cin.nextInt(); A = new int[H, W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i, j] = cin.nextInt(); } } bool isStartLeft = true; List<state> states = new List<state>(); for (int i = 0; i < H; i++) { if (isStartLeft) { // 左から for (int j = 0; j < W; j++) { states.Add(new state(j, i)); } } else { // 右から for (int j = W - 1; - 1 < j; j--) { states.Add(new state(j, i)); } } isStartLeft = !isStartLeft; } List<string> ret = new List<string>(); for (int i = 0; i < states.Count - 1; i++) { if (A[states[i].Y, states[i].X] % 2 == 1) { A[states[i + 1].Y, states[i + 1].X] += 1; ret.Add(string.Format("{0} {1} {2} {3}", states[i].Y, states[i].X, states[i + 1].Y, states[i + 1].X)); } } Write(ret.Count); ret.ForEach(x => Write(x)); } void Write<T>(T v) { Console.WriteLine(v); } int Pow(int x, int y) { return (int)Math.Pow(double.Parse(x.ToString()), double.Parse(y.ToString())); } double Pow(double x, double y) { return Math.Pow(x, y); } 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.Diagnostics; using System.IO; using System.Linq; using System.Text; class Myon { public Myon() {} public static int Main() { cin = new Scanner(); new Myon().calc(); return 0; } static Scanner cin; struct state { public int X; public int Y; public state(int x, int y) { X = x; Y = y; } } // メンバ変数--- int H; int W; int[,] A; // ------------- void calc() { H = cin.nextInt(); W = cin.nextInt(); A = new int[H, W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i, j] = cin.nextInt(); } } bool isStartLeft = true; List<state> states = new List<state>(); for (int i = 0; i < H; i++) { if (isStartLeft) { // 左から for (int j = 0; j < W; j++) { states.Add(new state(j, i)); } } else { // 右から for (int j = W - 1; - 1 < j; j--) { states.Add(new state(j, i)); } } isStartLeft = !isStartLeft; } List<string> ret = new List<string>(); for (int i = 0; i < states.Count - 1; i++) { if (A[states[i].Y, states[i].X] % 2 == 1) { A[states[i + 1].Y, states[i + 1].X] += 1; ret.Add(string.Format("{0} {1} {2} {3}", states[i].Y + 1, states[i].X + 1, states[i + 1].Y + 1, states[i + 1].X + 1)); } } Write(ret.Count); ret.ForEach(x => Write(x)); } void Write<T>(T v) { Console.WriteLine(v); } int Pow(int x, int y) { return (int)Math.Pow(double.Parse(x.ToString()), double.Parse(y.ToString())); } double Pow(double x, double y) { return Math.Pow(x, y); } 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, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
888
8
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using static util; using P = pair<int, int>; 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(); const int M = 1000000007; const int M2 = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int h, w; sc.Multi(out h, out w); var a = new int [h].Select(x => sc.IntArr).ToArray(); var ans = new List<int[]>(); for (int i = 0; i < h; i++) { for (int j = 0; j + 1 < w; j++) { if (a[i][j] % 2 == 1) { ans.Add(new[] { i + 1, j + 1, i + 1, j + 2 }); --a[i][j]; ++a[i][j + 1]; } } if (i < h - 1 && a[i][w - 1] % 2 == 1) { ans.Add(new[] { i + 1, w, i + 2, w }); --a[i][w - 1]; ++a[i + 1][w - 1]; } } foreach (var item in ans) { Prt(item); } sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { 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) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P { get { int a, b; Multi(out a, out b); return new P(a, b); } } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); 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); 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]); } public void Multi<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 = 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]); f = cv<Y>(ar[5]); } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using static util; using P = pair<int, int>; 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(); const int M = 1000000007; const int M2 = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int h, w; sc.Multi(out h, out w); var a = new int [h].Select(x => sc.IntArr).ToArray(); var ans = new List<int[]>(); for (int i = 0; i < h; i++) { for (int j = 0; j + 1 < w; j++) { if (a[i][j] % 2 == 1) { ans.Add(new[] { i + 1, j + 1, i + 1, j + 2 }); --a[i][j]; ++a[i][j + 1]; } } if (i < h - 1 && a[i][w - 1] % 2 == 1) { ans.Add(new[] { i + 1, w, i + 2, w }); --a[i][w - 1]; ++a[i + 1][w - 1]; } } Prt(ans.Count); foreach (var item in ans) { Prt(item); } sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { 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) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P { get { int a, b; Multi(out a, out b); return new P(a, b); } } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); 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); 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]); } public void Multi<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 = 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]); f = cv<Y>(ar[5]); } }
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 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, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
2,179
7
using System; using System.Collections.Generic; using System.Linq; using System.IO; // using System.Text; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; // using System.Numerics; // using static System.Math; // using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } void solve() { int H = cin.nextint; int W = cin.nextint; var A = new int [H][]; for (int i = 0; i < H; i++) { A[i] = cin.scanint; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] % 2 == 1) { if (j == W - 1) { if (i != H - 1) { WriteLine($"{i + 1} {j + 1} {i + 2} {j + 1}"); A[i + 1][j]++; } } else { WriteLine($"{i + 1} {j + 1} {i + 1} {j + 2}"); A[i][j + 1]++; } } } } } } 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.Text; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; // using System.Numerics; // using static System.Math; // using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } void solve() { int H = cin.nextint; int W = cin.nextint; var A = new int [H][]; for (int i = 0; i < H; i++) { A[i] = cin.scanint; } int cnt = 0; var SB = new StringBuilder(); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (A[i][j] % 2 == 1) { if (j == W - 1) { if (i != H - 1) { cnt++; SB.AppendLine($"{i + 1} {j + 1} {i + 2} {j + 1}"); A[i + 1][j]++; } } else { cnt++; SB.AppendLine($"{i + 1} {j + 1} {i + 1} {j + 2}"); A[i][j + 1]++; } } } } WriteLine(cnt); Write(SB); } } 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); } } }
[["+", 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], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 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, 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], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 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], ["-", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 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], ["+", 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], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 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
616
42
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // using static System.Linq.Enumerable; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; using static AtCoder.StreamExtensions; using static AtCoder.Matrix; namespace AtCoder { static class Program { static void Main() { var h = ReadInt(); var w = ReadInt(); var a = ReadLongMatrix(h, w).SelectMatrix(MyMath.IsOdd); var moves = new List<LongFromToVector>(); Action<LongFromToVector> writeMove = m => WriteLine($"{m.Start.Y} {m.Start.X} {m.End.Y} {m.End.X}"); Action<VectorInt2, VectorInt2> move = (from, to) => { // writeMove(new LongFromToVector(from, to)); if (!a[from.Y][from.X]) return; a[from.Y][from.X] = !a[from.Y][from.X]; a[to.Y][to.X] = !a[to.Y][to.X]; moves.Add(new LongFromToVector(from, to)); }; foreach (var i in FromTo(0, h - 1)) { foreach (var j in FromTo(0, w - 2)) move(new VectorInt2(j, i), new VectorInt2(j + 1, i)); if (i < h - 1) move(new VectorInt2(w - 1, i), new VectorInt2(w - 1, i + 1)); } WriteLine(moves.Count()); moves.ForEach(writeMove); } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class Algorithm { public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, long width) => BinSearch(range, isBigger, x => range.Right - range.Left < width); public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, Func<LongRange, bool> stopCondition) { if (stopCondition(range)) return range; var middle = range.Left + (range.Right - range.Left) / 2; return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle), isBigger, stopCondition) : BinSearch(new LongRange(middle, range.Right), isBigger, stopCondition); } } static class MyMath { public static long GCD(long a, long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a; 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 long LowerBound(this long m, long lbound) => Max(m, lbound); public static long UpperBound(this long m, long ubound) => Min(m, ubound); public static long Bound(this long m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static long LowerBound(this int m, long lbound) => Max(m, lbound); public static long UpperBound(this int m, long ubound) => Min(m, ubound); public static long Bound(this int m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); 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 != 0; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 0; public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits(); 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(this long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static long Pow(this int i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); } static class Util { public static InvalidOperationException UnreachableException = new InvalidOperationException("unreachable."); public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); 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 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 VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static VectorDouble2 ReadVectorDouble2() => new VectorDouble2(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 bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); } static class ParametricExtensions { 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 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 S Call<S>(this S s, Func<S, S> func, int times) => times == 0 ? s : Call(func(s), func, times - 1); } static class StreamExtensions { 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(); 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 void ForEach<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<Tuple<T1, T2>> Cartesian<T1, T2>(IEnumerable<T1> s1, IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select new Tuple<T1, T2>(v1, v2); public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>( IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select new Tuple<T1, T2, T3>(v1, v2, v3); public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3, IEnumerable<T4> s4) => from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4); 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 T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T max = source.First(); foreach (var item in source) if (selector(item) > selector(max)) max = item; return max; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T min = source.First(); foreach (var item in source) if (selector(item) < selector(min)) min = item; return min; } public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) { for (int i = 0; i < source.Count; i++) if (condition(source[i])) return i; return -1; } public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) => ChunkBy(source, Id, EqualityComparer<T>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector) => ChunkBy(source, selector, EqualityComparer<S>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector, IEqualityComparer<S> comparer) { while (source.Any()) { var v = selector(source.First()); var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList(); yield return l; source = source.Skip(l.Count()); } } } static class Matrix { public static List<List<T>> Transpose<T>(this List<List<T>> source) => Range(0, source[0].Count) .Select(i => source.Select(x => x[i]).ToList()) .ToList(); public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) { foreach (var line in source) line.Show().WriteLine(); } public static List<List<long>> ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList(); public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source, Func<S, T> f) => source.Select(x => x.Select(f).ToList()).ToList(); } 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(); } public 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); public override string ToString() => $"({X}, {Y})"; } struct VectorDouble2 { public double X { get; set; } public double Y { get; set; } public VectorDouble2(double x, double y) { X = x; Y = y; } static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y); static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i); static public VectorDouble2 operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y); static public VectorDouble2 operator /(VectorDouble2 v1, double i) => new VectorDouble2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; public VectorDouble2 Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian), X *Sin(radian) + Y * Cos(radian)); } 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 bool Contains(T t) => dictionary.ContainsKey(t); public void RemoveIfAny(T t) { if (dictionary.ContainsKey(t)) { dictionary[t]--; if (dictionary[t] == 0) { dictionary.Remove(t); } } } 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(); } public struct LongRange { public long Left; public long Right; public LongRange(long left, long right) { Left = left; Right = right; } } public struct LongFromToVector { public VectorInt2 Start; public VectorInt2 End; public LongFromToVector(VectorInt2 start, VectorInt2 end) { Start = start; End = end; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // using static System.Linq.Enumerable; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; using static AtCoder.StreamExtensions; using static AtCoder.Matrix; namespace AtCoder { static class Program { static void Main() { var h = ReadInt(); var w = ReadInt(); var a = ReadLongMatrix(h, w).SelectMatrix(MyMath.IsOdd); Action<LongFromToVector> writeMove = m => WriteLine( $"{m.Start.Y + 1} {m.Start.X + 1} {m.End.Y + 1} {m.End.X + 1}"); var moves = new List<LongFromToVector>(); Action<VectorInt2, VectorInt2> move = (from, to) => { // writeMove(new LongFromToVector(from, to)); if (!a[from.Y][from.X]) return; a[from.Y][from.X] = !a[from.Y][from.X]; a[to.Y][to.X] = !a[to.Y][to.X]; moves.Add(new LongFromToVector(from, to)); }; foreach (var i in FromTo(0, h - 1)) { foreach (var j in FromTo(0, w - 2)) move(new VectorInt2(j, i), new VectorInt2(j + 1, i)); if (i < h - 1) move(new VectorInt2(w - 1, i), new VectorInt2(w - 1, i + 1)); } WriteLine(moves.Count()); moves.ForEach(writeMove); } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class Algorithm { public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, long width) => BinSearch(range, isBigger, x => range.Right - range.Left < width); public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, Func<LongRange, bool> stopCondition) { if (stopCondition(range)) return range; var middle = range.Left + (range.Right - range.Left) / 2; return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle), isBigger, stopCondition) : BinSearch(new LongRange(middle, range.Right), isBigger, stopCondition); } } static class MyMath { public static long GCD(long a, long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a; 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 long LowerBound(this long m, long lbound) => Max(m, lbound); public static long UpperBound(this long m, long ubound) => Min(m, ubound); public static long Bound(this long m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static long LowerBound(this int m, long lbound) => Max(m, lbound); public static long UpperBound(this int m, long ubound) => Min(m, ubound); public static long Bound(this int m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); 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 != 0; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 0; public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits(); 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(this long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static long Pow(this int i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); } static class Util { public static InvalidOperationException UnreachableException = new InvalidOperationException("unreachable."); public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); 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 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 VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static VectorDouble2 ReadVectorDouble2() => new VectorDouble2(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 bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); } static class ParametricExtensions { 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 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 S Call<S>(this S s, Func<S, S> func, int times) => times == 0 ? s : Call(func(s), func, times - 1); } static class StreamExtensions { 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(); 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 void ForEach<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<Tuple<T1, T2>> Cartesian<T1, T2>(IEnumerable<T1> s1, IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select new Tuple<T1, T2>(v1, v2); public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>( IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select new Tuple<T1, T2, T3>(v1, v2, v3); public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3, IEnumerable<T4> s4) => from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4); 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 T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T max = source.First(); foreach (var item in source) if (selector(item) > selector(max)) max = item; return max; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T min = source.First(); foreach (var item in source) if (selector(item) < selector(min)) min = item; return min; } public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) { for (int i = 0; i < source.Count; i++) if (condition(source[i])) return i; return -1; } public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) => ChunkBy(source, Id, EqualityComparer<T>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector) => ChunkBy(source, selector, EqualityComparer<S>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector, IEqualityComparer<S> comparer) { while (source.Any()) { var v = selector(source.First()); var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList(); yield return l; source = source.Skip(l.Count()); } } } static class Matrix { public static List<List<T>> Transpose<T>(this List<List<T>> source) => Range(0, source[0].Count) .Select(i => source.Select(x => x[i]).ToList()) .ToList(); public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) { foreach (var line in source) line.Show().WriteLine(); } public static List<List<long>> ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList(); public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source, Func<S, T> f) => source.Select(x => x.Select(f).ToList()).ToList(); } 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(); } public 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); public override string ToString() => $"({X}, {Y})"; } struct VectorDouble2 { public double X { get; set; } public double Y { get; set; } public VectorDouble2(double x, double y) { X = x; Y = y; } static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y); static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i); static public VectorDouble2 operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y); static public VectorDouble2 operator /(VectorDouble2 v1, double i) => new VectorDouble2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; public VectorDouble2 Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian), X *Sin(radian) + Y * Cos(radian)); } 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 bool Contains(T t) => dictionary.ContainsKey(t); public void RemoveIfAny(T t) { if (dictionary.ContainsKey(t)) { dictionary[t]--; if (dictionary[t] == 0) { dictionary.Remove(t); } } } 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(); } public struct LongRange { public long Left; public long Right; public LongRange(long left, long right) { Left = left; Right = right; } } public struct LongFromToVector { public VectorInt2 Start; public VectorInt2 End; public LongFromToVector(VectorInt2 start, VectorInt2 end) { Start = start; End = end; } } }
[["-", 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, 230, 0, 228], ["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 17, 72], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 12, 203], ["+", 0, 212, 0, 218, 8, 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, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24]]
8
4,590
30
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using System.IO; class Solve { const int mod = 1000000007; static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); int K = int.Parse(Console.ReadLine()); Console.WriteLine((K / 2) * (1 - (K / 2))); Console.Out.Flush(); } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using System.IO; class Solve { const int mod = 1000000007; static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); int K = int.Parse(Console.ReadLine()); int e = K / 2; Console.WriteLine(e * (K - e)); Console.Out.Flush(); } }
[["+", 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, 198, 0, 200, 0, 212, 0, 16, 31, 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, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 85], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 31, 203], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 12, 23, 0, 16, 12, 23, 0, 16, 17, 85], ["-", 12, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 16, 12, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22]]
8
126
21
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC108A { class Class1 { static void Main() { Console.WriteLine("sga"); var K = int.Parse(Console.ReadLine()); if (K % 2 == 0) { Console.WriteLine((K / 2) * (K / 2)); } else { Console.WriteLine(((K - 1) / 2) * ((K + 1) / 2)); } } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC108A { class Class1 { static void Main() { var K = int.Parse(Console.ReadLine()); if (K % 2 == 0) { Console.WriteLine((K / 2) * (K / 2)); } else { Console.WriteLine(((K - 1) / 2) * ((K + 1) / 2)); } } } }
[["-", 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
130
9
using System; namespace Atcoder { public class Program { public static void Main(string[] args) { int b = int.Parse(Console.ReadLine()); if (b % 2 == 0) { Console.WriteLine(Math.Pow((double)b, 2)); } else { Console.WriteLine((b - 1) * (b + 1) / 4); } } } }
using System; namespace Atcoder { public class Program { public static void Main(string[] args) { int b = int.Parse(Console.ReadLine()); if (b % 2 == 0) { Console.WriteLine(b * b / 4); } else { Console.WriteLine((b - 1) * (b + 1) / 4); } } } }
[["-", 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], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
87
14
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var t = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number)); var x1 = t[0]; var y1 = t[1]; var x2 = t[2]; var y2 = t[3]; var diffX = Math.Abs(x2 - x1); var diffY = Math.Abs(y2 - y1); if (x1 == x2) { if (y1 < y2) { Console.WriteLine($"{x1 - diffY} {y2} {x1 - diffY} {y1}"); } else { Console.WriteLine($"{x1 + diffY} {y2} {x1 + diffY} {y1}"); } } else if (y1 == y2) { if (x1 < x2) { Console.WriteLine($"{x2} {y2 + diffX} {x1} {y1 + diffX}"); } else { Console.WriteLine($"{x2} {y2 - diffX} {x1} {y1 - diffX}"); } } else if (y1 < y2) { if (x1 < x2) { Console.WriteLine( $"{x2 - diffY} {y2 + diffX} {x1 - diffY} {y1 + diffX}"); } else { Console.WriteLine( $"{x2 - diffY} {y2 - diffX} {x1 - diffY} {y1 - diffX}"); } } else { if (x1 < x2) { Console.WriteLine( $"{x2 + diffY} {y2 - diffX} {x1 + diffY} {y1 - diffX}"); } else { Console.WriteLine( $"{x2 + diffY} {y2 + diffX} {x1 + diffY} {y1 + diffX}"); } } //デバッグ実行での確認用。そのまま提出しても問題なし Console.ReadKey(); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var t = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number)); var x1 = t[0]; var y1 = t[1]; var x2 = t[2]; var y2 = t[3]; var diffX = Math.Abs(x2 - x1); var diffY = Math.Abs(y2 - y1); if (x1 == x2) { if (y1 < y2) { Console.WriteLine($"{x1 - diffY} {y2} {x1 - diffY} {y1}"); } else { Console.WriteLine($"{x1 + diffY} {y2} {x1 + diffY} {y1}"); } } else if (y1 == y2) { if (x1 < x2) { Console.WriteLine($"{x2} {y2 + diffX} {x1} {y1 + diffX}"); } else { Console.WriteLine($"{x2} {y2 - diffX} {x1} {y1 - diffX}"); } } else if (x1 < x2) { if (y1 < y2) { Console.WriteLine( $"{x2 - diffY} {y2 + diffX} {x1 - diffY} {y1 + diffX}"); } else { Console.WriteLine( $"{x2 + diffY} {y2 + diffX} {x1 + diffY} {y1 + diffX}"); } } else { if (y1 < y2) { Console.WriteLine( $"{x2 - diffY} {y2 - diffX} {x1 - diffY} {y1 - diffX}"); } else { Console.WriteLine( $"{x2 + diffY} {y2 - diffX} {x1 + diffY} {y1 - diffX}"); } } //デバッグ実行での確認用。そのまま提出しても問題なし Console.ReadKey(); } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["-", 75, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 75, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 17, 33], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 17, 72], ["-", 75, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 75, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 75, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["+", 75, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 17, 72], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 17, 33]]
8
429
28
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static Scanner input; static void Main() { input = new Scanner(); double[] xy12 = input.splitDouble(); double dx12 = xy12[2] - xy12[0]; double dy12 = xy12[3] - xy12[1]; double[] d_xy3 = new double[2] { dy12 * -1, dx12 }; double[] d_xy4 = new double[2] { d_xy3[1] * -1, d_xy3[0] }; WriteLine(xy12[2] + d_xy3[0] + " " + xy12[3] + d_xy3[1] + " " + xy12[2] + d_xy3[0] + d_xy4[0] + " " + xy12[3] + d_xy3[1] + d_xy4[1]); } } class Scanner { public Scanner() {} public void skip() { ReadLine(); return; } public string String() { return ReadLine(); } public string[] splitString() { return ReadLine().Split(); } public string[] linesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] jaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int Int() { return int.Parse(ReadLine()); } public int[] splitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] linesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] jaggedArrayInt(int len) { var arr = new int [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } return arr; } public long Long() { return long.Parse(ReadLine()); } public long[] splitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] linesLong(int len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] jaggedArrayLong(int len) { var arr = new long [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } return arr; } public double Double() { return double.Parse(ReadLine()); } public double[] splitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] linesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] jaggedArrayDouble(int len) { var arr = new double [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } return arr; } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static Scanner input; static void Main() { input = new Scanner(); double[] xy12 = input.splitDouble(); double dx12 = xy12[2] - xy12[0]; double dy12 = xy12[3] - xy12[1]; double[] d_xy3 = new double[2] { dy12 * -1, dx12 }; double[] d_xy4 = new double[2] { d_xy3[1] * -1, d_xy3[0] }; WriteLine((xy12[2] + d_xy3[0]) + " " + (xy12[3] + d_xy3[1]) + " " + (xy12[2] + d_xy3[0] + d_xy4[0]) + " " + (xy12[3] + d_xy3[1] + d_xy4[1])); } } class Scanner { public Scanner() {} public void skip() { ReadLine(); return; } public string String() { return ReadLine(); } public string[] splitString() { return ReadLine().Split(); } public string[] linesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] jaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int Int() { return int.Parse(ReadLine()); } public int[] splitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] linesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] jaggedArrayInt(int len) { var arr = new int [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } return arr; } public long Long() { return long.Parse(ReadLine()); } public long[] splitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] linesLong(int len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] jaggedArrayLong(int len) { var arr = new long [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } return arr; } public double Double() { return double.Parse(ReadLine()); } public double[] splitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] linesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] jaggedArrayDouble(int len) { var arr = new double [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } return arr; } }
[["+", 31, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 31, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
902
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int x1 = n[0]; int y1 = n[1]; int x2 = n[2]; int y2 = n[3]; int xc = x2 - x1; int yc = y2 - y1; Console.WriteLine(xc + " " + yc); Console.WriteLine("{0} {1} {2} {3}", x2 - yc, y2 + xc, x1 - yc, y1 + xc); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int x1 = n[0]; int y1 = n[1]; int x2 = n[2]; int y2 = n[3]; int xc = x2 - x1; int yc = y2 - y1; Console.WriteLine("{0} {1} {2} {3}", x2 - yc, y2 + xc, x1 - yc, y1 + xc); } } }
[["-", 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], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 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, 213, 3, 4, 0, 28, 0, 5, 0, 62]]
8
159
13
#pragma warning disable using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Diagnostics; using System.Numerics; using System.Collections; static class MainClass { public static void Main() { var xy = Console.ReadLine().SplittedStringToInt32List(); var x1 = xy[0]; var y1 = xy[1]; var x2 = xy[2]; var y2 = xy[3]; Console.WriteLine( $"{x2 - x1 - y2} {y1 - y2 + x2} {y1 - y2 + x1} {x2 - x1 + y1}"); } #region ライブラリ #region 二分探索 public static int LowerBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int 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 int LowerBound<T>(this IEnumerable<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } public static int UpperBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int 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 int UpperBound<T>(this IEnumerable<T> arr, T value) { return UpperBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } #endregion #region bit全探索 /// <summary> /// Bit全探索用のライブラリ /// </summary> /// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param> /// <returns>できた配列</returns> public static List<List<bool>> CreateBits(int len) { return CreateBitsPri(new List<List<bool>>(), len, 0); } private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count) { if (count == 0) { var lss = new List<bool>(); lss.Add(true); bits.Add(lss); var lx = new List<bool>(); lx.Add(false); bits.Add(lx); count++; return CreateBitsPri(bits, len, count); } if (len - count == 0) return bits; count++; var ls = new List<List<bool>>(); foreach (var item in bits) { var x = item.ToList(); x.Add(true); item.Add(false); ls.Add(item); ls.Add(x); } return CreateBitsPri(ls, len, count); } #endregion #region 文字列処理 public static int ToInt32(this string str) { return int.Parse(str); } public static List<string> SplittedStringToList(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } public static List<int> SplittedStringToInt32List(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)) .ToList(); } #endregion #region エラトステネスの篩 /** * MIT License Copyright (c) 2018 gushwell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **/ public class BoundedBoolArray { private BitArray _array; private int _lower; public BoundedBoolArray(int lower, int upper) { _array = new BitArray(upper - lower + 1); _lower = lower; } public bool this[int index] { get { return _array[index - _lower]; } set { _array[index - _lower] = value; } } } public static IEnumerable<int> GeneratePrimes() { var primes = new List<int>() { 2, 3 }; foreach (var p in primes) yield return p; int ix = 0; while (true) { int prime1st = primes[ix]; int prime2nd = primes[++ix]; var lower = prime1st * prime1st; var upper = prime2nd * prime2nd - 1; var sieve = new BoundedBoolArray(lower, upper); foreach (var prime in primes.Take(ix)) { var start = (int)Math.Ceiling((double)lower / prime) * prime; for (int index = start; index <= upper; index += prime) sieve[index] = true; } for (int i = lower; i <= upper; i++) { if (sieve[i] == false) { primes.Add(i); yield return i; } } } } #endregion #region DeepClone public static T DeepClone<T>(this T src) { using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); memoryStream.Seek(0, SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); } } #endregion #region 順列を作るやつ public static List<List<int>> GeneratePermutations(int n) { if (n > 14) throw new ArgumentOutOfRangeException(); var ls = new List<List<int>>(); ls.Add(new List<int>() { 1 }); for (int i = 0; i < n - 1; i++) { var newls = new List<List<int>>(); ls.ForEach(x => { var len = x.Count; for (int j = 0; j <= len; j++) { var item = x.DeepClone(); item.Insert(j, i + 2); newls.Add(item); } }); ls = newls; } return ls; } #endregion #endregion }
#pragma warning disable using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Diagnostics; using System.Numerics; using System.Collections; static class MainClass { public static void Main() { var xy = Console.ReadLine().SplittedStringToInt32List(); var x1 = xy[0]; var y1 = xy[1]; var x2 = xy[2]; var y2 = xy[3]; Console.WriteLine( $"{x2 + y1 - y2} {y2 - x1 + x2} {y1 - y2 + x1} {x2 - x1 + y1}"); Console.ReadLine(); } #region ライブラリ #region 二分探索 public static int LowerBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int 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 int LowerBound<T>(this IEnumerable<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } public static int UpperBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int 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 int UpperBound<T>(this IEnumerable<T> arr, T value) { return UpperBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } #endregion #region bit全探索 /// <summary> /// Bit全探索用のライブラリ /// </summary> /// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param> /// <returns>できた配列</returns> public static List<List<bool>> CreateBits(int len) { return CreateBitsPri(new List<List<bool>>(), len, 0); } private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count) { if (count == 0) { var lss = new List<bool>(); lss.Add(true); bits.Add(lss); var lx = new List<bool>(); lx.Add(false); bits.Add(lx); count++; return CreateBitsPri(bits, len, count); } if (len - count == 0) return bits; count++; var ls = new List<List<bool>>(); foreach (var item in bits) { var x = item.ToList(); x.Add(true); item.Add(false); ls.Add(item); ls.Add(x); } return CreateBitsPri(ls, len, count); } #endregion #region 文字列処理 public static int ToInt32(this string str) { return int.Parse(str); } public static List<string> SplittedStringToList(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } public static List<int> SplittedStringToInt32List(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)) .ToList(); } #endregion #region エラトステネスの篩 /** * MIT License Copyright (c) 2018 gushwell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **/ public class BoundedBoolArray { private BitArray _array; private int _lower; public BoundedBoolArray(int lower, int upper) { _array = new BitArray(upper - lower + 1); _lower = lower; } public bool this[int index] { get { return _array[index - _lower]; } set { _array[index - _lower] = value; } } } public static IEnumerable<int> GeneratePrimes() { var primes = new List<int>() { 2, 3 }; foreach (var p in primes) yield return p; int ix = 0; while (true) { int prime1st = primes[ix]; int prime2nd = primes[++ix]; var lower = prime1st * prime1st; var upper = prime2nd * prime2nd - 1; var sieve = new BoundedBoolArray(lower, upper); foreach (var prime in primes.Take(ix)) { var start = (int)Math.Ceiling((double)lower / prime) * prime; for (int index = start; index <= upper; index += prime) sieve[index] = true; } for (int i = lower; i <= upper; i++) { if (sieve[i] == false) { primes.Add(i); yield return i; } } } } #endregion #region DeepClone public static T DeepClone<T>(this T src) { using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); memoryStream.Seek(0, SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); } } #endregion #region 順列を作るやつ public static List<List<int>> GeneratePermutations(int n) { if (n > 14) throw new ArgumentOutOfRangeException(); var ls = new List<List<int>>(); ls.Add(new List<int>() { 1 }); for (int i = 0; i < n - 1; i++) { var newls = new List<List<int>>(); ls.ForEach(x => { var len = x.Count; for (int j = 0; j <= len; j++) { var item = x.DeepClone(); item.Insert(j, i + 2); newls.Add(item); } }); ls = newls; } return ls; } #endregion #endregion }
[["+", 0, 283, 0, 284, 0, 16, 31, 16, 17, 72], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 12, 22], ["-", 0, 283, 0, 284, 0, 16, 31, 16, 12, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 16, 17, 33], ["-", 0, 283, 0, 284, 0, 16, 31, 16, 31, 22], ["-", 0, 283, 0, 284, 0, 16, 31, 16, 17, 33], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 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
1,299
14
using System; namespace Atcoder { public class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int x1 = int.Parse(input[0]); int y1 = int.Parse(input[1]); int x2 = int.Parse(input[2]); int y2 = int.Parse(input[3]); int x3; int x4; int y3; int y4; x3 = x2 - (y2 - y1); y3 = y2 - (x1 - x2); x4 = x1 - (y2 - y1); y4 = y1 - (x1 - x2); Console.WriteLine(x3 + ' ' + y3 + ' ' + x4 + ' ' + y4); } } }
using System; namespace Atcoder { public class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int x1 = int.Parse(input[0]); int y1 = int.Parse(input[1]); int x2 = int.Parse(input[2]); int y2 = int.Parse(input[3]); int x3 = x2 - (y2 - y1); int y3 = y2 - (x1 - x2); int x4 = x1 - (y2 - y1); int y4 = y1 - (x1 - x2); Console.WriteLine(x3 + " " + y3 + " " + x4 + " " + y4); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 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, 1, 0, 11, 31, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 31, 16, 31, 16, 31, 16, 12, 252, 0, 104], ["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 252, 0, 104], ["+", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62]]
8
171
26
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); var N = int.Parse(inputs[0]); var K = int.Parse(inputs[1]); var num = 0; if (K % 2 == 0) { var harf = 0; for (var i = 1; i < N + 1; i++) { if (i % K == K / 2) { harf++; } } if (harf != 0) { if (N >= K) { num = (int)Math.Pow((double)(N / K), 3) + (int)Math.Pow((double)harf, 3); } else { num = (int)Math.Pow((double)harf, 3); } } } else { if (N >= K) { num = (int)Math.Pow((double)(N / K), 3); } } Console.WriteLine(num); Console.Read(); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); var N = long.Parse(inputs[0]); var K = long.Parse(inputs[1]); long num = 0; if (K % 2 == 0) { long harf = 0; for (var i = 1; i < N + 1; i++) { if (i % K == K / 2) { harf++; } } if (harf != 0) { if (N >= K) { num = (long)Math.Pow((double)(N / K), 3) + (long)Math.Pow((double)harf, 3); } else { num = (long)Math.Pow((double)harf, 3); } } } else { if (N >= K) { num = (long)Math.Pow((double)(N / K), 3); } } Console.WriteLine(num); Console.Read(); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["-", 75, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 75, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199]]
8
242
16
using System; using System.Collections.Generic; using System.Linq; 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 num = N / K; double ans = Math.Pow(num, 3); if (K % 2 == 0) { num = (N + K / 2) / K; ans += Math.Pow(num, 3); } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; 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 num = N / K; long ans = (long)Math.Pow(num, 3); if (K % 2 == 0) { num = (N + K / 2) / K; ans += (long)Math.Pow(num, 3); } Console.WriteLine(ans); } }
[["-", 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], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 0, 25]]
8
130
8
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var line = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = line[0], K = line[1]; var dict = new Dictionary<long, long>(); dict[K] = 0; for (var i = 1; i <= N; i++) { if (dict.ContainsKey(i % K)) dict[i % K]++; else dict[i % K] = 1; } var ret = 0L; for (var a = 0; a < K; a++) { var b = (K - a) % K; var c = (K - a) % K; if ((b + c) % K != 0) continue; ret += dict[a] * dict[b] * dict[c]; } Console.WriteLine(ret); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var line = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = line[0], K = line[1]; var dict = new Dictionary<long, long>(); dict[K] = 0; for (var i = 1; i <= N; i++) { if (dict.ContainsKey(i % K)) dict[i % K]++; else dict[i % K] = 1; } var ret = 0L; for (var a = 0; a < K; a++) { var b = (K - a) % K; var c = (K - a) % K; if ((b + c) % K != 0) continue; if (!dict.ContainsKey(a) || !dict.ContainsKey(b)) continue; ret += dict[a] * dict[b] * dict[c]; } Console.WriteLine(ret); } } }
[["+", 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, 241, 0, 111], ["+", 15, 16, 31, 241, 0, 213, 63, 214, 205, 22], ["+", 15, 16, 31, 241, 0, 213, 63, 214, 0, 131], ["+", 15, 16, 31, 241, 0, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 241, 0, 213, 3, 4, 0, 24], ["+", 31, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 31, 241, 0, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 111], ["+", 15, 16, 12, 241, 0, 213, 63, 214, 205, 22], ["+", 15, 16, 12, 241, 0, 213, 63, 214, 0, 131], ["+", 15, 16, 12, 241, 0, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 241, 0, 213, 3, 4, 0, 24], ["+", 12, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 12, 241, 0, 213, 3, 4, 0, 25], ["+", 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
219
20
using System; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { int N, K; ReadMulti(out N, out K); long divisible = N / K; if (IsOdd(K)) { WriteAnswer(Math.Pow(divisible, 3)); } else { var half = N / (K / 2) - divisible; WriteAnswer(Math.Pow(divisible, 3) + Math.Pow(half, 3)); } } 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.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { int N, K; ReadMulti(out N, out K); long d = N / K; if (IsOdd(K)) { WriteAnswer(d * d * d); } else { long h = N / (K / 2) - d; WriteAnswer(d * d * d + h * h * h); } } 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; } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 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], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 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, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 21], ["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 12, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22]]
8
762
47
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 K = NextInt(); if (K % 2 == 1) { int e = (int)Math.Floor(N / (K + .0)); Console.WriteLine(Math.Pow(e, 3)); } else { int a = (int)Math.Floor(N / (K + .0)); int b = (int)Math.Floor((N + (K / 2)) / (K + .0)); Console.WriteLine(Math.Pow(a, 3) + Math.Pow(b, 3)); } } } public class Input { private static Queue<string> queue = new Queue<string>(); private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); } public static string NextString() { Confirm(); return queue.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(queue.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 K = NextInt(); if (K % 2 == 1) { int e = (int)Math.Floor(N / (K + .0)); long ans = (long)Math.Pow(e, 3); Console.WriteLine(ans); } else { int a = (int)Math.Floor(N / (K + .0)); int b = (int)Math.Floor((N + (K / 2)) / (K + .0)); long ans = (long)Math.Pow(a, 3) + (long)Math.Pow(b, 3); Console.WriteLine(ans); } } } public class Input { private static Queue<string> queue = new Queue<string>(); private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); } public static string NextString() { Confirm(); return queue.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(queue.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(); } }
[["-", 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], ["+", 0, 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, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 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], ["-", 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], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 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]]
8
454
31
using System; using System.Linq; using System.Text.RegularExpressions; namespace abc108_c { class program { static void Main(string[] args) { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int K = input[1]; long ans = 0; if (K % 2 == 0) { K /= 2; for (int i = 1; i <= N / K; i++) { double max = ((double)i + (double)N / (double)K) / 2; double min = ((double)i + 1 / (double)K) / 2; ans += ((int)Math.Floor(max) - (int)Math.Ceiling(min) + 1) * ((int)Math.Floor(max) - (int)Math.Ceiling(min) + 1); } } else { for (int i = 1; i <= N / K; i++) { double max = (double)i + (double)N / (double)K; double min = (double)i + 1 / (double)K; ans += ((int)Math.Floor(max) - (int)Math.Ceiling(min) + 1) * ((int)Math.Floor(max) - (int)Math.Ceiling(min) + 1); } } Console.WriteLine(ans); } } }
using System; using System.Linq; using System.Text.RegularExpressions; namespace abc108_c { class program { static void Main(string[] args) { long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = input[0]; long K = input[1]; long ans = 0; if (K % 2 == 0) { K /= 2; for (long i = 1; i <= N / K; i++) { double max = ((double)i + (double)N / (double)K) / 2; double min = ((double)i + 1 / (double)K) / 2; ans += ((long)Math.Floor(max) - (long)Math.Ceiling(min) + 1) * ((long)Math.Floor(max) - (long)Math.Ceiling(min) + 1); } } else { for (long i = 1; i <= N / K; i++) { double max = (double)i + (double)N / (double)K; double min = (double)i + 1 / (double)K; ans += ((long)Math.Floor(max) - (long)Math.Ceiling(min) + 1) * ((long)Math.Floor(max) - (long)Math.Ceiling(min) + 1); } } Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["-", 31, 23, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 31, 23, 0, 16, 31, 16, 31, 74, 39, 199], ["-", 31, 23, 0, 16, 31, 16, 12, 74, 39, 199], ["+", 31, 23, 0, 16, 31, 16, 12, 74, 39, 199], ["-", 12, 23, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 12, 23, 0, 16, 31, 16, 31, 74, 39, 199], ["-", 12, 23, 0, 16, 31, 16, 12, 74, 39, 199], ["+", 12, 23, 0, 16, 31, 16, 12, 74, 39, 199], ["-", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 57, 75, 196, 0, 7, 10, 198, 39, 199]]
8
315
28
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = input[0]; int K = input[1]; int count1 = 0; int count2 = 0; int sum = 0; // Kの倍数である数値の個数を数える for (int i = 1; i <= N; i++) { if (i % K == 0) { count1 += 1; } } // 余りがKの半分となる数値の個数を数える for (int i = 1; i <= N; i++) { if (i % K == K / 2) { count2 += 1; } } sum += count1 * count1 * count1; if (K % 2 == 0) // Kが偶数のとき { sum += count2 * count2 * count2; } Console.WriteLine(sum); } }
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = input[0]; int K = input[1]; int count1 = 0; int count2 = 0; long sum = 0; // Kの倍数である数値の個数を数える for (int i = 1; i <= N; i++) { if (i % K == 0) { count1 += 1; } } // 余りがKの半分となる数値の個数を数える for (int i = 1; i <= N; i++) { if (i % K == K / 2) { count2 += 1; } } sum += (long)count1 * count1 * count1; if (K % 2 == 0) // Kが偶数のとき { sum += (long)count2 * count2 * count2; } Console.WriteLine(sum); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25]]
8
185
8
using System; public class C { public static void Main() { string[] args = Console.ReadLine().Split(' '); int n = Int32.Parse(args[0]); int k = Int32.Parse(args[1]); int num = n / k; long result = num * num * num; if (k % 2 == 0) { num = 0; for (int i = 1; i <= n; i++) { if (i % k == k / 2) num++; } result += num * num * num; } Console.WriteLine(result); } }
using System; public class C { public static void Main() { string[] args = Console.ReadLine().Split(' '); long n = Int64.Parse(args[0]); long k = Int64.Parse(args[1]); long num = n / k; long result = num * num * num; if (k % 2L == 0L) { num = 0L; for (long i = 1L; i <= n; i++) { if (i % k == k / 2L) num++; } result += num * num * num; } Console.WriteLine(result); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
134
22
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); if (k % 2 == 0) { var k2 = k / 2; var a0 = n / k; var a1 = (n - k2) / k + 1; var w1 = (long)Math.Pow(a0, 3) + (long)Math.Pow(a1, 3); Console.WriteLine(w1); } else { var a0 = n / k; var w1 = (long)Math.Pow(a0, 3); Console.WriteLine(w1); } } }
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); if (k % 2 == 0) { var k2 = k / 2; var a0 = n / k; int a1; if (n - k2 >= 0) a1 = (n - k2) / k + 1; else a1 = 0; var w1 = (long)Math.Pow(a0, 3) + (long)Math.Pow(a1, 3); Console.WriteLine(w1); } else { var a0 = n / k; var w1 = (long)Math.Pow(a0, 3); Console.WriteLine(w1); } } }
[["-", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 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, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 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], ["+", 64, 196, 0, 57, 75, 1, 0, 11, 12, 203]]
8
167
17
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); if (k % 2 == 0) { var k2 = k / 2; var a0 = 0; var a1 = 0; for (int i = 1; i <= n; i++) { if (i % k == 0) a0++; else if (i % k == k2) a1++; } Console.WriteLine(Math.Pow(a0, 3) + Math.Pow(a1, 3)); } else { var a0 = 0; for (int i = 1; i <= n; i++) if (i % k == 0) a0++; Console.WriteLine(Math.Pow(a0, 3)); } } }
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); if (k % 2 == 0) { var k2 = k / 2; var a0 = 0; var a1 = 0; for (int i = 1; i <= n; i++) { if (i % k == 0) a0++; else if (i % k == k2) a1++; } var w1 = (long)Math.Pow(a0, 3) + (long)Math.Pow(a1, 3); Console.WriteLine(w1); } else { var a0 = 0; for (int i = 1; i <= n; i++) if (i % k == 0) a0++; var w2 = (long)Math.Pow(a0, 3); Console.WriteLine(w2); } } }
[["-", 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, 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, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 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], ["-", 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, 197, 0, 198, 39, 216, 0, 217], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 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]]
8
200
31
using System; public class AtCoder { public static void Main() { string[] s; s = Console.ReadLine().Trim().Split(' '); double n, k; n = double.Parse(s[0]); k = double.Parse(s[1]); double x = Math.Floor(n / k); double y = Math.Floor(n / k - 0.5) + 1; double z; if (k % 2 == 1) { z = Math.Pow(x, 3); } else { z = Math.Pow(x, 3) + Math.Pow(y, 3); } Console.WriteLine(z); } }
using System; public class AtCoder { public static void Main() { string[] s; s = Console.ReadLine().Trim().Split(' '); double n, k; n = double.Parse(s[0]); k = double.Parse(s[1]); double x = Math.Floor(n / k); double y = Math.Floor(n / k - 0.5) + 1; long z; if (k % 2 == 1) { z = (long)Math.Pow(x, 3); } else { z = (long)Math.Pow(x, 3) + (long)Math.Pow(y, 3); } Console.WriteLine(z); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 25]]
8
151
11
using System; namespace Atcoder { public class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); if (k % 2 != 0) { int x = k; int b = 0; while (x <= n) { b++; x += k; } Console.WriteLine(b * b * b); } else { int x = k / 2; int b = 0; int sp = 0; bool isbaisuu = false; while (x <= n) { if (isbaisuu) { b++; isbaisuu = false; } else { sp++; isbaisuu = true; } x += k / 2; } Console.WriteLine(b * b * b + sp * sp * sp); } } } }
using System; namespace Atcoder { public class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); if (k % 2 != 0) { int x = k; int b = 0; while (x <= n) { b++; x += k; } Console.WriteLine((long)b * b * b); } else { int x = k / 2; int b = 0; int sp = 0; bool isbaisuu = false; while (x <= n) { if (isbaisuu) { b++; isbaisuu = false; } else { sp++; isbaisuu = true; } x += (k / 2); } Console.WriteLine((long)b * b * b + (long)sp * sp * sp); } } } }
[["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["+", 0, 16, 31, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 16, 31, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 16, 31, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 16, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 16, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 16, 12, 16, 31, 16, 31, 74, 0, 25]]
8
193
11
using System; class Program { static void Main() { long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long ans = 0; long q = 0; if ((s[1] & 1) == 0) { q = (s[0] - (s[1] / 2)) / s[1] + 1; ans += q * q * q; } if (s[0] >= s[1]) { q = s[0] / s[1]; ans += q * q * q; } Console.WriteLine("{0}", ans); } }
using System; class Program { static void Main() { long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long ans = 0; long q = 0; if ((s[1] & 1) == 0 && s[1] / 2 <= s[0]) { q = (s[0] - (s[1] / 2)) / s[1] + 1; ans += q * q * q; } if (s[0] >= s[1]) { q = s[0] / s[1]; ans += q * q * q; } Console.WriteLine("{0}", ans); } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 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, 85], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 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
141
12
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; class Program { static void Main() { int[] NK = ReadIntN(); int N = NK[0]; int K = NK[1]; long ans = 0; ans = (long)Pow(N / K, 3); if (K % 2 == 0) { ans += (long)Pow(((N - (K / 2)) / K + 1), 3); } WriteLine(ans); ReadLine(); return; } #region Reader static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrN() { return Console.ReadLine().Split(' '); } static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } static int[] ReadIntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } static long[] ReadLongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } static long[,] ReadLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReadTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReadTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadIntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReadTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReadAdjacencyList(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 = ReadIntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; class Program { static void Main() { long[] NK = ReadLongN(); long N = NK[0]; long K = NK[1]; long ans = (long)Pow(N / K, 3); if (K % 2 == 0) { ans += (long)Pow((N + (K / 2)) / K, 3); } WriteLine(ans); ReadLine(); return; } #region Reader static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrN() { return Console.ReadLine().Split(' '); } static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } static int[] ReadIntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } static long[] ReadLongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } static long[,] ReadLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReadTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReadTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadIntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReadTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReadAdjacencyList(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 = ReadIntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 11, 12, 74, 51, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 23, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 23, 0, 16, 12, 203], ["-", 51, 213, 3, 4, 0, 28, 0, 23, 0, 25]]
8
893
18
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nk = ReadLib.ReadAsIntArray(); var score = Calculation.Calculate(nk[0], nk[1]); Console.WriteLine(score); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { internal static long Calculate(int n, int k) { var p = n / k; var pcases = (long)Math.Pow(p, 3); if (k % 2 == 1) { return pcases; } var q = (n - k / 2) / k + 1; var qcases = (long)Math.Pow(q, 3); return pcases + qcases; } } static class RootedTreeNodesFactory { public class RootedTreeNode { public int Id { get; } public int Parent { get; } public int Depth { get; set; } int[] Childs { get; } public RootedTreeNode(int id, int parent, int[] childs) { this.Id = id; this.Parent = parent; this.Childs = childs; } } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>計数ソート</summary> public static int[] CountingSort(int[] aArr, int k) { int[] b, c; var n = aArr.Length; b = new int[n]; c = Enumerable.Repeat(0, k + 1).ToArray(); for (int i = 0; i < n; i++) { c[aArr[i]]++; } for (int i = 1; i <= k; i++) { c[i] += c[i - 1]; } for (int i = n - 1; i >= 0; i--) { b[c[aArr[i]] - 1] = aArr[i]; c[aArr[i]]--; } return b; } } /// <summary>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>拡張メソッドs</summary> static class Extention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var nk = ReadLib.ReadAsIntArray(); var score = Calculation.Calculate(nk[0], nk[1]); Console.WriteLine(score); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { internal static long Calculate(int n, int k) { var p = n / k; var pcases = (long)Math.Pow(p, 3); if (k % 2 == 1) { return pcases; } var q = (n - k / 2) / k + 1; var qcases = (n < (k / 2)) ? 0 : (long)Math.Pow(q, 3); return pcases + qcases; } } static class RootedTreeNodesFactory { public class RootedTreeNode { public int Id { get; } public int Parent { get; } public int Depth { get; set; } int[] Childs { get; } public RootedTreeNode(int id, int parent, int[] childs) { this.Id = id; this.Parent = parent; this.Childs = childs; } } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>計数ソート</summary> public static int[] CountingSort(int[] aArr, int k) { int[] b, c; var n = aArr.Length; b = new int[n]; c = Enumerable.Repeat(0, k + 1).ToArray(); for (int i = 0; i < n; i++) { c[aArr[i]]++; } for (int i = 1; i <= k; i++) { c[i] += c[i - 1]; } for (int i = n - 1; i >= 0; i--) { b[c[aArr[i]] - 1] = aArr[i]; c[aArr[i]]--; } return b; } } /// <summary>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>拡張メソッドs</summary> static class Extention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } }
[["+", 0, 212, 0, 41, 15, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 17, 18], ["+", 0, 41, 15, 23, 0, 16, 12, 23, 0, 24], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 17, 85], ["+", 15, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 41, 15, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 41, 15, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 200, 0, 212, 0, 41, 75, 74, 0, 24]]
8
3,242
12
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace AtCoder_Project_CSharp { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var t = Console.ReadLine(); var ss = s; for (int i = 0; i < s.Length; i++) { Console.WriteLine(ss); if (ss == t) { Console.WriteLine("Yes"); return; } ss = ss.Insert(0, ss.Last().ToString()).Remove(ss.Length); } Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace AtCoder_Project_CSharp { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var t = Console.ReadLine(); var ss = s; for (int i = 0; i < s.Length; i++) { if (ss == t) { Console.WriteLine("Yes"); return; } ss = ss.Insert(0, ss.Last().ToString()).Remove(ss.Length); } 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, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
143
7
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace ConsoleApplication1 { internal static class Program { public static void Main(string[] args) { Solve(Console.OpenStandardInput(), Console.OpenStandardOutput()); } internal static void Solve(Stream inputStream, Stream outputStream) { // ABC 103 B - String Rotation var scanner = new StreamScanner(inputStream); var writer = new StreamWriter(outputStream) { AutoFlush = false }; Action<string> Write = (string str) => writer.Write(str); Action<string> WriteLine = (string str) => writer.WriteLine(str); Action Flush = () => writer.Flush(); var s = scanner.Scan(); var t = scanner.Scan(); Console.WriteLine(s); if (s.Equals(t)) { WriteLine("Yes"); Flush(); return; } for (var i = 0; i < s.Length; i++) { // swap s = new string(s.Skip(1).ToArray()) + s.First().ToString(); if (s.Equals(t)) { WriteLine("Yes"); Flush(); return; } } WriteLine("No"); Flush(); } } // https://qiita.com/Camypaper/items/de6d576fe5513743a50e public class StreamScanner { private readonly Stream stream; private readonly byte[] buf = new byte[1024]; private int len, pos; private bool isEof = false; public bool IsEndOfStream => isEof; public StreamScanner(Stream stream) { this.stream = stream; } private byte Read() { if (isEof) throw new EndOfStreamException(); if (pos >= len) { pos = 0; if ((len = stream.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[pos++]; } public char Char() { byte b = 0; do b = Read(); while (b < 33 || 126 < b); 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 long Long() { long ret = 0; byte b = 0; var ng = false; do b = Read(); while (b != '-' && (b < '0' || '9' < b)); 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 (int)Long(); } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace ConsoleApplication1 { internal static class Program { public static void Main(string[] args) { Solve(Console.OpenStandardInput(), Console.OpenStandardOutput()); } internal static void Solve(Stream inputStream, Stream outputStream) { // ABC 103 B - String Rotation var scanner = new StreamScanner(inputStream); var writer = new StreamWriter(outputStream) { AutoFlush = false }; Action<string> Write = (string str) => writer.Write(str); Action<string> WriteLine = (string str) => writer.WriteLine(str); Action Flush = () => writer.Flush(); var s = scanner.Scan(); var t = scanner.Scan(); if (s.Equals(t)) { WriteLine("Yes"); Flush(); return; } for (var i = 0; i < s.Length; i++) { // swap s = new string(s.Skip(1).ToArray()) + s.First().ToString(); if (s.Equals(t)) { WriteLine("Yes"); Flush(); return; } } WriteLine("No"); Flush(); } } // https://qiita.com/Camypaper/items/de6d576fe5513743a50e public class StreamScanner { private readonly Stream stream; private readonly byte[] buf = new byte[1024]; private int len, pos; private bool isEof = false; public bool IsEndOfStream => isEof; public StreamScanner(Stream stream) { this.stream = stream; } private byte Read() { if (isEof) throw new EndOfStreamException(); if (pos >= len) { pos = 0; if ((len = stream.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[pos++]; } public char Char() { byte b = 0; do b = Read(); while (b < 33 || 126 < b); 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 long Long() { long ret = 0; byte b = 0; var ng = false; do b = Read(); while (b != '-' && (b < '0' || '9' < b)); 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 (int)Long(); } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } }
[["-", 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
654
7
using System; using System.Linq; using System.Collections.Generic; using System.Numerics; using static System.Console; class Program { internal static void Main(string[] args) { var S = ReadLine(); var T = ReadLine(); for (int i = 0; i < S.Length; i++) { var ans = true; var idx = 0; for (int j = i; j < S.Length; j++) { var tmp = j; if (j >= S.Length) { tmp -= S.Length; } if (S[tmp] != T[idx]) { ans = false; } idx++; } if (ans) { WriteLine("Yes"); return; } } WriteLine("No"); } }
using System; using System.Linq; using System.Collections.Generic; using System.Numerics; using static System.Console; class Program { internal static void Main(string[] args) { var S = ReadLine(); var T = ReadLine(); for (int i = 0; i < S.Length; i++) { var ans = true; var idx = 0; var tmp = i; for (int j = 0; j < S.Length; j++) { if (tmp >= S.Length) { tmp -= S.Length; } if (S[tmp] != T[idx]) { ans = false; } idx++; tmp++; } if (ans) { WriteLine("Yes"); return; } } WriteLine("No"); } }
[["+", 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], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 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], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22]]
8
166
17
using System; using System.Linq; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { WriteLine(ReadLineParseIntArray().Select(x => x - 1).Sum()); } static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
using System; using System.Linq; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { ReadLine(); WriteLine(ReadLineParseIntArray().Select(x => x - 1).Sum()); } static int ReadLineParseInt() => int.Parse(ReadLine()); static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 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, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 306, 0, 221], ["+", 0, 195, 8, 306, 0, 213, 63, 214, 205, 199], ["+", 0, 195, 8, 306, 0, 213, 63, 214, 0, 131], ["+", 0, 195, 8, 306, 0, 213, 63, 214, 141, 22], ["+", 0, 195, 8, 306, 0, 213, 3, 4, 0, 24], ["+", 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, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 306, 0, 213, 3, 4, 0, 25], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 0, 35]]
8
104
19
using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Security.Permissions; using System.Text; using static System.Console; using static System.Math; using static Ex; class AC { /*------------------------------------------------------------------*/ private int N; private int[] A; void Solve() { io.i(out N); io.ini(out A, N); A.Sum().Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] args) => new AC().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => WriteLine(f ? "YES" : "NO"); public void Yn(bool f) => WriteLine(f ? "Yes" : "No"); public void yn(bool f) => WriteLine(f ? "yes" : "no"); #endregion public IO() { SetOut(_sw); } } static class Ex { #region マクロもどき public static Dictionary<T1, T2> MERGE<T1, T2>(Dictionary<T1, T2> xs, Dictionary<T1, T2> ys) => xs.Except(xs.Join(ys, z => z.Key, z => z.Key, (a, b) => a)) .Concat(ys) .ToDictionary(z => z.Key, z => z.Value); public static void LOG<T>(T x, [CallerLineNumber] int line = 0) => Error.WriteLine($"--- LOG[{line}]: {x} ---"); public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void REP(int a, int b, Action<int, int> f) => REP(a, i => REP(b, j => f(i, j))); public static void REP(int a, int b, int c, Action<int, int, int> f) => REP(a, i => REP(b, j => REP(c, k => f(i, j, k)))); public static void REPEQ(int a, int b, Action<int, int> f) => REPEQ(a, i => REPEQ(b, j => f(i, j))); public static void REPEQ(int a, int b, int c, Action<int, int, int> f) => REPEQ(a, i => REPEQ(b, j => REPEQ(c, k => f(i, j, k)))); public static T MIN<T>(params T[] xs) => xs.Min(); public static T MAX<T>(params T[] xs) => xs.Max(); public static IEnumerable<int> RANGE(int s, int e) => Enumerable.Range(s, e - s + 1); public static int LCM(int a, int b) => a * (b / GCD(a, b)); public static int GCD(int a, int b) => (a < b) ? GCD(b, a) : b == 0 ? a : GCD(b, a % b); public static int LCM(params int[] xs) => xs.Aggregate(LCM); public static int GCD(params int[] xs) => xs.Aggregate(GCD); public static long LCM(long a, long b) => a * (b / GCD(a, b)); public static long GCD(long a, long b) => (a < b) ? GCD(b, a) : b == 0L ? a : GCD(b, a % b); public static long LCM(params long[] xs) => xs.Aggregate(LCM); public static long GCD(params long[] xs) => xs.Aggregate(GCD); #endregion #region 拡張メソッド public static void Rep(this int x, Action<int> f) => REP(x, f); public static void RepEq(this int x, Action<int> f) => REPEQ(x, f); public static int ToInt(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt32(n); } public static int ToInt(this char c) => ToInt(c.ToString()); public static int ToInt(this char[] c) => ToInt(new string(c)); public static long ToLong(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt64(n); } public static long ToLong(this int x) => (long)x; public static IEnumerable<long> ToLong(this IEnumerable<int> xs) => xs.Select(x => x.ToLong()); public static long ToLong(this char c) => ToLong(c.ToString()); public static long ToLong(this char[] c) => ToLong(new string(c)); public static int ToMod(this int x) => x % (int)(1e9 + 7); public static long ToMod(this long x) => x % (long)(1e9 + 7); public static void Do<T>(this T x, Action<T> f) => f(x); public static TU Then<T, TU>(this T x, Func<T, TU> f) => f(x); public static void Fun<T>(this T[] xs, Action<int> f) => REP(xs.Length, f); public static void Fun<T>(this T[,] xxs, Action<int, int> f) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => f(i, j))); public static bool IsIn<T>(this T[] xs, int i) => 0 <= i && i < xs.Length; public static bool IsIn<T>(this T[,] xxs, int i, int j) => 0 <= i && i < xxs.GetLength(0) && 0 <= j && j < xxs.GetLength(1); public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public class IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public static IEnumerable<IndexedItem<T>> Indexed<T>( this IEnumerable<T> xs) => xs.Select((x, i) => new IndexedItem<T>(i, x)); public static Dictionary<long, int> PrimeFactor(this int x) => ((long)x).PrimeFactor(); public static Dictionary<long, int> PrimeFactor(this long n) { var ret = new Dictionary<long, int>(); for (var i = 2; i <= n; ++i) { if (!ret.ContainsKey(i)) ret[i] = 0; while (n % i == 0) { ++ret[i]; n /= i; } } return ret.Where(kp => kp.Value != 0) .ToDictionary(kp => kp.Key, kp => kp.Value); } public static void Set<T>(this T[] xs, T v) => REP(xs.Length, i => xs[i] = v); public static void Set<T>(this T[,] xxs, T v) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => xxs[i, j] = v)); public static T[] Sort<T>(this T[] xs) { Array.Sort(xs); return xs; } public static T[] SortR<T>(this T[] xs) { Array.Reverse(xs.Sort()); return xs; } public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0'); public static int RoundOff(this double v, int n) => (int) Round(v, n - 1, MidpointRounding.AwayFromZero); public static int RoundUp(this double v) => (int)Ceiling(v); public static int RoundDown(this double v) => (int)Floor(v); public static bool Odd(this int v) => (v & 1) != 0; public static bool Odd(this long v) => (v & 1) != 0; public static bool Eve(this int v) => !v.Odd(); public static bool Eve(this long v) => !v.Odd(); public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this List<T> xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this T[,] xs) => xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Write($"{xs[i, j]} ")); WriteLine(); }); public static void Prt_<T>(this T[] xs) => WriteLine(string.Join(" ", xs)); public static void Log<T>(this T x, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"--- LOG[{line}]: {x} ---"); #endif } public static void Log<T>(this T[] xs, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"^^^ LOG[{line}] ^^^"); xs.Iter(x => Error.WriteLine(x)); Error.WriteLine($"vvv LOG[{line}] vvv\n"); #endif } public static void Log<T>(this T[,] xs, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"^^^ LOG[{line}] ^^^"); xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Error.Write($"{xs[i, j]} ")); Error.WriteLine(); }); Error.WriteLine($"vvv LOG[{line}] vvv\n"); #endif } public static string Reversed(this string s) => string.Join("", s.Reverse()); public static string Repeat(this string s, int n) => string.Concat(Enumerable.Repeat(s, n).ToArray()); #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Security.Permissions; using System.Text; using static System.Console; using static System.Math; using static Ex; class AC { /*------------------------------------------------------------------*/ private int N; private int[] A; void Solve() { io.i(out N); io.ini(out A, N); A.Select(x => x - 1).Sum().Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] args) => new AC().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => WriteLine(f ? "YES" : "NO"); public void Yn(bool f) => WriteLine(f ? "Yes" : "No"); public void yn(bool f) => WriteLine(f ? "yes" : "no"); #endregion public IO() { SetOut(_sw); } } static class Ex { #region マクロもどき public static Dictionary<T1, T2> MERGE<T1, T2>(Dictionary<T1, T2> xs, Dictionary<T1, T2> ys) => xs.Except(xs.Join(ys, z => z.Key, z => z.Key, (a, b) => a)) .Concat(ys) .ToDictionary(z => z.Key, z => z.Value); public static void LOG<T>(T x, [CallerLineNumber] int line = 0) => Error.WriteLine($"--- LOG[{line}]: {x} ---"); public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void REP(int a, int b, Action<int, int> f) => REP(a, i => REP(b, j => f(i, j))); public static void REP(int a, int b, int c, Action<int, int, int> f) => REP(a, i => REP(b, j => REP(c, k => f(i, j, k)))); public static void REPEQ(int a, int b, Action<int, int> f) => REPEQ(a, i => REPEQ(b, j => f(i, j))); public static void REPEQ(int a, int b, int c, Action<int, int, int> f) => REPEQ(a, i => REPEQ(b, j => REPEQ(c, k => f(i, j, k)))); public static T MIN<T>(params T[] xs) => xs.Min(); public static T MAX<T>(params T[] xs) => xs.Max(); public static IEnumerable<int> RANGE(int s, int e) => Enumerable.Range(s, e - s + 1); public static int LCM(int a, int b) => a * (b / GCD(a, b)); public static int GCD(int a, int b) => (a < b) ? GCD(b, a) : b == 0 ? a : GCD(b, a % b); public static int LCM(params int[] xs) => xs.Aggregate(LCM); public static int GCD(params int[] xs) => xs.Aggregate(GCD); public static long LCM(long a, long b) => a * (b / GCD(a, b)); public static long GCD(long a, long b) => (a < b) ? GCD(b, a) : b == 0L ? a : GCD(b, a % b); public static long LCM(params long[] xs) => xs.Aggregate(LCM); public static long GCD(params long[] xs) => xs.Aggregate(GCD); #endregion #region 拡張メソッド public static void Rep(this int x, Action<int> f) => REP(x, f); public static void RepEq(this int x, Action<int> f) => REPEQ(x, f); public static int ToInt(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt32(n); } public static int ToInt(this char c) => ToInt(c.ToString()); public static int ToInt(this char[] c) => ToInt(new string(c)); public static long ToLong(this string s) { double n; double.TryParse(s.TrimStart('0'), out n); return Convert.ToInt64(n); } public static long ToLong(this int x) => (long)x; public static IEnumerable<long> ToLong(this IEnumerable<int> xs) => xs.Select(x => x.ToLong()); public static long ToLong(this char c) => ToLong(c.ToString()); public static long ToLong(this char[] c) => ToLong(new string(c)); public static int ToMod(this int x, int mod = (int)(1e9 + 7)) => x % mod; public static long ToMod(this long x, long mod = (long)(1e9 + 7)) => x % mod; public static void Do<T>(this T x, Action<T> f) => f(x); public static TU Then<T, TU>(this T x, Func<T, TU> f) => f(x); public static void Fun<T>(this T[] xs, Action<int> f) => REP(xs.Length, f); public static void Fun<T>(this T[,] xxs, Action<int, int> f) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => f(i, j))); public static bool IsIn<T>(this T[] xs, int i) => 0 <= i && i < xs.Length; public static bool IsIn<T>(this T[,] xxs, int i, int j) => 0 <= i && i < xxs.GetLength(0) && 0 <= j && j < xxs.GetLength(1); public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public class IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public static IEnumerable<IndexedItem<T>> Indexed<T>( this IEnumerable<T> xs) => xs.Select((x, i) => new IndexedItem<T>(i, x)); public static Dictionary<long, int> PrimeFactor(this int x) => ((long)x).PrimeFactor(); public static Dictionary<long, int> PrimeFactor(this long n) { var ret = new Dictionary<long, int>(); for (var i = 2; i <= n; ++i) { if (!ret.ContainsKey(i)) ret[i] = 0; while (n % i == 0) { ++ret[i]; n /= i; } } return ret.Where(kp => kp.Value != 0) .ToDictionary(kp => kp.Key, kp => kp.Value); } public static void Set<T>(this T[] xs, T v) => REP(xs.Length, i => xs[i] = v); public static void Set<T>(this T[,] xxs, T v) => REP(xxs.GetLength(0), i => REP(xxs.GetLength(1), j => xxs[i, j] = v)); public static T[] Sort<T>(this T[] xs) { Array.Sort(xs); return xs; } public static T[] SortR<T>(this T[] xs) { Array.Reverse(xs.Sort()); return xs; } public static string Pad0<T>(this T s, int n) => s.ToString().PadLeft(n, '0'); public static int RoundOff(this double v, int n) => (int) Round(v, n - 1, MidpointRounding.AwayFromZero); public static int RoundUp(this double v) => (int)Ceiling(v); public static int RoundDown(this double v) => (int)Floor(v); public static bool Odd(this int v) => (v & 1) != 0; public static bool Odd(this long v) => (v & 1) != 0; public static bool Eve(this int v) => !v.Odd(); public static bool Eve(this long v) => !v.Odd(); public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this T[] xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this List<T> xs) => xs.Iter(x => WriteLine(x)); public static void Prt<T>(this T[,] xs) => xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Write($"{xs[i, j]} ")); WriteLine(); }); public static void Prt_<T>(this T[] xs) => WriteLine(string.Join(" ", xs)); public static void Log<T>(this T x, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"--- LOG[{line}]: {x} ---"); #endif } public static void Log<T>(this T[] xs, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"^^^ LOG[{line}] ^^^"); xs.Iter(x => Error.WriteLine(x)); Error.WriteLine($"vvv LOG[{line}] vvv\n"); #endif } public static void Log<T>(this T[,] xs, [CallerLineNumber] int line = 0) { #if DEBUG Error.WriteLine($"^^^ LOG[{line}] ^^^"); xs.GetLength(0).Rep(i => { xs.GetLength(1).Rep(j => Error.Write($"{xs[i, j]} ")); Error.WriteLine(); }); Error.WriteLine($"vvv LOG[{line}] vvv\n"); #endif } public static string Reversed(this string s) => string.Join("", s.Reverse()); public static string Repeat(this string s, int n) => string.Concat(Enumerable.Repeat(s, n).ToArray()); #endregion }
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 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], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["-", 0, 235, 8, 201, 0, 195, 8, 306, 0, 221], ["-", 8, 201, 0, 195, 8, 306, 0, 16, 31, 22], ["-", 8, 201, 0, 195, 8, 306, 0, 16, 17, 109], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 195, 54, 55, 0, 220, 0, 212, 0, 32], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 306, 0, 221], ["+", 8, 201, 0, 195, 8, 306, 0, 16, 31, 22], ["+", 8, 201, 0, 195, 8, 306, 0, 16, 17, 109], ["+", 8, 201, 0, 195, 8, 306, 0, 16, 12, 22], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 220, 0, 212, 0, 74, 51, 23, 0, 25]]
8
3,571
35
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc103 /// 2020/02/02 /// </summary> namespace ABC103 { public class Program { public static void Main(string[] args) { // A(); 8m // B(); 17m // C(); 50m D(); } public static void D() { long N = rl; long M = rl; Dictionary<long, long> G = new Dictionary<long, long>(); for (int i = 0; i < M; i++) { long a = rl; long b = rl; if (G.ContainsKey(a)) { G[a] = Min(G[a], b); } else { G[a] = b; } } long ans = 0; long right = INF; foreach (var key in G.Keys.OrderBy(n => n)) { if (right <= key) { ans++; } ChMin(ref right, Min(key, G[key])); } ans++; Console.WriteLine(ans); } public static void C() { int N = ReadInt(); int[] A = ReadIntArray(); long ans = 0; for (int i = 0; i < N; i++) { ans += A[i] - 1; } Console.WriteLine(ans); } public static void B() { string S = ReadString(); string T = ReadString(); int len = S.Length; bool ok = true; for (int i = 0; i < S.Length; i++) { ok = true; for (int j = 0; j < S.Length; j++) { if (T[j] != S[(j + i) % len]) { ok = false; break; } } if (ok) break; } Console.WriteLine(ok ? "Yes" : "No"); } public static void A() { long[] A = rla; Sort(A); long ans = 0; for (int i = 0; i <= 1; i++) { ans += A[i + 1] - A[i]; } Console.WriteLine(ans); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc103 /// 2020/02/02 /// </summary> namespace ABC103 { public class Program { public static void Main(string[] args) { // A(); 8m // B(); 17m // C(); 50m D(); } public static void D() { long N = rl; long M = rl; Dictionary<long, long> G = new Dictionary<long, long>(); for (int i = 0; i < M; i++) { long a = rl; long b = rl; if (G.ContainsKey(a)) { G[a] = Min(G[a], b); } else { G[a] = b; } } long ans = 0; long right = INF; foreach (var left in G.Keys.OrderBy(n => n)) { if (right <= left) { ans++; right = G[left]; } else { ChMin(ref right, G[left]); } } ans++; Console.WriteLine(ans); } public static void C() { int N = ReadInt(); int[] A = ReadIntArray(); long ans = 0; for (int i = 0; i < N; i++) { ans += A[i] - 1; } Console.WriteLine(ans); } public static void B() { string S = ReadString(); string T = ReadString(); int len = S.Length; bool ok = true; for (int i = 0; i < S.Length; i++) { ok = true; for (int j = 0; j < S.Length; j++) { if (T[j] != S[(j + i) % len]) { ok = false; break; } } if (ok) break; } Console.WriteLine(ok ? "Yes" : "No"); } public static void A() { long[] A = rla; Sort(A); long ans = 0; for (int i = 0; i <= 1; i++) { ans += A[i + 1] - A[i]; } Console.WriteLine(ans); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 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, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["+", 0, 210, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 75, 196, 0, 46]]
8
3,654
21
using System; using System.Collections.Generic; using System.Linq; namespace D { class Program { static void Main(string[] args) { int[] NM = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray(); List<Tuple<int, int>> req = Enumerable.Range(0, NM[1]) .Select(i => { int[] ab = Console.ReadLine() .Split() .Select(j => Convert.ToInt32(j)) .ToArray(); return new Tuple<int, int>(ab[0], ab[1]); }) .OrderByDescending(i => i) .ToList(); int ans = 0; int edge = NM[0] + 1; req.ForEach(i => { if (i.Item1 < edge && i.Item2 < edge) { ans++; edge = i.Item1; } }); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace D { class Program { static void Main(string[] args) { int[] NM = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray(); int ans = 0; int edge = NM[0] + 1; Enumerable.Range(0, NM[1]) .Select(i => { int[] ab = Console.ReadLine() .Split() .Select(j => Convert.ToInt32(j)) .ToArray(); return new Tuple<int, int>(ab[0], ab[1]); }) .OrderByDescending(i => i) .ToList() .ForEach(i => { if (i.Item1 < edge && i.Item2 <= edge) { ans++; edge = i.Item1; } }); Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 18], ["-", 0, 198, 39, 236, 237, 238, 0, 236, 141, 22], ["-", 39, 236, 237, 238, 0, 236, 237, 238, 0, 18], ["-", 39, 236, 237, 238, 0, 236, 237, 238, 0, 21], ["+", 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], ["-", 39, 236, 237, 238, 0, 236, 237, 238, 0, 47], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 47], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 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, 203], ["+", 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, 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 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, 203], ["-", 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, 203], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
215
39
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace ABC103D { class Program { static void Solve() { var n = Input.NextInt(); var m = Input.NextInt(); var list = new List<Tuple<int, int>>(); for (int i = 0; i < m; i++) { var a = Input.NextInt(); var b = Input.NextInt(); list.Add(new Tuple<int, int>(a, b)); } list.Sort((x, y) => x.Item1 - y.Item1); int right = list[0].Item2; var count = 0; for (int i = 1; i < m; i++) { if (right < list[i].Item1) { // ここでぶった切る count++; } right = Math.Min(right, list[i].Item2); } count++; Console.WriteLine(count); } #region Competitive Template public static void Main(string[] args) { var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 仮想的に標準入力をセットする // NextLine系を使っていると使えない // Input.SetText(""); Solve(); Console.Out.Flush(); } static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace ABC103D { class Program { static void Solve() { var n = Input.NextInt(); var m = Input.NextInt(); var list = new List<Tuple<int, int>>(); for (int i = 0; i < m; i++) { var a = Input.NextInt(); var b = Input.NextInt(); list.Add(new Tuple<int, int>(a, b)); } list.Sort((x, y) => x.Item2 - y.Item2); int right = 0; var count = 0; for (int i = 0; i < m; i++) { if (right <= list[i].Item1) { right = list[i].Item2; // ここでぶった切る count++; } } Console.WriteLine(count); } #region Competitive Template public static void Main(string[] args) { var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 仮想的に標準入力をセットする // NextLine系を使っていると使えない // Input.SetText(""); Solve(); Console.Out.Flush(); } static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } #endregion } }
[["-", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 214, 205, 204, 205, 22], ["-", 0, 212, 0, 214, 205, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 214, 205, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 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, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 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], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
869
27
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { int answer = 0; int lastPosition = -1; string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 int n = int.Parse(input[0]); int m = int.Parse(input[1]); List<int[]> bridgeList = new List<int[]>(); for (int i = 0; i < m; i++) { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); //1行ごとに受け取る bridgeList.Add(new int[2] { nums[0] - 1, nums[1] - 1 }); } bridgeList.OrderBy(a => a[1]).ThenBy(a => a[0]); for (int i = 0; i < m; i++) { if (bridgeList[i][1] > lastPosition + 1 && bridgeList[i][0] > lastPosition) answer++; lastPosition = bridgeList[i][1] - 1; } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { int answer = 0; int lastPosition = -1; string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 int n = int.Parse(input[0]); int m = int.Parse(input[1]); List<int[]> bridgeList = new List<int[]>(); for (int i = 0; i < m; i++) { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); //1行ごとに受け取る bridgeList.Add(new int[2] { nums[0] - 1, nums[1] - 1 }); } bridgeList.Sort((a, b) => a[1].CompareTo(b[1])); for (int i = 0; i < m; i++) { if (bridgeList[i][1] > lastPosition + 1 && bridgeList[i][0] > lastPosition) { answer++; lastPosition = bridgeList[i][1] - 1; } } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 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, 218, 54, 55, 0, 21], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 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, 204, 205, 22], ["+", 8, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 0, 218, 8, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
256
18
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.IO; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray(int n) { var array = Array(); var result = new int[n]; for (int i = 0; i < n; i++) { result[i] = int.Parse(array[i]); } return result; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } public uint NextUint() { return uint.Parse(Next()); } } struct S { public int A, B; public S(int a, int b) { A = a; B = b; } } class Program { private int N, M; private S[] S; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); M = sc.NextInt(); S = new S[M]; for (int i = 0; i < M; i++) { S[i] = new S(sc.NextInt() - 1, sc.NextInt() - 1); } } public void Solve() { Scan(); Array.Sort(S, (a, b) => { if (a.A == b.A) { return -a.B.CompareTo(b.B); } else { return a.A.CompareTo(b.A); } }); int left = -1; int right = N; int cnt = 0; bool flag = true; // Console.WriteLine(); for (int i = 0; i < M; i++) { if (left < S[i].A) { left = S[i].A; } right = Math.Min(right, S[i].B); if (right <= left) { cnt++; left = S[i - 1].A + 1; right = N; flag = false; continue; } flag = true; } if (right > left && flag) cnt++; Console.WriteLine(cnt); } static void Main() => new Program().Solve(); } }
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.IO; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray(int n) { var array = Array(); var result = new int[n]; for (int i = 0; i < n; i++) { result[i] = int.Parse(array[i]); } return result; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } public uint NextUint() { return uint.Parse(Next()); } } struct S { public int A, B; public S(int a, int b) { A = a; B = b; } } class Program { private int N, M; private S[] S; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); M = sc.NextInt(); S = new S[M]; for (int i = 0; i < M; i++) { S[i] = new S(sc.NextInt() - 1, sc.NextInt() - 1); } } public void Solve() { Scan(); Array.Sort(S, (a, b) => { if (a.A == b.A) { return -a.B.CompareTo(b.B); } else { return a.A.CompareTo(b.A); } }); int left = -1; int right = N; int cnt = 0; bool flag = true; // Console.WriteLine(); for (int i = 0; i < M; i++) { if (left < S[i].A) { left = S[i].A; } right = Math.Min(right, S[i].B); if (right <= left) { cnt++; left = S[i].A; right = S[i].B; flag = false; continue; } flag = true; } if (right > left) cnt++; Console.WriteLine(cnt); } static void Main() => new Program().Solve(); } }
[["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 1, 0, 11, 12, 214, 205, 204, 205, 22], ["+", 0, 11, 12, 214, 205, 204, 206, 207, 0, 70], ["+", 12, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 214, 205, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
716
13
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var l = 0; var r = 0; var count = 0; while (r < N) { if (A[l] == A[r]) { r++; } else { count += (r - l + 1) / 2; l = r; } } count += (r - l) / 2; Console.WriteLine(count); } }
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var l = 0; var r = 0; var count = 0; while (r < N) { if (A[l] == A[r]) { r++; } else { count += (r - l) / 2; l = r; } if (r == N) { count += (r - l) / 2; } // Console.WriteLine(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, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 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, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
8
145
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace workspace { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] an = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int ans = 0; for (int i = 0; i < an.Length - 2; i++) { if (an[i] == an[i + 1]) { if (an[i + 1] == an[i + 2]) { an[i + 1] = an[i] + 1 > 10000 ? an[i] - 1 : an[i] + 1; } an[i] = an[i + 1] + 1 > 10000 ? an[i] - 1 : an[i] + 1; ans++; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace workspace { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] an = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int ans = 0; for (int i = 0; i < an.Length - 2; i++) { if (an[i] == an[i + 1]) { if (an[i + 1] == an[i + 2]) { an[i + 1] = an[i] + 1 > 10000 ? an[i] - 1 : an[i] + 1; } an[i] = an[i + 1] + 1 > 10000 ? an[i] - 1 : an[i] + 1; ans++; } } if (an[an.Length - 2] == an[an.Length - 1]) ans++; Console.WriteLine(ans); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
218
23
using System; using System.Linq; namespace AGC026_A { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var cnt = 0; for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) { cnt++; i++; } } } } }
using System; using System.Linq; namespace AGC026_A { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var cnt = 0; for (int i = 0; i < n - 1; i++) { if (a[i] == a[i + 1]) { cnt++; i++; } } Console.WriteLine(cnt); } } }
[["+", 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
110
7
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() { for (; T > 0; T--) { Read(); var chk = Check(); Console.WriteLine(chk ? "Yes" : "No"); } } bool Check() { long a = A, b = B, c = C, d = D; if (b > a) { return false; } a -= b; // Console.WriteLine("a:{0}",a); if (a > c) { a -= (((a - c) + b - 1) / b) * b; } // Console.WriteLine("a:{0}",a); if (a < 0) return false; // Console.WriteLine("1"); if (a <= C - D) return false; // Console.WriteLine("2"); if (D < B) return false; // if(D == B) return true; var unit = gcd(D, B); // Console.WriteLine("unit:{0}",unit); a += (((C - a + 1) + unit - 1) / unit) * unit; // Console.WriteLine("a:{0}",a); return (a - B >= Math.Max(0, C - D)); } long gcd(long a, long b) { return a == 0 ? b : gcd(b % a, a); } void Read() { var d = rla(); A = d[0]; B = d[1]; C = d[2]; D = d[3]; } int T; long A, B, C, D; public Sol() { T = ri(); } 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() { for (; T > 0; T--) { Read(); var chk = Check(); Console.WriteLine(chk ? "Yes" : "No"); } } bool Check() { long a = A, b = B, c = C, d = D; if (b > a) { return false; } a -= b; // Console.WriteLine("a:{0}",a); if (a > c) { a -= (((a - c) + b - 1) / b) * b; } // Console.WriteLine("a:{0}",a); if (a < 0) return false; // Console.WriteLine("1"); // if(a <= C - D) return false; // Console.WriteLine("2"); if (D < B) return false; // if(D == B) return true; var unit = gcd(D, B); // Console.WriteLine("unit:{0}",unit); a += (((C - a + 1) + unit - 1) / unit) * unit; // Console.WriteLine("a:{0}",a); return (a - B >= Math.Max(0, C - D)); } long gcd(long a, long b) { return a == 0 ? b : gcd(b % a, a); } void Read() { var d = rla(); A = d[0]; B = d[1]; C = d[2]; D = d[3]; } int T; long A, B, C, D; public Sol() { T = ri(); } 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, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 37, 0, 211, 0, 147], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24]]
8
564
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoundHound_Inc { class Program { static void Main(string[] args) { int a, b, c, d, f; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = a + b; d = a * b; f = 15; if (!(c > f && c < f)) { Console.WriteLine("+"); } else if (!(d > f && d < f)) { Console.WriteLine("*"); } else { Console.WriteLine("x"); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoundHound_Inc { class Program { static void Main(string[] args) { int a, b, c, d, f; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = a + b; d = a * b; f = 15; if (!(c > f) && (!(c < f))) { Console.WriteLine("+"); } else if (!(d > f) && (!(d < f))) { Console.WriteLine("*"); } else { Console.WriteLine("x"); } Console.ReadKey(); } } }
[["+", 0, 57, 15, 16, 31, 241, 0, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 23, 0, 241, 0, 111], ["+", 15, 16, 12, 23, 0, 241, 0, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 241, 0, 23, 0, 25], ["+", 75, 57, 15, 16, 31, 241, 0, 23, 0, 25], ["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 24], ["+", 75, 57, 15, 16, 12, 23, 0, 241, 0, 111]]
8
180
10
using System; namespace ProCon_ { class Program { static void Main(string[] args) { string input = ""; input = Console.ReadLine(); char[] li = new char[input.Length]; li = input.ToCharArray(); bool judge = li[0] == 'A'; int count_C = 0; for (int i = 2; i < input.Length - 1; i++) { if (li[i] == 'C') { count_C++; li[i] = 'c'; } } if (count_C == 1) judge = true; else judge = false; li[0] = 'a'; foreach (char c in li) { judge = judge && !Char.IsUpper(c); } if (judge) { Console.WriteLine("AC"); } else Console.WriteLine("WA"); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProCon_ { class Program { static void Main(string[] args) { string input = ""; input = Console.ReadLine(); char[] li = new char[input.Length]; li = input.ToCharArray(); bool judge = li[0] == 'A'; int count_C = 0; for (int i = 2; i < input.Length - 1; i++) { if (li[i] == 'C') { count_C++; li[i] = 'c'; } } if (count_C == 1) { judge = judge && true; } else judge = judge && false; li[0] = 'a'; foreach (char c in li) { judge = judge && !Char.IsUpper(c); } if (judge) { Console.WriteLine("AC"); } else Console.WriteLine("WA"); Console.ReadLine(); } } }
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 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], ["+", 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], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 98], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 17, 98]]
8
195
30
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); if (!S.StartsWith("A")) { Console.WriteLine("WA"); return; } var tmp = S.Substring(2, S.Length - (S.Length - 4)); if (tmp.Where(x => x == 'C').ToList().Count != 1) { Console.WriteLine("WA"); return; } var cindex = tmp.IndexOf('C') + 2; S = S.Remove(cindex, 1).Remove(0, 1); bool ret = false; foreach (var item in S) { ret = new Regex("[a-z]").IsMatch(item.ToString()); if (!ret) { break; } } if (ret) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); // 条件を順番に潰していく。 // WAの条件に引っかかった時点で出力し、最後まで残ったものがACになる。 // Aから始まるか判定 if (!S.StartsWith("A")) { Console.WriteLine("WA"); return; } // 3文字目と末尾から2文字目の間にCがあるか判定 var tmp = S.Substring(2, S.Length - 3); if (tmp.Where(x => x == 'C').ToList().Count != 1) { Console.WriteLine("WA"); return; } // 3文字目と末尾から2文字目に存在する大文字Cの位置を求める var cindex = tmp.IndexOf('C') + 2; // AとCを消す S = S.Remove(cindex, 1).Remove(0, 1); bool ret = true; foreach (var item in S) { if (char.IsUpper(item)) { ret = false; break; } } if (ret) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } } }
[["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 16, 12, 23, 0, 16, 31, 214, 205, 22], ["-", 0, 16, 12, 23, 0, 16, 31, 214, 0, 131], ["-", 0, 16, 12, 23, 0, 16, 31, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 11, 12, 213, 63, 214, 205, 230, 0, 228], ["-", 0, 11, 12, 213, 63, 214, 205, 230, 39, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 205, 230, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 205, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 12, 213, 63, 214, 205, 230, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["-", 0, 210, 8, 196, 0, 57, 15, 241, 0, 111], ["-", 0, 210, 8, 196, 0, 57, 15, 241, 0, 22], ["-", 8, 196, 0, 210, 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, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
241
8
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); if (!S.StartsWith("A")) { Console.WriteLine("WA"); return; } var tmp = S.Substring(2, S.Length - (S.Length - 4)); if (tmp.Where(x => x == 'C').ToList().Count != 1) { Console.WriteLine("WA"); return; } var cindex = tmp.IndexOf('C') + 2; S = S.Remove(cindex, 1).Remove(0, 1); bool ret = false; foreach (var item in S) { ret = new Regex("[a-z]").IsMatch(item.ToString()); if (!ret) { break; } } if (ret) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); // 条件を順番に潰していく。 // WAの条件に引っかかった時点で出力し、最後まで残ったものがACになる。 // Aから始まるか判定 if (!S.StartsWith("A")) { Console.WriteLine("WA"); return; } // 3文字目と末尾から2文字目の間にCがあるか判定 var tmp = S.Substring(2, S.Length - 3); if (tmp.Where(x => x == 'C').ToList().Count != 1) { Console.WriteLine("WA"); return; } // 3文字目と末尾から2文字目に存在する大文字Cの位置を求める var cindex = tmp.IndexOf('C') + 2; // AとCを消す S = S.Remove(cindex, 1).Remove(0, 1); bool ret = false; foreach (var item in S) { ret = new Regex("[a-z]").IsMatch(item.ToString()); if (!ret) { break; } } if (ret) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } } }
[["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 16, 12, 23, 0, 16, 31, 214, 205, 22], ["-", 0, 16, 12, 23, 0, 16, 31, 214, 0, 131], ["-", 0, 16, 12, 23, 0, 16, 31, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
241
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace AIZUproject08 { // 128B /*class Data { public int ID { get; set; } public string Name { get; set; } public int Evaluation { get; set; } } class Program { static void Main() { List<Data> datalist = new List<Data>(); Data data; int N = int.Parse(Console.ReadLine()); for (int i=0;i< N;i++) { var temp = Console.ReadLine().Split(' '); data = new Data(); data.ID = i + 1; data.Name = temp[0]; data.Evaluation = int.Parse(temp[1]); datalist.Add(data); } datalist = datalist.OrderBy(n => n.Name).ThenByDescending(n => n.Evaluation).ToList(); foreach (var ans in datalist) { Console.WriteLine(ans.ID); } } }*/ // 127B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int r = input[0]; int D = input[1]; int X = input[2]; for (int i=0;i<10;i++) { var ans = r * X - D; Console.WriteLine(ans); X = ans; } } }*/ // 126B /*class Program { static void Main() { List<int> mae = new List<int>(); List<int> ushiro = new List<int>(); string input = Console.ReadLine(); var rabel = "NA"; for (int i = 0; i < 2; i++) { char moji = input[i]; mae.Add(int.Parse(string.Join("",moji))); } for (int i = 2; i < 4; i++) { char moji = input[i]; ushiro.Add(int.Parse(string.Join("", moji))); } int A = 10 * mae[0] + 1 * mae[1]; int B = 10 * ushiro[0] + 1 * ushiro[1]; if (0 <= A && A <= 99 && 0 < B && B < 13) { rabel = "YYMM"; if (0 < A && A < 13 && 0 < B && B < 13) { rabel = "AMBIGUOUS"; } } else if (0 <= B && B <= 99 && 0 < A && A < 13) { rabel = "MMYY"; if (0 < A && A < 13 && 0 < B && B < 13) { rabel = "AMBIGUOUS"; } } Console.WriteLine(rabel); } }*/ // 125B /*class Program { static void Main() { int N = int.Parse(Console.ReadLine()); int[] V = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] C = Console.ReadLine().Split().Select(int.Parse).ToArray(); int Answer = 0; for (int i=0;i<N;i++) { var temp = V[i] - C[i]; if (temp > 0) { Answer += temp; } } Console.WriteLine(Answer); } }*/ // 124B // count変数の初期化忘れがち!! /*class Program { static void Main() { int Ans = 0; int count = 0; int N = int.Parse(Console.ReadLine()); int[] Height = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i =0;i<Height.Length;i++) { for (int j=0;j<i;j++) { if (Height[i] >= Height[j]) { Ans++; } } if (Ans == i) { count++; } Ans = 0; } Console.WriteLine(count); } }*/ // 123B /*class Program { static void Main() { List<int> time = new List<int>(); List<int> sample = new List<int>(); int[] aa = new int[5]; for (int i = 0;i<5;i++) { int dish = int.Parse(Console.ReadLine()); time.Add(dish); } time.CopyTo(aa); int ans = 0; foreach (int a in time) { var temp = a % 10; sample.Add(temp); } var jj = sample.IndexOf(sample.Min()); time.RemoveAt(jj); time.Add(aa[jj]); foreach (int n in time) { ans += n; if (ans % 10 != 0) { ans += 10 - (ans % 10); } } Console.WriteLine(ans); } }*/ // 122B /*class Program { static void Main() { int anscount = 0; List<int> Answer = new List<int>(); string S = Console.ReadLine(); char[] Cstr = new char[S.Length]; for (int i=0;i<S.Length;i++) { Cstr[i] = S[i]; } for (int i=0;i<Cstr.Length;i++) { var temp = i; while (true) { if (temp < Cstr.Length) { if (Cstr[temp] == 'A' || Cstr[temp] == 'C' || Cstr[temp] == 'G' || Cstr[temp] == 'T') { anscount++; temp++; } else { Answer.Add(anscount); anscount = 0; break; } } else { Answer.Add(anscount); anscount = 0; break; } } } Console.WriteLine(Answer.Max()); } }*/ // 122B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int C = input[2]; int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray(); List<int[]> AA = new List<int[]>(); for (int i =0;i< N;i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); AA.Add(a); } int Ans = 0; List<int> mans = new List<int>(); for (int i =0;i<N;i++) { for (int j=0;j<M;j++) { Ans += AA[i][j] * B[j]; } var ans =Ans + C; mans.Add(ans); Ans = 0; } int count = 0; foreach (int n in mans) { if (n > 0) { count++; } } Console.WriteLine(count); } }*/ // 120B /*class Program { static void Main() { List<int> Array1 = new List<int>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; int K = input[2]; int index = 1; List<int> a = new List<int>(); a.Add(A); a.Add(B); var aa = a.Max(); while (true) { if (A % index == 0 && B % index == 0) { Array1.Add(index); index++; } else { index++; } if (aa+1 == index) { break; } } //配列逆になってない //100 100 1 100 //16 16 4 2 //16 16 3 4 Array1.Sort(); Array1.Reverse(); Console.WriteLine(Array1[K-1]); } }*/ // 118B /*class Program { static void Main() { int Ans = 0; List<int[]> table = new List<int[]>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int[] bb = new int[M]; for (int i=0;i<N;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); table.Add(temp); } for (int i = 0; i < M; i++) { var ans = N; bb[i] = ans; } foreach (int[] n in table) { //初期化 for (int i=1;i<n.Length;i++) { bb[n[i]-1] = bb[n[i]-1]-1; } } for (int i = 0;i< bb.Length;i++) { if (bb[i] ==0) { Ans++; } } Console.WriteLine(Ans); } }*/ // 119B /*class Data { public double Get { get; set; } public string Which { get; set; } } class Program { static void Main() { double Ans = 0; List<Data> table = new List<Data>(); Data data; int N = int.Parse(Console.ReadLine()); for (int i=0;i< N; i++) { data = new Data(); var w = Console.ReadLine().Split(); data.Get = double.Parse(w[0]); data.Which = w[1]; table.Add(data); } foreach(Data nn in table) { if (nn.Which == "JPY") { Ans += nn.Get; } else { Ans += (nn.Get/1.0) * 380000.0; } } Console.WriteLine(Ans); } }*/ // 117B /*class Program { static void Main() { int ans = 0; int N = int.Parse(Console.ReadLine()); int[] length = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i =0;i<length.Length;i++) { ans += length[i]; } ans = ans - length.Max(); if (length.Max() < ans) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }*/ // 116B /*class Progaram { static void Main() { int Ans = 0; int S = int.Parse(Console.ReadLine()); List<int> Answer = new List<int>(); int ans = S; Answer.Add(S); bool bunn = false; while (true) { if (ans %2 ==0) { ans = ans / 2; Answer.Add(ans); } else if (ans % 2 == 1) { ans = 3 * ans + 1; Answer.Add(ans); } for (int i=0;i<Answer.Count;i++) { for (int j =i+1;j<Answer.Count;j++) { if (Answer[i] == Answer[j]) { Ans = j; bunn =true; } } } if (bunn) { break; } } Console.WriteLine(Ans+1); } }*/ // 115B /*class Program { static void Main() { int Answer = 0; int N = int.Parse(Console.ReadLine()); List<int> price = new List<int>(); for (int i=0;i<N;i++) { var temp = int.Parse(Console.ReadLine()); price.Add(temp); } price.Sort(); price.Reverse(); price[0] = price[0] / 2; foreach (int n in price) { Answer += n; } Console.WriteLine(Answer); } }*/ // 114B /*class Program { static void Main() { int an = 0; List<int> Answer = new List<int>(); string S = Console.ReadLine(); char[] temp = new char[S.Length]; for (int i=0;i<S.Length;i++) { temp[i] = S[i]; } for (int i=0;i<S.Length-2;i++) { var a = Convert.ToInt32(temp[i].ToString()); var b = Convert.ToInt32(temp[i + 1].ToString()); var c = Convert.ToInt32(temp[i + 2].ToString()); an = a * 100 + b * 10 + c; var tempAns = Math.Abs(753 - an); Answer.Add(tempAns); } Console.WriteLine(Answer.Min()); } }*/ // 112B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int T = input[1]; List<int[]> table = new List<int[]>(); List<int[]> table2 = new List<int[]>(); for (int i=0;i<N;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); table.Add(temp); } foreach (int[] time in table) { if (time[1] <= T) { table2.Add(time); } } List<int> anss = new List<int>(); foreach (int[] ans in table2) { anss.Add(ans[0]); } if (anss.Count == 0) { Console.WriteLine("TLE"); } else { Console.WriteLine(anss.Min()); } } }*/ // 111B /*class Program { static void Main() { int N = int.Parse(Console.ReadLine()); while (true) { int hun = N / 100; int ten = N % 100 /10; int one = N % 10; if (hun == ten && ten == one && one == hun) { break; } N++; } Console.WriteLine(N); } }*/ // 110B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int X = input[2]; int Y = input[3]; int counter = 0; int counter1 = 0; bool ans = false; int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] y = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i =0;i<y.Length;i++) { if (y[i] > X && y[i] <= Y) { counter = 0; for (int j = 0; j < x.Length; j++) { if (y[i] > x[j]) { counter++; } } if (counter == x.Length) { counter1 = 0; for (int k = 0;k< y.Length;k++) { if (y[i] <= y[k]) { counter1++; } } if (counter1 == y.Length) { Console.WriteLine("No War"); ans = true; break; } } } } if (ans == false) { Console.WriteLine("War"); } } }*/ // 109B /*class Program { static void Main() { List<string> Str = new List<string>(); List<string> Str2 = new List<string>(); List<char[]> oo = new List<char[]>(); int N = int.Parse(Console.ReadLine()); int koko = 0; bool te = false; bool kko = false; for (int i = 0; i < N; i++) { var str = Console.ReadLine(); Str.Add(str); } foreach (string ans in Str) { char[] temp = ans.ToCharArray(); oo.Add(temp); if (oo[temp.Length-1] == temp[0] || te == false) { koko++; var a = string.Join("", tempbefore).ToString(); var ss = string.Join("", temp).ToString(); Array.Copy(temp, tempbefore, temp.Length); Str2.Add(a); foreach (string nn in Str2) { if (a == nn) { kko = true; } } if (kko == true) { break; } te = true; Array.Copy(temp, tempbefore, temp.Length); } else { break; } } if (koko == N-1) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }*/ /*class Program { static void Main() { int count = 1; bool flag = false; List<string> strArray = new List<string>(); int N = int.Parse(Console.ReadLine()); for (int i =0;i<N;i++) { string input = Console.ReadLine(); strArray.Add(input); } for (int a = 0;a<N;a++) { for (int i =a+1; i< N; i++) { if (strArray[a] == strArray[i]) { flag = true; } } } if (flag == false) { for (int i = 0; i < N - 1; i++) { //stringからchar[] char[] temp = strArray[i].ToCharArray(); char[] temp1 = strArray[i + 1].ToCharArray(); if (temp[temp.Length - 1] == temp1[0]) { count++; } else { flag = true; break; } } if (count == N) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); } } }*/ // 108B /*class Program { static void Main() { List<int[]> ans = new List<int[]>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int X1 = input[0]; int Y1 = input[1]; int X2 = input[2]; int Y2 = input[3]; if (X1==X2) { if (Y1 > Y2) { var X4 = X1 + Math.Abs(X1 - X2); var Y4 = Y1; var X3 = X1 + Math.Abs(X1 - X2); var Y3 = Y2; Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); } if (Y2 > Y1) { var X4 = X1-Math.Abs(X1 - X2); var Y4 = Y1; var X3 = X1 - Math.Abs(X1 - X2); var Y3 = Y2; Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); } } if (Y1 == Y2) { /*var X4 = Math.Min(X1, X2); //Math.Abs(Y1 - Y2); var Y4 = Math.Abs(X1-X2); var X3 = Math.Max(X1,X2); var Y3 = Y4; Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); if (X1 > X2) { var X4 = X1; var Y4 = Y1 - Math.Abs(X1 - X2); var X3 = X2; var Y3 = Y2 - Math.Abs(X1 - X2); Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); } if (X2 > X1) { var X4 = X1 - Math.Abs(X1 - X2); var Y4 = Y1; var X3 = X1 - Math.Abs(X1 - X2); var Y3 = Y2; Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); } } } }*/ // Contest131A /*class Program { static void Main() { bool flag = false; List<int> temp = new List<int>(); string input = Console.ReadLine(); for (int i = 0; i < input.Length; i++) { var a = Convert.ToInt32(input[i].ToString()); temp.Add(a); } for (int i=0;i<input.Length-1;i++) { if (temp[i] == temp[i+1]) { flag = true; } } if (flag == true) { Console.WriteLine("Bad"); } else { Console.WriteLine("Good"); } } }*/ // Contest131B /* class Program { static void Main() { int ans = 0; int mm = 0; int index = 0; int sum = 0; List<int> array = new List<int>(); List<int> array1 = new List<int>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int L = input[1]; for (int i = 1;i<=N;i++) { var azi = L + i - 1; array.Add(azi); } for (int i=0;i<N;i++) { sum += array[i]; } for (int i=0;i<N;i++) { var temp = Math.Abs(array[i]); array1.Add(temp); } index = array1.IndexOf(array1.Min()); for(int i=0;i<N;i++) { if (i == index) { ans += 0; } else { ans += array[i]; } } Console.WriteLine(ans); } }*/ // Contest131C /*class Program { static void Main() { } }*/ // Contest131D&& ans % D != 0 /*class Data { public int a { get; set; } public int b { get; set; } } class Program { static void Main() { List<Data> data = new List<Data>(); List<int[]> ans = new List<int[]>(); int N = int.Parse(Console.ReadLine()); for (int i=0; i<N; i++) { var drr = new Data(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); drr.a = input[0]; drr.b = input[1]; data.Add(drr); } data = data.OrderBy(n => n.b).ToList(); int Ans = 0; bool flag = false; foreach (Data aa in data) { Ans += aa.a; if (Ans > aa.b) { flag = true; break; } } if (flag) { Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } } }*/ // 108B /*class Data { public List<string> Y { get; set; } public List<string> X { get; set; } } class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int H = input[0]; int W = input[1]; List<int> Y = new List<int>(); List<int> X = new List<int>(); //List<Data> griddata = new List<Data>(); //Data data = new Data(); List<char[]> temparray = new List<char[]>(); for (int y = 0; y < H; y++) { var temp = Console.ReadLine().ToArray(); temparray.Add(temp); } int count1 = 0; for (int i = 0; i < H; i++) { var num = 0; for (int j = 0; j < W; j++) { num = i; if (temparray[i][j] == '.') { count1++; } } if (count1 == W) { Y.Add(num); } count1 = 0; } int count2 = 0; for (int i = 0; i < W; i++) { var num = 0; for (int j = 0; j < H; j++) { num = i; if (temparray[j][i] == '.') { count2++; } } if (count2 == H) { X.Add(num); } count2 = 0; } //for (int i = 0; i < Y.Count; i++) for (int i = Y.Count-1; i >= 0; i--) { temparray.RemoveAt(Y[i]); } for (int j = 0; j < X.Count; j++) { for (int i = 0; i < temparray.Count; i++) { Array.Clear(temparray[i], X[j], 1); } } List<char[]> ko = new List<char[]>(); int count = 0; var aa = new List<char>(); foreach (char[] a in temparray) { foreach (char b in a) { if (b != '\0') { aa.Add(b); } } foreach (char ji in aa) { Console.Write(ji); } //ko.Add(mo); Console.Write('\n'); aa.RemoveRange(0,aa.Count); } } }*/ // 105B /*class Program { static void Main() { int Ans = 0; int count = 0; int N = int.Parse(Console.ReadLine()); for (int i = 1; i<=N;i++) { if (i % 2 == 1) { for (int j = 1; j <= i; j++) { if (i % j == 0) { count++; } } if (count == 8) { Ans++; } count = 0; } } Console.WriteLine(Ans); } }*/ // 104B // ApproaCh // AccccCcccc // AmvlkweClF // ATCoder class Program { static void Main() { bool flag = false; int count = 0; string S = Console.ReadLine(); List<char> carray = new List<char>(); foreach (char n in S) { carray.Add(n); } for (int i = 0; i < carray.Count - 1; i++) { if (carray[0] == 'A') { if (2 <= i && i <= carray.Count - 1) { if (carray[i] == 'C') { count++; } } } else { break; } } if (count == 1) { foreach (char m in carray) { if (char.IsUpper(m)) { if (m != 'C' && m != 'A') { flag = true; } } } } if (flag) { Console.WriteLine("WA"); } else { Console.WriteLine("AC"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace AIZUproject08 { // 128B /*class Data { public int ID { get; set; } public string Name { get; set; } public int Evaluation { get; set; } } class Program { static void Main() { List<Data> datalist = new List<Data>(); Data data; int N = int.Parse(Console.ReadLine()); for (int i=0;i< N;i++) { var temp = Console.ReadLine().Split(' '); data = new Data(); data.ID = i + 1; data.Name = temp[0]; data.Evaluation = int.Parse(temp[1]); datalist.Add(data); } datalist = datalist.OrderBy(n => n.Name).ThenByDescending(n => n.Evaluation).ToList(); foreach (var ans in datalist) { Console.WriteLine(ans.ID); } } }*/ // 127B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int r = input[0]; int D = input[1]; int X = input[2]; for (int i=0;i<10;i++) { var ans = r * X - D; Console.WriteLine(ans); X = ans; } } }*/ // 126B /*class Program { static void Main() { List<int> mae = new List<int>(); List<int> ushiro = new List<int>(); string input = Console.ReadLine(); var rabel = "NA"; for (int i = 0; i < 2; i++) { char moji = input[i]; mae.Add(int.Parse(string.Join("",moji))); } for (int i = 2; i < 4; i++) { char moji = input[i]; ushiro.Add(int.Parse(string.Join("", moji))); } int A = 10 * mae[0] + 1 * mae[1]; int B = 10 * ushiro[0] + 1 * ushiro[1]; if (0 <= A && A <= 99 && 0 < B && B < 13) { rabel = "YYMM"; if (0 < A && A < 13 && 0 < B && B < 13) { rabel = "AMBIGUOUS"; } } else if (0 <= B && B <= 99 && 0 < A && A < 13) { rabel = "MMYY"; if (0 < A && A < 13 && 0 < B && B < 13) { rabel = "AMBIGUOUS"; } } Console.WriteLine(rabel); } }*/ // 125B /*class Program { static void Main() { int N = int.Parse(Console.ReadLine()); int[] V = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] C = Console.ReadLine().Split().Select(int.Parse).ToArray(); int Answer = 0; for (int i=0;i<N;i++) { var temp = V[i] - C[i]; if (temp > 0) { Answer += temp; } } Console.WriteLine(Answer); } }*/ // 124B // count変数の初期化忘れがち!! /*class Program { static void Main() { int Ans = 0; int count = 0; int N = int.Parse(Console.ReadLine()); int[] Height = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i =0;i<Height.Length;i++) { for (int j=0;j<i;j++) { if (Height[i] >= Height[j]) { Ans++; } } if (Ans == i) { count++; } Ans = 0; } Console.WriteLine(count); } }*/ // 123B /*class Program { static void Main() { List<int> time = new List<int>(); List<int> sample = new List<int>(); int[] aa = new int[5]; for (int i = 0;i<5;i++) { int dish = int.Parse(Console.ReadLine()); time.Add(dish); } time.CopyTo(aa); int ans = 0; foreach (int a in time) { var temp = a % 10; sample.Add(temp); } var jj = sample.IndexOf(sample.Min()); time.RemoveAt(jj); time.Add(aa[jj]); foreach (int n in time) { ans += n; if (ans % 10 != 0) { ans += 10 - (ans % 10); } } Console.WriteLine(ans); } }*/ // 122B /*class Program { static void Main() { int anscount = 0; List<int> Answer = new List<int>(); string S = Console.ReadLine(); char[] Cstr = new char[S.Length]; for (int i=0;i<S.Length;i++) { Cstr[i] = S[i]; } for (int i=0;i<Cstr.Length;i++) { var temp = i; while (true) { if (temp < Cstr.Length) { if (Cstr[temp] == 'A' || Cstr[temp] == 'C' || Cstr[temp] == 'G' || Cstr[temp] == 'T') { anscount++; temp++; } else { Answer.Add(anscount); anscount = 0; break; } } else { Answer.Add(anscount); anscount = 0; break; } } } Console.WriteLine(Answer.Max()); } }*/ // 122B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int C = input[2]; int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray(); List<int[]> AA = new List<int[]>(); for (int i =0;i< N;i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); AA.Add(a); } int Ans = 0; List<int> mans = new List<int>(); for (int i =0;i<N;i++) { for (int j=0;j<M;j++) { Ans += AA[i][j] * B[j]; } var ans =Ans + C; mans.Add(ans); Ans = 0; } int count = 0; foreach (int n in mans) { if (n > 0) { count++; } } Console.WriteLine(count); } }*/ // 120B /*class Program { static void Main() { List<int> Array1 = new List<int>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; int K = input[2]; int index = 1; List<int> a = new List<int>(); a.Add(A); a.Add(B); var aa = a.Max(); while (true) { if (A % index == 0 && B % index == 0) { Array1.Add(index); index++; } else { index++; } if (aa+1 == index) { break; } } //配列逆になってない //100 100 1 100 //16 16 4 2 //16 16 3 4 Array1.Sort(); Array1.Reverse(); Console.WriteLine(Array1[K-1]); } }*/ // 118B /*class Program { static void Main() { int Ans = 0; List<int[]> table = new List<int[]>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int[] bb = new int[M]; for (int i=0;i<N;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); table.Add(temp); } for (int i = 0; i < M; i++) { var ans = N; bb[i] = ans; } foreach (int[] n in table) { //初期化 for (int i=1;i<n.Length;i++) { bb[n[i]-1] = bb[n[i]-1]-1; } } for (int i = 0;i< bb.Length;i++) { if (bb[i] ==0) { Ans++; } } Console.WriteLine(Ans); } }*/ // 119B /*class Data { public double Get { get; set; } public string Which { get; set; } } class Program { static void Main() { double Ans = 0; List<Data> table = new List<Data>(); Data data; int N = int.Parse(Console.ReadLine()); for (int i=0;i< N; i++) { data = new Data(); var w = Console.ReadLine().Split(); data.Get = double.Parse(w[0]); data.Which = w[1]; table.Add(data); } foreach(Data nn in table) { if (nn.Which == "JPY") { Ans += nn.Get; } else { Ans += (nn.Get/1.0) * 380000.0; } } Console.WriteLine(Ans); } }*/ // 117B /*class Program { static void Main() { int ans = 0; int N = int.Parse(Console.ReadLine()); int[] length = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i =0;i<length.Length;i++) { ans += length[i]; } ans = ans - length.Max(); if (length.Max() < ans) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }*/ // 116B /*class Progaram { static void Main() { int Ans = 0; int S = int.Parse(Console.ReadLine()); List<int> Answer = new List<int>(); int ans = S; Answer.Add(S); bool bunn = false; while (true) { if (ans %2 ==0) { ans = ans / 2; Answer.Add(ans); } else if (ans % 2 == 1) { ans = 3 * ans + 1; Answer.Add(ans); } for (int i=0;i<Answer.Count;i++) { for (int j =i+1;j<Answer.Count;j++) { if (Answer[i] == Answer[j]) { Ans = j; bunn =true; } } } if (bunn) { break; } } Console.WriteLine(Ans+1); } }*/ // 115B /*class Program { static void Main() { int Answer = 0; int N = int.Parse(Console.ReadLine()); List<int> price = new List<int>(); for (int i=0;i<N;i++) { var temp = int.Parse(Console.ReadLine()); price.Add(temp); } price.Sort(); price.Reverse(); price[0] = price[0] / 2; foreach (int n in price) { Answer += n; } Console.WriteLine(Answer); } }*/ // 114B /*class Program { static void Main() { int an = 0; List<int> Answer = new List<int>(); string S = Console.ReadLine(); char[] temp = new char[S.Length]; for (int i=0;i<S.Length;i++) { temp[i] = S[i]; } for (int i=0;i<S.Length-2;i++) { var a = Convert.ToInt32(temp[i].ToString()); var b = Convert.ToInt32(temp[i + 1].ToString()); var c = Convert.ToInt32(temp[i + 2].ToString()); an = a * 100 + b * 10 + c; var tempAns = Math.Abs(753 - an); Answer.Add(tempAns); } Console.WriteLine(Answer.Min()); } }*/ // 112B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int T = input[1]; List<int[]> table = new List<int[]>(); List<int[]> table2 = new List<int[]>(); for (int i=0;i<N;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); table.Add(temp); } foreach (int[] time in table) { if (time[1] <= T) { table2.Add(time); } } List<int> anss = new List<int>(); foreach (int[] ans in table2) { anss.Add(ans[0]); } if (anss.Count == 0) { Console.WriteLine("TLE"); } else { Console.WriteLine(anss.Min()); } } }*/ // 111B /*class Program { static void Main() { int N = int.Parse(Console.ReadLine()); while (true) { int hun = N / 100; int ten = N % 100 /10; int one = N % 10; if (hun == ten && ten == one && one == hun) { break; } N++; } Console.WriteLine(N); } }*/ // 110B /*class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int X = input[2]; int Y = input[3]; int counter = 0; int counter1 = 0; bool ans = false; int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] y = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i =0;i<y.Length;i++) { if (y[i] > X && y[i] <= Y) { counter = 0; for (int j = 0; j < x.Length; j++) { if (y[i] > x[j]) { counter++; } } if (counter == x.Length) { counter1 = 0; for (int k = 0;k< y.Length;k++) { if (y[i] <= y[k]) { counter1++; } } if (counter1 == y.Length) { Console.WriteLine("No War"); ans = true; break; } } } } if (ans == false) { Console.WriteLine("War"); } } }*/ // 109B /*class Program { static void Main() { List<string> Str = new List<string>(); List<string> Str2 = new List<string>(); List<char[]> oo = new List<char[]>(); int N = int.Parse(Console.ReadLine()); int koko = 0; bool te = false; bool kko = false; for (int i = 0; i < N; i++) { var str = Console.ReadLine(); Str.Add(str); } foreach (string ans in Str) { char[] temp = ans.ToCharArray(); oo.Add(temp); if (oo[temp.Length-1] == temp[0] || te == false) { koko++; var a = string.Join("", tempbefore).ToString(); var ss = string.Join("", temp).ToString(); Array.Copy(temp, tempbefore, temp.Length); Str2.Add(a); foreach (string nn in Str2) { if (a == nn) { kko = true; } } if (kko == true) { break; } te = true; Array.Copy(temp, tempbefore, temp.Length); } else { break; } } if (koko == N-1) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }*/ /*class Program { static void Main() { int count = 1; bool flag = false; List<string> strArray = new List<string>(); int N = int.Parse(Console.ReadLine()); for (int i =0;i<N;i++) { string input = Console.ReadLine(); strArray.Add(input); } for (int a = 0;a<N;a++) { for (int i =a+1; i< N; i++) { if (strArray[a] == strArray[i]) { flag = true; } } } if (flag == false) { for (int i = 0; i < N - 1; i++) { //stringからchar[] char[] temp = strArray[i].ToCharArray(); char[] temp1 = strArray[i + 1].ToCharArray(); if (temp[temp.Length - 1] == temp1[0]) { count++; } else { flag = true; break; } } if (count == N) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); } } }*/ // 108B /*class Program { static void Main() { List<int[]> ans = new List<int[]>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int X1 = input[0]; int Y1 = input[1]; int X2 = input[2]; int Y2 = input[3]; if (X1==X2) { if (Y1 > Y2) { var X4 = X1 + Math.Abs(X1 - X2); var Y4 = Y1; var X3 = X1 + Math.Abs(X1 - X2); var Y3 = Y2; Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); } if (Y2 > Y1) { var X4 = X1-Math.Abs(X1 - X2); var Y4 = Y1; var X3 = X1 - Math.Abs(X1 - X2); var Y3 = Y2; Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); } } if (Y1 == Y2) { /*var X4 = Math.Min(X1, X2); //Math.Abs(Y1 - Y2); var Y4 = Math.Abs(X1-X2); var X3 = Math.Max(X1,X2); var Y3 = Y4; Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); if (X1 > X2) { var X4 = X1; var Y4 = Y1 - Math.Abs(X1 - X2); var X3 = X2; var Y3 = Y2 - Math.Abs(X1 - X2); Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); } if (X2 > X1) { var X4 = X1 - Math.Abs(X1 - X2); var Y4 = Y1; var X3 = X1 - Math.Abs(X1 - X2); var Y3 = Y2; Console.WriteLine(X3 + " " + Y3 + " " + X4 + " " + Y4); } } } }*/ // Contest131A /*class Program { static void Main() { bool flag = false; List<int> temp = new List<int>(); string input = Console.ReadLine(); for (int i = 0; i < input.Length; i++) { var a = Convert.ToInt32(input[i].ToString()); temp.Add(a); } for (int i=0;i<input.Length-1;i++) { if (temp[i] == temp[i+1]) { flag = true; } } if (flag == true) { Console.WriteLine("Bad"); } else { Console.WriteLine("Good"); } } }*/ // Contest131B /* class Program { static void Main() { int ans = 0; int mm = 0; int index = 0; int sum = 0; List<int> array = new List<int>(); List<int> array1 = new List<int>(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int L = input[1]; for (int i = 1;i<=N;i++) { var azi = L + i - 1; array.Add(azi); } for (int i=0;i<N;i++) { sum += array[i]; } for (int i=0;i<N;i++) { var temp = Math.Abs(array[i]); array1.Add(temp); } index = array1.IndexOf(array1.Min()); for(int i=0;i<N;i++) { if (i == index) { ans += 0; } else { ans += array[i]; } } Console.WriteLine(ans); } }*/ // Contest131C /*class Program { static void Main() { } }*/ // Contest131D&& ans % D != 0 /*class Data { public int a { get; set; } public int b { get; set; } } class Program { static void Main() { List<Data> data = new List<Data>(); List<int[]> ans = new List<int[]>(); int N = int.Parse(Console.ReadLine()); for (int i=0; i<N; i++) { var drr = new Data(); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); drr.a = input[0]; drr.b = input[1]; data.Add(drr); } data = data.OrderBy(n => n.b).ToList(); int Ans = 0; bool flag = false; foreach (Data aa in data) { Ans += aa.a; if (Ans > aa.b) { flag = true; break; } } if (flag) { Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } } }*/ // 108B /*class Data { public List<string> Y { get; set; } public List<string> X { get; set; } } class Program { static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int H = input[0]; int W = input[1]; List<int> Y = new List<int>(); List<int> X = new List<int>(); //List<Data> griddata = new List<Data>(); //Data data = new Data(); List<char[]> temparray = new List<char[]>(); for (int y = 0; y < H; y++) { var temp = Console.ReadLine().ToArray(); temparray.Add(temp); } int count1 = 0; for (int i = 0; i < H; i++) { var num = 0; for (int j = 0; j < W; j++) { num = i; if (temparray[i][j] == '.') { count1++; } } if (count1 == W) { Y.Add(num); } count1 = 0; } int count2 = 0; for (int i = 0; i < W; i++) { var num = 0; for (int j = 0; j < H; j++) { num = i; if (temparray[j][i] == '.') { count2++; } } if (count2 == H) { X.Add(num); } count2 = 0; } //for (int i = 0; i < Y.Count; i++) for (int i = Y.Count-1; i >= 0; i--) { temparray.RemoveAt(Y[i]); } for (int j = 0; j < X.Count; j++) { for (int i = 0; i < temparray.Count; i++) { Array.Clear(temparray[i], X[j], 1); } } List<char[]> ko = new List<char[]>(); int count = 0; var aa = new List<char>(); foreach (char[] a in temparray) { foreach (char b in a) { if (b != '\0') { aa.Add(b); } } foreach (char ji in aa) { Console.Write(ji); } //ko.Add(mo); Console.Write('\n'); aa.RemoveRange(0,aa.Count); } } }*/ // 105B /*class Program { static void Main() { int Ans = 0; int count = 0; int N = int.Parse(Console.ReadLine()); for (int i = 1; i<=N;i++) { if (i % 2 == 1) { for (int j = 1; j <= i; j++) { if (i % j == 0) { count++; } } if (count == 8) { Ans++; } count = 0; } } Console.WriteLine(Ans); } }*/ // 104B // ApproaCh // AccccCcccc // AmvlkweClF // ATCoder class Program { static void Main() { bool flag = false; int count = 0; string S = Console.ReadLine(); List<char> carray = new List<char>(); foreach (char n in S) { carray.Add(n); } for (int i = 0; i < carray.Count - 1; i++) { if (carray[0] == 'A') { if (2 <= i && i <= carray.Count - 1 && carray[i] == 'C') { count++; } } else { break; } } if (count == 1) { foreach (char m in carray) { if (char.IsUpper(m)) { if (m != 'C' && m != 'A') { flag = true; } } } } else { flag = true; } if (flag) { Console.WriteLine("WA"); } else { Console.WriteLine("AC"); } } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 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, 64, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 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], ["+", 75, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
8
300
13
using System; using System.Collections.Generic; using System.Linq; namespace ABC099 { class Program { static void Main(string[] args) { List<string> list = new List<string>(); while (true) { string line = Console.ReadLine(); if (line == null) break; list.Add(line); } var str = list[0].ToCharArray(); int count = str.Where(x => x == 'C').Count(); if (!str[0].Equals('A')) { Console.WriteLine("WA"); } else if (str.Last().Equals('C')) { Console.WriteLine("WA"); } else if (str[1].Equals('C')) { Console.WriteLine("WA"); } else if (str.First().Equals('A') && str.Contains('C') && count == 1) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC099 { class Program { static void Main(string[] args) { List<string> list = new List<string>(); while (true) { string line = Console.ReadLine(); if (line == null) break; list.Add(line); } var str = list[0].ToCharArray(); int count = str.Where(x => x == 'C').Count(); int ucount = 0; foreach (var item in str) { if (char.IsUpper(item)) { ucount++; } } if (!str[0].Equals('A')) { Console.WriteLine("WA"); } else if (str.Last().Equals('C')) { Console.WriteLine("WA"); } else if (str[1].Equals('C')) { Console.WriteLine("WA"); } else if (str.First().Equals('A') && str.Contains('C') && count == 1 && ucount == 2) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } } }
[["+", 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, 197, 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, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 24], ["+", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 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, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46], ["+", 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, 60], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 12, 203]]
8
241
32
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; class Program { static void Main() { string S = Console.ReadLine(); bool ans = false; if (S.StartsWith("A", StringComparison.Ordinal)) { if (S.Substring(2, S.Length - 2 - 1).Contains('C')) { var tmp = S.Replace("C", "").Replace("A", ""); if (tmp.ToLower() == tmp) { ans = true; } } } Console.WriteLine(ans ? "AC" : "WA"); } } static class MathUtil { public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; class Program { static void Main() { string S = Console.ReadLine(); bool ans = false; if (S.StartsWith("A", StringComparison.Ordinal)) { if (S.Substring(2, S.Length - 2 - 1).Count(ch => ch == 'C') == 1) { var tmp = S.Replace("C", "").Replace("A", ""); if (tmp.ToLower() == tmp) { ans = true; } } } Console.WriteLine(ans ? "AC" : "WA"); } } static class MathUtil { public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
[["-", 64, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 31, 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, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203]]
8
393
8
using System; using System.Linq; public class Program { static void Main() { var s = Console.ReadLine(); if (s.Substring(0, 1) == "A" && char.IsLower(s[1])) { var buf = s.Substring(2).ToCharArray(); if (buf.Where(x => x == 'C').Count() == 1) { if (buf.Where(x => x != 'C').All(x => char.IsLower(x))) { Console.WriteLine("AC"); return; } } } Console.WriteLine("WA"); } }
using System; using System.Linq; public class Program { static void Main() { var s = Console.ReadLine(); if (s.Substring(0, 1) == "A" && char.IsLower(s[1])) { var buf = s.Substring(2).ToCharArray(); if (buf.Last() != 'C' && buf.Where(x => x == 'C').Count() == 1) { if (buf.Where(x => x != 'C').All(x => char.IsLower(x))) { Console.WriteLine("AC"); return; } } } Console.WriteLine("WA"); } }
[["+", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 16, 31, 16, 12, 252, 0, 104], ["+", 0, 57, 15, 16, 31, 16, 12, 252, 0, 253], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 0, 131]]
8
142
10
using System; namespace ABC104_B_AcCepted { internal class Program { public static void Main(string[] args) { string s = Console.ReadLine(); string[] sArr = new string[s.Length]; for (int i = 0; i < s.Length; i++) { sArr[i] = s.Substring(i, 1); } int countC = 0; int appearC = 0; bool smallChar = true; for (int i = 2; i < s.Length - 1; i++) { if (sArr[i] == "C") { countC++; appearC = i; } } for (int i = 1; i < s.Length; i++) { if (!char.IsLower(sArr[i], 0)) { if (i != 0 && i != appearC) { smallChar = false; Console.WriteLine(smallChar); } } } if (sArr[0] == "A" && countC == 1 && smallChar) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } } }
using System; namespace ABC104_B_AcCepted { internal class Program { public static void Main(string[] args) { string s = Console.ReadLine(); string[] sArr = new string[s.Length]; for (int i = 0; i < s.Length; i++) { sArr[i] = s.Substring(i, 1); } int countC = 0; int appearC = 0; bool smallChar = true; for (int i = 2; i < s.Length - 1; i++) { if (sArr[i] == "C") { countC++; appearC = i; } } for (int i = 1; i < s.Length; i++) { if (!char.IsLower(sArr[i], 0)) { if (i != 0 && i != appearC) { smallChar = false; } } } if (sArr[0] == "A" && countC == 1 && smallChar) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } } }
[["-", 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], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
231
7
using System; namespace abc104_b { class Program { static void Main(string[] args) { string s = Console.ReadLine(); bool ret = true; if (s[0] != 'A') ret = false; int count = 0; for (int i = 2; i < s.Length - 1; i++) if (s[i] == 'C') count++; if (count != 1) ret = false; count = 0; for (int i = 0; i < s.Length; i++) if ('A' <= s[i]) count++; if (count > 2) ret = false; Console.WriteLine(ret ? "AC" : "WA"); } } }
using System; namespace abc104_b { class Program { static void Main(string[] args) { string s = Console.ReadLine(); bool ret = true; if (s[0] != 'A') ret = false; int count = 0; for (int i = 2; i < s.Length - 1; i++) if (s[i] == 'C') count++; if (count != 1) ret = false; count = 0; for (int i = 0; i < s.Length; i++) { if (s[i] <= 'Z') count++; } if (count > 2) ret = false; Console.WriteLine(ret ? "AC" : "WA"); } } }
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 7, 8, 57, 15, 16, 31, 252, 0, 104], ["-", 0, 7, 8, 57, 15, 16, 31, 252, 0, 253], ["-", 8, 196, 0, 7, 8, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
157
10
using System; using System.Linq; public class Hello { public static void Main() { var S = Console.ReadLine(); if (S[0] == 'A' && S[2] == 'C' && S.Count(s => s == 'C') == 1) { for (var i = 0; i < S.Length; i++) { if (i == 0 || i == 2) { continue; } else { if (char.IsUpper(S[i])) { Console.WriteLine("WA"); return; } } } Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } }
using System; using System.Linq; public class Hello { public static void Main() { var S = Console.ReadLine(); if (S[0] == 'A' && S.Substring(2, S.Length - 3).Contains('C') && S.Count(c => c == 'C') == 1) { for (var i = 0; i < S.Length; i++) { if (i == 0 || S[i] == 'C') { continue; } else { if (char.IsUpper(S[i])) { Console.WriteLine("WA"); return; } } } Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } }
[["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 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], ["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 104], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253]]
8
148
28
using System; using System.Runtime.Remoting.Contexts; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } } class Program { private string S; private void Scan() { Scanner sc = new Scanner(); S = sc.Next(); } public void Solve() { Scan(); bool flagA = false; int cntC = 0; for (int i = 0; i < S.Length; i++) { if ('A' <= S[i] && S[i] <= 'Z') { if (i == 0 && S[i] == 'A') { flagA = true; } if (2 <= i && i <= S.Length - 2 && S[i] == 'C') { cntC++; } } else if ('a' <= S[i] && S[i] <= 'z') { } else { Console.WriteLine("WA"); return; } } if (flagA && cntC == 1) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } static void Main() => new Program().Solve(); } }
using System; using System.Runtime.Remoting.Contexts; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } } class Program { private string S; private void Scan() { Scanner sc = new Scanner(); S = sc.Next(); } public void Solve() { Scan(); bool flagA = false; int cntC = 0; for (int i = 0; i < S.Length; i++) { if ('A' <= S[i] && S[i] <= 'Z') { if (i == 0 && S[i] == 'A') { flagA = true; } else if (2 <= i && i <= S.Length - 2 && S[i] == 'C') { cntC++; } else { Console.WriteLine("WA"); return; } } else if ('a' <= S[i] && S[i] <= 'z') { } else { Console.WriteLine("WA"); return; } } if (flagA && cntC == 1) { Console.WriteLine("AC"); } else { Console.WriteLine("WA"); } } static void Main() => new Program().Solve(); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 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, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 57, 75, 196, 0, 37, 0, 38]]
8
505
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC104 { class Program { static void Main(string[] args) { // 65 90 67 string s = Console.ReadLine(); string subs = ""; string ans = "AC"; int flag = 0; if (s.Substring(0, 1) != "A") { ans = "WA"; } if (s[1] == 67) { ans = "WA"; } for (int i = 2; i < s.Length - 1; i++) { subs = s.Substring(i, 1); if ((s[i] >= 65 && s[i] <= 90) && (flag == 1 || s[i] != 67)) { ans = "WA"; } if (subs == "C") { flag = 1; } } if (flag == 0) { ans = "WA"; } if (s[s.Length - 1] <= 90 && s[s.Length - 1] >= 65) { ans = "WA"; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC104 { class Program { static void Main(string[] args) { // 65 90 67 string s = Console.ReadLine(); string subs = ""; string ans = "AC"; int flag = 0; if (s.Substring(0, 1) != "A") { ans = "WA"; } if (s[1] >= 65 && s[1] <= 90) { ans = "WA"; } for (int i = 2; i < s.Length - 1; i++) { subs = s.Substring(i, 1); if ((s[i] >= 65 && s[i] <= 90) && (flag == 1 || s[i] != 67)) { ans = "WA"; } if (subs == "C") { flag = 1; } } if (flag == 0) { ans = "WA"; } if (s[s.Length - 1] <= 90 && s[s.Length - 1] >= 65) { ans = "WA"; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
251
11
using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); Console.WriteLine(check(s) ? "AC" : "WA"); } public static bool check(string s) { var sL = s.Length; if (s[0] != 'A') return false; var s2 = s.Substring(2, sL - 3); var a = s2.Length - s2.Replace("C", "").Length; if (a != 1) return false; var w = s2.Replace("C", "c"); for (int i = 1; i < w.Length; i++) if (Char.IsUpper(w[i])) return false; return true; } }
using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); Console.WriteLine(check(s) ? "AC" : "WA"); } public static bool check(string s) { var sL = s.Length; if (s[0] != 'A') return false; var s2 = s.Substring(2, sL - 3); var a = s2.Length - s2.Replace("C", "").Length; if (a != 1) return false; var count = 0; for (int i = 1; i < s.Length; i++) if (Char.IsUpper(s[i])) count++; if (count == 1) return true; else return false; } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 15, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 15, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 8, 196, 0, 7, 8, 57, 64, 37, 0, 38], ["-", 0, 7, 8, 57, 64, 37, 0, 211, 0, 147], ["+", 0, 7, 8, 57, 64, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 57, 64, 1, 0, 223, 0, 29], ["+", 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, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 37, 0, 38], ["+", 8, 196, 0, 57, 75, 37, 0, 211, 0, 147]]
8
172
33
using System; namespace AtCoder.Problems { public class ProblemAbc079C { public static void Main(string[] args) { var s = new Solve079C(); s.Solve(); } public class Scanner { private string[] _s; private int _i; private readonly char[] _separators = 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(_separators, StringSplitOptions.RemoveEmptyEntries); if (_s.Length == 0) return Next(); _i = 0; return _s[_i++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public ulong NextULong() => ulong.Parse(Next()); public double NextDouble() => double.Parse(Next()); public int[] GetIntArray(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[] GetLongArray(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[] GetDoubleArray(int n, double add = 0) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = NextDouble() + add; } return array; } } } public class Solve079C { public void Solve() { var cin = new ProblemAbc079C.Scanner(); var d = cin.NextInt(); var g = cin.NextInt(); var p = new int[d]; var c = new int[d]; for (int i = 0; i < d; i++) { p[i] = cin.NextInt(); c[i] = cin.NextInt(); } var result = GetAnswer(d, g, p, c); Console.WriteLine(result); } public long GetAnswer(int d, int g, int[] p, int[] c) { var ans = long.MaxValue; for (uint flag = 0; flag < 1 << d; ++flag) { var sum = 0L; var count = 0L; for (int i = 0; i < d; i++) { if ((flag & (1 << i)) != 0) { sum += (i + 1) * 100 * p[i] + c[i]; count += p[i]; } } if (sum >= g) { ans = Math.Min(ans, count); continue; } for (int i = d - 1; i >= 0; i--) { if ((flag & (1 << i)) != 0) { continue; } var cnt = (g - sum) / ((i + 1) * 100); if (cnt < p[i]) { ans = Math.Min(ans, count + cnt); break; } cnt = p[i] - 1; sum += (i + 1) * 100 * cnt; count += cnt; } } return ans; } } }
using System; namespace AtCoder.Problems { public class ProblemAbc079C { public static void Main(string[] args) { var s = new Solve079C(); s.Solve(); } public class Scanner { private string[] _s; private int _i; private readonly char[] _separators = 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(_separators, StringSplitOptions.RemoveEmptyEntries); if (_s.Length == 0) return Next(); _i = 0; return _s[_i++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public ulong NextULong() => ulong.Parse(Next()); public double NextDouble() => double.Parse(Next()); public int[] GetIntArray(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[] GetLongArray(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[] GetDoubleArray(int n, double add = 0) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = NextDouble() + add; } return array; } } } public class Solve079C { public void Solve() { var cin = new ProblemAbc079C.Scanner(); var d = cin.NextInt(); var g = cin.NextInt(); var p = new int[d]; var c = new int[d]; for (int i = 0; i < d; i++) { p[i] = cin.NextInt(); c[i] = cin.NextInt(); } var result = GetAnswer(d, g, p, c); Console.WriteLine(result); } public long GetAnswer(int d, int g, int[] p, int[] c) { var ans = long.MaxValue; for (uint flag = 0; flag < 1 << d; ++flag) { var sum = 0L; var count = 0L; for (int i = 0; i < d; i++) { if ((flag & (1 << i)) != 0) { sum += (i + 1) * 100 * p[i] + c[i]; count += p[i]; } } if (sum >= g) { ans = Math.Min(ans, count); continue; } for (int i = d - 1; i >= 0; i--) { if ((flag & (1 << i)) != 0) { continue; } var remain = g - sum; var point = (i + 1) * 100; var cnt = remain / point; if (remain % point != 0) { cnt++; } if (cnt < p[i]) { ans = Math.Min(ans, count + cnt); break; } cnt = p[i] - 1; sum += point * cnt; count += cnt; } } return ans; } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 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, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 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, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 11, 12, 16, 31, 16, 31, 23, 0, 24], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22]]
8
767
37
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Competition { public class Program { static string abcd = ""; static void Main(string[] args) { var dg = Console.ReadLine().Split(' '); var D = int.Parse(dg[0]); var G = long.Parse(dg[1]); long[] p = new long[D]; long[] c = new long[D]; for (var i = 0; i < D; i++) { long[] pc = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); p[i] = pc[0]; c[i] = pc[1]; } long res = 1 << 29; for (int bit = 0; bit < (1 << D); bit++) { long sum = 0; long num = 0; for (int i = 0; i < D; i++) { if ((bit & (1 << i)) == 1) { sum += c[i] + p[i] * 100 * (i + 1); num += p[i]; } } if (sum >= G) res = Math.Min(res, num); else { for (int i = D - 1; i >= 0; i--) { if ((bit & (1 << i)) == 1) continue; for (int j = 0; j < p[i]; j++) { if (sum >= G) break; sum += 100 * (i + 1); ++num; } } res = Math.Min(res, num); } } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Competition { public class Program { static void Main(string[] args) { var dg = Console.ReadLine().Split(' '); var D = int.Parse(dg[0]); var G = long.Parse(dg[1]); long[] p = new long[D]; long[] c = new long[D]; for (var i = 0; i < D; i++) { long[] pc = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); p[i] = pc[0]; c[i] = pc[1]; } long res = 1 << 29; for (int bit = 0; bit < (1 << D); bit++) { long sum = 0; long num = 0; for (int i = 0; i < D; i++) { if ((bit & (1 << i)) == (1 << i)) { sum += c[i] + p[i] * 100 * (i + 1); num += p[i]; } } if (sum >= G) { res = Math.Min(res, num); } else { for (int i = D - 1; i >= 0; i--) { if ((bit & (1 << i)) == (1 << i)) continue; for (int j = 0; j < p[i]; j++) { if (sum >= G) break; sum += 100 * (i + 1); ++num; } } res = Math.Min(res, num); } } Console.WriteLine(res); } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["-", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 151], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
391
17
using System; using System.Linq; using System.Collections.Generic; using static System.Math; using static System.Console; using System.Text; class Program { static void Main(string[] args) { solve(); } static Scanner cin; static int D; static int G; static int[] p; static int[] c; static void input() { cin = new Scanner(); D = cin.nextInt(); G = cin.nextInt(); p = new int[D]; c = new int[D]; for (int i = 0; i < D; i++) { p[i] = cin.nextInt(); c[i] = cin.nextInt(); } } static void solve() { input(); int[] dp = new int[D * 100 + 1]; int sumP = 0; for (int d = 0; d < D; d++) { sumP += p[d]; for (int i = sumP; i > 0; i--) { if (i - p[d] >= 0) dp[i] = Max(dp[i], dp[i - p[d]] + (d + 1) * 100 * p[d] + c[d]); for (int j = 1; i - j >= 0; j++) { dp[i] = Max(dp[i], dp[i - j] + 100 * (d + 1) * j); } } } for (int i = 1; i < dp.Length; i++) { if (dp[i] >= G) { WriteLine(i); return; } } } 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[] ArrayDounble(int N, int add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Math; using static System.Console; using System.Text; class Program { static void Main(string[] args) { solve(); } static Scanner cin; static int D; static int G; static int[] p; static int[] c; static void input() { cin = new Scanner(); D = cin.nextInt(); G = cin.nextInt(); p = new int[D]; c = new int[D]; for (int i = 0; i < D; i++) { p[i] = cin.nextInt(); c[i] = cin.nextInt(); } } static void solve() { input(); int[] dp = new int[D * 100 + 1]; int sumP = 0; for (int d = 0; d < D; d++) { sumP += p[d]; for (int i = sumP; i > 0; i--) { if (i - p[d] >= 0) dp[i] = Max(dp[i], dp[i - p[d]] + (d + 1) * 100 * p[d] + c[d]); for (int j = 1; j <= p[d] && i - j >= 0; j++) { dp[i] = Max(dp[i], dp[i - j] + 100 * (d + 1) * j); } } } for (int i = 1; i < dp.Length; i++) { if (dp[i] >= G) { WriteLine(i); return; } } } 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[] ArrayDounble(int N, int add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
[["+", 8, 196, 0, 7, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 19], ["+", 0, 7, 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, 7, 15, 16, 17, 98]]
8
715
7
using System; using System.Collections.Generic; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; int D; long G; long[] p; long[] c; public void Do() { cin = new Scanner(); D = cin.nextInt(); G = cin.nextLong(); p = new long[D]; c = new long[D]; for (int i = 0; i < D; i++) { p[i] = cin.nextLong(); c[i] = cin.nextLong(); } Console.WriteLine(dfs(0, 0)); } long solveToG(int isComplete) { long score = 0; long num = 0; for (int i = 1; i <= D; i++) { if ((isComplete >> i & 1) == 1) { score += c[i - 1] + i * 100 * p[i - 1]; num += p[i - 1]; } } if (score >= G) { return num; } long remaining = G - score; for (int i = D; i >= 1; i--) { if ((isComplete >> i & 1) == 1) { continue; } if (remaining <= i * 100 * p[i - 1]) { num += remaining / (i * 100); return num; } else if (remaining < i * 100 * p[i - 1]) { num += remaining / (i * 100) + 1; return num; } else { num += p[i - 1]; remaining -= i * 100 * p[i - 1]; } } return 100000000; } long dfs(int n, int isComplete) { if (n == D) { return solveToG(isComplete); } return Math.Min(dfs(n + 1, isComplete), dfs(n + 1, isComplete + (1 << n + 1))); } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; int D; long G; long[] p; long[] c; public void Do() { cin = new Scanner(); D = cin.nextInt(); G = cin.nextLong(); p = new long[D]; c = new long[D]; for (int i = 0; i < D; i++) { p[i] = cin.nextLong(); c[i] = cin.nextLong(); } Console.WriteLine(dfs(0, 0)); } long solveToG(int isComplete) { long score = 0; long num = 0; for (int i = 1; i <= D; i++) { if ((isComplete >> i & 1) == 1) { score += c[i - 1] + i * 100 * p[i - 1]; num += p[i - 1]; } } if (score >= G) { return num; } long remaining = G - score; for (int i = D; i >= 1; i--) { if ((isComplete >> i & 1) == 1) { continue; } if (remaining <= i * 100 * p[i - 1]) { num += remaining / (i * 100); if (remaining % (i * 100) != 0) { num++; } return num; } else { num += p[i - 1]; remaining -= i * 100 * p[i - 1]; } } return 100000000; } long dfs(int n, int isComplete) { if (n == D) { return solveToG(isComplete); } return Math.Min(dfs(n + 1, isComplete), dfs(n + 1, isComplete + (1 << n + 1))); } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 48], ["-", 75, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 0, 11, 12, 16, 31, 16, 12, 23, 0, 24], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 17, 48], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 16, 12, 23, 0, 25], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
845
30
using System; using System.Linq; using System.Collections.Generic; class Cmondai { static void Main() { var dg = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); var D = (int)dg[0]; var G = dg[1]; var list = new List<long[]>(); for (int i = 0; i < D; ++i) { var pc = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); list.Add(new long[2] { pc[0], pc[1] }); } var ans = long.MaxValue; for (int i = 0; i < (Math.Pow(2, D)); i++) { var count = 0L; var total = 0L; for (int j = 0; j < D; j++) { if ((1 & i >> j) == 1) { count += list[j][0]; total += list[j][0] * 100 * (j + 1) + list[j][1]; } } if (total < G) { for (int j = D - 1; 0 <= j; --j) { if ((1 & i >> j) == 0) { var add = (G - total) / ((j + 1) * 100); if (add <= list[j][0]) { count += add; total += add * 100 * (j + 1); if (G <= total) ans = Math.Min(ans, count); } break; } } } else ans = Math.Min(ans, count); } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Cmondai { static void Main() { var dg = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); var D = (int)dg[0]; var G = dg[1]; var list = new List<long[]>(); for (int i = 0; i < D; ++i) { var pc = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); list.Add(new long[2] { pc[0], pc[1] }); } var ans = long.MaxValue; for (int i = 0; i < (Math.Pow(2, D)); i++) { var count = 0L; var total = 0L; for (int j = 0; j < D; j++) { if ((1 & i >> j) == 1) { count += list[j][0]; total += list[j][0] * 100 * (j + 1) + list[j][1]; } } if (total < G) { for (int j = D - 1; 0 <= j; --j) { if ((1 & i >> j) == 0) { var add = ((G - total) + ((j + 1) * 100) - 1) / ((j + 1) * 100); if (add <= list[j][0]) { count += add; total += add * 100 * (j + 1); if (G <= total) ans = Math.Min(ans, count); } break; } } } else ans = Math.Min(ans, count); } Console.WriteLine(ans); } }
[["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["+", 31, 23, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 31, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 48], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 23, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203]]
8
395
14
using System; class Program { static int[] p; static int[] c; static int G; static int D; static void Main(string[] args) { var dg = Console.ReadLine().Split(' '); D = int.Parse(dg[0]); G = int.Parse(dg[1]); p = new int[D]; c = new int[D]; for (int i = 0; i < D; i++) { var s = Console.ReadLine().Split(' '); p[i] = int.Parse(s[0]); c[i] = int.Parse(s[1]); } var ans = dfs(0, new bool[D]); Console.WriteLine(ans); } static int dfs(int n, bool[] v) { if (v.Length <= n) { return m1(v); } v[n] = true; var left = dfs(n + 1, v); v[n] = false; var right = dfs(n + 1, v); return Math.Min(left, right); } static int m1(bool[] v) { var g = 0; var ans = 0; for (int i = 0; i < D; i++) { if (v[i]) { ans += p[i]; g += (i + 1) * 100 * p[i]; g += c[i]; } } if (G <= g) { return ans; } for (int i = D - 1; i >= 0; i--) { if (!v[i]) { var n = Math.Min(p[i], ceil(G - g, (i + 1) * 100)); ans += n; g += (i + 1) * 100 * n; } } if (G <= g) { return ans; } else { return int.MaxValue; } } static int ceil(int a, int b) { return a / b + (a % b > 0 ? 1 : 0); } }
using System; class Program { static int[] p; static int[] c; static int G; static int D; static void Main(string[] args) { var dg = Console.ReadLine().Split(' '); D = int.Parse(dg[0]); G = int.Parse(dg[1]); p = new int[D]; c = new int[D]; for (int i = 0; i < D; i++) { var s = Console.ReadLine().Split(' '); p[i] = int.Parse(s[0]); c[i] = int.Parse(s[1]); } var ans = dfs(0, new bool[D]); Console.WriteLine(ans); } static int dfs(int n, bool[] v) { if (v.Length <= n) { return m1(v); } v[n] = true; var left = dfs(n + 1, v); v[n] = false; var right = dfs(n + 1, v); return Math.Min(left, right); } static int m1(bool[] v) { var g = 0; var ans = 0; for (int i = 0; i < D; i++) { if (v[i]) { ans += p[i]; g += (i + 1) * 100 * p[i]; g += c[i]; } } if (G <= g) { return ans; } var j = D - 1; for (; j >= 0 && v[j]; j--) { } var n = Math.Min(p[j], ceil(G - g, (j + 1) * 100)); ans += n; g += (j + 1) * 100 * n; if (G <= g) { return ans; } else { return int.MaxValue; } } static int ceil(int a, int b) { return a / b + (a % b > 0 ? 1 : 0); } }
[["-", 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], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 31, 22], ["-", 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, 68], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 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, 241, 0, 111], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 98], ["-", 15, 241, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
461
34
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int D = int.Parse(s[0]); int G = int.Parse(s[1]); List<int[]> list = new List<int[]>(); for (int i = 0; i < D; i++) { int[] xz = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); list.Add(xz); } int min = int.MaxValue; int n = (int)Math.Pow(2, D); for (int i = 0; i < n; i++) { int k = i, counter = 0, countProblems = 0; int sum = 0; List<int> plist = new List<int>(); while (counter < D) { int[] v = list[counter]; if (k % 2 == 1) { sum += v[0] * (counter + 1) * 100 + v[1]; countProblems += v[0]; } else { plist.AddRange(Enumerable.Repeat((counter + 1) * 100, v[0] - 1)); } k /= 2; counter++; } plist.Reverse(); foreach (int p in plist) { sum += p; countProblems++; if (sum >= G) break; } if (sum >= G && countProblems < min) min = countProblems; } Console.WriteLine(min); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int D = int.Parse(s[0]); int G = int.Parse(s[1]); List<int[]> list = new List<int[]>(); for (int i = 0; i < D; i++) { int[] xz = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); list.Add(xz); } int min = int.MaxValue; int n = (int)Math.Pow(2, D); for (int i = 0; i < n; i++) { int k = i, counter = 0, countProblems = 0; int sum = 0; List<int> plist = new List<int>(); while (counter < D) { int[] v = list[counter]; if (k % 2 == 1) { sum += v[0] * (counter + 1) * 100 + v[1]; countProblems += v[0]; } else { plist.AddRange(Enumerable.Repeat((counter + 1) * 100, v[0] - 1)); } k /= 2; counter++; } plist.Reverse(); if (sum < G) { foreach (int p in plist) { sum += p; countProblems++; if (sum >= G) break; } } if (sum >= G && countProblems < min) min = countProblems; } Console.WriteLine(min); } } }
[["+", 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, 18], ["+", 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, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 210, 8, 196, 0, 46]]
8
376
8
using System; using System.Linq; namespace abc104_c { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); Tuple<int, int>[] arr = new Tuple<int, int>[x[0]]; for (int i = 0; i < x[0]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); arr[i] = new Tuple<int, int>(a[0], a[1]); } int ret = int.MaxValue; for (int i = 0; i < 2 << x[0]; i++) { int now = 0; int sum = 0; for (int j = 0; j < x[0]; j++) { if ((i & (1 << j)) > 0) { now += arr[j].Item1; sum += 100 * (j + 1) * arr[j].Item1 + arr[j].Item2; } } if (sum < x[1]) { int j = x[0] - 1; while ((i & (1 << j)) > 0) j--; int point = 100 * (j + 1); now += (x[1] - sum + (point - 1)) / point; } ret = Math.Min(ret, now); } Console.WriteLine(ret); } } }
using System; using System.Linq; namespace abc104_c { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); Tuple<int, int>[] arr = new Tuple<int, int>[x[0]]; for (int i = 0; i < x[0]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); arr[i] = new Tuple<int, int>(a[0], a[1]); } int ret = int.MaxValue; for (int i = 0; i < 2 << x[0]; i++) { int now = 0; int sum = 0; for (int j = 0; j < x[0]; j++) { if ((i & (1 << j)) > 0) { now += arr[j].Item1; sum += 100 * (j + 1) * arr[j].Item1 + arr[j].Item2; } } if (sum < x[1]) { int j = x[0] - 1; while ((i & (1 << j)) > 0) j--; int point = 100 * (j + 1); int should = (x[1] - sum + (point - 1)) / point; if (should > arr[j].Item1) now += 999999; else now += (x[1] - sum + (point - 1)) / point; } ret = Math.Min(ret, now); } Console.WriteLine(ret); } } }
[["+", 0, 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, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 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, 47], ["+", 0, 57, 15, 16, 12, 214, 205, 204, 205, 22], ["+", 15, 16, 12, 214, 205, 204, 206, 207, 0, 70], ["+", 12, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 214, 205, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 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], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95]]
8
338
36
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { string S = NextString(); int N = S.Length; long len = 0, a = 0, ab = 0, abc = 0; foreach (char c in S) { if (c == 'A') { a += RepPow(3, len); } else if (c == 'B') { ab += a; } else if (c == 'C') { abc += ab; } else { abc = abc * 3 + ab; ab = ab * 3 + a; a = a * 3 + RepPow(3, len); len++; } } Console.WriteLine(abc % MOD); } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static long RepPow(long x, long p, long m = 1000000007) { if (p == 0) return 1; if (p == 1) return x % m; long b = RepPow(x, p / 2, m) % m; if (p % 2 == 0) { return (b * b) % m; } else { return (x * ((b * b) % m)) % m; } } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; 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(); } public long Abs(long a, long b) => Math.Abs(a - b); }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { string S = NextString(); int N = S.Length; long len = 0, a = 0, ab = 0, abc = 0; foreach (char c in S) { if (c == 'A') { a += RepPow(3, len); } else if (c == 'B') { ab += a; } else if (c == 'C') { abc += ab; } else { abc = abc * 3 + ab; ab = ab * 3 + a; a = a * 3 + RepPow(3, len); len++; } a %= MOD; ab %= MOD; abc %= MOD; } Console.WriteLine(abc % MOD); } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static long RepPow(long x, long p, long m = 1000000007) { if (p == 0) return 1; if (p == 1) return x % m; long b = RepPow(x, p / 2, m) % m; if (p % 2 == 0) { return (b * b) % m; } else { return (x * ((b * b) % m)) % m; } } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; 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(); } public long Abs(long a, long b) => Math.Abs(a - b); }
[["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
661
12
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string str = Console.ReadLine(); long[] S = new long[str.Length]; long t = 1; long At = 0; long Bt = 0; long Ct = 0; long b = 1; long Ab = 0; long Bb = 0; long Cb = 0; for (var i = 0; i < str.Length; i++) { if (str.Substring(i, 1) == "A") { At = At + t; } else if (str.Substring(i, 1) == "B") { Bt = Bt + At; } else if (str.Substring(i, 1) == "C") { Ct = Ct + Bt; } else { Ct = Ct * 3 + Bt; Bt = Bt * 3 + At; At = At * 3 + t; t = t * 3; } Ct = Ct % 1000000007; } Console.WriteLine(Ct % 1000000007); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string str = Console.ReadLine(); long[] S = new long[str.Length]; long t = 1; long At = 0; long Bt = 0; long Ct = 0; for (var i = 0; i < str.Length; i++) { if (str.Substring(i, 1) == "A") { At = At + t; } else if (str.Substring(i, 1) == "B") { Bt = Bt + At; } else if (str.Substring(i, 1) == "C") { Ct = Ct + Bt; } else { Ct = Ct * 3 + Bt; Bt = Bt * 3 + At; At = At * 3 + t; t = t * 3; } t = t % 1000000007; At = At % 1000000007; Bt = Bt % 1000000007; Ct = Ct % 1000000007; } Console.WriteLine(Ct % 1000000007); } }
[["-", 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 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], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
224
38
using System; public class Hello { public static int MOD = 1000000007; public static void Main() { var s = Console.ReadLine().Trim(); var sL = s.Length; var a1 = new int[sL]; var q1 = new int[sL]; var c2 = new int[sL]; var q2 = new int[sL]; var ca1 = 0; var cc2 = 0; var cq1 = 0; var cq2 = 0; for (int i = 0; i < s.Length; i++) { a1[i] = ca1; q1[i] = cq1; c2[sL - 1 - i] = cc2; q2[sL - 1 - i] = cq2; if (s[i] == 'A') ca1++; else if (s[i] == '?') cq1++; if (s[sL - 1 - i] == 'C') cc2++; else if (s[sL - 1 - i] == '?') cq2++; } var ans = 0L; for (int i = 1; i <= sL - 2; i++) { if (s[i] == 'B' | s[i] == '?') { var acount = (long)a1[i]; var qcount = q1[i]; var wwa = (acount * (get3power(3, qcount))) % MOD; wwa += (qcount * (get3power(3, qcount - 1))) % MOD; wwa %= MOD; var ccount = c2[i]; var qcount2 = q2[i]; var wwc = (ccount * (get3power(3, qcount2))) % MOD; wwc += (qcount2 * (get3power(3, qcount2 - 1))) % MOD; wwc %= MOD; ans += (wwa * wwc) % MOD; ans %= MOD; } } Console.WriteLine(ans); } public static long get3power(int a, int b) { if (b == 0) return 1L; if (b == 1) return (long)(a % MOD); var k = (int)(Math.Log10(b) / Math.Log10(2)) + 1; var p = new long[k]; p[0] = (long)a; for (int i = 1; i < k; i++) p[i] = (p[i - 1] * p[i - 1]) % MOD; var ret = 1L; for (int i = 0; i < k; i++) if (((b >> i) & 1) == 1) { ret *= p[i]; ret %= MOD; } return ret; } }
using System; public class Hello { public static int MOD = 1000000007; public static void Main() { var s = Console.ReadLine().Trim(); var sL = s.Length; var a1 = new int[sL]; var q1 = new int[sL]; var c2 = new int[sL]; var q2 = new int[sL]; var ca1 = 0; var cc2 = 0; var cq1 = 0; var cq2 = 0; for (int i = 0; i < s.Length; i++) { a1[i] = ca1; q1[i] = cq1; c2[sL - 1 - i] = cc2; q2[sL - 1 - i] = cq2; if (s[i] == 'A') ca1++; else if (s[i] == '?') cq1++; if (s[sL - 1 - i] == 'C') cc2++; else if (s[sL - 1 - i] == '?') cq2++; } var ans = 0L; for (int i = 1; i <= sL - 2; i++) { if (s[i] == 'B' | s[i] == '?') { var acount = (long)a1[i]; var qcount = q1[i]; var wwa = (acount * (get3power(3, qcount))) % MOD; if (qcount >= 1) wwa += (qcount * (get3power(3, qcount - 1))) % MOD; wwa %= MOD; var ccount = c2[i]; var qcount2 = q2[i]; var wwc = (ccount * (get3power(3, qcount2))) % MOD; if (qcount2 >= 1) wwc += (qcount2 * (get3power(3, qcount2 - 1))) % MOD; wwc %= MOD; ans += (wwa * wwc) % MOD; ans %= MOD; } } Console.WriteLine(ans); } public static long get3power(int a, int b) { if (b == 0) return 1L; if (b == 1) return (long)(a % MOD); var k = (int)(Math.Log10(b) / Math.Log10(2)) + 1; var p = new long[k]; p[0] = (long)a; for (int i = 1; i < k; i++) p[i] = (p[i - 1] * p[i - 1]) % MOD; var ret = 1L; for (int i = 0; i < k; i++) if (((b >> i) & 1) == 1) { ret *= p[i]; ret %= MOD; } return ret; } }
[["+", 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, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25]]
8
569
12
using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Linq; class P { static int mod = 1000000007; static void Main() { string s = Console.ReadLine(); int n = s.Length; int[,] count = new int[n + 1, 4]; for (int i = 1; i <= n; i++) { count[i, 0] = count[i - 1, 0]; count[i, 1] = count[i - 1, 1]; count[i, 2] = count[i - 1, 2]; count[i, 3] = count[i - 1, 3]; if (s[i - 1] == 'A') count[i, 0]++; if (s[i - 1] == 'B') count[i, 1]++; if (s[i - 1] == 'C') count[i, 2]++; if (s[i - 1] == '?') count[i, 3]++; } long ans = 0; if (count[n, 3] >= 3) { //'?'を3個使う long q = count[n, 3]; long p = Math.Max(q - 3, 0); long t = (q * (q - 1)) % mod; t = (t * (q - 2)) % mod; t = (t * POW(6, mod - 2)) % mod; ans = (ans + (t * POW(3, p)) % mod) % mod; } if (count[n, 3] >= 2) { //'?'を2個使う for (int i = 0; i < n; i++) { long p = Math.Max(count[n, 3] - 2, 0); if (s[i] == 'A') { long q = count[n, 3] - count[i + 1, 3]; ans = (ans + ((q * (q - 1)) / 2 % mod * POW(3, p)) % mod) % mod; } if (s[i] == 'B') { long ql = count[i, 3]; long qr = count[n, 3] - count[i + 1, 3]; ans = (ans + (ql * qr) % mod * POW(3, p) % mod) % mod; } if (s[i] == 'C') { long q = count[i, 3]; ans = (ans + (q * (q - 1)) / 2 % mod * POW(3, p) % mod) % mod; } } } long q0 = 0; { //'?'を0個使う StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) if (s[i] != '?') sb.Append(s[i]); q0 = Calc(sb.ToString()); ans += q0 * POW(3, count[n, 3]) % mod; ans %= mod; } long q1 = 0; if (count[n, 3] >= 1) { //'?'を1個使う long q = count[n, 3]; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (s[i] != '?') sb.Append(s[i]); else sb.Append('A'); } ans = (ans + (Calc(sb.ToString()) - q0) * POW(3, q - 1) % mod) % mod; sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (s[i] != '?') sb.Append(s[i]); else sb.Append('B'); } ans = (ans + (Calc(sb.ToString()) - q0) * POW(3, q - 1) % mod) % mod; sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (s[i] != '?') sb.Append(s[i]); else sb.Append('C'); } ans = (ans + (Calc(sb.ToString()) - q0) * POW(3, q - 1) % mod) % mod; } while (ans < 0) ans += mod; Console.WriteLine(ans); } static long POW(long a, long n) { if (n == 0) return 1; if (n == 1) return a % mod; long m = n / 2; if (n % 2 == 0) { long temp = POW(a, m); return (temp * temp) % mod; } else { long temp = POW(a, m); return ((temp * temp) % mod * a) % mod; } } static long Calc(string s) //'A''B''C'のみの文字列からABC数を計算 { long[] a = new long[s.Length + 1]; long[] b = new long[s.Length + 1]; long[] c = new long[s.Length + 1]; for (int i = 1; i <= s.Length; i++) { a[i] = a[i - 1]; b[i] = b[i - 1]; c[i] = c[i - 1]; if (s[i - 1] == 'A') a[i]++; if (s[i - 1] == 'B') b[i]++; if (s[i - 1] == 'C') c[i]++; } long[] bc = new long[s.Length]; for (int i = 0; i < s.Length; i++) if (s[i] == 'B') bc[i] = c[s.Length] - c[i + 1]; long[] bcs = new long[s.Length]; bcs[s.Length - 1] = bc[s.Length - 1]; for (int i = s.Length - 2; i >= 0; i--) bcs[i] = bcs[i + 1] + bc[i]; long ans = 0; for (int i = 0; i < s.Length - 1; i++) if (s[i] == 'A') ans = (ans + bcs[i + 1] % mod) % mod; return ans; } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Linq; class P { static int mod = 1000000007; static void Main() { string s = Console.ReadLine(); int n = s.Length; int[,] count = new int[n + 1, 4]; for (int i = 1; i <= n; i++) { count[i, 0] = count[i - 1, 0]; count[i, 1] = count[i - 1, 1]; count[i, 2] = count[i - 1, 2]; count[i, 3] = count[i - 1, 3]; if (s[i - 1] == 'A') count[i, 0]++; if (s[i - 1] == 'B') count[i, 1]++; if (s[i - 1] == 'C') count[i, 2]++; if (s[i - 1] == '?') count[i, 3]++; } long ans = 0; if (count[n, 3] >= 3) { //'?'を3個使う long q = count[n, 3]; long p = Math.Max(q - 3, 0); long t = (q * (q - 1)) % mod; t = (t * (q - 2)) % mod; t = (t * POW(6, mod - 2)) % mod; ans = (ans + (t * POW(3, p)) % mod) % mod; } if (count[n, 3] >= 2) { //'?'を2個使う for (int i = 0; i < n; i++) { long p = Math.Max(count[n, 3] - 2, 0); if (s[i] == 'A') { long q = count[n, 3] - count[i + 1, 3]; ans = (ans + ((q * (q - 1)) / 2 % mod * POW(3, p)) % mod) % mod; } if (s[i] == 'B') { long ql = count[i, 3]; long qr = count[n, 3] - count[i + 1, 3]; ans = (ans + (ql * qr) % mod * POW(3, p) % mod) % mod; } if (s[i] == 'C') { long q = count[i, 3]; ans = (ans + (q * (q - 1)) / 2 % mod * POW(3, p) % mod) % mod; } } } long q0 = 0; { //'?'を0個使う StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) if (s[i] != '?') sb.Append(s[i]); q0 = Calc(sb.ToString()); ans += q0 * POW(3, count[n, 3]) % mod; ans %= mod; } long q1 = 0; if (count[n, 3] >= 1) { //'?'を1個使う long q = count[n, 3]; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (s[i] != '?') sb.Append(s[i]); else sb.Append('A'); } ans = (ans + (Calc(sb.ToString()) - q0) * POW(3, q - 1) % mod) % mod; sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (s[i] != '?') sb.Append(s[i]); else sb.Append('B'); } ans = (ans + (Calc(sb.ToString()) - q0) * POW(3, q - 1) % mod) % mod; sb = new StringBuilder(); for (int i = 0; i < n; i++) { if (s[i] != '?') sb.Append(s[i]); else sb.Append('C'); } ans = (ans + (Calc(sb.ToString()) - q0) * POW(3, q - 1) % mod) % mod; } while (ans < 0) ans += mod; Console.WriteLine(ans); } static long POW(long a, long n) { if (n == 0) return 1; if (n == 1) return a % mod; long m = n / 2; if (n % 2 == 0) { long temp = POW(a, m); return (temp * temp) % mod; } else { long temp = POW(a, m); return ((temp * temp) % mod * a) % mod; } } static long Calc(string s) //'A''B''C'のみの文字列からABC数を計算 { try { long[] a = new long[s.Length + 1]; long[] b = new long[s.Length + 1]; long[] c = new long[s.Length + 1]; for (int i = 1; i <= s.Length; i++) { a[i] = a[i - 1]; b[i] = b[i - 1]; c[i] = c[i - 1]; if (s[i - 1] == 'A') a[i]++; if (s[i - 1] == 'B') b[i]++; if (s[i - 1] == 'C') c[i]++; } long[] bc = new long[s.Length]; for (int i = 0; i < s.Length; i++) if (s[i] == 'B') bc[i] = c[s.Length] - c[i + 1]; long[] bcs = new long[s.Length]; bcs[s.Length - 1] = bc[s.Length - 1]; for (int i = s.Length - 2; i >= 0; i--) bcs[i] = bcs[i + 1] + bc[i]; long ans = 0; for (int i = 0; i < s.Length - 1; i++) if (s[i] == 'A') ans = (ans + bcs[i + 1] % mod) % mod; return ans; } catch { return 0; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 246, 0, 247], ["+", 0, 195, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 38], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 203], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 35], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 46]]
8
1,413
9
using System; using System.Collections.Generic; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } } class SegTree { private readonly long[] Array; private readonly int N; public SegTree(int size) { N = 1; while (N < size) { N *= 2; } Array = new long[N * 2]; } public void Update(long item, int index) { index += N; Array[index] = item; while (index > 1) { index /= 2; Array[index] = Array[index * 2] + Array[index * 2 + 1]; } } private long Q(int left, int right, int k, int l, int r) { if (left <= l && r <= right) { return Array[k]; } if (r <= left || right <= l) { return 0; } return Q(left, right, k * 2, l, (l + r) / 2) + Q(left, right, k * 2 + 1, (l + r) / 2, r); } public long Query(int left, int right) { return Q(left, right, 1, 0, N); } public long this[int i] { get { return Array[i + N]; } set { Update(value, i); } } } class Program { private string S; private const int Mod = (int)1e9 + 7; private int[] ACnt, CCnt, QCnt; private long[] PoW3; private List<int> BIndex; private void Scan() { Scanner sc = new Scanner(); S = sc.Next(); } public void Solve() { Scan(); PoW3 = new long[100001]; PoW3[0] = 1; for (int i = 1; i < 100001; i++) { PoW3[i] = (PoW3[i - 1] * 3) % Mod; } int n = S.Length; ACnt = new int[n + 1]; CCnt = new int[n + 1]; QCnt = new int[n + 1]; BIndex = new List<int>(); for (int i = 0; i < n; i++) { switch (S[i]) { case 'A': ACnt[i + 1] = 1; break; case 'B': BIndex.Add(i); break; case 'C': CCnt[i + 1] = 1; break; case '?': QCnt[i + 1] = 1; BIndex.Add(i); break; } ACnt[i + 1] += ACnt[i]; CCnt[i + 1] += CCnt[i]; QCnt[i + 1] += QCnt[i]; } long ans = 0; foreach (int i in BIndex) { long aa = (long)(ACnt[i] - ACnt[0]) * Pow(QCnt[i] - QCnt[0]); long aq = (long)(QCnt[i] - QCnt[0]) * Pow(QCnt[i] - QCnt[0] - 1); long cc = (long)(CCnt[n] - CCnt[i + 1]) * Pow(QCnt[n] - QCnt[i + 1]); long cq = (long)(QCnt[n] - QCnt[i + 1]) * Pow(QCnt[n] - QCnt[i + 1] - 1); ans += ((aa + aq) % Mod * (cc + cq) % Mod) % Mod; ans %= Mod; } Console.WriteLine(ans); } private long Pow(int n) { if (n < 0) return 0; return PoW3[n]; } static void Main() => new Program().Solve(); } }
using System; using System.Collections.Generic; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } } class SegTree { private readonly long[] Array; private readonly int N; public SegTree(int size) { N = 1; while (N < size) { N *= 2; } Array = new long[N * 2]; } public void Update(long item, int index) { index += N; Array[index] = item; while (index > 1) { index /= 2; Array[index] = Array[index * 2] + Array[index * 2 + 1]; } } private long Q(int left, int right, int k, int l, int r) { if (left <= l && r <= right) { return Array[k]; } if (r <= left || right <= l) { return 0; } return Q(left, right, k * 2, l, (l + r) / 2) + Q(left, right, k * 2 + 1, (l + r) / 2, r); } public long Query(int left, int right) { return Q(left, right, 1, 0, N); } public long this[int i] { get { return Array[i + N]; } set { Update(value, i); } } } class Program { private string S; private const int Mod = (int)1e9 + 7; private int[] ACnt, CCnt, QCnt; private long[] PoW3; private List<int> BIndex; private void Scan() { Scanner sc = new Scanner(); S = sc.Next(); } public void Solve() { Scan(); PoW3 = new long[100001]; PoW3[0] = 1; for (int i = 1; i < 100001; i++) { PoW3[i] = (PoW3[i - 1] * 3) % Mod; } int n = S.Length; ACnt = new int[n + 1]; CCnt = new int[n + 1]; QCnt = new int[n + 1]; BIndex = new List<int>(); for (int i = 0; i < n; i++) { switch (S[i]) { case 'A': ACnt[i + 1] = 1; break; case 'B': BIndex.Add(i); break; case 'C': CCnt[i + 1] = 1; break; case '?': QCnt[i + 1] = 1; BIndex.Add(i); break; } ACnt[i + 1] += ACnt[i]; CCnt[i + 1] += CCnt[i]; QCnt[i + 1] += QCnt[i]; } long ans = 0; foreach (int i in BIndex) { long aa = ((long)(ACnt[i] - ACnt[0]) * Pow(QCnt[i] - QCnt[0])) % Mod; long aq = ((long)(QCnt[i] - QCnt[0]) * Pow(QCnt[i] - QCnt[0] - 1)) % Mod; long cc = ((long)(CCnt[n] - CCnt[i + 1]) * Pow(QCnt[n] - QCnt[i + 1])) % Mod; long cq = ((long)(QCnt[n] - QCnt[i + 1]) * Pow(QCnt[n] - QCnt[i + 1] - 1)) % Mod; ans += ((aa + aq) % Mod * (cc + cq) % Mod) % Mod; ans %= Mod; } Console.WriteLine(ans); } private long Pow(int n) { if (n < 0) return 0; return PoW3[n]; } static void Main() => new Program().Solve(); } }
[["+", 0, 16, 31, 23, 0, 16, 31, 74, 0, 24], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25]]
8
1,065
16
using System; using System.Collections.Generic; using System.Linq; using System.Security.Policy; using System.Web; namespace Competitive { internal class Solution { public string S; public long[] B, C, BC, ABC, T; public void Run() { S = Console.ReadLine(); int L = S.Length; B = new long[S.Length + 1]; C = new long[S.Length + 1]; BC = new long[S.Length + 1]; ABC = new long[S.Length + 1]; T = new long[S.Length + 1]; B[L] = 0; C[L] = 0; BC[L] = 0; ABC[L] = 0; T[L] = 1; for (int i = L - 1; i >= 0; i--) { if (S[i] == 'A' || S[i] == '?') { B[i] += B[i + 1]; C[i] += C[i + 1]; BC[i] += BC[i + 1]; ABC[i] += ABC[i + 1]; T[i] += T[i + 1]; ABC[i] += BC[i + 1]; } if (S[i] == 'B' || S[i] == '?') { B[i] += B[i + 1]; C[i] += C[i + 1]; BC[i] += BC[i + 1]; ABC[i] += ABC[i + 1]; T[i] += T[i + 1]; B[i] += T[i + 1]; BC[i] += C[i + 1]; } if (S[i] == 'C' || S[i] == '?') { B[i] += B[i + 1]; C[i] += C[i + 1]; BC[i] += BC[i + 1]; ABC[i] += ABC[i + 1]; T[i] += T[i + 1]; C[i] += T[i + 1]; } B[i] %= 1000000007; C[i] %= 1000000007; BC[i] %= 1000000007; ABC[i] %= 1000000007; } Console.WriteLine(ABC[0]); } } // libs ---------- // common ---------- internal static class Input { public static string ReadString() { string line = Console.ReadLine(); return line; } public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static long ReadLong() { string line = Console.ReadLine(); return long.Parse(line); } public static long[] ReadLongArray() { string line = Console.ReadLine(); return line.Split(' ').Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Security.Policy; using System.Web; namespace Competitive { internal class Solution { public string S; public long[] B, C, BC, ABC, T; public void Run() { S = Console.ReadLine(); int L = S.Length; B = new long[S.Length + 1]; C = new long[S.Length + 1]; BC = new long[S.Length + 1]; ABC = new long[S.Length + 1]; T = new long[S.Length + 1]; B[L] = 0; C[L] = 0; BC[L] = 0; ABC[L] = 0; T[L] = 1; for (int i = L - 1; i >= 0; i--) { if (S[i] == 'A' || S[i] == '?') { B[i] += B[i + 1]; C[i] += C[i + 1]; BC[i] += BC[i + 1]; ABC[i] += ABC[i + 1]; T[i] += T[i + 1]; ABC[i] += BC[i + 1]; } if (S[i] == 'B' || S[i] == '?') { B[i] += B[i + 1]; C[i] += C[i + 1]; BC[i] += BC[i + 1]; ABC[i] += ABC[i + 1]; T[i] += T[i + 1]; B[i] += T[i + 1]; BC[i] += C[i + 1]; } if (S[i] == 'C' || S[i] == '?') { B[i] += B[i + 1]; C[i] += C[i + 1]; BC[i] += BC[i + 1]; ABC[i] += ABC[i + 1]; T[i] += T[i + 1]; C[i] += T[i + 1]; } B[i] %= 1000000007; C[i] %= 1000000007; BC[i] %= 1000000007; T[i] %= 1000000007; ABC[i] %= 1000000007; } Console.WriteLine(ABC[0]); } } // libs ---------- // common ---------- internal static class Input { public static string ReadString() { string line = Console.ReadLine(); return line; } public static int ReadInt() { string line = Console.ReadLine(); return int.Parse(line); } public static int[] ReadIntArray() { string line = Console.ReadLine(); return line.Split(' ').Select(int.Parse).ToArray(); } public static long ReadLong() { string line = Console.ReadLine(); return long.Parse(line); } public static long[] ReadLongArray() { string line = Console.ReadLine(); return line.Split(' ').Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { string line = Console.ReadLine(); return line.Split(' ').Select(double.Parse).ToArray(); } } internal class Program { public static void Main(string[] args) { var s = new Solution(); s.Run(); } } }
[["+", 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, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
750
7
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var list = new List<int>(); var sum = 0; for (var x = 0; x < str.Count(); x++) { list.Add(str[x]); } sum = list.Max() - list.Min(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var list = new List<int>(); var sum = 0; for (var x = 0; x < str.Count(); x++) { list.Add(str[x]); } sum = list.Max() - list.Min(); Console.WriteLine(sum); } } }
[["+", 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
119
7
using System; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { var a = ReadIntArray(); Array.Sort(a); var ans = a[0] - a[1]; ans += a[2] - a[1]; WriteAnswer(ans); } 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.Diagnostics; using System.IO; using System.Linq; namespace AtCoder { class Practice { static void Main() => CustomMain(); static void Solve() { var a = ReadIntArray(); Array.Sort(a); var ans = Math.Abs(a[0] - a[1]); ans += Math.Abs(a[2] - a[1]); WriteAnswer(ans); } 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, 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], ["+", 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, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
727
10
using System; namespace AtCoder.ABC103 { public class A { public static void Solve() { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int min = 0; int x, y, z; x = Math.Abs(a - b); y = Math.Abs(b - c); z = Math.Abs(a - c); min = Math.Min(x, y); min = Math.Min(min, z); Console.WriteLine(min); } } } namespace AtCoder { class Program { static void Main(string[] args) { ABC103.A.Solve(); } } }
using System; using System.Numerics; namespace Atcoder.ABC103 { public class A { public static void Solve() { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int max = 0; int x, y, z; x = Math.Abs(a - b); y = Math.Abs(b - c); z = Math.Abs(a - c); // // Console.WriteLine(x); // Console.WriteLine(y); // Console.WriteLine(z); max = Math.Max(x, y); max = Math.Max(max, z); Console.WriteLine(max); } } } namespace Atcoder { class Program { static void Main(string[] args) { ABC103.A.Solve(); } } }
[["+", 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], ["-", 36, 36, 0, 208, 0, 209, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 209, 141, 232, 234, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22]]
8
180
23
using System; using System.Linq; using System.Collections.Generic; using static System.Math; public class Program { public static void Main(string[] args) { List<int> task = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToList(); int answer = 0; for (int i = 0; i < task.Count() - 1; i++) { answer += task[i] - task[i + 1]; } Console.WriteLine(answer); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Math; public class Program { public static void Main(string[] args) { List<int> task = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToList(); int answer = 0; for (int i = 0; i < task.Count() - 1; i++) { answer += task[i + 1] - task[i]; } Console.WriteLine(answer); } }
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
120
4
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var T = Console.ReadLine(); var ret = false; for (int i = T.Length - 1; i >= 0; i--) { var takeIndex = i; var takeLen = T.Length - i; var take = T.Substring(takeIndex, takeLen); T = T.Substring(0, takeIndex); T = T.Insert(0, take); if (S == T) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var T = Console.ReadLine(); var ret = false; for (int i = T.Length - 1; i >= 0; i--) { var take = T.Substring(T.Length - 1, 1); T = T.Substring(0, T.Length - 1); T = T.Insert(0, take); if (S == T) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
[["-", 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], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 205, 22], ["-", 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, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
167
28
using System; using System.Linq; namespace B.String_Rotation { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var T = Console.ReadLine(); bool ans = false; for (int i = 0; i < S.Length; i++) { S = string.Concat(S.Last(), S); S = S.Remove(S.Length - 1); ans = S == T ? true : false; } Console.WriteLine(ans ? "Yes" : "No"); } } }
using System; using System.Linq; namespace B.String_Rotation { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var T = Console.ReadLine(); bool ans = false; for (int i = 0; i < S.Length; i++) { S = string.Concat(S.Last(), S); S = S.Remove(S.Length - 1); if (S == T) { ans = true; break; } } Console.WriteLine(ans ? "Yes" : "No"); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 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], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["-", 0, 1, 0, 11, 12, 41, 75, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
123
14
using System; using System.Collections.Generic; namespace ABC103_B_String_Rotation { internal class Program { public static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); List<string> rollS = new List<string>(); bool matchStr = false; for (int i = 0; i < s.Length; i++) { rollS.Add(s.Substring(i, 1)); } string endStr = ""; for (int i = 0; i < s.Length; i++) { for (int j = s.Length - 1; j > 0; j--) { if (j == s.Length - 1) { endStr = rollS[j]; } rollS[j] = rollS[j - 1]; if (j == 1) { rollS[0] = endStr; } } string rollEndS = ""; foreach (var str in rollS) { rollEndS += str; } Console.WriteLine(rollEndS); if (rollEndS == t) { matchStr = true; break; } } if (matchStr) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; namespace ABC103_B_String_Rotation { internal class Program { public static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); List<string> rollS = new List<string>(); bool matchStr = false; for (int i = 0; i < s.Length; i++) { rollS.Add(s.Substring(i, 1)); } string endStr = ""; for (int i = 0; i < s.Length; i++) { for (int j = s.Length - 1; j > 0; j--) { if (j == s.Length - 1) { endStr = rollS[j]; } rollS[j] = rollS[j - 1]; if (j == 1) { rollS[0] = endStr; } } string rollEndS = ""; foreach (var str in rollS) { rollEndS += str; } if (rollEndS == t) { matchStr = true; break; } } if (matchStr) { 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, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
257
7
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication9 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int count = 0; for (int i = 1; i < N; i++) { if (i % 2 == 1 && DivisorsNum(i) == 8) { count++; } } Console.WriteLine(count); } public static int DivisorsNum(int N) { int count = 0; for (int i = 1; i < N; i++) { if (N % i == 0) { count++; } } return count; } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication9 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int count = 0; for (int i = 1; i <= N; i++) { if (i % 2 == 1 && DivisorsNum(i)) { count++; } } Console.WriteLine(count); } public static bool DivisorsNum(int N) { int count = 0; for (int i = 1; i <= N; i++) { if (N % i == 0) { count++; } if (count > 8) return false; } if (count == 8) return true; else return false; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 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, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 37, 0, 211, 0, 147], ["+", 0, 7, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 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, 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, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 37, 0, 211, 0, 146], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 37, 0, 38], ["+", 8, 196, 0, 57, 75, 37, 0, 211, 0, 147]]
8
160
4
using System; using System.Numerics; namespace study11 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int caunto = 0; int ans = 0; for (int a = 1; a <= N; a++) for (int b = 1; b <= N; b++) if (a % b == 0) { caunto++; if (caunto == 8) ans++; caunto = 0; } Console.WriteLine(ans); } } }
using System; using System.Numerics; namespace study11 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int caunto = 0; int ans = 0; for (int a = 1; a <= N; a += 2) { caunto = 0; for (int b = 1; b <= a; b++) { if (a % b == 0) caunto++; } if (caunto == 8) ans++; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 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, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 7, 8, 7, 8, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
112
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp62 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int type_A = 0; //〇×〇×〇×△型を探す for (int k = 1; k <= N; k += 2) { for (int i = 1; i * i * i <= k; i++) { if (!isPrime(i)) { continue; } if (N % i == 0 && k % (i * i) == 0 && k % (i * i * i) == 0 && k / (i * i * i) != i) { if (isPrime(k / (i * i * i))) { Console.WriteLine("(k, i) = " + k + " " + i); type_A++; } } } } int type_B = 0; //〇×△×◇型を探す for (int i = 1; i * (i + 1) * (i + 2) <= N; i += 2) { for (int j = i + 2; i * i * j <= N; j += 2) { for (int k = j + 2; i * j * k <= N; k += 2) { if (isPrime(i) && isPrime(j) && isPrime(k) && i * j * k <= N) { type_B++; } } } } Console.WriteLine(type_A + type_B); } //素数かどうかを返す static bool isPrime(int N) { if (N == 1) { return false; } if (N == 2 || N == 3) { return true; } for (int i = 2; i * i <= N; i++) { if (N % i == 0) { return false; } } return true; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp62 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int type_A = 0; //〇×〇×〇×△型を探す for (int k = 1; k <= N; k += 2) { for (int i = 1; i * i * i <= k; i++) { if (!isPrime(i)) { continue; } if (k % i == 0 && k % (i * i) == 0 && k % (i * i * i) == 0 && k / (i * i * i) != i) { if (isPrime(k / (i * i * i))) { // Console.WriteLine("(k, i) = " + k + " " + i); type_A++; } } } } int type_B = 0; //〇×△×◇型を探す for (int i = 1; i * (i + 1) * (i + 2) <= N; i += 2) { for (int j = i + 2; i * i * j <= N; j += 2) { for (int k = j + 2; i * j * k <= N; k += 2) { if (isPrime(i) && isPrime(j) && isPrime(k) && i * j * k <= N) { // Console.WriteLine("(i, j, k) = " + i + " " + j + " " + k); type_B++; } } } } Console.WriteLine(type_A + type_B); } //素数かどうかを返す static bool isPrime(int N) { if (N == 1) { return false; } if (N == 2 || N == 3) { return true; } for (int i = 2; i * i <= N; i++) { if (N % i == 0) { return false; } } return true; } } }
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 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, 16, 31, 16, 31, 16, 31, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 31, 5, 0, 222], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 12, 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], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
386
19
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder1 { class MainClass { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); if (n < 105) Console.WriteLine(0); else if (n < 135) Console.WriteLine(1); else if (n < 189) Console.WriteLine(2); else Console.WriteLine(3); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder1 { class MainClass { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); if (n < 105) Console.WriteLine(0); else if (n < 135) Console.WriteLine(1); else if (n < 165) Console.WriteLine(2); else if (n < 189) Console.WriteLine(3); else if (n < 195) Console.WriteLine(4); else Console.WriteLine(5); Console.Out.Flush(); } } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 18], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
181
30
using System; using System.IO; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); // 3 5 7 11 // 105 // 165 // 195 Console.WriteLine(n < 105 ? 0 : n < 165 ? 1 : n < 195 ? 2 : 3); } }
using System; using System.IO; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); Console.WriteLine(n < 105 ? 0 : n < 135 ? 1 : n < 165 ? 2 : n < 189 ? 3 : n < 195 ? 4 : 5); } }
[["-", 0, 28, 0, 41, 75, 41, 15, 16, 12, 203], ["+", 0, 28, 0, 41, 75, 41, 15, 16, 12, 203], ["-", 0, 41, 75, 41, 75, 41, 15, 16, 12, 203], ["+", 0, 41, 75, 41, 75, 41, 15, 16, 12, 203], ["+", 75, 41, 75, 41, 75, 41, 15, 16, 31, 22], ["+", 75, 41, 75, 41, 75, 41, 15, 16, 17, 18], ["+", 75, 41, 75, 41, 75, 41, 15, 16, 12, 203], ["+", 0, 41, 75, 41, 75, 41, 75, 41, 0, 101], ["+", 0, 41, 75, 41, 75, 41, 75, 41, 0, 102], ["+", 75, 41, 75, 41, 75, 41, 75, 41, 0, 101], ["+", 75, 41, 75, 41, 75, 41, 75, 41, 64, 203], ["+", 75, 41, 75, 41, 75, 41, 75, 41, 0, 102], ["+", 75, 41, 75, 41, 75, 41, 75, 41, 75, 203]]
8
130
16
using System; using System.Collections.Generic; class c { static void Main() { int n = int.Parse(Console.ReadLine()); var list = new List<int> { 105, 135, 165, 195 }; int ans = 0; for (int i = 0; i <= n; i++) { if (list.Contains(i)) ans++; } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class c { static void Main() { int n = int.Parse(Console.ReadLine()); var list = new List<int> { 105, 135, 165, 189, 195 }; int ans = 0; for (int i = 0; i <= n; i++) { if (list.Contains(i)) ans++; } Console.WriteLine(ans); } }
[["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["+", 0, 200, 0, 212, 0, 230, 10, 229, 0, 21], ["+", 0, 200, 0, 212, 0, 230, 10, 229, 0, 203]]
8
93
7
using System; class MainClass { public static void Main(string[] args) { int cnt = 0; int ans = 0; int num = int.Parse(Console.ReadLine()); for (int i = 0; i < num; i++) { if (i % 2 == 1) { for (int j = 1; j < num; j++) { if (i % j == 0) { cnt++; if (cnt == 8) { ans++; } } } } } Console.WriteLine(ans); } }
using System; class MainClass { public static void Main(string[] args) { int cnt = 0; int ans = 0; int num = int.Parse(Console.ReadLine()); for (int i = 1; i <= num; i++) { if (i % 2 == 1) { cnt = 0; for (int j = 1; j <= i; j++) { if (i % j == 0) { cnt++; if (cnt == 8) { ans++; } } } } } Console.WriteLine(ans); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22]]
8
116
12
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var num = int.Parse(ReadLine()); int count = 0; if (105 <= num) ++count; if (135 <= num) ++count; if (165 <= num) ++count; if (189 <= num) ++count; WriteLine(count); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var num = int.Parse(ReadLine()); int count = 0; if (105 <= num) ++count; if (135 <= num) ++count; if (165 <= num) ++count; if (189 <= num) ++count; if (195 <= num) ++count; WriteLine(count); } }
[["+", 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, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 241, 0, 29], ["+", 8, 196, 0, 57, 64, 1, 0, 241, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
94
9
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); if (n < 104) { Console.WriteLine(0); goto end; } if (n == 105) { Console.WriteLine(1); goto end; } var res = 1; for (int i = 106; i <= n; i++) { if (i % 2 == 1) { var count = 0; for (int j = 1; j <= n; j++) if (i % j == 0) count++; if (count == 8) res++; } } Console.WriteLine(res); end:; } }
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); if (n <= 104) { Console.WriteLine(0); goto end; } if (n <= 106) { Console.WriteLine(1); goto end; } var res = 1; for (int i = 107; i <= n; i += 2) { var count = 1; for (int j = 1; j <= n / 2; j += 2) if (i % j == 0) count++; if (count == 8) res++; } Console.WriteLine(res); end:; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 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, 195, 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], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 7, 26, 11, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
150
6
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int inpt = int.Parse(Reader.ReadLine()); int ans = 0; for (int i = 105; i <= inpt; i++) { if (YakusuCount(i) == 8) { ans++; } } Console.WriteLine(ans); } private int YakusuCount(int num) { int ans = 0; bool isHeihou = false; for (int i = 1; i * i <= num; i++) { if (num % i == 0) { ans++; } if (i * i == num) { isHeihou = true; } } ans = ans * 2; if (isHeihou) { ans--; } return ans; } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 200 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int inpt = int.Parse(Reader.ReadLine()); int ans = 0; for (int i = 105; i <= inpt; i++) { if (i % 2 == 0) { continue; } if (YakusuCount(i) == 8) { ans++; } } Console.WriteLine(ans); } private int YakusuCount(int num) { int ans = 0; bool isHeihou = false; for (int i = 1; i * i <= num; i++) { if (num % i == 0) { ans++; } if (i * i == num) { isHeihou = true; } } ans = ans * 2; if (isHeihou) { ans--; } return ans; } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 200 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 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, 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, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24]]
8
286
12
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 readonly long Mod = 1000000000 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var S = ReadLine(); var K = Sarray()[0]; long cnt = S.Length; for (var i = 0; i < S.Length; ++i) { if (S[i] != '1') { WriteLine(S[i]); return; } } WriteLine(S[(int)K - 1]); // Out.Flush(); } } }
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 readonly long Mod = 1000000000 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var S = ReadLine(); var K = Sarray()[0]; long cnt = S.Length; for (var i = 0; i < S.Length; ++i) { if (S[i] != '1' || K - 1 == i) { WriteLine(S[i]); return; } } // Out.Flush(); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 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, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 16, 31, 74, 0, 24], ["-", 206, 207, 0, 28, 0, 16, 31, 74, 39, 199], ["-", 206, 207, 0, 28, 0, 16, 31, 74, 0, 25], ["-", 206, 207, 0, 28, 0, 16, 31, 74, 51, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
206
19
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.C { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var S = ReadText(); var K = ReadLong(); var s = 'x'; for (int i = 0; i < S.Length; i++) { var item = S[i]; if (item != '1') { if (K <= i) { s = '1'; break; } s = item; break; } } return s; } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.C { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var S = ReadText(); var K = ReadLong(); var s = 'x'; for (int i = 0; i < S.Length; i++) { var item = S[i]; if (i + 1 == K) { s = item; break; } if (item != '1') { s = item; break; } } return s; } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 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, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 252, 0, 104], ["-", 64, 196, 0, 1, 0, 11, 12, 252, 0, 253], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 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, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45]]
8
430
26
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var s = ReadLine(); var k = IO.RLong; for (int i = 0; i < s.Length; i++) { if (s[i] != '1') { if (k <= i) { WriteLine('1'); return; } WriteLine(s[i]); return; } } } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var s = ReadLine(); var k = IO.RLong; for (int i = 0; i < s.Length; i++) { if (s[i] != '1') { if (k <= i) { WriteLine('1'); return; } WriteLine(s[i]); return; } } WriteLine('1'); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } }
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 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, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
536
7
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; 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 S = sc.ReadStr(); var K = sc.ReadLong(); var lastIndex1 = S.LastIndexOf('1'); if (lastIndex1 + 1 >= K) Console.WriteLine(1); else { var ans = S.SkipWhile(c => c == '1').First(); 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; using System.Numerics; 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 S = sc.ReadStr(); var K = sc.ReadLong(); if (S.TakeWhile(c => c == '1').Count() >= K) Console.WriteLine(1); else { var ans = S.SkipWhile(c => c == '1').First(); 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; } }
[["-", 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], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 31, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 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, 60], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25]]
8
1,135
19
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var S = Console.ReadLine(); var K = long.Parse(Console.ReadLine()); var count = 0; while (S[count] == '1') { count++; } if (count >= K) { Console.WriteLine(1); } else { Console.WriteLine(S[count]); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var S = Console.ReadLine(); var K = long.Parse(Console.ReadLine()); int count = 0; while (count < S.Length && S[count] == '1') { count++; } if (count >= K) { Console.WriteLine(1); } else { Console.WriteLine(S[count]); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 18], ["+", 0, 52, 15, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 52, 15, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 52, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98]]
8
107
8
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_C.Lib_IO; using static Contest_C.Lib_Minifunc; public static class Contest_C { public static void Main() { checked{ string s; ll k; Lib_IO.rm(out s); Lib_IO.rm(out k); for (int i = 0; i < s.Length; i++) { ll v = int.Parse(s[i].ToString()); try{ k-=Pow(v,5000000000000000L); }catch{ k = 0; } if(k<=0) { wm(v); return; } } } } public static long Pow(long x, long n, long m=long.MaxValue) { long ret = 1; while (n > 0) { if ((n & 1) == 1) ret = (ret * x) % m; x = (x * x) % m; n >>= 1; } return ret; } #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_C.Lib_IO; using static Contest_C.Lib_Minifunc; public static class Contest_C { public static void Main() { checked{ string s; ll k; Lib_IO.rm(out s); Lib_IO.rm(out k); for (int i = 0; i < s.Length; i++) { ll v = int.Parse(s[i].ToString()); k-=Pow(v,5000000000000000L); if(k<=0) { wm(v); return; } } } } public static long Pow(long x, long n){ checked{ long ret = 1; try{ while (n > 0) { if ((n & 1) == 1) ret = (ret * x); x = (x * x); n >>= 1; } }catch{ ret = ll.MaxValue; } return ret; } } #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, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["-", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["-", 8, 196, 0, 246, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249], ["-", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["-", 0, 248, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 248, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 246, 0, 248, 8, 196, 0, 46], ["-", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 0, 195, 54, 55, 0, 220, 0, 212, 0, 32], ["-", 54, 55, 0, 220, 0, 212, 0, 214, 205, 199], ["-", 54, 55, 0, 220, 0, 212, 0, 214, 0, 131], ["-", 54, 55, 0, 220, 0, 212, 0, 214, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["+", 8, 196, 0, 287, 0, 196, 0, 246, 0, 247], ["+", 0, 287, 0, 196, 0, 246, 8, 196, 0, 45], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 17, 109], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 287, 0, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 287, 0, 196, 0, 246, 0, 248, 0, 249], ["+", 0, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 0, 248, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 0, 196, 0, 246, 0, 248, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46]]
8
3,034
36
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc106 /// 2020/02/01 /// </summary> namespace ABC106 { public class Program { public static void Main(string[] args) { // A(); 4m // B(); 9m C(); // D(); } public static void D() {} public static void C() { string S = ReadString(); long K = rl; long res = 1; for (int i = 0; i < S.Length; i++) { if (S[i] != '1') { res = long.Parse(S[i].ToString()); break; } } if (K == 1 && res == 1) Console.WriteLine(1); else Console.WriteLine(res); } public static void B() { long N = rl; long[] res = new long[N + 1]; for (int i = 1; i <= N; i += 2) { long divisor = 1; for (int j = 3; j <= i; j++) { if (i % j == 0) divisor++; } res[i] = divisor; } long ans = 0; foreach (var div in res) { if (div == 8) ans++; } Console.WriteLine(ans); } public static void A() { long A = rl; long B = rl; long ans = A * B - A - B + 1; Console.WriteLine(ans); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc106 /// 2020/02/01 /// </summary> namespace ABC106 { public class Program { public static void Main(string[] args) { // A(); 4m // B(); 9m C(); // D(); } public static void D() {} public static void C() { string S = ReadString(); long K = rl; long res = 1; long cnt = 0; for (int i = 0; i < S.Length; i++) { if (S[i] != '1') { res = long.Parse(S[i].ToString()); break; } else { cnt++; } } if (K <= cnt) Console.WriteLine(1); else Console.WriteLine(res); } public static void B() { long N = rl; long[] res = new long[N + 1]; for (int i = 1; i <= N; i += 2) { long divisor = 1; for (int j = 3; j <= i; j++) { if (i % j == 0) divisor++; } res[i] = divisor; } long ans = 0; foreach (var div in res) { if (div == 8) ans++; } Console.WriteLine(ans); } public static void A() { long A = rl; long B = rl; long ans = A * B - A - B + 1; Console.WriteLine(ans); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["+", 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 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], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 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], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
3,504
19