buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); int x = int.Parse(input[1]); long[] ai = Console.ReadLine().Split(' ').Select(w => long.Parse(w)).ToArray(); long ans = 0; long work; if (ai[0] > x && ai[1] > x) { ans += ai[0]; ai[0] = 0; } else if (ai[0] + ai[1] >= x) { if (ai[0] > ai[1]) { ans += ai[0] - x; ai[0] = x; } } for (int i = 0; i < ai.Length - 1; ++i) { if (ai[i] + ai[i + 1] > x) { work = ai[i + 1]; ai[i + 1] = x - ai[i]; ans += work - ai[i + 1]; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); int x = int.Parse(input[1]); long[] ai = Console.ReadLine().Split(' ').Select(w => long.Parse(w)).ToArray(); long ans = 0; long work; if (ai[0] > x && ai[1] > x) { ans += ai[0] - x; ai[0] = x; } else if (ai[0] + ai[1] >= x) { if (ai[0] > ai[1]) { work = ai[0]; ai[0] = x - ai[1]; ans += work - ai[0]; } } for (int i = 0; i < ai.Length - 1; ++i) { if (ai[i] + ai[i + 1] > x) { work = ai[i + 1]; ai[i + 1] = x - ai[i]; ans += work - ai[i + 1]; } } Console.WriteLine(ans); } } }
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 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, 16, 17, 33], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22]]
8
269
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; static class Program { class PriorityQueue<T> { private readonly List<T> m_list; private readonly Func<T, T, int> m_compare; public int Count { get; private set; } public PriorityQueue(int capacity, Func<T, T, int> compare) { m_list = new List<T>(capacity); m_compare = compare; Count = 0; } private int Add(T value) { if (Count == m_list.Count) { m_list.Add(value); } else { m_list[Count] = value; } return Count++; } private void Swap(int a, int b) { T tmp = m_list[a]; m_list[a] = m_list[b]; m_list[b] = tmp; } public void Enqueue(T value) { int c = Add(value); while (c > 0) { int p = (c - 1) / 2; if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; } c = p; } } public T Dequeue() { T value = m_list[0]; m_list[0] = m_list[--Count]; int p = 0; while (true) { int c1 = p * 2 + 1; int c2 = p * 2 + 2; if (c1 >= Count) { break; } int c = (c2 >= Count || m_compare(m_list[c1], m_list[c2]) < 0) ? c1 : c2; if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; } p = c; } return value; } } class Point { public readonly double x; public readonly double y; public Point(double x, double y) { this.x = x; this.y = y; } public static double Distance(Point a, Point b) { double x = a.x - b.x; double y = a.y - b.y; return Math.Sqrt(x * x + y * y); } } class Circle { public readonly Point o; public readonly double r; public Circle(double[] args) { o = new Point(args[0], args[1]); r = args[2]; } } static double Solve(Point s, Point t, int N, Circle[] circles) { const double INF = double.MaxValue * 0.25; var D = new double [N + 2][]; for (int i = 0; i < N + 2; ++i) { D[i] = Enumerable.Repeat(INF, N + 2).ToArray(); D[i][i] = 0; } for (int i = 0; i < N; ++i) { double ds = Math.Max(Point.Distance(s, circles[i].o) - circles[i].r, 0); D[0][i + 1] = ds; D[i + 1][0] = ds; double dt = Math.Max(Point.Distance(t, circles[i].o) - circles[i].r, 0); D[N + 1][i + 1] = dt; D[i + 1][N + 1] = dt; for (int j = i + 1; j < N; ++j) { double d = Math.Max(Point.Distance(circles[i].o, circles[j].o) - circles[i].r - circles[j].r, 0); D[i + 1][j + 1] = d; D[j + 1][i + 1] = d; } } var f = new bool[N + 2]; var q = new PriorityQueue<int>(N + 2, (a, b) => D[0][a].CompareTo(D[0][b])); for (int i = 0; i < N; ++i) { f[i + 1] = true; q.Enqueue(i + 1); } while (q.Count > 0) { int i = q.Dequeue(); f[i] = false; for (int j = 1; j < N + 2; ++j) { if (D[0][i] + D[i][j] < D[0][j]) { D[0][j] = D[0][i] + D[i][j]; if (j < N + 1 && !f[j]) { f[j] = true; q.Enqueue(j); } } } } return D[0][N + 1]; } static void Main(string[] args) { var V1 = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); var s = new Point(V1[0], V1[1]); var t = new Point(V1[2], V1[3]); int N = int.Parse(Console.ReadLine()); var circles = new Circle[N]; for (int i = 0; i < N; ++i) { var V2 = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); circles[i] = new Circle(V2); } Console.WriteLine(Solve(s, t, N, circles)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; static class Program { class PriorityQueue<T> { private readonly List<T> m_list; private readonly Func<T, T, int> m_compare; public int Count { get; private set; } public PriorityQueue(int capacity, Func<T, T, int> compare) { m_list = new List<T>(capacity); m_compare = compare; Count = 0; } private int Add(T value) { if (Count == m_list.Count) { m_list.Add(value); } else { m_list[Count] = value; } return Count++; } private void Swap(int a, int b) { T tmp = m_list[a]; m_list[a] = m_list[b]; m_list[b] = tmp; } public void Enqueue(T value) { int c = Add(value); while (c > 0) { int p = (c - 1) / 2; if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; } c = p; } } public T Dequeue() { T value = m_list[0]; m_list[0] = m_list[--Count]; int p = 0; while (true) { int c1 = p * 2 + 1; int c2 = p * 2 + 2; if (c1 >= Count) { break; } int c = (c2 >= Count || m_compare(m_list[c1], m_list[c2]) < 0) ? c1 : c2; if (m_compare(m_list[c], m_list[p]) < 0) { Swap(p, c); } else { break; } p = c; } return value; } } class Point { public readonly double x; public readonly double y; public Point(double x, double y) { this.x = x; this.y = y; } public static double Distance(Point a, Point b) { double x = a.x - b.x; double y = a.y - b.y; return Math.Sqrt(x * x + y * y); } } class Circle { public readonly Point o; public readonly double r; public Circle(double[] args) { o = new Point(args[0], args[1]); r = args[2]; } } static double Solve(Point s, Point t, int N, Circle[] circles) { const double INF = double.MaxValue * 0.25; var D = new double [N + 2][]; for (int i = 0; i < N + 2; ++i) { D[i] = Enumerable.Repeat(INF, N + 2).ToArray(); D[i][i] = 0; } D[0][N + 1] = Point.Distance(s, t); for (int i = 0; i < N; ++i) { double ds = Math.Max(Point.Distance(s, circles[i].o) - circles[i].r, 0); D[0][i + 1] = ds; D[i + 1][0] = ds; double dt = Math.Max(Point.Distance(t, circles[i].o) - circles[i].r, 0); D[N + 1][i + 1] = dt; D[i + 1][N + 1] = dt; for (int j = i + 1; j < N; ++j) { double d = Math.Max(Point.Distance(circles[i].o, circles[j].o) - circles[i].r - circles[j].r, 0); D[i + 1][j + 1] = d; D[j + 1][i + 1] = d; } } var f = new bool[N + 2]; var q = new PriorityQueue<int>(N + 2, (a, b) => D[0][a].CompareTo(D[0][b])); for (int i = 0; i < N; ++i) { f[i + 1] = true; q.Enqueue(i + 1); } while (q.Count > 0) { int i = q.Dequeue(); f[i] = false; for (int j = 1; j < N + 2; ++j) { if (D[0][i] + D[i][j] < D[0][j]) { D[0][j] = D[0][i] + D[i][j]; if (j < N + 1 && !f[j]) { f[j] = true; q.Enqueue(j); } } } } return D[0][N + 1]; } static void Main(string[] args) { var V1 = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); var s = new Point(V1[0], V1[1]); var t = new Point(V1[2], V1[3]); int N = int.Parse(Console.ReadLine()); var circles = new Circle[N]; for (int i = 0; i < N; ++i) { var V2 = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); circles[i] = new Circle(V2); } Console.WriteLine(Solve(s, t, N, circles)); } }
[["+", 0, 1, 0, 11, 31, 204, 205, 204, 205, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
1,197
19
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; class Myon { static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); return 0; } public void calc() { double xs, ys, xt, yt; xs = cin.nextDouble(); ys = cin.nextDouble(); xt = cin.nextDouble(); yt = cin.nextDouble(); double ans = double.MaxValue; int N = cin.nextInt(); bool[] used = new bool[N]; double[] dist = new double[N]; double[] x = new double[N]; double[] y = new double[N]; double[] r = new double[N]; for (int i = 0; i < N; i++) { x[i] = cin.nextDouble(); y[i] = cin.nextDouble(); r[i] = cin.nextDouble(); } for (int i = 0; i < N; i++) { dist[i] = hypot(xs - x[i], ys - y[i]) - r[i]; if (dist[i] < 0) dist[i] = 0; } for (int i = 0; i < N; i++) { int best = -1; double bestdist = double.MaxValue; for (int j = 0; j < N; j++) { if (!used[j] && bestdist > dist[j]) { best = j; bestdist = dist[j]; } } int start = best; for (int j = 0; j < N; j++) { double add = hypot(x[start] - x[j], y[start] - y[j]) - r[start] - r[j]; if (add < 0) add = 0; dist[j] = Math.Min(dist[j], dist[start] + add); } used[start] = true; ans = Math.Min( ans, dist[start] + Math.Max(0, hypot(xt - x[start], yt - y[start]) - r[start])); } Console.WriteLine("{0:0.0000000000000000}", ans); } double hypot(double x, double y) { return Math.Sqrt(x * x + y * y); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; class Myon { static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); return 0; } public void calc() { double xs, ys, xt, yt; xs = cin.nextDouble(); ys = cin.nextDouble(); xt = cin.nextDouble(); yt = cin.nextDouble(); double ans = hypot(xs - xt, ys - yt); int N = cin.nextInt(); bool[] used = new bool[N]; double[] dist = new double[N]; double[] x = new double[N]; double[] y = new double[N]; double[] r = new double[N]; for (int i = 0; i < N; i++) { x[i] = cin.nextDouble(); y[i] = cin.nextDouble(); r[i] = cin.nextDouble(); } for (int i = 0; i < N; i++) { dist[i] = hypot(xs - x[i], ys - y[i]) - r[i]; if (dist[i] < 0) dist[i] = 0; } for (int i = 0; i < N; i++) { int best = -1; double bestdist = double.MaxValue; for (int j = 0; j < N; j++) { if (!used[j] && bestdist > dist[j]) { best = j; bestdist = dist[j]; } } int start = best; for (int j = 0; j < N; j++) { double add = hypot(x[start] - x[j], y[start] - y[j]) - r[start] - r[j]; if (add < 0) add = 0; dist[j] = Math.Min(dist[j], dist[start] + add); } used[start] = true; ans = Math.Min( ans, dist[start] + Math.Max(0, hypot(xt - x[start], yt - y[start]) - r[start])); } Console.WriteLine("{0:0.0000000000000000}", ans); } double hypot(double x, double y) { return Math.Sqrt(x * x + y * y); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
772
13
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 long[][] nums = new long [2 * n][]; //座標と種類 long memo = 0; long multiplyMemo = 1; long answer = 1; long mod = 1000000007; for (long i = 0; i < n; i++) { nums[i] = new long[2]; nums[i][0] = long.Parse(Console.ReadLine()); nums[i][1] = 0; } for (long i = n; i < 2 * n; i++) { nums[i] = new long[2]; nums[i][0] = long.Parse(Console.ReadLine()); nums[i][1] = 1; } Array.Sort(nums, (a, b) => a[0].CompareTo(b[0])); for (long i = 0; i < 2 * n; i++) { if (nums[i][1] == 0) { memo++; if (memo > 1) answer *= Math.Abs(memo); answer %= mod; } else { memo--; if (memo < -1) answer *= Math.Abs(memo); answer %= mod; } Console.WriteLine(answer); } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p) { long num = 2; long answer = 1; long check = a; long memo = x % p; while (check > 0) { if (check % num == num / 2) { check -= num / 2; answer *= memo; answer %= p; } memo *= memo; memo %= p; num *= 2; } return answer; } static long DivideModReverse(long x, long p) //戻り値はx^-1(mod p), pは素数 { long answer = DivideMod(x, p - 2, p); return answer; } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 long[][] nums = new long [2 * n][]; //座標と種類 long memo = 0; long multiplyMemo = 1; long answer = 1; long mod = 1000000007; for (long i = 0; i < n; i++) { nums[i] = new long[2]; nums[i][0] = long.Parse(Console.ReadLine()); nums[i][1] = 0; } for (long i = n; i < 2 * n; i++) { nums[i] = new long[2]; nums[i][0] = long.Parse(Console.ReadLine()); nums[i][1] = 1; } Array.Sort(nums, (a, b) => a[0].CompareTo(b[0])); for (long i = 0; i < 2 * n; i++) { if (nums[i][1] == 0) { memo++; if (memo > 1) answer *= Math.Abs(memo); answer %= mod; } else { memo--; if (memo < -1) answer *= Math.Abs(memo); answer %= mod; } // Console.WriteLine(answer); } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p) { long num = 2; long answer = 1; long check = a; long memo = x % p; while (check > 0) { if (check % num == num / 2) { check -= num / 2; answer *= memo; answer %= p; } memo *= memo; memo %= p; num *= 2; } return answer; } static long DivideModReverse(long x, long p) //戻り値はx^-1(mod p), pは素数 { long answer = DivideMod(x, p - 2, p); return answer; } }
[["-", 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
432
7
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Runtime.Remoting.Contexts; using System.Security.Cryptography.X509Certificates; 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 int N; private long[] A; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); A = new long[N]; for (int i = 0; i < N; i++) { A[i] = sc.NextLong(); } } public void Solve() { Scan(); long x = 0; foreach (long i in A) { x ^= i; } int cnt = 0; for (int i = 29; i >= 0; i--) { foreach (var i1 in A) { var u = i1 ^ (i1 - 1); if ((x & ((u + 1) >> 1)) > 0) { x ^= u; cnt++; break; } } } Console.WriteLine(x == 0 ? cnt : -1); } static void Main(string[] args) { new Program().Solve(); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Runtime.Remoting.Contexts; using System.Security.Cryptography.X509Certificates; 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 int N; private long[] A; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); A = new long[N]; for (int i = 0; i < N; i++) { A[i] = sc.NextLong(); } } public void Solve() { Scan(); long x = 0; foreach (long i in A) { x ^= i; } int cnt = 0; for (int i = 29; i >= 0; i--) { var b = 1 << i; foreach (var i1 in A) { var u = i1 ^ (i1 - 1); if ((x & ((u + 1) >> 1)) > 0) { if ((b & u) > 0) { x ^= u; cnt++; break; } } } } Console.WriteLine(x == 0 ? cnt : -1); } static void Main(string[] args) { new Program().Solve(); } } }
[["+", 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, 16, 31, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 151], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 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, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 67], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
529
19
using System; #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion public class Program { private int N, A, B, C; private ModInt[] Fact; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); A = sc.NextInt(); B = sc.NextInt(); C = sc.NextInt(); Fact = new ModInt[10001]; Fact[0] = 1; for (int i = 1; i <= N; i++) { Fact[i] = Fact[i - 1] * i; } // タイプ1 A A len 1 A +1: B +0: C +0 // タイプ2 C1 C2 C3 C1 C2 C3 len3 A +0: B +0: C +3 // タイプ3 C A A C len2 A +1: B +0: C +1 // タイプ4 B1 C1 B1 C2 C1 C3 C2 B2 C3 B2 len X (X>=2) A +0: B +2: C // +(X-2) if (B % 2 == 0) { Console.WriteLine(0); return; } ModInt ans = 0; for (int type2 = 0; type2 * 3 <= C; type2++) { for (int type3 = 0; type2 * 3 + type3 <= C && type3 <= A; type3++) { int type1 = A - type3; int type4 = B / 2; int type4C = C - type2 * 3 - type3; // (type1 + type2 + type3 + type4)! / // (type1!*type2!*type3!*type4!)*type4C H type4 ans += Fact[type1 + type2 + type3 + type4] * H(type4C, type4) * ModInt.Inverse(Fact[type1] * Fact[type2] * Fact[type3] * Fact[type4]); } } Console.WriteLine(ans); } private ModInt H(int n, int m) { if (m == 0) return n == 0 ? 1 : 0; return Combination(n + m - 1, m - 1); } private ModInt Combination(int n, int m) { return Fact[n] * ModInt.Inverse(Fact[n - m] * Fact[m]); } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion public class Program { private int N, A, B, C; private ModInt[] Fact; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); A = sc.NextInt(); B = sc.NextInt(); C = sc.NextInt(); Fact = new ModInt[10001]; Fact[0] = 1; for (int i = 1; i <= N; i++) { Fact[i] = Fact[i - 1] * i; } // タイプ1 A A len 1 A 1: B 0: C 0 // タイプ2 C1 C2 C3 C1 C2 C3 len 3 A 0: B 0: C 3 // タイプ3 C A A C len 2 A 1: B 0: C 1 // タイプ4 B1 C1 B1 C2 C1 C3 C2 B2 C3 B2 len X (X>=2) A 0: B 2: C (X-2) if (B % 2 != 0) { Console.WriteLine(0); return; } ModInt ans = 0; for (int type2 = 0; type2 * 3 <= C; type2++) { for (int type3 = 0; type2 * 3 + type3 <= C && type3 <= A; type3++) { int type1 = A - type3; int type4 = B / 2; int type4C = C - type2 * 3 - type3; // (type1 + type2 + type3 + type4)! / // (type1!*type2!*type3!*type4!)*type4 H type4C ans += Fact[type1 + type2 + type3 + type4] * H(type4, type4C) * ModInt.Inverse(Fact[type1] * Fact[type2] * Fact[type3] * Fact[type4]); } } Console.WriteLine(ans); } private ModInt H(int n, int m) { if (n == 0) return m == 0 ? 1 : 0; return Combination(n + m - 1, n - 1); } private ModInt Combination(int n, int m) { return Fact[n] * ModInt.Inverse(Fact[n - m] * Fact[m]); } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 31, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 12, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["+", 12, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["+", 31, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 37, 0, 41, 15, 16, 31, 22], ["+", 0, 57, 64, 37, 0, 41, 15, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
1,122
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long N = inputArray[0]; // N <= 1+2+ + kのとき、kを最大とする数の和で表現できる //まずkを求める long k = 0; long kSum = 0; while (true) { kSum += k; if (N <= kSum) { break; } k++; } while (true) { Console.WriteLine(k); N = N - k; if (N > (k - 1)) { k--; } else { Console.WriteLine(N); break; } } } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long N = inputArray[0]; // N <= 1+2+ + kのとき、kを最大とする数の和で表現できる //まずkを求める long k = 0; long kSum = 0; while (true) { kSum += k; if (N <= kSum) { break; } k++; } while (true) { Console.WriteLine(k); N = N - k; if (N == 0) { return; } if (N > (k - 1)) { k--; } else { Console.WriteLine(N); break; } } } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
[["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 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]]
8
256
10
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; // using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n, m; sc.Multi(out n, out m); var x = sc.IntArr; // Array.Sort(x); var modm = new int[m]; var modcnt = new int[m]; var cnt = new int[100001]; foreach (var item in x) { ++modm[item % m]; ++cnt[item]; } for (int i = 0; i < 100001; i++) { modcnt[i % m] += cnt[i] / 2; } int ans = 0; ans += Math.Min(modm[0] / 2, modcnt[0]); if (m % 2 == 0) { ans += Math.Min(modm[m / 2] / 2, modcnt[m / 2]); } for (int i = 1; i * 2 < m; i++) { int ma = Math.Min(modm[i], modm[m - i]); modm[i] -= ma; modm[m - i] -= ma; ans += ma; ans += Math.Min(modm[i] / 2, modcnt[i]); ans += Math.Min(modm[m - i] / 2, modcnt[m - i]); } Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) => a.Max(); static T Min<T>(params T[] a) => a.Min(); static void DBG<T>(params T[] a) => Console.WriteLine(string.Join(" ", a)); static void DBG(params object[] a) => Console.WriteLine(string.Join(" ", a)); static void Prt<T>(params T[] a) => sw.WriteLine(string.Join(" ", a)); static void Prt(params object[] a) => sw.WriteLine(string.Join(" ", a)); } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => 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 ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } } } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); 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(); 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]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static long[][] trans(long[][] A) { int n = A[0].Length, m = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a * (b / gcd(a, b)); public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; // using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n, m; sc.Multi(out n, out m); var x = sc.IntArr; // Array.Sort(x); var modm = new int[m]; var modcnt = new int[m]; var cnt = new int[100001]; foreach (var item in x) { ++modm[item % m]; ++cnt[item]; } for (int i = 0; i < 100001; i++) { modcnt[i % m] += cnt[i] / 2; } int ans = 0; ans += modm[0] / 2; if (m % 2 == 0) { ans += modm[m / 2] / 2; } for (int i = 1; i * 2 < m; i++) { int ma = Math.Min(modm[i], modm[m - i]); modm[i] -= ma; modm[m - i] -= ma; ans += ma; ans += Math.Min(modm[i] / 2, modcnt[i]); ans += Math.Min(modm[m - i] / 2, modcnt[m - i]); } Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) => a.Max(); static T Min<T>(params T[] a) => a.Min(); static void DBG<T>(params T[] a) => Console.WriteLine(string.Join(" ", a)); static void DBG(params object[] a) => Console.WriteLine(string.Join(" ", a)); static void Prt<T>(params T[] a) => sw.WriteLine(string.Join(" ", a)); static void Prt(params object[] a) => sw.WriteLine(string.Join(" ", a)); } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => 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 ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } } } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); 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(); 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]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static long[][] trans(long[][] A) { int n = A[0].Length, m = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a * (b / gcd(a, b)); public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
[["-", 0, 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, 21], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22]]
8
2,943
22
using System; namespace cf16e { class Program { static void Main(string[] args) { checked // Debug { string[] input = Console.ReadLine().Split(); long n = long.Parse(input[0]); long a = long.Parse(input[1]); long answer = n; for (int i = 2; i <= 39; ++i) { long x = FindPowerNth(n, i); if (x == 1) break; long c = PowerN(x, i); int j; for (j = 0; c >= n; ++j) c = c / x * (x + 1); long ans = (x * i + j) + a * (i - 1); if (answer > ans) answer = ans; } Console.WriteLine(answer); } } static long FindPowerNth(long n, int i) { long x = (long)Math.Pow(n, 1 / (double)i); while (PowerN(x, i) <= n) x++; return x - 1; } static long PowerN(long n, int i) { long x = n; for (int ii = 1; ii < i; ++ii) x *= n; return x; } } }
using System; namespace cf16e { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); long n = long.Parse(input[0]); long a = long.Parse(input[1]); long answer = n; for (int i = 2; i <= 39; ++i) { long x = FindPowerNth(n, i); if (x <= 1) break; long c = PowerN(x, i); int j; for (j = 0; c < n; ++j) c = c / x * (x + 1); long ans = (x * i + j) + a * (i - 1); if (answer > ans) answer = ans; } Console.WriteLine(answer); } static long FindPowerNth(long n, int i) { if (n < (1L << i)) return 1; long x = (long)Math.Pow(n, 1 / (double)i); while (PowerN(x, i) <= n) ++x; return x - 1; } static long PowerN(long n, int i) { long x = n; for (int ii = 1; ii < i; ++ii) x *= n; return x; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["-", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 235, 8, 201, 0, 195, 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, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 31, 203], ["+", 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], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["-", 8, 196, 0, 52, 8, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 52, 8, 1, 0, 241, 0, 22]]
8
269
22
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Runtime.InteropServices; using System.Runtime.Remoting.Messaging; using System.Security.Principal; using System.Text; class Simple { int H, W; string[,] S; void Solve() { // input H = io.Int; W = io.Int; S = new string[H, W]; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { S[i, j] = io.String; } } // cal Func<string, bool> isSnuke = (str) => str == "snuke"; var alpArr = Enumerable.Range('A', 'Z').ToArray(); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (isSnuke(S[i, j])) { // ret Console.WriteLine((i + 1).ToString() + Convert.ToChar(j)); return; } } } } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Runtime.InteropServices; using System.Runtime.Remoting.Messaging; using System.Security.Principal; using System.Text; class Simple { int H, W; string[,] S; void Solve() { // input H = io.Int; W = io.Int; S = new string[H, W]; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { S[i, j] = io.String; } } // cal Func<string, bool> isSnuke = (str) => str == "snuke"; var alpArr = Enumerable.Range('A', 'Z').ToArray(); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (isSnuke(S[i, j])) { // ret Console.WriteLine(Convert.ToChar(alpArr[j]) + (i + 1).ToString()); return; } } } } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
[["+", 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], ["+", 31, 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, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 16, 12, 213, 63, 214, 205, 23, 0, 24], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 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, 16, 12, 213, 3, 4, 0, 28, 0, 22]]
8
513
17
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int[] a = Read.Ints(); for (int i = 0; i < a[0]; i++) { string[] s = Read.Strs(); for (int k = 0; k < a[1]; k++) { if (s[k] == "snuke") { Console.WriteLine((k + 'A') + "" + (i + 1)); } } } } } public static class Read { public static string read() { return Console.ReadLine(); } public static void outl(string n = "") { Console.WriteLine(n); return; } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (int i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] Ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int[] a = Read.Ints(); for (int i = 0; i < a[0]; i++) { string[] s = Read.Strs(); for (int k = 0; k < a[1]; k++) { if (s[k] == "snuke") { Console.WriteLine((char)(k + 'A') + "" + (i + 1)); break; } } } Console.ReadLine(); } } public static class Read { public static string read() { return Console.ReadLine(); } public static void outl(string n = "") { Console.WriteLine(n); return; } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (int i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] Ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
[["+", 0, 28, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 16, 31, 16, 31, 74, 51, 23, 0, 24], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 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, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
314
11
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // Initialize var lst = new List<string>(new[] { "dream", "dreamer", "erase", "eraser" }); var S = cin.ReadLine; // Process var find = true; while (find) { find = false; foreach (var text in lst) { find = S.EndsWith(text); if (find) S = S.Remove(S.Length - text.Length); } } // Output WriteLine(S == string.Empty ? "YES" : "NO"); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // Initialize var lst = new List<string>(new[] { "dream", "dreamer", "erase", "eraser" }); var S = cin.ReadLine; // Process var find = true; while (find) { find = false; foreach (var text in lst) { if (S.EndsWith(text)) { S = S.Remove(S.Length - text.Length); find = true; } } if (S == string.Empty) break; } // Output WriteLine(S == string.Empty ? "YES" : "NO"); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 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], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 15, 22], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 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, 146], ["+", 0, 210, 8, 196, 0, 57, 64, 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], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 199], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 35]]
8
534
24
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public void Slove() { var inputs = Console.ReadLine().Split(); int n = int.Parse(inputs[0]); int t = int.Parse(inputs[1]); int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] maxList = new int[n]; maxList[n - 1] = array[n - 1]; foreach (int i in Enumerable.Range(0, n).Reverse().Skip(1)) { maxList[i] = Math.Max(maxList[i + 1], array[i]); } int result = 0; int max = 0; foreach (int i in Enumerable.Range(0, n - 1)) { int temp = maxList[i] - array[i]; if (temp > max) { max = temp; result = 1; } else if (temp == max) result++; } System.Console.WriteLine(string.Join(",", maxList)); System.Console.WriteLine(result); } static void Main(string[] args) { new Program().Slove(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public void Slove() { var inputs = Console.ReadLine().Split(); int n = int.Parse(inputs[0]); int t = int.Parse(inputs[1]); int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] maxList = new int[n]; maxList[n - 1] = array[n - 1]; foreach (int i in Enumerable.Range(0, n).Reverse().Skip(1)) { maxList[i] = Math.Max(maxList[i + 1], array[i]); } int result = 0; int max = 0; foreach (int i in Enumerable.Range(0, n - 1)) { int temp = maxList[i] - array[i]; if (temp > max) { max = temp; result = 1; } else if (temp == max) result++; } // System.Console.WriteLine(string.Join(",", maxList)); System.Console.WriteLine(result); } static void Main(string[] args) { new Program().Slove(); } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 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, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 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
282
18
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); S = new string(S.Reverse().ToArray()); var a = new string[] { "dream", "dreamer", "erase", "eraser" }; for (int i = 0; i < a.Length; i++) { a[i] = new string(a[i].Reverse().ToArray()); } for (int i = 0; i < S.Length; i++) { foreach (var p in a) { var ok = true; for (int j = 0; j < p.Length; j++) { if (i + j == S.Length || p[j] != S[i + j]) { ok = false; break; } } if (ok) { i += p.Length - 1; if (i == S.Length - 1) { Console.WriteLine("YES"); return; } break; } else { Console.WriteLine("NO"); return; } } } Console.WriteLine("NO"); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); S = new string(S.Reverse().ToArray()); var a = new string[] { "dream", "dreamer", "erase", "eraser" }; for (int i = 0; i < a.Length; i++) { a[i] = new string(a[i].Reverse().ToArray()); } for (int i = 0; i < S.Length; i++) { var any = false; foreach (var p in a) { var ok = true; for (int j = 0; j < p.Length; j++) { if (i + j == S.Length || p[j] != S[i + j]) { ok = false; break; } } any |= ok; if (ok) { i += p.Length - 1; if (i == S.Length - 1) { Console.WriteLine("YES"); return; } break; } } if (!any) break; } Console.WriteLine("NO"); } 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], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 160], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 210, 8, 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], ["-", 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, 7, 8, 196, 0, 210, 8, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 111], ["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 8, 196, 0, 57, 75, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 75, 196, 0, 37, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 210, 8, 196, 0, 46]]
8
1,287
26
using System; namespace ABC049C { class Program { static void Main(string[] args) { var input = Console.ReadLine(); Console.WriteLine(Inspect(input, 0) ? "YES" : "NO"); } private static string[] targets = new[] { "dream", "dreamer", "erase", "eraser" }; private static bool Inspect(string str, int start) { if (str.Length == start) { return true; } if (str.Length > start) { return false; } var result = false; for (int i = 0; i < targets.Length; i++) { if (IsMatch(str, targets[i], start)) { result = Inspect(str, start + targets[i].Length); if (result) { break; } } } return result; } private static bool IsMatch(string str, string target, int start) { for (int i = 0; i < target.Length && start + i < str.Length; i++) { if (target[i] != str[start + i]) { return false; } } return true; } } }
using System; namespace ABC049C { class Program { static void Main(string[] args) { var input = Console.ReadLine(); Console.WriteLine(Inspect(input, 0) ? "YES" : "NO"); } private static string[] targets = new[] { "dream", "dreamer", "erase", "eraser" }; private static bool Inspect(string str, int start) { if (start == str.Length) { return true; } if (start > str.Length) { return false; } var result = false; for (int i = 0; i < targets.Length; i++) { if (IsMatch(str, targets[i], start)) { result = Inspect(str, start + targets[i].Length); if (result) { break; } } } return result; } private static bool IsMatch(string str, string target, int start) { for (int i = 0; i < target.Length && start + i < str.Length; i++) { if (target[i] != str[start + i]) { return false; } } return true; } } }
[["+", 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, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
248
8
using System; using System.Collections.Generic; public class CSharp { public static void Main() { Kyopuro chokudai = new Kyopuro(); chokudai.AtCoder(); } } public class Kyopuro { int n, k; int[] a, b, v, p, ans; int[] pmin, pmax; bool yn; bool[] vtd, odd; List<int>[] list; public void AtCoder() { string[] s = Console.ReadLine().Split(' '); n = int.Parse(s[0]); a = new int[n - 1]; b = new int[n - 1]; for (int i = 0; i < n - 1; i++) { s = Console.ReadLine().Split(' '); a[i] = int.Parse(s[0]) - 1; b[i] = int.Parse(s[1]) - 1; } k = int.Parse(Console.ReadLine()); v = new int[k]; p = new int[k]; for (int i = 0; i < k; i++) { s = Console.ReadLine().Split(' '); v[i] = int.Parse(s[0]) - 1; p[i] = int.Parse(s[1]); } list = new List<int>[n]; for (int i = 0; i < n; i++) list[i] = new List<int>(); for (int i = 0; i < n - 1; i++) { list[a[i]].Add(b[i]); list[b[i]].Add(a[i]); } ans = new int[n]; for (int i = 0; i < n; i++) ans[i] = -999999; for (int i = 0; i < k; i++) { ans[v[i]] = p[i]; } yn = true; vtd = new bool[n]; odd = new bool[n]; DfsOdd(v[0], p[0]); for (int i = 0; i < n; i++) { if (ans[i] != -999999) { if (odd[i] && ans[i] % 2 == 0) yn = false; if (!odd[i] && ans[i] % 2 == 1) yn = false; } } pmin = new int[n]; pmax = new int[n]; for (int i = 0; i < n; i++) { pmin[i] = -999999; pmax[i] = 99999999; if (ans[i] != -999999) { pmin[i] = ans[i]; pmax[i] = ans[i]; } } vtd = new bool[n]; int start = 0; while (list[start].Count != 1) start++; if (yn) { Dfs(start); vtd = new bool[n]; Dfs2(start, -1); } if (yn) { Console.WriteLine("Yes"); for (int i = 0; i < n; i++) { Console.WriteLine(ans[i]); } } else Console.WriteLine("No"); } public void DfsOdd(int x, int y) { if (y % 2 == 1) odd[x] = true; else odd[x] = false; vtd[x] = true; foreach (int i in list[x]) { if (!vtd[i]) DfsOdd(i, y + 1); } } public void Dfs(int u) { vtd[u] = true; foreach (int i in list[u]) { if (!vtd[i]) { Dfs(i); if (pmin[i] != -999999) { pmin[u] = Math.Max(pmin[u], pmin[i] - 1); pmax[u] = Math.Min(pmax[u], pmax[i] + 1); } } } if (ans[u] != -999999) { pmin[u] = ans[u]; pmax[u] = ans[u]; } } public void Dfs2(int u, int par) { vtd[u] = true; if (ans[u] == -999999) { int dif = pmax[u] - pmin[u]; if (dif < 0) yn = false; if (par == -1) { ans[u] = pmin[u]; } else { if (ans[par] - 1 >= pmin[u]) ans[u] = ans[par] - 1; if (ans[par] + 1 <= pmax[u]) ans[u] = ans[par] + 1; if (ans[u] == -999999) yn = false; } } foreach (int i in list[u]) if (!vtd[i]) Dfs2(i, u); } public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); } }
using System; using System.Collections.Generic; public class CSharp { public static void Main() { Kyopuro chokudai = new Kyopuro(); chokudai.AtCoder(); } } public class Kyopuro { int n, k; int[] a, b, v, p, ans; int[] pmin, pmax; bool yn; bool[] vtd, odd; List<int>[] list; public void AtCoder() { string[] s = Console.ReadLine().Split(' '); n = int.Parse(s[0]); a = new int[n - 1]; b = new int[n - 1]; for (int i = 0; i < n - 1; i++) { s = Console.ReadLine().Split(' '); a[i] = int.Parse(s[0]) - 1; b[i] = int.Parse(s[1]) - 1; } k = int.Parse(Console.ReadLine()); v = new int[k]; p = new int[k]; for (int i = 0; i < k; i++) { s = Console.ReadLine().Split(' '); v[i] = int.Parse(s[0]) - 1; p[i] = int.Parse(s[1]); } list = new List<int>[n]; for (int i = 0; i < n; i++) list[i] = new List<int>(); for (int i = 0; i < n - 1; i++) { list[a[i]].Add(b[i]); list[b[i]].Add(a[i]); } ans = new int[n]; for (int i = 0; i < n; i++) ans[i] = -999999; for (int i = 0; i < k; i++) { ans[v[i]] = p[i]; } yn = true; vtd = new bool[n]; odd = new bool[n]; DfsOdd(v[0], p[0]); for (int i = 0; i < n; i++) { if (ans[i] != -999999) { if (odd[i] && ans[i] % 2 == 0) yn = false; if (!odd[i] && ans[i] % 2 == 1) yn = false; } } pmin = new int[n]; pmax = new int[n]; for (int i = 0; i < n; i++) { pmin[i] = -999999; pmax[i] = 99999999; if (ans[i] != -999999) { pmin[i] = ans[i]; pmax[i] = ans[i]; } } vtd = new bool[n]; int start = 0; while (list[start].Count != 1) start++; if (yn) { Dfs(start); vtd = new bool[n]; Dfs2(start, -1); } if (yn) { Console.WriteLine("Yes"); for (int i = 0; i < n; i++) { Console.WriteLine(ans[i]); } } else Console.WriteLine("No"); } public void DfsOdd(int x, int y) { if (y % 2 == 1) odd[x] = true; else odd[x] = false; vtd[x] = true; foreach (int i in list[x]) { if (!vtd[i]) DfsOdd(i, y + 1); } } public void Dfs(int u) { vtd[u] = true; foreach (int i in list[u]) { if (!vtd[i]) { Dfs(i); if (pmin[i] != -999999) { pmin[u] = Math.Max(pmin[u], pmin[i] - 1); pmax[u] = Math.Min(pmax[u], pmax[i] + 1); } } } if (ans[u] != -999999) { pmin[u] = ans[u]; pmax[u] = ans[u]; } } public void Dfs2(int u, int par) { vtd[u] = true; if (ans[u] == -999999) { int dif = pmax[u] - pmin[u]; if (dif < 0) yn = false; if (par == -1) { ans[u] = pmin[u]; } else { if (ans[par] - 1 >= pmin[u]) ans[u] = ans[par] - 1; if (ans[par] + 1 <= pmax[u]) ans[u] = ans[par] + 1; if (ans[u] == -999999) yn = false; } } else { if (par != -1) { int dif = ans[u] - ans[par]; if (dif != 1 && dif != -1) yn = false; } } foreach (int i in list[u]) if (!vtd[i]) Dfs2(i, u); } public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 79], ["+", 75, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 75, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 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, 204, 205, 22], ["+", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 75, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 75, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 203], ["+", 75, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,124
40
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); string s = sc.Next(); string t = sc.Next(); int count = 0; while (true) { if (s.Substring(s.Length - count, 1) == t.Substring(count, 1)) { count++; } else { break; } } int answer = s.Length + t.Length - count; Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); string s = sc.Next(); string t = sc.Next(); int count = n; while (true) { if (s.Substring(s.Length - count, count) == t.Substring(0, count)) { break; } else { count--; } } int answer = s.Length + t.Length - count; Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 15, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 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, 93, 0, 94], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 68]]
8
426
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { public Program() {} Scanner cin; long[] All; long[] Pate; void myon() { cin = new Scanner(); int N = cin.nextInt(); string S = cin.next(); string T = cin.next(); int start = Math.Max(0, S.Length - T.Length); int Ans = S.Length + T.Length; for (int i = start; i < S.Length; i++) { bool flag = true; for (int j = i; j < S.Length; j++) { if (S[j] != T[j - i]) { flag = false; break; } } if (flag) Ans = i + T.Length; } Console.WriteLine(Ans); } static void Main(string[] args) { new Program().myon(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { public Program() {} Scanner cin; long[] All; long[] Pate; void myon() { cin = new Scanner(); int N = cin.nextInt(); string S = cin.next(); string T = cin.next(); int start = Math.Max(0, S.Length - T.Length); int Ans = S.Length + T.Length; for (int i = start; i < S.Length; i++) { bool flag = true; for (int j = i; j < S.Length; j++) { if (S[j] != T[j - i]) { flag = false; break; } } if (flag) Ans = Math.Min(Ans, i + T.Length); } Console.WriteLine(Ans); } static void Main(string[] args) { new Program().myon(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
[["+", 64, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
385
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class Abc_049_C { // https://atcoder.jp/contests/abc049/tasks/arc065_a public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); string[] divide = new string[4] { "dream", "dreamer", "erase", "eraser" }; for (int k = 0; k < 4; ++k) divide[k] = new string(divide[k].Reverse().ToArray()); // 文字列の入力 string s = Console.ReadLine(); s = new string(s.Reverse().ToArray()); bool can = true; for (int i = 0; i < s.Length; i++) { bool can2 = false; for (int j = 0; j < 4; j++) { string d = divide[j]; if (s.Length >= d.Length && s.Substring(0, d.Length) == d) { s = s.Remove(0, d.Length); can2 = true; if (string.IsNullOrEmpty(s)) { Console.WriteLine("YES"); Console.Out.Flush(); return; } } } if (!can2) { can = false; break; } } Console.WriteLine("NO"); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class Abc_049_C { // https://atcoder.jp/contests/abc049/tasks/arc065_a public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); string[] divide = new string[4] { "dream", "dreamer", "erase", "eraser" }; for (int k = 0; k < 4; ++k) divide[k] = new string(divide[k].Reverse().ToArray()); // 文字列の入力 string s = Console.ReadLine(); s = new string(s.Reverse().ToArray()); bool can = true; while (can) { bool can2 = false; for (int j = 0; j < 4; j++) { string d = divide[j]; if (s.Length >= d.Length && s.Substring(0, d.Length) == d) { s = s.Remove(0, d.Length); can2 = true; if (string.IsNullOrEmpty(s)) { Console.WriteLine("YES"); Console.Out.Flush(); return; } } } if (!can2) { can = false; break; } } Console.WriteLine("NO"); Console.Out.Flush(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 0, 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, 52, 15, 22]]
8
323
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { void Calc() { var sc = new Scanner(); int N = sc.NextInt(); string C = Console.ReadLine(); string D = Console.ReadLine(); if (C == D) { Console.WriteLine(N); } if (N == 1 && C != D) { { Console.WriteLine(2); } } if (N != 1 && C != D) { for (int i = 1; i < N; i++) { if (D.Substring(0, i) == C.Substring(N - i)) { Console.WriteLine(2 * N - (i)); } } } } static void Main() { new Program().Calc(); } class Scanner { string[] s = new string[0]; int i = 0; char[] cs = new char[] { ' ' }; public string Next() { if (i < s.Length) return s[i++]; s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { void Calc() { var sc = new Scanner(); int N = sc.NextInt(); int a = 0; string C = Console.ReadLine(); string D = Console.ReadLine(); if (C == D) { Console.WriteLine(N); } if (N == 1 && C != D) { { Console.WriteLine(2); } } if (N != 1 && C != D) { for (int i = 1; i < N; i++) { if (D.Substring(0, i) == C.Substring(N - i)) { a = i; } } Console.WriteLine(N * 2 - a); } } static void Main() { new Program().Calc(); } class Scanner { string[] s = new string[0]; int i = 0; char[] cs = new char[] { ' ' }; public string Next() { if (i < s.Length) return s[i++]; s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } }
[["+", 0, 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, 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, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 203], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46]]
8
316
21
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { var S = new string(GetStr().Reverse().ToArray()); var len = S.Length; var words = new string[] { "dream", "dreamer", "erase", "eraser" } .Select(s => new string(s.Reverse().ToArray())) .ToArray(); bool b = true; for (int i = 0; i < len;) { if (S[i] == 'e' && i <= len - 5) { if (S.Substring(i, 5) == words[2]) { i += 5; continue; } } if (S[i] == 'r' && i <= len - 7) { if (S.Substring(i, 7) == words[1]) { i += 7; continue; } if (S.Substring(i, 6) == words[3]) { i += 6; continue; } } if (S[i] == 'm' && i <= len - 5) { if (S.Substring(i, 5) == words[0]) { i += 5; continue; } } b = false; break; } var ans = b.YESNO(); Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { var S = new string(GetStr().Reverse().ToArray()); var len = S.Length; var words = new string[] { "dream", "dreamer", "erase", "eraser" } .Select(s => new string(s.Reverse().ToArray())) .ToArray(); bool b = true; for (int i = 0; i < len;) { if (S[i] == 'e' && i <= len - 5) { if (S.Substring(i, 5) == words[2]) { i += 5; continue; } } if (S[i] == 'r' && i <= len - 7) { if (S.Substring(i, 7) == words[1]) { i += 7; continue; } } if (S[i] == 'r' && i <= len - 6) { if (S.Substring(i, 6) == words[3]) { i += 6; continue; } } if (S[i] == 'm' && i <= len - 5) { if (S.Substring(i, 5) == words[0]) { i += 5; continue; } } b = false; break; } var ans = b.YESNO(); Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } }
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 252, 0, 104], ["+", 0, 57, 15, 16, 31, 16, 12, 252, 0, 253], ["+", 0, 7, 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, 19], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 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, 57, 0, 121]]
8
1,363
19
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int max = 0; for (int i = 0; i < N; i++) { // Console.WriteLine(S.Substring(i)); // Console.WriteLine(T.Substring(0,N-i)); if (S.Substring(i) == T.Substring(0, N - i)) { max = N - i; } } Console.WriteLine(N * 2 - max); } int N; String S, T; public Sol() { N = ri(); S = rs(); T = rs(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int max = 0; for (int i = N - 1; i >= 0; i--) { // Console.WriteLine(S.Substring(i)); // Console.WriteLine(T.Substring(0,N-i)); if (S.Substring(i) == T.Substring(0, N - i)) { max = N - i; } } Console.WriteLine(N * 2 - max); } int N; String S, T; public Sol() { N = ri(); S = rs(); T = rs(); } 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, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
376
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { public class Program { static void Main(string[] args) { String input = Console.ReadLine(); String temp = input; String ans = "YES"; var mdl = new modl(); while (ans == "YES") { if (temp.Length == 0) { break; } if (mdl.isDreamer(temp)) { temp = temp.Substring(6, temp.Length); continue; } if (mdl.isEraser(temp)) { temp = temp.Substring(5, temp.Length); continue; } if (mdl.isDream(temp)) { temp = temp.Substring(5, temp.Length); continue; } if (mdl.isErase(temp)) { temp = temp.Substring(5, temp.Length); continue; } ans = "NO"; } Console.WriteLine(ans); } } public class modl { public bool isDream(string str) { if (str.Length < 5) { return false; } String sub = str.Substring(0, 5); if (sub == "dream") { return true; } return false; } public bool isDreamer(string str) { if (str.Length < 7) { return false; } String sub = str.Substring(0, 7); if (sub == "dreamer") { return true; } return false; } public bool isErase(string str) { if (str.Length < 5) { return false; } String sub = str.Substring(0, 5); if (sub == "erase") { return true; } return false; } public bool isEraser(string str) { if (str.Length < 6) { return false; } String sub = str.Substring(0, 6); if (sub == "eraser") { return true; } return false; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { public class Program { static void Main(string[] args) { String input = Console.ReadLine(); String temp = input; String ans = "YES"; var mdl = new modl(); while (ans == "YES") { if (temp.Length == 0) { break; } if (mdl.isDreamer(temp)) { temp = temp.Substring(0, temp.Length - 7); continue; } if (mdl.isEraser(temp)) { temp = temp.Substring(0, temp.Length - 6); continue; } if (mdl.isDream(temp)) { temp = temp.Substring(0, temp.Length - 5); continue; } if (mdl.isErase(temp)) { temp = temp.Substring(0, temp.Length - 5); continue; } ans = "NO"; } Console.WriteLine(ans); } } public class modl { public bool isDream(string str) { if (str.Length < 5) { return false; } String sub = str.Substring(str.Length - 5); if (sub == "dream") { return true; } return false; } public bool isDreamer(string str) { if (str.Length < 7) { return false; } String sub = str.Substring(str.Length - 7); if (sub == "dreamer") { return true; } return false; } public bool isErase(string str) { if (str.Length < 5) { return false; } String sub = str.Substring(str.Length - 5); if (sub == "erase") { return true; } return false; } public bool isEraser(string str) { if (str.Length < 6) { return false; } String sub = str.Substring(str.Length - 6); if (sub == "eraser") { return true; } return false; } } }
[["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 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], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
420
40
using System; class Program { static void Main() { string s = Console.ReadLine(); string ans = "YES"; int n = s.Length; while (ans == "YES" && n > 0) { if (n < 5) { ans = "NO"; break; } if (s.Substring(n - 5, 5) == "dream" || s.Substring(n - 5, 5) == "erase") { n -= 5; } else if (n >= 7 && s.Substring(n - 7, 7) == "dreamer") { s = s.Substring(n -= 7); } else if (n >= 6 && s.Substring(n - 6, 6) == "eraser") { s = s.Substring(n -= 6); } else { ans = "NO"; } } Console.WriteLine("{0}", ans); } }
using System; class Program { static void Main() { string s = Console.ReadLine(); string ans = "YES"; int n = s.Length; while (ans == "YES" && n > 0) { if (n < 5) { ans = "NO"; break; } if (s.Substring(n - 5, 5) == "dream" || s.Substring(n - 5, 5) == "erase") { n -= 5; } else if (n >= 7 && s.Substring(n - 7, 7) == "dreamer") { n -= 7; } else if (n >= 6 && s.Substring(n - 6, 6) == "eraser") { n -= 6; } else { ans = "NO"; } } Console.WriteLine("{0}", ans); } }
[["-", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
195
14
using System; class Program { static void Main() { string s = Console.ReadLine(); string ans = "YES"; while (ans == "YES" && s.Length > 0) { if (s.Length < 5) { ans = "NO"; break; } if (s.Substring(s.Length - 5) == "dream" || s.Substring(s.Length - 5) == "erase") { s = s.Substring(0, s.Length - 5); } else if (s.Substring(s.Length - 7) == "dreamer") { s = s.Substring(0, s.Length - 7); } else if (s.Substring(s.Length - 6) == "eraser") { s = s.Substring(0, s.Length - 6); } else { ans = "NO"; } } Console.WriteLine("{0}", ans); } }
using System; class Program { static void Main() { string s = Console.ReadLine(); string ans = "YES"; while (ans == "YES" && s.Length > 0) { if (s.Length < 5) { ans = "NO"; break; } if (s.Substring(s.Length - 5) == "dream" || s.Substring(s.Length - 5) == "erase") { s = s.Substring(0, s.Length - 5); } else if (s.Length >= 7 && s.Substring(s.Length - 7) == "dreamer") { s = s.Substring(0, s.Length - 7); } else if (s.Length >= 6 && s.Substring(s.Length - 6) == "eraser") { s = s.Substring(0, s.Length - 6); } else { ans = "NO"; } } Console.WriteLine("{0}", ans); } }
[["+", 75, 57, 15, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 20], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 75, 57, 15, 16, 31, 16, 31, 214, 205, 22], ["+", 75, 57, 15, 16, 31, 16, 31, 214, 0, 131], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 20], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 98]]
8
203
12
using System; using System.Text; using System.Collections.Generic; class Solve { int N; long[] x; int M; long K; int[] a; int[] original; public Solve() {} public static int Main() { new Solve().Calc(); return 0; } void Calc() { getinput(); int[] swap = new int[N - 1]; long[] dx = new long[N - 1]; long[] adx = new long[N - 1]; original = new int[N - 1]; for (int i = 0; i < N - 1; i++) { original[i] = i; } for (int i = 0; i < M; i++) { int j = original[a[i] - 1]; original[a[i] - 1] = original[a[i]]; original[a[i]] = j; } swap = m(K); for (int i = 0; i < N - 1; i++) { dx[i] = x[i + 1] - x[i]; } for (int i = 0; i < N - 1; i++) { adx[swap[i]] = dx[i]; } StringBuilder sb = new StringBuilder(); long count = x[0]; sb.Append(count + "\n"); for (int i = 0; i < N - 1; i++) { count += adx[i]; sb.Append(count + "\n"); } Console.Write(sb.ToString()); } int[] m(long k) { if (k <= 1) { return original; } else if (k % 2 == 0) { int[] s = m(k / 2); int[] t = new int[N - 1]; for (int i = 0; i < N - 1; i++) { t[i] = s[s[i]]; } return t; } else { int[] s = m(k - 1); int[] t = new int[N - 1]; for (int i = 0; i < N - 1; i++) { t[i] = original[s[i]]; } return t; } } void getinput() { N = int.Parse(Console.ReadLine()); x = new long[N]; string[] str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { x[i] = Int64.Parse(str[i]); } str = Console.ReadLine().Split(' '); M = int.Parse(str[0]); K = Int64.Parse(str[1]); a = new int[M]; str = Console.ReadLine().Split(' '); for (int i = 0; i < M; i++) { a[i] = int.Parse(str[i]) - 1; } } }
using System; using System.Text; using System.Collections.Generic; class Solve { int N; long[] x; int M; long K; int[] a; int[] original; public Solve() {} public static int Main() { new Solve().Calc(); return 0; } void Calc() { getinput(); int[] swap; long[] dx = new long[N - 1]; long[] adx = new long[N - 1]; original = new int[N - 1]; for (int i = 0; i < N - 1; i++) { original[i] = i; } for (int i = 0; i < M; i++) { int j = original[a[i] - 1]; original[a[i] - 1] = original[a[i]]; original[a[i]] = j; } swap = m(K); for (int i = 0; i < N - 1; i++) { dx[i] = x[i + 1] - x[i]; } for (int i = 0; i < N - 1; i++) { adx[i] = dx[swap[i]]; } StringBuilder sb = new StringBuilder(); long count = x[0]; sb.Append(count + "\n"); for (int i = 0; i < N - 1; i++) { count += adx[i]; sb.Append(count + "\n"); } Console.Write(sb.ToString()); } int[] m(long k) { if (k <= 1) { return original; } else if (k % 2 == 0) { int[] s = m(k / 2); int[] t = new int[N - 1]; for (int i = 0; i < N - 1; i++) { t[i] = s[s[i]]; } return t; } else { int[] s = m(k - 1); int[] t = new int[N - 1]; for (int i = 0; i < N - 1; i++) { t[i] = original[s[i]]; } return t; } } void getinput() { N = int.Parse(Console.ReadLine()); x = new long[N]; string[] str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { x[i] = Int64.Parse(str[i]); } str = Console.ReadLine().Split(' '); M = int.Parse(str[0]); K = Int64.Parse(str[1]); a = new int[M]; str = Console.ReadLine().Split(' '); for (int i = 0; i < M; i++) { a[i] = int.Parse(str[i]) - 1; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 33], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["-", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73]]
8
681
14
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; // using System.Numerics; using Number = System.Int64; using static System.Math; // using static MathEx; // using P = System.Collections.Generic.KeyValuePair<int, int>; namespace Program { public class Solver { public void Solve() { var n = ri; var A = Enumerate(3, x => sc.Integer(n)); for (int i = 0; i < 3; i++) for (int j = 0; j < n; j++) A[i][j]--; var ok = true; var P = Enumerate(2, x => new List<int>()); var par = new int[2]; for (int i = 0; i < n; i++) { var a = new int[] { A[0][i], A[1][i], A[2][i] }; Array.Sort(a); if (A[1][i] != a[1]) ok = false; if (a[1] - a[0] != 1) ok = false; if (a[2] - a[1] != 1) ok = false; var x = a[0] / 3; if (Math.Abs(i - x) % 2 == 1) ok = false; if (a[0] == A[0][i]) { if (Math.Abs(i - x) == 2) { Debug.WriteLine(i); par[i % 2] ^= 1; } } else { if (Math.Abs(i - x) == 0) { Debug.WriteLine(i); par[i % 2] ^= 1; } } P[i % 2].Add(a[0]); } var inv = new int[2]; for (int k = 0; k < 2; k++) f(P[k], 0, P[k].Count, ref inv[k]); Debug.WriteLine(P[0].AsJoinedString()); Debug.WriteLine(P[1].AsJoinedString()); Debug.WriteLine(par.AsJoinedString()); Debug.WriteLine(inv.AsJoinedString()); Debug.WriteLine(""); for (int k = 0; k < 2; k++) if (par[k] != inv[k ^ 1]) ok = false; if (ok) IO.Printer.Out.WriteLine("Yes"); else IO.Printer.Out.WriteLine("No"); } List<int> f(List<int> a, int l, int r, ref int inv) { if (r - l == 1) return new List<int>() { a[l] }; var m = (l + r) / 2; var L = f(a, l, m, ref inv); var R = f(a, m, r, ref inv); var ret = new List<int>(); l = 0; r = 0; while (l < L.Count || r < R.Count) { if (r < R.Count && (l == L.Count || L[l] > R[r])) ret.Add(R[r++]); else { inv ^= (~R.BinarySearch(L[l])) % 2; ret.Add(L[l++]); } } Debug.WriteLine(ret.AsJoinedString()); return ret; } //* int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); char rc => sc.Char(); [System.Diagnostics.Conditional("DEBUG")] void put(params object[] a) => Debug.WriteLine(string.Join(" ", a)); //*/ public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { public static string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } public static string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } public static void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using SB = System.Text.StringBuilder; // using System.Numerics; using Number = System.Int64; using static System.Math; // using static MathEx; // using P = System.Collections.Generic.KeyValuePair<int, int>; namespace Program { public class Solver { public void Solve() { var n = ri; var A = Enumerate(3, x => sc.Integer(n)); for (int i = 0; i < 3; i++) for (int j = 0; j < n; j++) A[i][j]--; var ok = true; var P = Enumerate(2, x => new List<int>()); var par = new int[2]; for (int i = 0; i < n; i++) { var a = new int[] { A[0][i], A[1][i], A[2][i] }; Array.Sort(a); if (A[1][i] != a[1]) ok = false; if (a[1] - a[0] != 1) ok = false; if (a[2] - a[1] != 1) ok = false; var x = a[0] / 3; if (Math.Abs(i - x) % 2 == 1) ok = false; if (a[0] == A[0][i]) { if (Math.Abs(i - x) % 4 == 2) { Debug.WriteLine(i); par[i % 2] ^= 1; } } else { if (Math.Abs(i - x) % 4 == 0) { Debug.WriteLine(i); par[i % 2] ^= 1; } } P[i % 2].Add(a[0]); } var inv = new int[2]; for (int k = 0; k < 2; k++) f(P[k], 0, P[k].Count, ref inv[k]); Debug.WriteLine(P[0].AsJoinedString()); Debug.WriteLine(P[1].AsJoinedString()); Debug.WriteLine(par.AsJoinedString()); Debug.WriteLine(inv.AsJoinedString()); Debug.WriteLine(""); for (int k = 0; k < 2; k++) if (par[k] != inv[k ^ 1]) ok = false; if (ok) IO.Printer.Out.WriteLine("Yes"); else IO.Printer.Out.WriteLine("No"); } List<int> f(List<int> a, int l, int r, ref int inv) { if (r - l == 1) return new List<int>() { a[l] }; var m = (l + r) / 2; var L = f(a, l, m, ref inv); var R = f(a, m, r, ref inv); var ret = new List<int>(); l = 0; r = 0; while (l < L.Count || r < R.Count) { if (r < R.Count && (l == L.Count || L[l] > R[r])) ret.Add(R[r++]); else { inv ^= (~R.BinarySearch(L[l])) % 2; ret.Add(L[l++]); } } return ret; } //* int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); char rc => sc.Char(); [System.Diagnostics.Conditional("DEBUG")] void put(params object[] a) => Debug.WriteLine(string.Join(" ", a)); //*/ public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { public static string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } public static string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } public static void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion
[["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 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], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
1,886
15
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; class P { static void Main() { int[] nkl = Console.ReadLine().Split().Select(int.Parse).ToArray(); UnionFind road = new UnionFind(nkl[0]); UnionFind train = new UnionFind(nkl[0]); for (int i = 0; i < nkl[1]; i++) { int[] ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); road.Unite(ab[0], ab[1]); } for (int i = 0; i < nkl[2]; i++) { int[] ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); train.Unite(ab[0], ab[1]); } int[] roadd = Enumerable.Range(0, road.Size).Select(x => road.Find(x)).ToArray(); int[] traind = Enumerable.Range(0, train.Size).Select(x => train.Find(x)).ToArray(); //<道路グループindex,<電車グループインデックス,属してるインデックス>> Dictionary<int, Dictionary<int, int>> dict = new Dictionary<int, Dictionary<int, int>>(); for (int i = 0; i < roadd.Length; i++) { if (!dict.ContainsKey(roadd[i])) dict.Add(roadd[i], new Dictionary<int, int>()); if (!dict[roadd[i]].ContainsKey(traind[i])) dict[roadd[i]].Add(traind[i], 0); dict[roadd[i]][traind[i]]++; } Console.WriteLine( string.Join(" ", Enumerable.Range(0, nkl[0]) .Select(x => dict[roadd[x]][traind[x]]) .ToArray())); } } class UnionFind { public int Size { get; private set; } List<int> parent; List<int> sizes; public UnionFind() { parent = new List<int>(65536); sizes = new List<int>(65536); } public UnionFind(int count) { parent = new List<int>(count); sizes = new List<int>(count); ExtendSize(count); } public bool Unite(int x, int y) { int xp = Find(x); int yp = Find(y); if (yp == xp) return false; if (sizes[xp] < sizes[yp]) { var tmp = xp; xp = yp; yp = tmp; } parent[yp] = xp; sizes[xp] += sizes[yp]; return true; } public IEnumerable<int> AllParents => parent.Where(x => x == parent[x]); public int GetSize(int x) { ExtendSize(x); return sizes[x]; } public bool IsSameGroup(int x, int y) => Find(x) == Find(y); public int Find(int x) { ExtendSize(x); return parent[x] == parent[parent[x]] ? parent[x] : parent[x] = Find(parent[x]); } public void ExtendSize(int treeSize) { while (Size < treeSize) { parent.Add(Size); parent.Add(1); Size++; } } }
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; class P { static void Main() { int[] nkl = Console.ReadLine().Split().Select(int.Parse).ToArray(); UnionFind road = new UnionFind(nkl[0]); UnionFind train = new UnionFind(nkl[0]); for (int i = 0; i < nkl[1]; i++) { int[] ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); road.Unite(ab[0], ab[1]); } for (int i = 0; i < nkl[2]; i++) { int[] ab = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); train.Unite(ab[0], ab[1]); } int[] roadd = Enumerable.Range(0, road.Size).Select(x => road.Find(x)).ToArray(); int[] traind = Enumerable.Range(0, train.Size).Select(x => train.Find(x)).ToArray(); //<道路グループindex,<電車グループインデックス,属してるインデックス>> Dictionary<int, Dictionary<int, int>> dict = new Dictionary<int, Dictionary<int, int>>(); for (int i = 0; i < roadd.Length; i++) { if (!dict.ContainsKey(roadd[i])) dict.Add(roadd[i], new Dictionary<int, int>()); if (!dict[roadd[i]].ContainsKey(traind[i])) dict[roadd[i]].Add(traind[i], 0); dict[roadd[i]][traind[i]]++; } Console.WriteLine( string.Join(" ", Enumerable.Range(0, nkl[0]) .Select(x => dict[roadd[x]][traind[x]]) .ToArray())); } } class UnionFind { public int Size { get; private set; } List<int> parent; List<int> sizes; public UnionFind() { Size = 0; parent = new List<int>(65536); sizes = new List<int>(65536); } public UnionFind(int count) { Size = 0; parent = new List<int>(count); sizes = new List<int>(count); ExtendSize(count); } public bool Unite(int x, int y) { int xp = Find(x); int yp = Find(y); if (yp == xp) return false; if (sizes[xp] < sizes[yp]) { var tmp = xp; xp = yp; yp = tmp; } parent[yp] = xp; sizes[xp] += sizes[yp]; return true; } public IEnumerable<int> AllParents => parent.Where(x => x == parent[x]); public int GetSize(int x) { ExtendSize(x + 1); return sizes[x]; } public bool IsSameGroup(int x, int y) => Find(x) == Find(y); public int Find(int x) { ExtendSize(x + 1); return parent[x] == parent[parent[x]] ? parent[x] : parent[x] = Find(parent[x]); } public void ExtendSize(int treeSize) { while (Size < treeSize) { parent.Add(Size); sizes.Add(1); Size++; } } }
[["+", 0, 263, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 263, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
8
815
14
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { string w = Input.ScanStr(); bool c = false, f = false; int i; for (i = 0; i < w.Length; i++) if (w[i] == 'C') c = true; for (; i < w.Length; i++) if (w[i] == 'F') f = true; Console.WriteLine(c && f ? "Yes" : "No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { string w = Input.ScanStr(); bool f = false; int i; for (i = 0; i < w.Length; i++) if (w[i] == 'C') break; for (; i < w.Length; i++) if (w[i] == 'F') f = true; Console.WriteLine(f ? "Yes" : "No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
[["-", 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, 211, 0, 147], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 0, 7, 8, 57, 64, 1, 0, 11, 31, 22], ["-", 8, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 57, 64, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 7, 8, 57, 64, 93, 0, 94], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98]]
8
656
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace atcoder { class Program { static int N; static int K; static int L; static Dictionary<int, List<int>> dictRoad; static Dictionary<int, List<int>> dictRail; static Dictionary<long, List<int>> dictColorAll; static int[] cityColorRoad; static int[] cityColorRail; static long[] cityColorAll; static int[] cityRet; public static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); N = int.Parse(s[0]); K = int.Parse(s[1]); L = int.Parse(s[2]); cityColorRoad = new int[N]; cityColorRail = new int[N]; cityRet = new int[N]; cityColorAll = new long[N]; dictRoad = new Dictionary<int, List<int>>(); dictRail = new Dictionary<int, List<int>>(); for (int i = 0; i < N; i++) { dictRoad.Add(i, new List<int>()); dictRail.Add(i, new List<int>()); } for (int i = 0; i < K; i++) { string[] line = Console.ReadLine().Split(' '); int c1 = int.Parse(line[0]) - 1; int c2 = int.Parse(line[1]) - 1; dictRoad[c1].Add(c2); dictRoad[c2].Add(c1); } for (int i = 0; i < K; i++) { string[] line = Console.ReadLine().Split(' '); int c1 = int.Parse(line[0]); int c2 = int.Parse(line[1]); dictRail[c1].Add(c2); dictRail[c2].Add(c1); } // Create Cluster int colorRoad; colorRoad = 0; for (int i = 0; i < N; i++) { if (cityColorRoad[i] == 0) { colorRoad++; Paint(i, colorRoad, dictRoad, cityColorRoad); } } int colorRail = 0; for (int i = 0; i < N; i++) { if (cityColorRail[i] == 0) { colorRail++; Paint(i, colorRail, dictRail, cityColorRail); } } for (int i = 0; i < N; i++) { cityColorAll[i] = (long)(cityColorRoad[i]) * 1000000 + (long)(cityColorRail[i]); } dictColorAll = new Dictionary<long, List<int>>(); for (int i = 1; i <= colorRoad; i++) { long c = cityColorAll[i]; if (!dictColorAll.ContainsKey(c)) { dictColorAll.Add(c, new List<int>()); } dictColorAll[c].Add(i); } // Create Answer var keys = dictColorAll.Keys.ToList(); for (int i = 0; i < keys.Count; i++) { var key = keys[i]; var list = dictColorAll[key]; for (int j = 0; j < list.Count; j++) { cityRet[list[j]] = list.Count; } } Console.WriteLine(string.Join(" ", cityRet)); } static public void Paint(int i, int color, Dictionary<int, List<int>> dict, int[] cityColors) { List<int> list = dict[i]; for (int j = 0; j < list.Count; j++) { int city = list[j]; if (cityColors[city] == 0) { cityColors[city] = color; Paint(city, color, dict, cityColors); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace atcoder { class Program { static int N; static int K; static int L; static Dictionary<int, List<int>> dictRoad; static Dictionary<int, List<int>> dictRail; static Dictionary<long, List<int>> dictColorAll; static int[] cityColorRoad; static int[] cityColorRail; static long[] cityColorAll; static int[] cityRet; public static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); N = int.Parse(s[0]); K = int.Parse(s[1]); L = int.Parse(s[2]); cityColorRoad = new int[N]; cityColorRail = new int[N]; cityRet = new int[N]; cityColorAll = new long[N]; dictRoad = new Dictionary<int, List<int>>(); dictRail = new Dictionary<int, List<int>>(); for (int i = 0; i < N; i++) { dictRoad.Add(i, new List<int>()); dictRail.Add(i, new List<int>()); } for (int i = 0; i < K; i++) { string[] line = Console.ReadLine().Split(' '); int c1 = int.Parse(line[0]) - 1; int c2 = int.Parse(line[1]) - 1; dictRoad[c1].Add(c2); dictRoad[c2].Add(c1); } for (int i = 0; i < L; i++) { string[] line = Console.ReadLine().Split(' '); int c1 = int.Parse(line[0]) - 1; int c2 = int.Parse(line[1]) - 1; dictRail[c1].Add(c2); dictRail[c2].Add(c1); } // Create Cluster int colorRoad = 0; for (int i = 0; i < N; i++) { if (cityColorRoad[i] == 0) { colorRoad++; cityColorRoad[i] = colorRoad; Paint(i, colorRoad, dictRoad, cityColorRoad); } } int colorRail = 0; for (int i = 0; i < N; i++) { if (cityColorRail[i] == 0) { colorRail++; cityColorRail[i] = colorRail; Paint(i, colorRail, dictRail, cityColorRail); } } for (int i = 0; i < N; i++) { cityColorAll[i] = (long)(cityColorRoad[i]) * 1000000 + (long)(cityColorRail[i]); } dictColorAll = new Dictionary<long, List<int>>(); for (int i = 0; i < N; i++) { long c = cityColorAll[i]; if (!dictColorAll.ContainsKey(c)) { dictColorAll.Add(c, new List<int>()); } dictColorAll[c].Add(i); } // Create Answer var keys = dictColorAll.Keys.ToList(); for (int i = 0; i < keys.Count; i++) { var key = keys[i]; var list = dictColorAll[key]; for (int j = 0; j < list.Count; j++) { cityRet[list[j]] = list.Count; } } Console.WriteLine(string.Join(" ", cityRet)); Console.Read(); } static public void Paint(int i, int color, Dictionary<int, List<int>> dict, int[] cityColors) { List<int> list = dict[i]; for (int j = 0; j < list.Count; j++) { int city = list[j]; if (cityColors[city] == 0) { cityColors[city] = color; Paint(city, color, dict, cityColors); } } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 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, 1, 0, 11, 31, 22], ["+", 64, 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], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 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, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 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
846
34
using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); var cp = s.IndexOf('C'); var fp = s.LastIndexOf('F'); Console.WriteLine(cp < fp ? "Yes" : "No"); } }
using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); var cp = s.IndexOf('C'); var fp = s.LastIndexOf('F'); Console.WriteLine(cp < fp && cp >= 0 && fp >= 0 ? "Yes" : "No"); } }
[["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 98], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 17, 20], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 31, 22], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 20], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 203]]
8
70
8
using System; class Program { static void Main(string[] args) { string input = Console.ReadLine(); if (input.Length <= 0) Console.Write("No"); else if (input.IndexOf("C") >= input.LastIndexOf("F")) { Console.Write("No"); } else Console.Write("Yes"); } }
using System; class Program { static void Main(string[] args) { string input = Console.ReadLine(); if (input.IndexOf("C") < 0) Console.Write("No"); else if (input.IndexOf("C") >= input.LastIndexOf("F")) { Console.Write("No"); } else Console.Write("Yes"); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 31, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
86
9
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); string s = Console.ReadLine(); int N = int.Parse(str[0]); int[] R = new int[N]; { int M = int.Parse(str[1]); int l = 0; int r = 0; for (int i = 0; i < M; i++) { str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]) - 1; int b = int.Parse(str[1]) - 1; if (l != a) { for (int j = l; j < a; j++) { R[j] = r; } l = a; } r = Math.Max(r, b); } for (int j = l; j < N; j++) { R[j] = Math.Max(r, j); } } int[] one = new int[N]; one[0] = s[0] == '1' ? 1 : 0; for (int i = 1; i < N; i++) { one[i] = one[i - 1] + (s[i] == '1' ? 1 : 0); } int C = one[N - 1]; long[,] dp = new long[N, C + 1]; dp[N - 1, C] = 1; for (int i = C - 1; i >= 0; i--) { dp[N - 1, i] = 0; } for (int i = N - 2; i >= 0; i--) { for (int j = 0; j < C; j++) { dp[i, j] = (one[R[i]] >= j && (R[i] + 1 - one[R[i]] >= i + 1 - j)) ? (dp[i + 1, j] + dp[i + 1, j + 1]) % Define.mod : 0; } dp[i, C] = (one[R[i]] >= C && (R[i] + 1 - one[R[i]] >= i + 1 - C)) ? dp[i + 1, C] : 0; } sb.Append((dp[0, 0] + dp[0, 1]) % Define.mod + "\n"); } } public static class Define { public const long mod = 1000000007; }
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); string s = Console.ReadLine(); int N = int.Parse(str[0]); int[] R = new int[N]; { int M = int.Parse(str[1]); int l = 0; int r = 0; for (int i = 0; i < M; i++) { str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]) - 1; int b = int.Parse(str[1]) - 1; if (l != a) { for (int j = l; j < a; j++) { R[j] = Math.Max(r, j); } l = a; } r = Math.Max(r, b); } for (int j = l; j < N; j++) { R[j] = Math.Max(r, j); } } int[] one = new int[N]; one[0] = s[0] == '1' ? 1 : 0; for (int i = 1; i < N; i++) { one[i] = one[i - 1] + (s[i] == '1' ? 1 : 0); } int C = one[N - 1]; long[,] dp = new long[N, C + 1]; dp[N - 1, C] = 1; for (int i = C - 1; i >= 0; i--) { dp[N - 1, i] = 0; } for (int i = N - 2; i >= 0; i--) { for (int j = 0; j < C; j++) { dp[i, j] = (one[R[i]] >= j && (R[i] + 1 - one[R[i]] >= i + 1 - j) && i + 1 >= j) ? (dp[i + 1, j] + dp[i + 1, j + 1]) % Define.mod : 0; } dp[i, C] = (one[R[i]] >= C && (R[i] + 1 - one[R[i]] >= i + 1 - C) && i + 1 >= C) ? dp[i + 1, C] : 0; } sb.Append((C != 0 ? (dp[0, 0] + dp[0, 1]) % Define.mod : dp[0, 0]) + "\n"); } } public static class Define { public const long mod = 1000000007; }
[["+", 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, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 41, 15, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 15, 23, 0, 16, 12, 16, 31, 16, 17, 72], ["+", 15, 23, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 12, 41, 15, 23, 0, 16, 12, 16, 17, 20], ["+", 12, 41, 15, 23, 0, 16, 12, 16, 12, 22], ["+", 0, 16, 31, 23, 0, 41, 15, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 41, 15, 16, 17, 79], ["+", 0, 16, 31, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 23, 0, 41, 0, 101], ["+", 31, 23, 0, 41, 64, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 41, 0, 102], ["+", 0, 16, 31, 23, 0, 41, 75, 204, 205, 22], ["+", 31, 23, 0, 41, 75, 204, 206, 207, 0, 70], ["+", 0, 41, 75, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 41, 75, 204, 206, 207, 0, 21], ["+", 31, 23, 0, 41, 75, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
8
632
32
using System; using System.Collections.Generic; namespace cswork { class Program { static void Main(string[] args) { string x = ReadStr(); Write("A" + x[0] + "C"); Exit(); } public static void Write(string str) { Console.WriteLine(str); } public static void Write(int i) { Console.WriteLine(i); } public static void Write(double d) { Console.WriteLine(d); } public static string ReadStr() { return Console.ReadLine(); } public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long Read() { return long.Parse(Console.ReadLine()); } public static double ReadDouble() { return double.Parse(Console.ReadLine()); } public static void Exit() {} public static List<string> ReadListStr() { return new List<string>(ReadStr().Split(" ")); } public static List<long> ReadList() { return ReadListStr().ConvertAll(x => long.Parse(x)); } public static List<int> ReadListInt() { return ReadListStr().ConvertAll(x => int.Parse(x)); } } }
using System; using System.Collections.Generic; namespace cswork { class Program { static void Main(string[] args) { List<string> s = ReadListStr(); string x = s[1]; Write("A" + x[0] + "C"); Exit(); } public static void Write(string str) { Console.WriteLine(str); } public static void Write(int i) { Console.WriteLine(i); } public static void Write(double d) { Console.WriteLine(d); } public static string ReadStr() { return Console.ReadLine(); } public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static long Read() { return long.Parse(Console.ReadLine()); } public static double ReadDouble() { return double.Parse(Console.ReadLine()); } public static void Exit() {} public static List<string> ReadListStr() { return new List<string>(ReadStr().Split(" ")); } public static List<long> ReadList() { return ReadListStr().ConvertAll(x => long.Parse(x)); } public static List<int> ReadListInt() { return ReadListStr().ConvertAll(x => int.Parse(x)); } } }
[["+", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 18], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 47], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73]]
8
276
15
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ string[] input = Console.ReadLine().Split().Select(i => (i)).ToArray(); Console.WriteLine(input[0][0] + input[1][0] + input[2][0]); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ string[] input = Console.ReadLine().Split().Select(i => (i)).ToArray(); Console.WriteLine(input[0][0] + "" + input[1][0] + "" + input[2][0]); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["+", 31, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62]]
8
104
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; class Program { static void Main() { var sc = new Scanner(); string a = Console.ReadLine(); string[] b = a.Split(' '); string c = b[1]; Console.WriteLine("A" + c + "C"); } } static class Extentions { public static IEnumerable<T> Outpuut<T>(this IEnumerable<T> source) { foreach (var item in source) { Console.WriteLine(item); } return source; } public static T Print<T>(this T obj) { Console.WriteLine(obj); return obj; } } public class Scanner { public Scanner() { byte[] inputBuffer = new byte[1024]; System.IO.Stream inputStream = Console.OpenStandardInput(inputBuffer.Length); Console.SetIn(new System.IO.StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)); } string[] buffer = new string[0]; int index = 0; public char[] SplitChars { get; set; } public string String() { if (index < buffer.Length) return buffer[index++]; string line = ""; while (line == "") line = Console.ReadLine(); if (line == null) return null; buffer = line.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); index = 0; return buffer[index++]; } public string[] StringArray(int count) { return NextArray(count, x => x); } public void Skip(int count) { for (int i = 0; i < count; i++) String(); } public T Next<T>(Func<string, T> parser) { return parser(String()); } public T[] NextArray<T>(int count, Func<string, T> parser) { var arr = new T[count]; for (int i = 0; i < count; i++) arr[i] = Next(parser); return arr; } public int Int() { return Next(int.Parse); } public int[] IntArray(int count) { return NextArray(count, int.Parse); } public double Double() { return Next(double.Parse); } public double[] DoubleArray(int count) { return NextArray(count, double.Parse); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; class Program { static void Main() { var sc = new Scanner(); string a = Console.ReadLine(); string[] b = a.Split(' '); string c = b[1]; char d = c[0]; Console.WriteLine("A" + d + "C"); } } static class Extentions { public static IEnumerable<T> Outpuut<T>(this IEnumerable<T> source) { foreach (var item in source) { Console.WriteLine(item); } return source; } public static T Print<T>(this T obj) { Console.WriteLine(obj); return obj; } } public class Scanner { public Scanner() { byte[] inputBuffer = new byte[1024]; System.IO.Stream inputStream = Console.OpenStandardInput(inputBuffer.Length); Console.SetIn(new System.IO.StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)); } string[] buffer = new string[0]; int index = 0; public char[] SplitChars { get; set; } public string String() { if (index < buffer.Length) return buffer[index++]; string line = ""; while (line == "") line = Console.ReadLine(); if (line == null) return null; buffer = line.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); index = 0; return buffer[index++]; } public string[] StringArray(int count) { return NextArray(count, x => x); } public void Skip(int count) { for (int i = 0; i < count; i++) String(); } public T Next<T>(Func<string, T> parser) { return parser(String()); } public T[] NextArray<T>(int count, Func<string, T> parser) { var arr = new T[count]; for (int i = 0; i < count; i++) arr[i] = Next(parser); return arr; } public int Int() { return Next(int.Parse); } public int[] IntArray(int count) { return NextArray(count, int.Parse); } public double Double() { return Next(double.Parse); } public double[] DoubleArray(int count) { return NextArray(count, double.Parse); } }
[["+", 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, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
8
527
10
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramB { static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var a = long.Parse(inputs[0]); var b = long.Parse(inputs[1]); var x = long.Parse(inputs[2]); var count = (b / x) - ((a - 1) / x); Console.WriteLine(count); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramB { static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); var a = long.Parse(inputs[0]); var b = long.Parse(inputs[1]); var x = long.Parse(inputs[2]); var count = (b / x) - ((a - 1) / x); if (a == 0 && x > 1) count++; Console.WriteLine(count); } } }
[["+", 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, 16, 31, 22], ["+", 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, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 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
115
13
using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; namespace AtCoder { class Program { const int BiggestMod = 1000000007; public static void Main() { var args = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var min = args[0] - 1; var max = args[1]; var separator = args[2]; Console.WriteLine((max / separator) - (min / separator)); } } }
using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; namespace AtCoder { class Program { const int BiggestMod = 1000000007; public static void Main() { var args = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var separator = args[2]; var min = args[0] - 1 + separator; var max = args[1] + separator; Console.WriteLine((max / separator) - (min / separator)); } } }
[["+", 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, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 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, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 8, 201, 0, 195, 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, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73]]
8
141
18
using Yorukatsu051.Questions; using Yorukatsu051.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu051.Questions { /// <summary> /// https://atcoder.jp/contests/abc048/tasks/abc048_b /// </summary> public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var abx = inputStream.ReadLongArray(); var a = abx[0]; var b = abx[1]; var x = abx[2]; yield return b / x - (a - 1) / x; } } } namespace Yorukatsu051 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu051.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Yorukatsu051.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using Yorukatsu051.Questions; using Yorukatsu051.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu051.Questions { /// <summary> /// https://atcoder.jp/contests/abc048/tasks/abc048_b /// </summary> public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var abx = inputStream.ReadLongArray(); var a = abx[0]; var b = abx[1]; var x = abx[2]; if (a == 0) { if (b == 0) { yield return 1; } else { yield return b / x + 1; } } else { yield return b / x - (a - 1) / x; } } } } namespace Yorukatsu051 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu051.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Yorukatsu051.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["+", 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], ["+", 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, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 285, 0, 286], ["+", 64, 196, 0, 57, 64, 196, 0, 285, 0, 38], ["+", 64, 196, 0, 57, 64, 196, 0, 285, 0, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 285, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 64, 196, 0, 57, 75, 196, 0, 285, 0, 286], ["+", 64, 196, 0, 57, 75, 196, 0, 285, 0, 38], ["+", 75, 196, 0, 285, 0, 16, 31, 16, 31, 22], ["+", 75, 196, 0, 285, 0, 16, 31, 16, 17, 85], ["+", 75, 196, 0, 285, 0, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 285, 0, 16, 17, 72], ["+", 0, 57, 75, 196, 0, 285, 0, 16, 12, 203], ["+", 64, 196, 0, 57, 75, 196, 0, 285, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 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, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
504
34
using System; namespace ABC048B { class Program { static void Main(string[] args) { var target = Console.ReadLine().Split(' '); long a = long.Parse(target[0]); long b = long.Parse(target[1]); long x = long.Parse(target[2]); long a1 = a / x; long b1 = b / x; Console.WriteLine(b1 - a1); } } }
using System; namespace ABC048B { class Program { static void Main(string[] args) { var target = Console.ReadLine().Split(' '); long a = long.Parse(target[0]); long b = long.Parse(target[1]); long x = long.Parse(target[2]); long a1 = a / x; long b1 = b / x; if (a % x == 0) b1++; Console.WriteLine(b1 - a1); } } }
[["+", 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, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 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], ["+", 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
100
11
using System; using System.Collections.Generic; using System.Linq; namespace ABC048B { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); long a = input[0]; long b = input[1]; long x = input[2]; if (a == 0) { a = 1; } var a_count = f(a, x); var b_count = f(b, x); Console.WriteLine(b_count - a_count); } static long f(long n, long x) { if (n == -1) { return 0; } return n / x + 1; } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC048B { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); long a = input[0]; long b = input[1]; long x = input[2]; var a_count = f(a - 1, x); var b_count = f(b, x); Console.WriteLine(b_count - a_count); } static long f(long n, long x) { if (n == -1) { return 0; } return n / x + 1; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 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, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
159
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long a = sc.NextLong(); long b = sc.NextLong(); long x = sc.NextLong(); long answer = b / x - (a - 1) / x; if (a == 0) { answer = b / x; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long a = sc.NextLong(); long b = sc.NextLong(); long x = sc.NextLong(); long answer = b / x - a / x; if (a % x == 0) { answer++; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 212, 0, 16, 12, 16, 31, 23, 0, 24], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 212, 0, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29]]
8
397
11
using System; using System.Linq; namespace B_Between { class Program { static void Main(string[] args) { var inputs = Console.ReadLine().ToLongArray(); var a = inputs[0]; var b = inputs[1]; var x = inputs[2]; var small = (a - 1) / x; var big = b / x; Console.WriteLine(big - small); } } static class StringExtention { static public int ToInt(this string input) { return int.Parse(input); } static public int[] ToIntArray(this string input) { return input.Split(' ').Select(int.Parse).ToArray(); } static public long ToLong(this string input) { return long.Parse(input); } static public long[] ToLongArray(this string input) { return input.Split(' ').Select(long.Parse).ToArray(); } } }
using System; using System.Linq; namespace B_Between { class Program { static void Main(string[] args) { var inputs = Console.ReadLine().ToLongArray(); var a = inputs[0]; var b = inputs[1]; var x = inputs[2]; var small = a == 0 ? -1 : (a - 1) / x; var big = b / x; Console.WriteLine(big - small); } } static class StringExtention { static public int ToInt(this string input) { return int.Parse(input); } static public int[] ToIntArray(this string input) { return input.Split(' ').Select(int.Parse).ToArray(); } static public long ToLong(this string input) { return long.Parse(input); } static public long[] ToLongArray(this string input) { return input.Split(' ').Select(long.Parse).ToArray(); } } }
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 200, 0, 212, 0, 41, 64, 241, 0, 33], ["+", 0, 200, 0, 212, 0, 41, 64, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102]]
8
202
7
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Diagnostics; using static System.Math; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; static long a, b, x; public static void Input() { var cin = new Solve(); var input = cin.SplitReaderL(); a = input[0]; b = input[1]; x = input[2]; } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); Console.WriteLine((b / x) - ((a - 1) / x)); // Console.Out.Flush(); } public int[] SplitReader() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReaderL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Diagnostics; using static System.Math; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; static long a, b, x; public static void Input() { var cin = new Solve(); var input = cin.SplitReaderL(); a = input[0]; b = input[1]; x = input[2]; } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); if (a == 0) { Console.WriteLine((b / x) + 1); } else { Console.WriteLine((b / x) - ((a - 1) / x)); } // Console.Out.Flush(); } public int[] SplitReader() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReaderL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } }
[["+", 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], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 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, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 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
234
24
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC048B { class Program { public static void Solve(Input input) { var a = input.NextLong(); var b = input.NextLong(); var x = input.NextLong(); Console.WriteLine((b / x) - ((a - 1) / x)); } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC048B { class Program { public static void Solve(Input input) { var a = input.NextLong(); var b = input.NextLong(); var x = input.NextLong(); if (a == 0) { Console.WriteLine(b / x + 1); } else { Console.WriteLine((b / x) - ((a - 1) / x)); } } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["+", 8, 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], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 85], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 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
1,683
22
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; class Solver { Scanner sc = new Scanner(); public void Solve() { var a = sc.nextLong(); var b = sc.nextLong(); var x = sc.nextLong(); WriteLine((b / x) - ((a - 1) / x)); } } 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; } } class Program { static void Main(string[] args) { Solver s = new Solver(); s.Solve(); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; class Solver { Scanner sc = new Scanner(); public void Solve() { var a = sc.nextLong(); var b = sc.nextLong(); var x = sc.nextLong(); if (a == 0) { WriteLine((b / x) + 1); } else { WriteLine((b / x) - ((a - 1) / x)); } } } 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; } } class Program { static void Main(string[] args) { Solver s = new Solver(); s.Solve(); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 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, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 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
471
22
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var abx = ReadSplitLong(); var a = abx[0]; var b = abx[1]; var x = abx[2]; var c = (a - 1) / x; Println(b / x - c); } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b); static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var abx = ReadSplitLong(); var a = abx[0]; var b = abx[1]; var x = abx[2]; var c = a == 0 ? -1 : (a - 1) / x; Println(b / x - c); } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b); static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 200, 0, 212, 0, 41, 64, 241, 0, 33], ["+", 0, 200, 0, 212, 0, 41, 64, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102]]
8
609
7
using System; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); long a = long.Parse(s[0]); long b = long.Parse(s[1]); long x = long.Parse(s[2]); Console.WriteLine(b / x + 1 - Math.Max((a - 1) / x + 1, 0)); } }
using System; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); long a = long.Parse(s[0]); long b = long.Parse(s[1]); long x = long.Parse(s[2]); Console.WriteLine(b / x + 1 - (a == 0 ? 0 : (a - 1) / x + 1)); } }
[["-", 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, 16, 12, 23, 0, 41, 15, 16, 31, 22], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 64, 203], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 0, 102], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
8
103
11
using System; using System.Collections.Generic; using System.Linq; using static AtCoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { private const int INF = 1000000007; public static void Main() { long[] x = LongLine(); long a = (x[1] % x[2] == 0 ? x[1] / x[2] + 1 : x[1] / x[2]); long b = (x[0] % x[2] == 0 ? x[0] / x[2] : x[0] / x[2] + 1); Console.WriteLine(a - b); } } public class AtCoder { public static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); int d = a % b; while (b != 0) { d = a % b; a = b; b = d; } return a; } public static long LCM(int a, int b) { return (long)a * b / GCD(a, b); } public static string StrReverce(string s) { return new string(s.Reverse().ToArray()); } public static int IntRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } public static long[] LSRead() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static long Combination(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r + 1), r) .ToList() .Aggregate((now, next) => now * next) / Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next); } public static long Permutation(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r), r) .ToList() .Aggregate((now, next) => now * next); } public static long RepPow(long x, long p, long m = 1000000007) { 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 static long LongRead() { return long.Parse(Console.ReadLine()); } public static long[] LongLine() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static int[] IntLine() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static AtCoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { private const int INF = 1000000007; public static void Main() { long[] x = LongLine(); long a = (x[1] / x[2]) + 1; long b = (x[0] % x[2] == 0 ? x[0] / x[2] : x[0] / x[2] + 1); Console.WriteLine(a - b); } } public class AtCoder { public static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); int d = a % b; while (b != 0) { d = a % b; a = b; b = d; } return a; } public static long LCM(int a, int b) { return (long)a * b / GCD(a, b); } public static string StrReverce(string s) { return new string(s.Reverse().ToArray()); } public static int IntRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } public static long[] LSRead() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static long Combination(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r + 1), r) .ToList() .Aggregate((now, next) => now * next) / Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next); } public static long Permutation(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r), r) .ToList() .Aggregate((now, next) => now * next); } public static long RepPow(long x, long p, long m = 1000000007) { 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 static long LongRead() { return long.Parse(Console.ReadLine()); } public static long[] LongLine() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static int[] IntLine() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } }
[["-", 0, 23, 0, 41, 15, 16, 31, 16, 17, 109], ["-", 0, 41, 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, 203], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 212, 0, 23, 0, 41, 15, 16, 17, 60], ["-", 0, 212, 0, 23, 0, 41, 15, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 23, 0, 41, 0, 101], ["-", 0, 41, 64, 16, 31, 16, 31, 204, 205, 22], ["-", 64, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 64, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["-", 0, 200, 0, 212, 0, 23, 0, 41, 0, 102], ["-", 0, 23, 0, 41, 75, 16, 31, 204, 205, 22], ["-", 0, 41, 75, 16, 31, 204, 206, 207, 0, 70], ["-", 75, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 41, 75, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 212, 0, 23, 0, 41, 75, 16, 17, 85], ["-", 0, 23, 0, 41, 75, 16, 12, 204, 205, 22], ["-", 0, 41, 75, 16, 12, 204, 206, 207, 0, 70], ["-", 75, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 41, 75, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 25]]
8
754
24
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]B - Between a and b ... var lines = ReadLines<long>(1).ToList(); long a = lines[0][0]; long b = lines[0][1]; long x = lines[0][2]; long count = GetDivisorsCount(a, b, x); Console.WriteLine(count); } static long GetDivisorsCount(long a, long b, long x) { long divisorsA = (a - 1) / x; long divisorsB = b / x; return divisorsB - divisorsA; } static IEnumerable<List<T>> ReadLines<T>(int count = 0, char separator = ' ') { //[summary]コンソールの値を読み込んで、List<T>のコレクションを返却 //読み込む行数が未指定のときは、1行目の値を"count"とみなす if (count == 0) { string line = Console.ReadLine().TrimEnd(); count = int.Parse(line); } for (int i = 0; i < count; i++) { //コンソールを1行読み込み string line = Console.ReadLine().TrimEnd(); // char型のときは1文字ずつに分割 if (typeof(T) == typeof(char)) { var list = line.ToCharArray().ToList(); yield return (List<T>)(object)list; } else { //読み込んだ値を"separator"で区切る var list = line.Split(separator).ToList(); // int型のときは数値に変換 if (typeof(T) == typeof(int)) { var numbers = list.ConvertAll(int.Parse); yield return (List<T>)(object)numbers; } else if (typeof(T) == typeof(long)) { var numbers = list.ConvertAll(long.Parse); yield return (List<T>)(object)numbers; } else { yield return (List<T>)(object)list; } } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]B - Between a and b ... var lines = ReadLines<long>(1).ToList(); long a = lines[0][0]; long b = lines[0][1]; long x = lines[0][2]; long count = GetDivisorsCount(a, b, x); Console.WriteLine(count); } static long GetDivisorsCount(long a, long b, long x) { long divisorsA = a / x; long divisorsB = b / x; long diff = divisorsB - divisorsA; if (a % x == 0) { diff++; } return diff; } static IEnumerable<List<T>> ReadLines<T>(int count = 0, char separator = ' ') { //[summary]コンソールの値を読み込んで、List<T>のコレクションを返却 //読み込む行数が未指定のときは、1行目の値を"count"とみなす if (count == 0) { string line = Console.ReadLine().TrimEnd(); count = int.Parse(line); } for (int i = 0; i < count; i++) { //コンソールを1行読み込み string line = Console.ReadLine().TrimEnd(); // char型のときは1文字ずつに分割 if (typeof(T) == typeof(char)) { var list = line.ToCharArray().ToList(); yield return (List<T>)(object)list; } else { //読み込んだ値を"separator"で区切る var list = line.Split(separator).ToList(); // int型のときは数値に変換 if (typeof(T) == typeof(int)) { var numbers = list.ConvertAll(int.Parse); yield return (List<T>)(object)numbers; } else if (typeof(T) == typeof(long)) { var numbers = list.ConvertAll(long.Parse); yield return (List<T>)(object)numbers; } else { yield return (List<T>)(object)list; } } } } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 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], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 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, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 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, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22]]
8
389
24
using System; using System.Collections.Generic; using System.Text; namespace AtTest.OtherPractice { class AtTemplate { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { string[] input = Console.ReadLine().Split(' '); long a = long.Parse(input[0]); long b = long.Parse(input[1]); long x = long.Parse(input[2]); long min = (a - 1) / x; long max = b / x; long cnt = max - min; Console.WriteLine(cnt); } } }
using System; using System.Collections.Generic; using System.Text; namespace AtTest.OtherPractice { class AtTemplate { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { string[] input = Console.ReadLine().Split(' '); long a = long.Parse(input[0]); long b = long.Parse(input[1]); long x = long.Parse(input[2]); long min = (a - 1) / x; if (a == 0) { min = -1; } long max = b / x; long cnt = max - min; Console.WriteLine(cnt); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
147
13
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.ReadLine(); } public void Solve(ConsoleInput cin) { long a = cin.ReadLong; long b = cin.ReadLong; long x = cin.ReadLong; long m = a > 0 ? a - 1 : 0; long sum = (b / x) - (m / x); Console.WriteLine(sum); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.ReadLine(); } public void Solve(ConsoleInput cin) { long a = cin.ReadLong; long b = cin.ReadLong; long x = cin.ReadLong; long m = a == 0 ? -1 : (a - 1) / x; long sum = (b / x) - m; Console.WriteLine(sum); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long num) { var ret = new string[num]; for (long i = 0; i < num; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long num) { var ret = new int[num]; for (long i = 0; i < num; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long num) { var ret = new long[num]; for (long i = 0; i < num; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 200, 0, 212, 0, 41, 15, 16, 17, 47], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["-", 0, 200, 0, 212, 0, 41, 64, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 75, 203], ["+", 0, 212, 0, 41, 75, 16, 31, 23, 0, 24], ["+", 0, 41, 75, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 41, 75, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 41, 75, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 41, 75, 16, 31, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 17, 85], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
8
486
15
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class MainClass { public static void Main(string[] args) { new MainClass().solve(); } Scanner cin = new Scanner(); long a, b, c; void solve() { a = cin.nextLong(); b = cin.nextLong(); c = cin.nextLong(); long ans = b / c - (a - 1) / c; Console.WriteLine(ans); } class Scanner { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; public Scanner() { nextBuffer = new string[0]; BufferCnt = 0; } public string next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } class Mathf { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class MainClass { public static void Main(string[] args) { new MainClass().solve(); } Scanner cin = new Scanner(); long a, b, c; void solve() { a = cin.nextLong(); b = cin.nextLong(); c = cin.nextLong(); long ans = (a != 0) ? b / c - (a - 1) / c : b / c + 1; Console.WriteLine(ans); } class Scanner { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; public Scanner() { nextBuffer = new string[0]; BufferCnt = 0; } public string next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } class Mathf { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } } } }
[["+", 0, 200, 0, 212, 0, 41, 15, 23, 0, 24], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 17, 79], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 15, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 212, 0, 41, 64, 16, 12, 16, 17, 85], ["+", 0, 212, 0, 41, 64, 16, 12, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 212, 0, 41, 75, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 12, 203]]
8
581
12
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); long a = long.Parse(str[1]); long b = long.Parse(str[0]); long x = long.Parse(str[2]); sb.Append((a / x - (b - 1) / x) + "\n"); } }
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); long a = long.Parse(str[1]); long b = long.Parse(str[0]); long x = long.Parse(str[2]); sb.Append((b == 0 ? (a / x + 1) : (a / x - (b - 1) / x)) + "\n"); } }
[["+", 0, 16, 31, 23, 0, 41, 15, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 16, 31, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 23, 0, 41, 0, 101], ["+", 0, 16, 31, 23, 0, 41, 64, 23, 0, 24], ["+", 0, 41, 64, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 41, 64, 23, 0, 16, 31, 16, 17, 85], ["+", 0, 41, 64, 23, 0, 16, 31, 16, 12, 22], ["+", 31, 23, 0, 41, 64, 23, 0, 16, 17, 72], ["+", 31, 23, 0, 41, 64, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 41, 64, 23, 0, 25], ["+", 0, 28, 0, 16, 31, 23, 0, 41, 0, 102], ["+", 0, 16, 31, 23, 0, 41, 75, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 41, 75, 23, 0, 25]]
8
162
14
using LIB; using System; using System.Linq; using System.Text; using System.Collections.Generic; class Program { public static IO IO = new IO(); static void Main(string[] args) { int[] n = IO.INT(' '); int[] t = IO.INT(' '); int max = t.Max(); int[] maxt = t.Where(x => x == max).ToArray(); int[] notmaxt = t.Where(x => x != max).ToArray(); int o = Math.Max(0, maxt.Sum() - notmaxt.Sum() - 1); IO.WRITE(o); IO.FLUSH(); } } namespace LIB { public class IO { private const int WMAX = 1000; private StringBuilder S = new StringBuilder(); private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); } private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); } private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; } private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; } private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } } public string STRING() { return R(s => s); } public string[] STRING(char c) { return R(s => s, c); } public string[] STRING(int l) { return R(s => s, l); } public string[][] STRING(int l, char c) { return R(s => s, l, c); } public int INT() { return R(int.Parse); } public int[] INT(char c) { return R(int.Parse, c); } public int[] INT(int l) { return R(int.Parse, l); } public int[][] INT(int l, char c) { return R(int.Parse, l, c); } public long LONG() { return R(long.Parse); } public long[] LONG(char c) { return R(long.Parse, c); } public long[] LONG(int l) { return R(long.Parse, l); } public long[][] LONG(int l, char c) { return R(long.Parse, l, c); } public double DOUBLE() { return R(double.Parse); } public double[] DOUBLE(char c) { return R(double.Parse, c); } public double[] DOUBLE(int l) { return R(double.Parse, l); } public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); } public void WRITE(string s, bool lf = true) { W(v => v, s, lf); } public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); } public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); } public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); } public void FLUSH() { Console.Write(S); S.Length = 0; } } }
using LIB; using System; using System.Linq; using System.Text; using System.Collections.Generic; class Program { public static IO IO = new IO(); static void Main(string[] args) { int[] n = IO.INT(' '); int[] t = IO.INT(' '); int max = t.Max(); int[] maxt = t.Where(x => x == max).ToArray(); int[] notmaxt = t.Where(x => x != max).ToArray(); int o = Math.Max(0, maxt.Max() - notmaxt.Sum() - maxt.Max() * (maxt.Count() - 1) - 1); IO.WRITE(o); IO.FLUSH(); } } namespace LIB { public class IO { private const int WMAX = 1000; private StringBuilder S = new StringBuilder(); private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); } private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); } private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; } private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; } private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } } public string STRING() { return R(s => s); } public string[] STRING(char c) { return R(s => s, c); } public string[] STRING(int l) { return R(s => s, l); } public string[][] STRING(int l, char c) { return R(s => s, l, c); } public int INT() { return R(int.Parse); } public int[] INT(char c) { return R(int.Parse, c); } public int[] INT(int l) { return R(int.Parse, l); } public int[][] INT(int l, char c) { return R(int.Parse, l, c); } public long LONG() { return R(long.Parse); } public long[] LONG(char c) { return R(long.Parse, c); } public long[] LONG(int l) { return R(long.Parse, l); } public long[][] LONG(int l, char c) { return R(long.Parse, l, c); } public double DOUBLE() { return R(double.Parse); } public double[] DOUBLE(char c) { return R(double.Parse, c); } public double[] DOUBLE(int l) { return R(double.Parse, l); } public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); } public void WRITE(string s, bool lf = true) { W(v => v, s, lf); } public void WRITE(int s, bool lf = true) { W(v => v.ToString(), s, lf); } public void WRITE(long s, bool lf = true) { W(v => v.ToString(), s, lf); } public void WRITE(double s, bool lf = true) { W(v => v.ToString(), s, lf); } public void FLUSH() { Console.Write(S); S.Length = 0; } } }
[["-", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 31, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 31, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 31, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 31, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 203]]
8
931
18
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class C { public static void Main() { int N = GetInt(); long[] T = Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); long[] A = Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); bool[] isKnown = new bool[N]; long max = long.MinValue; for (int i = 0; i < N; i++) { if (T[i] > max) { max = T[i]; isKnown[i] = true; } } max = long.MinValue; for (int i = N - 1; i >= 0; i--) { if (A[i] > max) { if (isKnown[i] && (A[i] != T[i])) { Console.WriteLine(0); return; } max = A[i]; isKnown[i] = true; } } long ans = 1; for (int i = 0; i < N; i++) { if (isKnown[i]) continue; ans = (ans * Math.Min(T[i], A[i])) % 1000000007; } Console.WriteLine(ans); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class C { public static void Main() { int N = GetInt(); long[] T = Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); long[] A = Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); bool[] isKnown = new bool[N]; long max = long.MinValue; for (int i = 0; i < N; i++) { if (T[i] > max) { max = T[i]; isKnown[i] = true; } } max = long.MinValue; for (int i = N - 1; i >= 0; i--) { if (A[i] > max) { if (isKnown[i]) { if (A[i] != T[i]) { Console.WriteLine(0); return; } } else { if (A[i] > T[i]) { Console.WriteLine(0); return; } } max = A[i]; isKnown[i] = true; } } long ans = 1; for (int i = 0; i < N; i++) { if (isKnown[i]) continue; ans = (ans * Math.Min(T[i], A[i])) % 1000000007; } Console.WriteLine(ans); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 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, 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, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 75, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
8
447
30
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long[] numsSub = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long[] numMemos = new long[n]; long[] numFixes = new long[n]; //固定値なら1 long maxMemo = 0; long answer = 1; long mod = 1000000007; for (long i = 0; i < n; i++) { if (nums[i] > maxMemo) { maxMemo = nums[i]; numFixes[i] = 1; } numMemos[i] = nums[i]; } maxMemo = 0; for (long i = 0; i < n; i++) { long memo = n - 1 - i; if (nums[memo] > maxMemo) { maxMemo = numsSub[memo]; if (numFixes[memo] == 1 && numMemos[memo] != maxMemo || numMemos[memo] < maxMemo) answer = 0; //不正なデータがある } else { if (numFixes[memo] == 1 && numMemos[memo] > maxMemo) answer = 0; //不正なデータがある if (numFixes[memo] != 1) { answer *= Math.Min(maxMemo, numMemos[memo]); answer %= mod; } } Console.WriteLine(answer); } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long[] numsSub = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long[] numMemos = new long[n]; long[] numFixes = new long[n]; //固定値なら1 long maxMemo = 0; long answer = 1; long mod = 1000000007; for (long i = 0; i < n; i++) { if (nums[i] > maxMemo) { maxMemo = nums[i]; numFixes[i] = 1; } numMemos[i] = nums[i]; } maxMemo = 0; for (long i = 0; i < n; i++) { long memo = n - 1 - i; if (numsSub[memo] > maxMemo) { maxMemo = numsSub[memo]; if (numFixes[memo] == 1 && numMemos[memo] != maxMemo || numMemos[memo] < maxMemo) answer = 0; //不正なデータがある } else { if (numFixes[memo] == 1 && numMemos[memo] > maxMemo) answer = 0; //不正なデータがある if (numFixes[memo] != 1) { answer *= Math.Min(maxMemo, numMemos[memo]); // Console.WriteLine(maxMemo+" "+ numMemos[memo]); answer %= mod; } } // Console.WriteLine(answer); } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 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
328
9
using System; using System.Collections.Generic; class Solve { int N; long[] t; long[] a; public Solve() {} public static int Main() { new Solve().Calc(); return 0; } void Calc() { getinput(); bool[] c = new bool[N]; long[] d = new long[N]; long count = 1; for (int i = 0; i < N; i++) { c[i] = false; } d[0] = t[0]; c[0] = true; for (int i = 1; i < N; i++) { if (t[i] > t[i - 1]) { d[i] = t[i]; c[i] = true; } } if (c[N - 1]) { if (d[N - 1] != a[N - 1]) { Console.WriteLine(0); return; } } else { c[N - 1] = true; d[N - 1] = a[N - 1]; } for (int i = N - 2; i >= 0; i--) { if (a[i] > a[i + 1]) { if (c[i]) { if (d[i] != a[i]) { Console.WriteLine(0); return; } } else { c[i] = true; d[i] = a[i]; } } } for (int i = 0; i < N; i++) { if (!c[i]) { long min; if (a[i] > t[i]) { min = t[i]; } else { min = a[i]; } count = (count * (min % Define.mod)) % Define.mod; } } Console.WriteLine(0); } void getinput() { string[] str; N = int.Parse(Console.ReadLine()); a = new long[N]; t = new long[N]; str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { t[i] = Int64.Parse(str[i]); } str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { a[i] = Int64.Parse(str[i]); } } } public static class Define { public const long mod = 1000000007; }
using System; using System.Collections.Generic; class Solve { int N; long[] t; long[] a; public Solve() {} public static int Main() { new Solve().Calc(); return 0; } void Calc() { getinput(); bool[] c = new bool[N]; long[] d = new long[N]; long count = 1; for (int i = 0; i < N; i++) { c[i] = false; } d[0] = t[0]; c[0] = true; for (int i = 1; i < N; i++) { if (t[i] > t[i - 1]) { d[i] = t[i]; c[i] = true; } } if (c[N - 1]) { if (d[N - 1] != a[N - 1]) { Console.WriteLine(0); return; } } else { c[N - 1] = true; d[N - 1] = a[N - 1]; } for (int i = N - 2; i >= 0; i--) { if (a[i] > a[i + 1]) { if (c[i]) { if (d[i] != a[i]) { Console.WriteLine(0); return; } } else { c[i] = true; d[i] = a[i]; } } else if (d[i] > a[i]) { Console.WriteLine(0); return; } } for (int i = 0; i < N; i++) { if (!c[i]) { long min; if (a[i] > t[i]) { min = t[i]; } else { min = a[i]; } count = (count * (min % Define.mod)) % Define.mod; } } Console.WriteLine(count); } void getinput() { string[] str; N = int.Parse(Console.ReadLine()); a = new long[N]; t = new long[N]; str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { t[i] = Int64.Parse(str[i]); } str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { a[i] = Int64.Parse(str[i]); } } } public static class Define { public const long mod = 1000000007; }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 0, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 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, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 75, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
559
26
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int n = sc.nextInt(); int[] t = sc.nextInt(n); int[] a = sc.nextInt(n); if (t[n - 1] != a[0]) // mujun { Console.WriteLine(0); return; } bool[] kakutei = new bool[n]; bool mujun = true; kakutei[0] = true; kakutei[n - 1] = true; for (int i = 1; i < n - 1; i++) { if (t[i] != t[i - 1]) kakutei[i] = true; if (a[i] != a[i + 1]) kakutei[i] = true; if (t[i] == a[i] && t[i] == t[0]) mujun = false; } if (mujun) { Console.WriteLine(0); return; } long ans = 1; for (int i = 0; i < n; i++) { if (kakutei[i] == false) { ans = (ans * Math.Abs(t[i] - a[i])) % Mod; } } Console.WriteLine(ans); } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int n = sc.nextInt(); int[] t = sc.nextInt(n); int[] a = sc.nextInt(n); if (t[n - 1] != a[0]) // mujun { Console.WriteLine(0); return; } if (n == 1) { Console.WriteLine(1); return; } bool[] kakutei = new bool[n]; bool mujun = true; kakutei[0] = true; kakutei[n - 1] = true; for (int i = 1; i < n - 1; i++) { if (t[i] != t[i - 1]) kakutei[i] = true; if (a[i] != a[i + 1]) kakutei[i] = true; if (t[i] == a[i] && t[i] == a[0]) mujun = false; } if (mujun) { Console.WriteLine(0); return; } long ans = 1; for (int i = 0; i < n; i++) { if (kakutei[i] == false) { ans = (ans * Math.Min(t[i], a[i])) % Mod; } } Console.WriteLine(ans); } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
[["+", 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, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["-", 31, 23, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 31, 23, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 21]]
8
1,418
23
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() { bool[] fix = new bool[N]; int[] min = new int[N]; int[] minf = new int[N]; for (int i = 0; i < N; i++) { if (i == 0) { fix[i] = true; minf[i] = T[i]; continue; } if (T[i] != T[i - 1]) { fix[i] = true; minf[i] = T[i]; continue; } min[i] = T[i]; } for (int i = N - 1; i >= 0; i--) { if (i == N - 1) { if (fix[i]) { if (A[i] != T[i]) { Console.WriteLine(0); return; } } else { if (min[i] >= A[i]) { minf[i] = A[i]; fix[i] = true; continue; } else { Console.WriteLine(0); return; } } } if (A[i] > A[i + 1]) { if (fix[i]) { if (A[i] != T[i]) { Console.WriteLine(0); return; } } else { if (min[i] >= A[i]) { minf[i] = A[i]; fix[i] = true; continue; } else { Console.WriteLine(0); return; } } } min[i] = Math.Min(min[i], A[i]); } long ans = 1; long mod = (long)1e9 + 7; for (int i = 0; i < N; i++) { if (fix[i]) continue; ans *= min[i]; ans %= mod; } Console.WriteLine(ans); } int N; int[] A, T; public Sol() { N = ri(); T = ria(); A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { bool[] fix = new bool[N]; int[] min = new int[N]; int[] minf = new int[N]; for (int i = 0; i < N; i++) { if (i == 0) { fix[i] = true; minf[i] = T[i]; continue; } if (i > 0 && T[i] != T[i - 1]) { fix[i] = true; minf[i] = T[i]; continue; } min[i] = T[i]; } for (int i = N - 1; i >= 0; i--) { if (i == N - 1) { if (fix[i]) { if (A[i] != T[i]) { Console.WriteLine(0); return; } } else { if (min[i] >= A[i]) { minf[i] = A[i]; fix[i] = true; continue; } else { Console.WriteLine(0); return; } } } if (i + 1 < N && A[i] > A[i + 1]) { if (fix[i]) { if (A[i] != T[i]) { Console.WriteLine(0); return; } } else { if (min[i] >= A[i]) { minf[i] = A[i]; fix[i] = true; continue; } else { Console.WriteLine(0); return; } } } min[i] = Math.Min(min[i], A[i]); } long ans = 1; long mod = (long)1e9 + 7; for (int i = 0; i < N; i++) { if (fix[i]) continue; ans *= min[i]; ans %= mod; } Console.WriteLine(ans); } int N; int[] A, T; public Sol() { N = ri(); T = ria(); A = ria(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22]]
8
719
10
using System; namespace ABC026A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a == b && a == c) Console.WriteLine(1); else if (a != b && a == c || b != c && b == a) Console.WriteLine(2); else Console.WriteLine(3); Console.ReadKey(); } } }
using System; namespace ABC026A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a == b && b == c) Console.WriteLine(1); else if (a != b && a != c && b != c) Console.WriteLine(3); else Console.WriteLine(2); Console.ReadKey(); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 106], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 75, 57, 15, 16, 12, 16, 12, 16, 17, 60], ["-", 75, 57, 15, 16, 12, 16, 12, 16, 12, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
138
14
using System; namespace ABC026A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a == b && a == c) Console.WriteLine("1"); else if (a == b && a != c || a == c && a != b) Console.WriteLine("2"); else Console.WriteLine("3"); Console.ReadKey(); } } }
using System; namespace ABC026A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a == b && a == c) Console.WriteLine("1"); else if (a == b || b == c || c == a) Console.WriteLine("2"); else Console.WriteLine("3"); Console.ReadKey(); } } }
[["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 98], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 17, 79], ["-", 75, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 75, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 106], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["-", 75, 57, 15, 16, 12, 16, 12, 16, 17, 79], ["-", 75, 57, 15, 16, 12, 16, 12, 16, 12, 22]]
8
144
8
using System; namespace ABC026A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a == b && a == c) Console.WriteLine("1"); else if (a == b && a != c || a == c && a != b) Console.WriteLine("2"); else Console.WriteLine("3"); Console.ReadKey(); } } }
using System; namespace ABC026A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a == b && a == c) Console.WriteLine("1"); else if (a == b && a != c || a == c && a != b || b == c && b != a) Console.WriteLine("2"); else Console.WriteLine("3"); Console.ReadKey(); } } }
[["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 106], ["+", 75, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 75, 57, 15, 16, 12, 16, 31, 16, 17, 60], ["+", 75, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 98], ["+", 75, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 75, 57, 15, 16, 12, 16, 12, 16, 17, 79], ["+", 75, 57, 15, 16, 12, 16, 12, 16, 12, 22]]
8
144
8
using System; namespace Vanila { public class Program { static void Main(string[] args) { string[] p = Console.ReadLine().Split(' '); string a = p[0]; string b = p[1]; string c = p[2]; if (p[0] == p[1] && p[1] == p[2]) { Console.WriteLine(1); } else if ((a != b && b == c) || (a == b && b != c) || (a != c && c == b)) { Console.WriteLine(2); } else { Console.WriteLine(3); } } public static long Max(long a, long b) { if (a <= b) return b; else return a; } public static long Min(long a, long b) { if (a == Max(a, b)) return b; else return a; } public static long GCD(long a, long b) { while (Max(a, b) % Min(a, b) != 0) { if (a < b) b %= a; else a %= b; } return Min(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } } }
using System; namespace Vanila { public class Program { static void Main(string[] args) { string[] p = Console.ReadLine().Split(' '); string a = p[0]; string b = p[1]; string c = p[2]; if (p[0] == p[1] && p[1] == p[2]) { Console.WriteLine(1); } else if ((a != b && b == c) || (b != c && c == a) || (c != a && a == b)) { Console.WriteLine(2); } else { Console.WriteLine(3); } } public static long Max(long a, long b) { if (a <= b) return b; else return a; } public static long Min(long a, long b) { if (a == Max(a, b)) return b; else return a; } public static long GCD(long a, long b) { while (Max(a, b) % Min(a, b) != 0) { if (a < b) b %= a; else a %= b; } return Min(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } } }
[["-", 31, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 31, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["-", 15, 16, 31, 16, 12, 23, 0, 16, 17, 98], ["-", 31, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 98], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 79], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 79], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22]]
8
286
14
using System; using System.Linq; class Program { static void Main(string[] args) { Console.WriteLine(Console.ReadLine().Distinct().Count()); } }
using System; using System.Linq; class Program { static void Main(string[] args) { Console.WriteLine(Console.ReadLine().Split(' ').Distinct().Count()); } }
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 205, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131]]
8
42
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] penk = new int[3]; var imp = Console.ReadLine().Split(' '); penk[0] = int.Parse(imp[0]); penk[1] = int.Parse(imp[1]); penk[2] = int.Parse(imp[2]); Array.Sort(penk); if ((penk[0] == penk[1]) && (penk[0] == penk[2])) { Console.Write('1'); } else if ((penk[0] == penk[1]) && (penk[1] < penk[2])) { Console.Write('2'); } else if (penk[0] < penk[1]) { Console.Write('3'); } else { } // System.Threading.Thread.Sleep(1000); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] penk = new int[3]; var imp = Console.ReadLine().Split(' '); penk[0] = int.Parse(imp[0]); penk[1] = int.Parse(imp[1]); penk[2] = int.Parse(imp[2]); Array.Sort(penk); if ((penk[0] == penk[1]) && (penk[0] == penk[2])) { Console.Write('1'); } else if ((penk[0] == penk[1]) && (penk[1] < penk[2]) || ((penk[1] == penk[2]) && (penk[0] < penk[1]))) { Console.Write('2'); } else if (penk[0] < penk[1]) { Console.Write('3'); } else { } // System.Threading.Thread.Sleep(1000); } } }
[["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 106], ["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 60], ["+", 0, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 75, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 17, 18], ["+", 0, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25]]
8
228
26
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var d = new Dictionary<char, int>(); string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); for (int i = 0; i < n; i++) { var s = Console.ReadLine().Trim()[0]; if (d.ContainsKey(s)) d[s]++; else d[s] = 1; } var a = new int[d.Count()]; var p = 0; foreach (var x in d.OrderByDescending(y => y.Value)) a[p++] = x.Value; Console.WriteLine(getAns(a, k)); } public static int getAns(int[] a, int k) { var aL = a.Length; var ret = 0; var p = 0; var count = 0; while (true) { if (a[p] >= 1) { a[p]--; count++; } p++; if (count < k && p == aL) break; if (count == k && p <= aL) { ret++; p = 0; count = 0; } } return ret; } }
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var d = new Dictionary<char, int>(); string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); for (int i = 0; i < n; i++) { var rs = Console.ReadLine().Trim(); var s = rs[0]; if (d.ContainsKey(s)) d[s]++; else d[s] = 1; } var a = new int[d.Count()]; var p = 0; foreach (var x in d.OrderByDescending(y => y.Value)) a[p++] = x.Value; Console.WriteLine(getAns(a, k)); } public static int getAns(int[] a, int k) { var aL = a.Length; if (k > aL) return 0; var ret = 0; var p = 0; var count = 0; while (true) { if (a[p] >= 1) { a[p]--; count++; } p++; if (count < k && p == aL) break; if (count == k && p <= aL) { ret++; p = 0; count = 0; Array.Sort(a); Array.Reverse(a); } } return ret; } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 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, 204, 205, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 8, 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], ["+", 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]]
8
304
30
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Simple { int N, K; string[] P; void Solve() { // input N = io.Int; K = io.Int; P = new string[N]; for (int i = 0; i < N; ++i) P[i] = io.String; // cal var ans = 0; var map = new int['z' - 'a' + 1]; for (int i = 0; i < P.Length; ++i) map[P[i][0] - 'A']++; for (;;) { var cnt = 0; for (int i = 0; i < map.Length; ++i) { if (map[i] > 0) { cnt++; map[i]--; } if (cnt == K) { ans++; break; } } if (cnt == 0 || cnt != K) break; } // ret Console.WriteLine(ans); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) { new Simple().Stream(); } void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Simple { int N, K; string[] P; void Solve() { // input N = io.Int; K = io.Int; P = new string[N]; for (int i = 0; i < N; ++i) P[i] = io.String; // cal var ans = 0; var map = new int['z' - 'a' + 1]; for (int i = 0; i < P.Length; ++i) map[P[i][0] - 'A']++; for (;;) { var cnt = 0; Array.Sort(map); Array.Reverse(map); for (int i = 0; i < map.Length; ++i) { if (map[i] > 0) { cnt++; map[i]--; } if (cnt == K) { ans++; break; } } if (cnt != K) break; } // ret Console.WriteLine(ans); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) { new Simple().Stream(); } void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
[["+", 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, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106]]
8
496
18
using System; using System.Collections.Generic; using System.IO; #region Program namespace Program { #region Solver public class Solver { static IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static readonly string AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char[] AZAry; int[] AZCnt; int N; int K; string[] P; #region Solver public Solver() { N = sc.Integer(); K = sc.Integer(); AZAry = new char[AZ.Length]; AZAry = AZ.ToCharArray(); P = new string[N]; AZCnt = new int[AZ.Length]; for (int i = 0; i < N; i++) { P[i] = sc.Scan(); AZCnt[AZ.IndexOf(P[i][0])]++; } } #endregion #region Solve public void Solve() { int cnt = 0; int total = 0; while (true) { if (N <= K * total) break; // 都度並び替える Array.Sort(AZCnt, AZAry); for (int i = AZ.Length - 1; 0 <= i; i--) { if (AZCnt[i] == 0) break; else if (cnt >= K) break; // アルファベットごとのカウント AZCnt[i]--; // 減らしたアルファベットの数 cnt++; } if (cnt >= K) total++; else break; } Console.WriteLine(total); } #endregion } #endregion } #endregion #region Execute class Execute { public static void Main(string[] args) { new Program.Solver().Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Program.IO namespace Program.IO { using System.Text; using System.Globalization; using System.Linq; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public StreamScanner(Stream stream) { str = stream; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public long Long() { if (isEof) { return long.MinValue; } 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 long[] Long(int n) { return enumerate(n, Long); } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public int[] Integer(int n) { return enumerate(n, Integer); } public char[] Char(int n) { return enumerate(n, Char); } public char Char() { byte b = 0; do { b = read(); } while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) { sb.Append(b); } return sb.ToString(); } private byte read() { if (isEof) { return 0; } if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } } } #endregion
using System; using System.Collections.Generic; using System.IO; #region Program namespace Program { #region Solver public class Solver { static IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static readonly string AZ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char[] AZAry; int[] AZCnt; int N; int K; string[] P; #region Solver public Solver() { N = sc.Integer(); K = sc.Integer(); AZAry = new char[AZ.Length]; AZAry = AZ.ToCharArray(); P = new string[N]; AZCnt = new int[AZ.Length]; for (int i = 0; i < N; i++) { P[i] = sc.Scan(); AZCnt[AZ.IndexOf(P[i][0])]++; } } #endregion #region Solve public void Solve() { int total = 0; while (true) { if (N <= K * total) break; // 都度並び替える Array.Sort(AZCnt, AZAry); int cnt = 0; for (int i = AZ.Length - 1; 0 <= i; i--) { if (AZCnt[i] == 0) break; else if (cnt >= K) break; // アルファベットごとのカウント AZCnt[i]--; // 減らしたアルファベットの数 cnt++; } if (cnt >= K) total++; else break; } Console.WriteLine(total); } #endregion } #endregion } #endregion #region Execute class Execute { public static void Main(string[] args) { new Program.Solver().Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Program.IO namespace Program.IO { using System.Text; using System.Globalization; using System.Linq; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public StreamScanner(Stream stream) { str = stream; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public long Long() { if (isEof) { return long.MinValue; } 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 long[] Long(int n) { return enumerate(n, Long); } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public int[] Integer(int n) { return enumerate(n, Integer); } public char[] Char(int n) { return enumerate(n, Char); } public char Char() { byte b = 0; do { b = read(); } while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) { sb.Append(b); } return sb.ToString(); } private byte read() { if (isEof) { return 0; } if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } } } #endregion
[["-", 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, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 52, 8, 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
1,032
10
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int[] A = new int[26]; for (int i = 0; i < N; i++) { A[P[i][0] - 'A']++; } Array.Sort(A); Array.Reverse(A); int ans = 0; while (true) { int k = 0; // Console.WriteLine(String.Join(" ",A)); for (int i = 0; i < 26; i++) { if (A[i] == 0) continue; k++; A[i]--; if (k == K) break; } if (k == K) { ans++; continue; } break; } Console.WriteLine(ans); } int N, K; String[] P; public Sol() { var d = ria(); N = d[0]; K = d[1]; P = new String[N]; for (int i = 0; i < N; i++) P[i] = rs(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int[] A = new int[26]; for (int i = 0; i < N; i++) { A[P[i][0] - 'A']++; } int ans = 0; while (true) { Array.Sort(A); Array.Reverse(A); int k = 0; // Console.WriteLine(String.Join(" ",A)); for (int i = 0; i < 26; i++) { if (A[i] == 0) continue; k++; A[i]--; if (k == K) break; } if (k == K) { ans++; continue; } break; } Console.WriteLine(ans); } int N, K; String[] P; public Sol() { var d = ria(); N = d[0]; K = d[1]; P = new String[N]; for (int i = 0; i < N; i++) P[i] = rs(); } 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, 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, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 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, 52, 0, 89], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["-", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45]]
8
490
20
using System; using System.Linq; namespace kupc2016_c { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (x[0] == 1) Console.WriteLine(x[1]); else Console.WriteLine(x[0] % 2 == 0 ? 127 * x[0] - x[1] : 128 * (x[0] - 1) - x[1]); } } } }
using System; using System.Linq; namespace kupc2016_c { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (x[0] == 1) Console.WriteLine(x[1]); else Console.WriteLine(x[0] % 2 == 1 ? 127 * (x[0] - 1) + x[1] : 127 * (x[0] - 1) + (127 ^ x[1])); } } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 41, 64, 16, 31, 16, 12, 23, 0, 24], ["+", 64, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 41, 64, 16, 31, 16, 12, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 17, 72], ["-", 0, 28, 0, 41, 75, 16, 31, 16, 31, 203], ["+", 0, 28, 0, 41, 75, 16, 31, 16, 31, 203], ["-", 3, 4, 0, 28, 0, 41, 75, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 17, 72], ["+", 0, 28, 0, 41, 75, 16, 12, 23, 0, 24], ["+", 0, 41, 75, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 41, 75, 16, 12, 23, 0, 16, 17, 140], ["+", 0, 28, 0, 41, 75, 16, 12, 23, 0, 25]]
8
145
14
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--) { var d = ria(); var N = d[0]; var D = d[1]; if (N == 1) { Console.WriteLine(D); continue; } if (N % 2 == 0) { Console.WriteLine(128 * N - D - N); continue; } Console.WriteLine(128 * (N - 1) - D); } } int T; 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--) { var d = ria(); var N = d[0]; var D = d[1]; if (N == 1) { Console.WriteLine(D); continue; } if (N % 2 == 0) { Console.WriteLine(127 * (N - 1) + (127 - D)); } else { Console.WriteLine(127 * (N - 1) + D); } } } int T; 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, 28, 0, 16, 31, 16, 31, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 203], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 31, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
389
21
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); string s = sc.Next(); long answer = 0; long count = 0; foreach (var c in s) { if (c == 'S') { count++; } else { if (count > 0) { count--; answer++; } } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); string s = sc.Next(); long remove = 0; long count = 0; foreach (var c in s) { if (c == 'S') { count++; } else { if (count > 0) { count--; remove++; } } } long answer = s.Length - remove * 2; Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 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, 200, 0, 212, 0, 16, 12, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
8
399
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_A(); } public static void Solve_A() { string s; MyIO.ReadMulti(out s); ll ans = 0; for (int i = s.Length - 1; 0 <= i; i--) { if (s[i] == 'S') { ans++; } else { break; } } MyIO.WriteMulti(ans * 2); } public static void Solve_B() { ll n; MyIO.ReadMulti(out n); VT<ll, ll>[] lrl; MyIO.ReadLines(n, out lrl); VT<ll, ll, ll>[] lri = new VT<ll, ll, ll>[n]; for (int i = 0; i < n; i++) { lri[i] = new VT<ll, ll, ll>(lrl[i].Item1, lrl[i].Item2, i); } Array.Sort(lri, (x, y) => (x.Item1.CompareTo(y.Item1))); VT<ll, ll>[] ll = new VT<ll, ll>[n + 2]; VT<ll, ll>[] rl = new VT<ll, ll>[n + 2]; ll[0] = new VT<ll, ll>(1, 1000000000); rl[n + 1] = new VT<ll, ll>(1, 1000000000); long ans = 0; /* for (int i = 1; i <= n; i++) { ll[i]= new VT<ll, ll>(Math.Max(lrl[i-1].Item1,ll[i-1].Item1),Math.Min(lrl[i-1].Item2,ll[i-1].Item2)); } for (int i = (int)n; 0<i; i--) { rl[i]= new VT<ll, ll>(Math.Max(lrl[i-1].Item1,rl[i+1].Item1),Math.Min(lrl[i-1].Item2,rl[i+1].Item2)); } for (int i = 1; i < n-1; i++) { ll v = ((ll[i].Item2>=ll[i].Item1)?(ll[i].Item2-ll[i].Item1+1):0) + ((rl[i+1].Item2>=rl[i+1].Item1)?(rl[i+1].Item2-rl[i+1].Item1+1):0); Chmax(ref ans, v); } */ ll l2 = lri[n - 1].Item1; ll r2 = lri[n - 1].Item2; ll i2 = lri[n - 1].Item3; ll i2a = lri[0].Item3; Array.Sort(lri, (x, y) => (x.Item2.CompareTo(y.Item2))); ll l1 = lri[0].Item1; ll r1 = lri[0].Item2; ll i1 = lri[0].Item3; if (i1 == i2) { l1 = lri[1].Item1; r1 = lri[1].Item2; i1 = lri[1].Item3; } ll i1a = lri[n - 1].Item3; if (i2a == i1a) { for (int i = 0; i < n; i++) { if (lri[i].Item3 == i1a) { l2 = lri[i].Item1; r2 = lri[i].Item2; } else { l1 = l1 < lri[i].Item1 ? lri[i].Item1 : l1; r1 = r1 < lri[i].Item2 ? r1 : lri[i].Item2; } } } else { for (int i = 0; i < n; i++) { ll tl1 = l1 < lrl[i].Item1 ? lrl[i].Item1 : l1; ll tl2 = l2 < lrl[i].Item1 ? lrl[i].Item1 : l2; ll tr1 = r1 < lrl[i].Item2 ? r1 : lrl[i].Item2; ll tr2 = r2 < lrl[i].Item2 ? r2 : lrl[i].Item2; ll d1 = Math.Max(r1 - l1, -1) - Math.Max(tr1 - tl1, -1); ll d2 = Math.Max(r2 - l2, -1) - Math.Max(tr2 - tl2, -1); if (d2 < d1) { l2 = tl2; r2 = tr2; } else { l1 = tl1; r1 = tr1; } } } ans = Math.Max(r1 - l1, -1) + Math.Max(r2 - l2, -1) + 2; MyIO.WriteMulti(ans); } public static void Solve_C() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) v = new[] { v[1], v[0] % v[1] }; return v[0]; } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_A(); } public static void Solve_A() { string s; MyIO.ReadMulti(out s); ll cnt = 0; ll ans = 0; for (int i = s.Length - 1; 0 <= i; i--) { if (s[i] == 'S') { cnt++; } else { cnt--; } Chmax(ref ans, cnt); } MyIO.WriteMulti(ans * 2); } public static void Solve_B() { ll n; MyIO.ReadMulti(out n); VT<ll, ll>[] lrl; MyIO.ReadLines(n, out lrl); VT<ll, ll, ll>[] lri = new VT<ll, ll, ll>[n]; for (int i = 0; i < n; i++) { lri[i] = new VT<ll, ll, ll>(lrl[i].Item1, lrl[i].Item2, i); } Array.Sort(lri, (x, y) => (x.Item1.CompareTo(y.Item1))); VT<ll, ll>[] ll = new VT<ll, ll>[n + 2]; VT<ll, ll>[] rl = new VT<ll, ll>[n + 2]; ll[0] = new VT<ll, ll>(1, 1000000000); rl[n + 1] = new VT<ll, ll>(1, 1000000000); long ans = 0; /* for (int i = 1; i <= n; i++) { ll[i]= new VT<ll, ll>(Math.Max(lrl[i-1].Item1,ll[i-1].Item1),Math.Min(lrl[i-1].Item2,ll[i-1].Item2)); } for (int i = (int)n; 0<i; i--) { rl[i]= new VT<ll, ll>(Math.Max(lrl[i-1].Item1,rl[i+1].Item1),Math.Min(lrl[i-1].Item2,rl[i+1].Item2)); } for (int i = 1; i < n-1; i++) { ll v = ((ll[i].Item2>=ll[i].Item1)?(ll[i].Item2-ll[i].Item1+1):0) + ((rl[i+1].Item2>=rl[i+1].Item1)?(rl[i+1].Item2-rl[i+1].Item1+1):0); Chmax(ref ans, v); } */ ll l2 = lri[n - 1].Item1; ll r2 = lri[n - 1].Item2; ll i2 = lri[n - 1].Item3; ll i2a = lri[0].Item3; Array.Sort(lri, (x, y) => (x.Item2.CompareTo(y.Item2))); ll l1 = lri[0].Item1; ll r1 = lri[0].Item2; ll i1 = lri[0].Item3; if (i1 == i2) { l1 = lri[1].Item1; r1 = lri[1].Item2; i1 = lri[1].Item3; } ll i1a = lri[n - 1].Item3; if (i2a == i1a) { for (int i = 0; i < n; i++) { if (lri[i].Item3 == i1a) { l2 = lri[i].Item1; r2 = lri[i].Item2; } else { l1 = l1 < lri[i].Item1 ? lri[i].Item1 : l1; r1 = r1 < lri[i].Item2 ? r1 : lri[i].Item2; } } } else { for (int i = 0; i < n; i++) { ll tl1 = l1 < lrl[i].Item1 ? lrl[i].Item1 : l1; ll tl2 = l2 < lrl[i].Item1 ? lrl[i].Item1 : l2; ll tr1 = r1 < lrl[i].Item2 ? r1 : lrl[i].Item2; ll tr2 = r2 < lrl[i].Item2 ? r2 : lrl[i].Item2; ll d1 = Math.Max(r1 - l1, -1) - Math.Max(tr1 - tl1, -1); ll d2 = Math.Max(r2 - l2, -1) - Math.Max(tr2 - tl2, -1); if (d2 < d1) { l2 = tl2; r2 = tr2; } else { l1 = tl1; r1 = tr1; } } } ans = Math.Max(r1 - l1, -1) + Math.Max(r2 - l2, -1) + 2; MyIO.WriteMulti(ans); } public static void Solve_C() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) v = new[] { v[1], v[0] % v[1] }; return v[0]; } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
[["+", 8, 196, 0, 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, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 68], ["+", 0, 7, 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, 275], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
3,129
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC005STing { class Program { static void Main(string[] args) { string X = Console.ReadLine(); Stack<char> stack = new Stack<char>(); foreach (var c in X) { if (c == 'T') { if (stack.Count > 0 && stack.Peek() == 'S') { stack.Pop(); } else { stack.Push(c); } } } Console.WriteLine(stack.Count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC005STing { class Program { static void Main(string[] args) { string X = Console.ReadLine(); Stack<char> stack = new Stack<char>(); foreach (var c in X) { if (c == 'T') { if (stack.Count > 0 && stack.Peek() == 'S') { stack.Pop(); } else { stack.Push(c); } } else { stack.Push(c); } } Console.WriteLine(stack.Count); } } }
[["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["+", 0, 210, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46]]
8
133
10
using System; using System.Collections.Generic; using System.Collections; using System.Linq; namespace tes { class contest { static void Main(string[] args) { string s = Console.ReadLine(); int count = 0; int countS = 0; int countT = 0; bool S = false; for (int i = 0; i < s.Length; i++) { if (s[i] == 'S' && countT == 0) { countS++; } else if (s[i] == 'T' && countS > 0) { countT++; } else if (s[i] == 'S' && countT > 0) { count += (countS >= countT) ? countT * 2 : countS * 2; countS = 1; countT = 0; } if (i == s.Length - 1 && countS > 0 && countT > 0) { count += (countS >= countT) ? countT * 2 : countS * 2; } } Console.WriteLine(s.Length - count); } } }
using System; using System.Collections.Generic; using System.Collections; using System.Linq; namespace tes { class contest { static void Main(string[] args) { string s = Console.ReadLine(); int count = 0; int countS = 0; int countT = 0; bool S = false; for (int i = 0; i < s.Length; i++) { if (s[i] == 'S' && countT == 0) { countS++; } else if (s[i] == 'T' && countS > 0) { countT++; } else if (s[i] == 'S' && countT > 0) { count += (countS >= countT) ? countT * 2 : countS * 2; countS = (countS > countT) ? countS - countT + 1 : 1; countT = 0; } if (i == s.Length - 1 && countS > 0 && countT > 0) { count += (countS >= countT) ? countT * 2 : countS * 2; } } Console.WriteLine(s.Length - count); } } }
[["+", 0, 1, 0, 11, 12, 41, 15, 23, 0, 24], ["+", 0, 11, 12, 41, 15, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 41, 15, 23, 0, 16, 17, 47], ["+", 0, 11, 12, 41, 15, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 41, 15, 23, 0, 25], ["+", 64, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 0, 11, 12, 41, 64, 16, 31, 16, 31, 22], ["+", 0, 11, 12, 41, 64, 16, 31, 16, 17, 33], ["+", 0, 11, 12, 41, 64, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 41, 64, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 64, 196, 0, 1, 0, 11, 12, 41, 75, 203]]
8
216
12
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; class P { static void Main() { int n = int.Parse(Console.ReadLine()); SegmentTree<int> StartIndexes = new SegmentTree<int>(Enumerable.Repeat(-1, n).ToArray(), int.MinValue, (x, y) => y == int.MinValue ? x : y); SegmentTree<int> EndIndexes = new SegmentTree<int>(Enumerable.Repeat(n, n).ToArray(), int.MinValue, (x, y) => y == int.MinValue ? x : y); long res = 0; foreach (var item in Console.ReadLine() .Split() .Select((x, y) => new Tuple<int, int>(int.Parse(x), y)) .OrderBy(x => x.Item1)) { long num = item.Item1; int index = item.Item2; var lIndex = StartIndexes.Query(index); var rIndex = EndIndexes.Query(index); StartIndexes.Operate(index, rIndex, index); EndIndexes.Operate(lIndex + 1, index, index); Debug.WriteLine($"{lIndex} {index} {rIndex}"); res += num * (lIndex - index) * (index - rIndex); } } } class SegmentTree<T> { public int Size { get; private set; } T IdentityElement; Func<T, T, T> Merge; int LeafCount; int TreeHeight; T[] Datas; public SegmentTree(int size, T identityElement, Func<T, T, T> merge) : this(Enumerable.Repeat(identityElement, size).ToArray(), identityElement, merge) {} public SegmentTree(T[] elems, T identityElement, Func<T, T, T> merge) { Size = elems.Length; IdentityElement = identityElement; Merge = merge; LeafCount = 1; TreeHeight = 1; while (LeafCount < elems.Length) { LeafCount <<= 1; TreeHeight++; } Datas = Enumerable.Repeat(identityElement, LeafCount) .Concat(elems) .Concat(Enumerable.Repeat(identityElement, LeafCount - Size)) .ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Operate(int l, int r, T x) { l += LeafCount; r += LeafCount - 1; Propagate(l); Propagate(r); while (l <= r) { if (l % 2 == 1) Datas[l] = Merge(Datas[l], x); if (r % 2 == 0) Datas[r] = Merge(Datas[r], x); l = (l + 1) / 2; r = (r - 1) / 2; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int index) { index += LeafCount; Propagate(index); return Datas[index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Propagate(int sectionIndex) { for (int i = TreeHeight - 1; i >= 1; i--) Eval(sectionIndex >> i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Eval(int sectionIndex) { Datas[sectionIndex * 2] = Merge(Datas[sectionIndex * 2], Datas[sectionIndex]); Datas[sectionIndex * 2 + 1] = Merge(Datas[sectionIndex * 2 + 1], Datas[sectionIndex]); Datas[sectionIndex] = IdentityElement; } }
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; class P { static void Main() { int n = int.Parse(Console.ReadLine()); SegmentTree<int> StartIndexes = new SegmentTree<int>(Enumerable.Repeat(-1, n).ToArray(), int.MinValue, (x, y) => y == int.MinValue ? x : y); SegmentTree<int> EndIndexes = new SegmentTree<int>(Enumerable.Repeat(n, n).ToArray(), int.MinValue, (x, y) => y == int.MinValue ? x : y); long res = 0; foreach (var item in Console.ReadLine() .Split() .Select((x, y) => new Tuple<int, int>(int.Parse(x), y)) .OrderBy(x => x.Item1)) { long num = item.Item1; int index = item.Item2; var lIndex = StartIndexes.Query(index); var rIndex = EndIndexes.Query(index); StartIndexes.Operate(index, rIndex, index); EndIndexes.Operate(lIndex + 1, index, index); Debug.WriteLine($"{lIndex} {index} {rIndex}"); res += num * (lIndex - index) * (index - rIndex); } Console.WriteLine(res); } } class SegmentTree<T> { public int Size { get; private set; } T IdentityElement; Func<T, T, T> Merge; int LeafCount; int TreeHeight; T[] Datas; public SegmentTree(int size, T identityElement, Func<T, T, T> merge) : this(Enumerable.Repeat(identityElement, size).ToArray(), identityElement, merge) {} public SegmentTree(T[] elems, T identityElement, Func<T, T, T> merge) { Size = elems.Length; IdentityElement = identityElement; Merge = merge; LeafCount = 1; TreeHeight = 1; while (LeafCount < elems.Length) { LeafCount <<= 1; TreeHeight++; } Datas = Enumerable.Repeat(identityElement, LeafCount) .Concat(elems) .Concat(Enumerable.Repeat(identityElement, LeafCount - Size)) .ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Operate(int l, int r, T x) { l += LeafCount; r += LeafCount - 1; Propagate(l); Propagate(r); while (l <= r) { if (l % 2 == 1) Datas[l] = Merge(Datas[l], x); if (r % 2 == 0) Datas[r] = Merge(Datas[r], x); l = (l + 1) / 2; r = (r - 1) / 2; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int index) { index += LeafCount; Propagate(index); return Datas[index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Propagate(int sectionIndex) { for (int i = TreeHeight - 1; i >= 1; i--) Eval(sectionIndex >> i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Eval(int sectionIndex) { Datas[sectionIndex * 2] = Merge(Datas[sectionIndex * 2], Datas[sectionIndex]); Datas[sectionIndex * 2 + 1] = Merge(Datas[sectionIndex * 2 + 1], Datas[sectionIndex]); Datas[sectionIndex] = IdentityElement; } }
[["+", 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
790
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace codefestival_2016_qualA_A { class Program { static void Main(string[] args) { string a = Console.ReadLine(); Console.WriteLine(a.Substring(0, 4) + " " + a.Substring(5)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace codefestival_2016_qualA_A { class Program { static void Main(string[] args) { string a = Console.ReadLine(); Console.WriteLine(a.Substring(0, 4) + " " + a.Substring(4)); Console.ReadLine(); } } }
[["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 12, 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
80
8
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { //出力の都度更新をやめる var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Ans(); //更新する Console.Out.Flush(); } public static void Ans() { checked { var inputArray = retreiveStringArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } var s = inputArray[0].Select(x => x).ToArray(); var K = retreiveLongArray()[0]; var z = (int)'z'; for (int i = 0; i < s.Count(); i++) { var need = z - (int)s[i] + 1; if (need <= K) { s[i] = 'a'; K -= need; } if (i == s.Count() - 1) { var change = ((s[i] - 'a') + K) % 26; s[i] = (char)('a' + change); continue; } } //答えの出力 var ans = string.Join("", s); Console.WriteLine(ans); } } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } /// <summary> /// 2組みずつの入力データ(数値)からTuppleListを作成する /// </summary> /// <param name="N"></param> /// <returns></returns> private static List<Tuple<long, long>> createLongTuppleList(long N) { var inpList = new List<Tuple<long, long>>(); for (int i = 0; i < N; i++) { var inp = retreiveLongArray(); var item1 = inp[0]; var item2 = inp[1]; inpList.Add(new Tuple<long, long>(item1, item2)); } return inpList; } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { //出力の都度更新をやめる var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Ans(); //更新する Console.Out.Flush(); } public static void Ans() { checked { var inputArray = retreiveStringArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } var s = inputArray[0].Select(x => x).ToArray(); var K = retreiveLongArray()[0]; var z = (int)'z'; for (int i = 0; i < s.Count(); i++) { var need = s[i] == 'a' ? 0 : z - (int)s[i] + 1; if (need <= K) { s[i] = 'a'; K -= need; } if (i == s.Count() - 1) { var change = ((s[i] - 'a') + K) % 26; s[i] = (char)('a' + change); continue; } } //答えの出力 var ans = string.Join("", s); Console.WriteLine(ans); } } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } /// <summary> /// 2組みずつの入力データ(数値)からTuppleListを作成する /// </summary> /// <param name="N"></param> /// <returns></returns> private static List<Tuple<long, long>> createLongTuppleList(long N) { var inpList = new List<Tuple<long, long>>(); for (int i = 0; i < N; i++) { var inp = retreiveLongArray(); var item1 = inp[0]; var item2 = inp[1]; inpList.Add(new Tuple<long, long>(item1, item2)); } return inpList; } } }
[["+", 0, 212, 0, 41, 15, 16, 31, 204, 205, 22], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["+", 0, 212, 0, 41, 15, 16, 12, 252, 0, 104], ["+", 0, 212, 0, 41, 15, 16, 12, 252, 0, 253], ["+", 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]]
8
494
11
using System; using System.Text; using System.Collections.Generic; using System.Collections; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { class Program { static int N; static long mod = 1000000007; static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray(); static void Main(string[] args) { var S = Console.ReadLine(); long K = long.Parse(Console.ReadLine()); var num = new long[S.Length]; for (int i = 0; i < S.Length; i++) { var tmp = S[i]; num[i] = (tmp - 97); } for (int i = 0; i < S.Length; i++) { if (num[i] + K >= 26) { var tmp2 = 26 - num[i]; K -= tmp2; num[i] = 0; } if (S.Length - 1 == i) { num[i] += K; num[i] %= 26; } } var ans = new List<char>(); for (int i = 0; i < S.Length; i++) { ans.Add((char)(97 + num[i])); } Console.WriteLine(String.Join("", ans)); } } }
using System; using System.Text; using System.Collections.Generic; using System.Collections; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { class Program { static int N; static long mod = 1000000007; static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray(); static void Main(string[] args) { var S = Console.ReadLine(); long K = long.Parse(Console.ReadLine()); var num = new long[S.Length]; for (int i = 0; i < S.Length; i++) { var tmp = S[i]; num[i] = (tmp - 97); } for (int i = 0; i < S.Length; i++) { if (num[i] + K >= 26) { if (i != S.Length - 1 && num[i] == 0) { continue; } var tmp2 = 26 - num[i]; K -= tmp2; num[i] = 0; } if (S.Length - 1 == i) { num[i] += (K % 26); // num[i] %= 26; } } var ans = new List<char>(); for (int i = 0; i < S.Length; i++) { ans.Add((char)(97 + num[i])); } // for (int i = 0; i < 26; i++) //{ // Console.WriteLine((char)(97 + i)); //} Console.WriteLine(String.Join("", ans)); } } }
[["+", 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, 79], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 205, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 0, 131], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 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, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 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, 116, 0, 117], ["+", 64, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 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], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 17, 109], ["+", 64, 196, 0, 1, 0, 11, 12, 23, 0, 25]]
8
315
30
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using CS = System.Runtime.CompilerServices; // using System.Diagnostics; using static System.Math; using ll = System.Int64; using static Contest_C.Lib_IO; using static Contest_C.Lib_Minifunc; namespace Contest_C { public static class Entry { public static void Main() { checked { int k; string s; Lib_IO.rm(out s); Lib_IO.rm(out k); StringBuilder ans = new StringBuilder(s); for (int i = 0; i < ans.Length; i++) { int a = 'z' - ans[i] + 1; if (a < k) { ans[i] = 'a'; k -= a; } } ans[ans.Length - 1] = (char)((ans[ans.Length - 1] - 'a' + k) % 26 + 'a'); Lib_IO.wm(ans); } } } #region BaseModule public static class Lib_Minifunc { public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 [CS.MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [CS.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 の方が小さければ交換 [CS.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 を更新 [CS.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 を更新 [CS.MethodImpl(256)] public static bool inside(long i, long n) => (0 <= i && i < n); [CS.MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x, w) && inside(y, h)); [CS.MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable { T m = a[0]; for (int i = 1; i < a.Length; i++) chmin(ref m, a[i]); return m; } [CS.MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable { T m = a[0]; for (int i = 1; i < a.Length; i++) chmax(ref m, a[i]); return m; } [CS.MethodImpl(256)] public static long mod(long a, long m = MOD1) { var v = a % m; return (v < 0 ? (m < 0 ? v - m : v + m) : v); } [CS.MethodImpl(256)] public static long ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0) ? a / b : a / b + 1); // 整数商の切り上げ [CS.MethodImpl(256)] public static long round(double a) => Convert.ToInt64(a); // 四捨五入 [CS.MethodImpl(256)] public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b); [CS.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); [CS.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); public static T[] initc<T>(long l1) where T : new() { var m = new T[l1]; for (int i = 0; i < m.Length; i++) m[i] = new T(); return m; } // new制約は遅い public static int[] range(long s, long c) => Enumerable.Range((int)s, (int)c).ToArray(); public static T[] inita<T>(long l1, T v = default(T)) => Enumerable.Repeat(v, (int)l1).ToArray(); public static T[][] inita<T>(long l1, long l2, T v = default(T)) { var m = new T[l1][]; for (int i = 0; i < m.Length; i++) m[i] = inita(l2, v); return m; } public static T[][][] inita<T>(long l1, long l2, long l3, T v = default(T)) { var m = new T[l1][][]; for (int i = 0; i < m.Length; i++) m[i] = inita(l2, l3, v); return m; } public static void shift(this IList<int> l, int o) { for (int i = 0; i < l.Count; i++) l[i] += o; } public static void shift(this IList<long> l, long o) { for (int i = 0; i < l.Count; i++) l[i] += o; } [CS.MethodImpl(256)] public static bool initd<T, U>(this IDictionary<T, U> d, T k, U v = default(U)) { if (d.ContainsKey(k)) { return false; } else { d[k] = v; return true; } } public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null) where T : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.CompareTo(y)); break; case -1: Array.Sort(a, (x, y) => y.CompareTo(x)); break; default: break; } } public static void sort<T, U>(this P<T, U>[] a, int o, Comparison<P<T, U>> f = null) where T : IComparable where U : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; default: break; } } public static void sort<T, U, V>(this P<T, U, V>[] a, int o, Comparison<P<T, U, V>> f = null) where T : IComparable where U : IComparable where V : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; case 3: Array.Sort(a, (x, y) => x.C.CompareTo(y.C)); break; case -3: Array.Sort(a, (x, y) => y.C.CompareTo(x.C)); break; default: break; } } public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o, Comparison<P<T, U, V, W>> f = null) where T : IComparable where U : IComparable where V : IComparable where W : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; case 3: Array.Sort(a, (x, y) => x.C.CompareTo(y.C)); break; case -3: Array.Sort(a, (x, y) => y.C.CompareTo(x.C)); break; case 4: Array.Sort(a, (x, y) => x.D.CompareTo(y.D)); break; case -4: Array.Sort(a, (x, y) => y.D.CompareTo(x.D)); break; default: break; } } } 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[] { ' ' }; [CS.MethodImpl(256)] static bool eq<T, U>() => typeof(T).Equals(typeof(U)); [CS.MethodImpl(256)] static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); [CS.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 = new T[z.Length]; for (int i = 0; i < a.Length; i++) a[i] = cv<T>(z[i]); 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); } [CS.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)); if (a.Count == 0) { Console.WriteLine(); } else { 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) { if (b.Count == 0) { Console.WriteLine(); } else { 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 CS = System.Runtime.CompilerServices; // using System.Diagnostics; using static System.Math; using ll = System.Int64; using static Contest_C.Lib_IO; using static Contest_C.Lib_Minifunc; namespace Contest_C { public static class Entry { public static void Main() { checked { int k; string s; Lib_IO.rm(out s); Lib_IO.rm(out k); StringBuilder ans = new StringBuilder(s); for (int i = 0; i < ans.Length; i++) { if (ans[i] == 'a') continue; int a = 'z' - ans[i] + 1; if (a <= k) { ans[i] = 'a'; k -= a; } } ans[ans.Length - 1] = (char)((ans[ans.Length - 1] - 'a' + k) % 26 + 'a'); Lib_IO.wm(ans); } } } #region BaseModule public static class Lib_Minifunc { public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 [CS.MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [CS.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 の方が小さければ交換 [CS.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 を更新 [CS.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 を更新 [CS.MethodImpl(256)] public static bool inside(long i, long n) => (0 <= i && i < n); [CS.MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x, w) && inside(y, h)); [CS.MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable { T m = a[0]; for (int i = 1; i < a.Length; i++) chmin(ref m, a[i]); return m; } [CS.MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable { T m = a[0]; for (int i = 1; i < a.Length; i++) chmax(ref m, a[i]); return m; } [CS.MethodImpl(256)] public static long mod(long a, long m = MOD1) { var v = a % m; return (v < 0 ? (m < 0 ? v - m : v + m) : v); } [CS.MethodImpl(256)] public static long ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0) ? a / b : a / b + 1); // 整数商の切り上げ [CS.MethodImpl(256)] public static long round(double a) => Convert.ToInt64(a); // 四捨五入 [CS.MethodImpl(256)] public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b); [CS.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); [CS.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); public static T[] initc<T>(long l1) where T : new() { var m = new T[l1]; for (int i = 0; i < m.Length; i++) m[i] = new T(); return m; } // new制約は遅い public static int[] range(long s, long c) => Enumerable.Range((int)s, (int)c).ToArray(); public static T[] inita<T>(long l1, T v = default(T)) => Enumerable.Repeat(v, (int)l1).ToArray(); public static T[][] inita<T>(long l1, long l2, T v = default(T)) { var m = new T[l1][]; for (int i = 0; i < m.Length; i++) m[i] = inita(l2, v); return m; } public static T[][][] inita<T>(long l1, long l2, long l3, T v = default(T)) { var m = new T[l1][][]; for (int i = 0; i < m.Length; i++) m[i] = inita(l2, l3, v); return m; } public static void shift(this IList<int> l, int o) { for (int i = 0; i < l.Count; i++) l[i] += o; } public static void shift(this IList<long> l, long o) { for (int i = 0; i < l.Count; i++) l[i] += o; } [CS.MethodImpl(256)] public static bool initd<T, U>(this IDictionary<T, U> d, T k, U v = default(U)) { if (d.ContainsKey(k)) { return false; } else { d[k] = v; return true; } } public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null) where T : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.CompareTo(y)); break; case -1: Array.Sort(a, (x, y) => y.CompareTo(x)); break; default: break; } } public static void sort<T, U>(this P<T, U>[] a, int o, Comparison<P<T, U>> f = null) where T : IComparable where U : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; default: break; } } public static void sort<T, U, V>(this P<T, U, V>[] a, int o, Comparison<P<T, U, V>> f = null) where T : IComparable where U : IComparable where V : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; case 3: Array.Sort(a, (x, y) => x.C.CompareTo(y.C)); break; case -3: Array.Sort(a, (x, y) => y.C.CompareTo(x.C)); break; default: break; } } public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o, Comparison<P<T, U, V, W>> f = null) where T : IComparable where U : IComparable where V : IComparable where W : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; case 3: Array.Sort(a, (x, y) => x.C.CompareTo(y.C)); break; case -3: Array.Sort(a, (x, y) => y.C.CompareTo(x.C)); break; case 4: Array.Sort(a, (x, y) => x.D.CompareTo(y.D)); break; case -4: Array.Sort(a, (x, y) => y.D.CompareTo(x.D)); break; default: break; } } } 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[] { ' ' }; [CS.MethodImpl(256)] static bool eq<T, U>() => typeof(T).Equals(typeof(U)); [CS.MethodImpl(256)] static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); [CS.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 = new T[z.Length]; for (int i = 0; i < a.Length; i++) a[i] = cv<T>(z[i]); 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); } [CS.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)); if (a.Count == 0) { Console.WriteLine(); } else { 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) { if (b.Count == 0) { Console.WriteLine(); } else { 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, 57, 0, 121], ["+", 0, 196, 0, 7, 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], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 0, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
4,263
15
using System; using System.Text; class Program { static void Main() { new Program().Solve(); } public void Solve() { string s = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); var t = new StringBuilder(); for (int i = 0; i < s.Length; i++) { if (i == s.Length - 1) { t.Append((char)((s[i] - 'a' + k) % 26 + 'a')); k = 0; } else if (s[i] == 'a') { continue; } else { if ('z' + 1 - s[i] <= k) { t.Append('a'); k -= 'z' + 1 - s[i]; if (k == 0) break; } else { t.Append(s[i]); } } } if (t.Length < s.Length) t.Append(s.Substring(t.Length)); Console.WriteLine(t); } }
using System; using System.Text; class Program { static void Main() { new Program().Solve(); } public void Solve() { string s = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); var t = new StringBuilder(); for (int i = 0; i < s.Length; i++) { if (i == s.Length - 1) { t.Append((char)((s[i] - 'a' + k) % 26 + 'a')); k = 0; } else if (s[i] == 'a') { t.Append('a'); } else if ('z' + 1 - s[i] <= k) { t.Append('a'); k -= 'z' + 1 - s[i]; if (k == 0) break; } else { t.Append(s[i]); } } if (t.Length < s.Length) t.Append(s.Substring(t.Length)); Console.WriteLine(t); } }
[["-", 0, 57, 75, 57, 64, 196, 0, 116, 0, 117], ["+", 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, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["-", 75, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
8
239
11
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const char White = '.'; const char Black = '#'; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var s = input.ReadLine().ToCharArray(); var k = int.Parse(input.ReadLine()); Func<char, char> f = (cc) => { if (cc == 'z') return 'a'; else return (char)(cc + 1); }; for (int i = 0; i < s.Length; i++) { var c = s[i]; if ('z' - c + 1 <= k) { s[i] = 'a'; k -= ('z' - c + 1); } } if (k > 0) { s[s.Length - 1] += (char)(k % ('z' - 'a' + 1)); } return new StringBuilder().Append(s); } static long[] ToIntArray(string strs, int n) { var ret = new long[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = long.Parse(spl[i]); return ret; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const char White = '.'; const char Black = '#'; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var s = input.ReadLine().ToCharArray(); var k = int.Parse(input.ReadLine()); Func<char, char> f = (cc) => { if (cc == 'z') return 'a'; else return (char)(cc + 1); }; for (int i = 0; i < s.Length; i++) { var c = s[i]; if (c != 'a' && 'z' - c + 1 <= k) { s[i] = 'a'; k -= ('z' - c + 1); } } if (k > 0) { long c = s[s.Length - 1] - 'a'; c += k; c %= 'z' - 'a' + 1; s[s.Length - 1] = (char)(c + 'a'); } return new StringBuilder().Append(s); } static long[] ToIntArray(string strs, int n) { var ret = new long[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = long.Parse(spl[i]); return ret; } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 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, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 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, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 252, 0, 104], ["+", 0, 200, 0, 212, 0, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 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, 74, 51, 23, 0, 24], ["-", 0, 11, 12, 74, 51, 23, 0, 16, 17, 109], ["-", 12, 74, 51, 23, 0, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 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], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 24], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 17, 72], ["+", 12, 74, 51, 23, 0, 16, 12, 252, 0, 104], ["+", 12, 74, 51, 23, 0, 16, 12, 252, 0, 253]]
8
381
42
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 long Mod = (long)1e9 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var S = ReadLine().ToCharArray(); ; var K = Sarray()[0]; var rem = K; for (var i = 0; i < S.Length; ++i) { var dirA = 'z' - S[i] + 1; if (dirA <= rem) { rem -= dirA; S[i] = 'a'; } } if (0 != rem) S[S.Length - 1] = (char)((S[S.Length - 1] - 'a' + rem + 26) % 26 + 'a'); WriteLine(S); // 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 long Mod = (long)1e9 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var S = ReadLine().ToCharArray(); var K = Sarray()[0]; var rem = K; for (var i = 0; i < S.Length; ++i) { var dirA = ('z' - S[i] + 1) % 26; if (dirA <= rem) { rem -= dirA; S[i] = 'a'; } } if (0 != rem) S[S.Length - 1] = (char)((S[S.Length - 1] - 'a' + rem) % 26 + 'a'); WriteLine(S); // Out.Flush(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 260, 0, 35], ["+", 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, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203]]
8
260
7
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Numerics; namespace CODEFESTIVAL2016QA.C { using static Util; public class Solver : SolverBase { char[] S; int K; public void Run() { S = ReadLine().ToCharArray(); K = ReadInt(); // 先頭から順に a にできるところを a にしていく var r = K; for (int i = 0; i < S.Length; i++) { var target = 'z' - S[i] + 1; if (target <= r) { r -= target; S[i] = 'a'; } } if (0 < r) { // 残りは末尾に適用 ただし、26のあまりを var c = S[S.Length - 1] - 'a'; var nc = (char)((c + r) % 26 + 'a'); S[S.Length - 1] = nc; } WriteLine(new string(S)); } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { 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; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder /// をセットする。 /// </summary> public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key, int adder) { if (dic.ContainsKey(key)) { dic[key] += adder; } else { dic[key] = adder; } } /// <summary> /// 文字列 s が chars に含まれる文字を含んでいるか? /// </summary> public static bool ContainsAny(this string s, char[] chars) { for (int j = 0; j < s.Length; j++) { if (chars.Contains(s[j])) return true; } return false; } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 /// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right // は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected string ReadString() => ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected char[] ReadCharArray() => ReadLine() .Split(' ') .Select<string, char>( s => s[0]) .ToArray(); virtual protected int[] ReadIntArray() => ReadLine() .Split(' ') .Select<string, int>( s => int.Parse(s)) .ToArray(); virtual protected void ReadInt2(out int a, out int b) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadInt3(out int a, out int b, out int c) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadInt4(out int a, out int b, out int c, out int d) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected long[] ReadLongArray() => ReadLine() .Split(' ') .Select<string, long>( s => long.Parse(s)) .ToArray(); virtual protected void ReadLong2(out long a, out long b) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadLong3(out long a, out long b, out long c) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadLong4(out long a, out long b, out long c, out long d) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected double[] ReadDoubleArray() => ReadLine() .Split(' ') .Select<string, double>( s => double.Parse(s)) .ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(bool[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j] ? "x " : ". "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(char[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j]); sb.Append(" "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Numerics; namespace CODEFESTIVAL2016QA.C { using static Util; public class Solver : SolverBase { char[] S; int K; public void Run() { S = ReadLine().ToCharArray(); // WriteLine(new string(S)); K = ReadInt(); // 先頭から順に a にできるところを a にしていく // ただし、すでに a のところは除く!!! var r = K; for (int i = 0; i < S.Length; i++) { if (S[i] == 'a') continue; var target = 'z' - S[i] + 1; if (target <= r) { r -= target; S[i] = 'a'; } } if (0 < r) { // 残りは末尾に適用 ただし、26のあまりを var c = S[S.Length - 1] - 'a'; var nc = (char)((c + r) % 26 + 'a'); S[S.Length - 1] = nc; } WriteLine(new string(S)); } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { 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; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder /// をセットする。 /// </summary> public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key, int adder) { if (dic.ContainsKey(key)) { dic[key] += adder; } else { dic[key] = adder; } } /// <summary> /// 文字列 s が chars に含まれる文字を含んでいるか? /// </summary> public static bool ContainsAny(this string s, char[] chars) { for (int j = 0; j < s.Length; j++) { if (chars.Contains(s[j])) return true; } return false; } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 /// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right // は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected string ReadString() => ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected char[] ReadCharArray() => ReadLine() .Split(' ') .Select<string, char>( s => s[0]) .ToArray(); virtual protected int[] ReadIntArray() => ReadLine() .Split(' ') .Select<string, int>( s => int.Parse(s)) .ToArray(); virtual protected void ReadInt2(out int a, out int b) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadInt3(out int a, out int b, out int c) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadInt4(out int a, out int b, out int c, out int d) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected long[] ReadLongArray() => ReadLine() .Split(' ') .Select<string, long>( s => long.Parse(s)) .ToArray(); virtual protected void ReadLong2(out long a, out long b) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadLong3(out long a, out long b, out long c) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadLong4(out long a, out long b, out long c, out long d) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected double[] ReadDoubleArray() => ReadLine() .Split(' ') .Select<string, double>( s => double.Parse(s)) .ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(bool[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j] ? "x " : ". "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(char[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j]); sb.Append(" "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
[["+", 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, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 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, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
2,440
13
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var sol = new Solve(); sol.Exec(); } } class Solve { public void Exec() { var s = Console.ReadLine().ToCharArray(); var n = int.Parse(Console.ReadLine()); for (var i = 0; i < s.Length; i++) { var diff = (('z' + 1) - s[i]); if (diff <= n) { n -= diff; s[i] = 'a'; } } var last = s.Length - 1; var cal = s[last] + n % 26; if (cal > 'z') cal -= 26; s[last] = (char)cal; Console.WriteLine(new string(s)); } } public class Util {}
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var sol = new Solve(); sol.Exec(); } } class Solve { public void Exec() { var s = Console.ReadLine().ToCharArray(); var n = int.Parse(Console.ReadLine()); for (var i = 0; i < s.Length; i++) { var diff = (('z' + 1) - s[i]); // Console.WriteLine(diff); if (s[i] != 'a' && diff <= n) { n -= diff; s[i] = 'a'; } } var last = s.Length - 1; var cal = s[last] + n % 26; if (cal > 'z') cal -= 26; s[last] = (char)cal; Console.WriteLine(new string(s)); } } public class Util {}
[["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 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, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
198
9
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); var s = Console.ReadLine(); int K = int.Parse(Console.ReadLine()); var res = new int[s.Length]; for (var i = 0; i < s.Length; i++) { res[i] = 'z' - s[i] + 1; } var ans = new StringBuilder(); for (var i = 0; i < s.Length - 1; i++) { if (res[i] <= K) { ans.Append('a'); K -= res[i]; } else { ans.Append(s[i]); } } if (res[s.Length - 1] <= K) { int r = (K - res[s.Length - 1]) % 26; char a = (char)('a' + r); ans.Append(a); } else { char a = (char)(s[s.Length - 1] + K); ans.Append(a); } Console.WriteLine(ans); // Console.Out.Flush(); } } public class Scanner { public int[] SplitRead() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReadL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); var s = Console.ReadLine(); int K = int.Parse(Console.ReadLine()); var res = new int[s.Length]; for (var i = 0; i < s.Length; i++) { res[i] = s[i] == 'a' ? 0 : 'z' - s[i] + 1; } var ans = new StringBuilder(); for (var i = 0; i < s.Length - 1; i++) { if (res[i] <= K) { ans.Append('a'); K -= res[i]; } else { ans.Append(s[i]); } } if (res[s.Length - 1] <= K) { int r = (K - res[s.Length - 1]) % 26; char a = (char)('a' + r); ans.Append(a); } else { char a = (char)(s[s.Length - 1] + K); ans.Append(a); } Console.WriteLine(ans); // Console.Out.Flush(); } } public class Scanner { public int[] SplitRead() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReadL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } } }
[["+", 0, 11, 12, 41, 15, 16, 31, 204, 205, 22], ["+", 12, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["+", 0, 11, 12, 41, 15, 16, 12, 252, 0, 253], ["+", 0, 11, 12, 41, 15, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 12, 41, 75, 16, 31, 16, 31, 252, 0, 104]]
8
498
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Program { private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static string Solve(string S, int K) { int N = S.Length; var s = S.ToCharArray(); for (int i = 0; i < N - 1; ++i) { int k = 'z' - s[i] + 1; if (K >= k) { s[i] = 'a'; K -= k; } } s[N - 1] = (char)((s[N - 1] - 'a' + K) % 26 + 'a'); return new string(s); } static void Main(string[] args) { string S = Read(); int K = ReadInt(); Console.WriteLine(Solve(S, K)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Program { private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static string Solve(string S, int K) { int N = S.Length; var s = S.ToCharArray(); for (int i = 0; i < N - 1; ++i) { int k = 'z' - s[i] + 1; if (s[i] != 'a' && K >= k) { s[i] = 'a'; K -= k; } } s[N - 1] = (char)((s[N - 1] - 'a' + K) % 26 + 'a'); return new string(s); } static void Main(string[] args) { string S = Read(); int K = ReadInt(); Console.WriteLine(Solve(S, K)); } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 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, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
344
9
using System; using System.Collections; using System.Collections.Generic; using System.Dynamic; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection.Emit; using System.Runtime.Remoting.Proxies; using System.Text; using static System.Console; using static System.Math; using static Ex; using static ArrayEx; class AC { /*------------------------------------------------------------------*/ string s; int K; void Solve() { io.i(out s, out K); var S = s.ToCharArray(); var left = K; REP(S.Length, i => { var d = dis(S[i]); if (d <= left) { S[i] = 'a'; left -= d; } }); var size = 'z' - 'a' + 1; var lst = (char)(S[S.LastIdx()] + left % size); if (lst > 'z') lst -= (char)size; S[S.LastIdx()] = lst; io.o(S.toString()); } int dis(char c) => 'z' - c + 1; /*------------------------------------------------------------------*/ 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(); } } #region OTHER class IO { #region INPUT 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() { byte b = 0; do b = ReadByte(); while (!IsAscii(b)); 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(); } private void Read<T>(out T v) => v = SuitType<T>(Next()); private bool TypeEqual<T, TU>() => typeof(T) == typeof(TU); private T SuitType<T>(string s) { if (TypeEqual<T, int>()) ConvertType<T, int>(int.Parse(s)); if (TypeEqual<T, long>()) ConvertType<T, long>(long.Parse(s)); if (TypeEqual<T, double>()) ConvertType<T, double>(double.Parse(s)); if (TypeEqual<T, char>()) ConvertType<T, char>(char.Parse(s)); return ConvertType<T, string>(s); } private T i<T>() => SuitType<T>(String); 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()); public void i<T>(out T v) => Read(out v); 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) a[i] = i<T>(); } 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) { a[i] = i<T>(); b[i] = i<TU>(); } } 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 (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<TU>(); c[i] = i<TV>(); } } 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) a[i, j] = i<T>(); } #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Console.Out.Flush(); public void o(params Object[] xs) => Print(false, xs); public void o_(params Object[] xs) => Print(true, xs); private void Print(bool isOneLine, params Object[] xs) { foreach (var x in xs) { if (x is int[]) PrintArr<int>(isOneLine, x); else if (x is long[]) PrintArr<int>(isOneLine, x); else if (x is double[]) PrintArr<int>(isOneLine, x); else if (x is char[]) PrintArr<int>(isOneLine, x); else if (x is string[]) PrintArr<int>(isOneLine, x); else if (x is bool[]) PrintArr<int>(isOneLine, x); else if (x is int[,]) PrintArr2D(ConvertType<int[,], object>(x)); else if (x is long[,]) PrintArr2D(ConvertType<long[,], object>(x)); else if (x is double[,]) PrintArr2D(ConvertType<double[,], object>(x)); else if (x is char[,]) PrintArr2D(ConvertType<char[,], object>(x)); else if (x is string[,]) PrintArr2D(ConvertType<string[,], object>(x)); else if (x is bool[,]) PrintArr2D(ConvertType<bool[,], object>(x)); else WriteLine(x); } } private void PrintArr2D<T>(T[,] a) { int a0 = a.GetLength(0), a1 = a.GetLength(1); for (int i = 0; i < a0; ++i) { for (int j = 0; j < a1 - 1; ++j) Write(a[i, j] + " "); WriteLine(a[i, a1 - 1]); } } private void PrintArr<T>(bool isOneLine, Object xs) { if (isOneLine) PrintArr1D_(ConvertType<T[], object>(xs)); else PrintArr1D(ConvertType<T[], object>(xs)); } private void PrintArr1D<T>(T[] xs) { foreach (var x in xs) WriteLine(x); } private void PrintArr1D_<T>(T[] xs) => WriteLine(string.Join(" ", xs)); 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 private T ConvertType<T, TU>(TU v) => (T)Convert.ChangeType(v, typeof(T)); public IO() { SetOut(_sw); } } static class Ex { public static void REP(int a, Action<int> act) => FOR(0, a, act); public static void FOR(int a, int b, Action<int> act) => FOR(a, b, 1, act); public static void FOR(int a, int b, int n, Action<int> act) { for (int i = a; i < b; i += n) act(i); } public static void REPEQ(int a, Action<int> act) => FOR(0, a + 1, act); public static void FOREQ(int a, int b, Action<int> act) => FOR(a, b + 1, act); public static void FOREQ(int a, int b, int n, Action<int> act) => FOR(a, b + 1, n, act); public static T MIN<T>(params T[] a) => a.Min(); public static T MAX<T>(params T[] a) => a.Max(); } static class NumEx { public static string toString(this double d) => d.ToString("R"); 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; } static class ArrayEx { public static void SET<T>(this T[] a, T v) { for (int i = 0; i < a.Length; ++i) a[i] = v; } public static void SET<T>(this T[,] a, T v) { for (int i = 0; i < a.GetLength(0); ++i) for (int j = 0; j < a.GetLength(1); ++j) a[i, j] = v; } public static IEnumerable<T> UNFOLD<T>(Func<int, T> func) => UNFOLD(0, func); public static IEnumerable<T> UNFOLD<T>(int s, Func<int, T> func) { while (true) yield return func(s++); } public static void ITER<T>(this IEnumerable<T> xs, Action<T> act) { foreach (var x in xs) act(x); } public static int LastIdx<T>(this T[] xs) => xs.Length - 1; public static string toString(this char[] xs) => new string(xs); } #endregion
using System; using System.Collections; using System.Collections.Generic; using System.Dynamic; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection.Emit; using System.Runtime.Remoting.Proxies; using System.Text; using static System.Console; using static System.Math; using static Ex; using static ArrayEx; class AC { /*------------------------------------------------------------------*/ string s; int K; void Solve() { io.i(out s, out K); var S = s.ToCharArray(); var left = K; REP(S.Length, i => { var d = dis(S[i]); if (S[i] != 'a' && d <= left) { S[i] = 'a'; left -= d; } }); var size = 'z' - 'a' + 1; var lst = (char)(S[S.LastIdx()] + left % size); if (lst > 'z') lst -= (char)size; S[S.LastIdx()] = lst; io.o(S.toString()); } int dis(char c) => 'z' - c + 1; /*------------------------------------------------------------------*/ 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(); } } #region OTHER class IO { #region INPUT 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() { byte b = 0; do b = ReadByte(); while (!IsAscii(b)); 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(); } private void Read<T>(out T v) => v = SuitType<T>(Next()); private bool TypeEqual<T, TU>() => typeof(T) == typeof(TU); private T SuitType<T>(string s) { if (TypeEqual<T, int>()) ConvertType<T, int>(int.Parse(s)); if (TypeEqual<T, long>()) ConvertType<T, long>(long.Parse(s)); if (TypeEqual<T, double>()) ConvertType<T, double>(double.Parse(s)); if (TypeEqual<T, char>()) ConvertType<T, char>(char.Parse(s)); return ConvertType<T, string>(s); } private T i<T>() => SuitType<T>(String); 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()); public void i<T>(out T v) => Read(out v); 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) a[i] = i<T>(); } 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) { a[i] = i<T>(); b[i] = i<TU>(); } } 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 (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<TU>(); c[i] = i<TV>(); } } 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) a[i, j] = i<T>(); } #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Console.Out.Flush(); public void o(params Object[] xs) => Print(false, xs); public void o_(params Object[] xs) => Print(true, xs); private void Print(bool isOneLine, params Object[] xs) { foreach (var x in xs) { if (x is int[]) PrintArr<int>(isOneLine, x); else if (x is long[]) PrintArr<int>(isOneLine, x); else if (x is double[]) PrintArr<int>(isOneLine, x); else if (x is char[]) PrintArr<int>(isOneLine, x); else if (x is string[]) PrintArr<int>(isOneLine, x); else if (x is bool[]) PrintArr<int>(isOneLine, x); else if (x is int[,]) PrintArr2D(ConvertType<int[,], object>(x)); else if (x is long[,]) PrintArr2D(ConvertType<long[,], object>(x)); else if (x is double[,]) PrintArr2D(ConvertType<double[,], object>(x)); else if (x is char[,]) PrintArr2D(ConvertType<char[,], object>(x)); else if (x is string[,]) PrintArr2D(ConvertType<string[,], object>(x)); else if (x is bool[,]) PrintArr2D(ConvertType<bool[,], object>(x)); else WriteLine(x); } } private void PrintArr2D<T>(T[,] a) { int a0 = a.GetLength(0), a1 = a.GetLength(1); for (int i = 0; i < a0; ++i) { for (int j = 0; j < a1 - 1; ++j) Write(a[i, j] + " "); WriteLine(a[i, a1 - 1]); } } private void PrintArr<T>(bool isOneLine, Object xs) { if (isOneLine) PrintArr1D_(ConvertType<T[], object>(xs)); else PrintArr1D(ConvertType<T[], object>(xs)); } private void PrintArr1D<T>(T[] xs) { foreach (var x in xs) WriteLine(x); } private void PrintArr1D_<T>(T[] xs) => WriteLine(string.Join(" ", xs)); 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 private T ConvertType<T, TU>(TU v) => (T)Convert.ChangeType(v, typeof(T)); public IO() { SetOut(_sw); } } static class Ex { public static void REP(int a, Action<int> act) => FOR(0, a, act); public static void FOR(int a, int b, Action<int> act) => FOR(a, b, 1, act); public static void FOR(int a, int b, int n, Action<int> act) { for (int i = a; i < b; i += n) act(i); } public static void REPEQ(int a, Action<int> act) => FOR(0, a + 1, act); public static void FOREQ(int a, int b, Action<int> act) => FOR(a, b + 1, act); public static void FOREQ(int a, int b, int n, Action<int> act) => FOR(a, b + 1, n, act); public static T MIN<T>(params T[] a) => a.Min(); public static T MAX<T>(params T[] a) => a.Max(); } static class NumEx { public static string toString(this double d) => d.ToString("R"); 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; } static class ArrayEx { public static void SET<T>(this T[] a, T v) { for (int i = 0; i < a.Length; ++i) a[i] = v; } public static void SET<T>(this T[,] a, T v) { for (int i = 0; i < a.GetLength(0); ++i) for (int j = 0; j < a.GetLength(1); ++j) a[i, j] = v; } public static IEnumerable<T> UNFOLD<T>(Func<int, T> func) => UNFOLD(0, func); public static IEnumerable<T> UNFOLD<T>(int s, Func<int, T> func) { while (true) yield return func(s++); } public static void ITER<T>(this IEnumerable<T> xs, Action<T> act) { foreach (var x in xs) act(x); } public static int LastIdx<T>(this T[] xs) => xs.Length - 1; public static string toString(this char[] xs) => new string(xs); } #endregion
[["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 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, 218, 8, 196, 0, 57, 15, 16, 17, 98]]
8
2,673
9
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { //////////////////////////////////////////////////////////// string s; int K; void Solve() { io.i(out s, out K); char[] ans = s.ToCharArray(); s.Length.REP(i => { if (s[i] != 'a' && 'z' - s[i] + 1 <= K) { ans[i] = 'a'; K -= 'z' - ans[i] + 1; } }); if (K > 0) { int last = ans[ans.Length - 1] + K % ('z' - 'a' + 1); if (last > 'z') last -= (char)('z' - 'a' + 1); ans[ans.Length - 1] = (char)last; } io.o(ans.toString()); } //////////////////////////////////////////////////////////// public static void Main() { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // cannot use break,continue,goto void FOR(int a, int b, Action<int> act) { for (int i = a; i < b; ++i) act(i); } void FORR(int a, int b, Action<int> act) { for (int i = a - 1; i >= b; --i) act(i); } #endregion //////////////////////////////////////////////////////////// } #region default class IO { TYPE tp; string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); tp = new TYPE(); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return tp.suitType<T>(String); } public void i<T>(out T v) { v = tp.suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; i++) a[i] = tp.suitType<T>(String); } public void ini<T, U>(out T[] a, out U[] b, int n) { a = new T[n]; b = new U[n]; for (int i = 0; i < n; i++) { a[i] = i<T>(); b[i] = i<U>(); } } public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) { a = new T[n]; b = new U[n]; c = new V[n]; for (int i = 0; i < n; i++) { a[i] = i<T>(); b[i] = i<U>(); c[i] = i<V>(); } } 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++) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void o<T>(T[,] a) { a.GetLength(0).REP(i => { a.GetLength(1).REP(j => or(a[i, j] + " ")); br(); }); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { o(connect<T>(a)); } public void or<T>(T a) { Console.Write(a); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } private string connect<T>(params T[] s) { return string.Join(" ", s); } } class TYPE { public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } public T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } public T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size; private int type; // type=0->min public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { public long mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { long ret = 1; for (long i = 1; i <= n; i++) ret = (ret * i) % mod; return ret; } public long ModC(long n, long r) { if (r == 0 || n == r) return 1; if (n == 0) return 0; if (n < 0 || n < r) throw new ArgumentException("n,r invalid"); else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long[,] C(int N) { long[,] Co = new long[N + 1, N + 1]; (N + 1).REP(i => (i + 1).REP(j => Co[i, j] = (j == 0 || j == i) ? 1L : Co[i - 1, j - 1] + Co[i - 1, j])); return Co; } public long DupC(long n, long r) { return ModC(n + r - 1, r); } public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, n) => GCD(v, n)); } public T Max<T>(params T[] a) { return a.Max(); } public T Min<T>(params T[] a) { return a.Min(); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int[] DigArr(int n) { int[] ret = new int[Digit(n)]; ret.Length.REP(i => ret[i] = DigVal(n, i + 1)); return ret; } public long DigArr2Num(IEnumerable<int> enu) { return enu.Aggregate((v, n) => v * 10 + n); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public long Tousa(long a, long d, long n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, long n) { return n * (2 * a + (n - 1) * d) / 2; } public long[] enuDivsor(long N) { var ret = new SortedSet<long>(); for (long i = 1; i * i <= N; i++) if (N % i == 0) { ret.Add(i); ret.Add(N / i); } return ret.ToArray(); } public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<List<int>>(); Arr.Length.REPR(i => s.Push(new List<int>() { i })); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) { var ret = new List<int>(); cur.ForEach(X => ret.Add(Arr[X])); yield return ret.ToArray(); } else Arr.Length.REPR(i => { if (!cur.Contains(i)) s.Push(new List<int>(cur) { i }); }); } } public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<List<int>>(); Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] })); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) yield return cur.ToArray(); else Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] })); } } public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<long[]> enuPart(string str) { var s = new Stack<Tuple<string, List<long>, int>>(); s.Push(Tuple.Create(str[0].ToString(), new List<long>(), 1)); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item3 >= str.Length) yield return (new List<long>(cur.Item2) { cur.Item1.toLong() }) .ToArray(); else { s.Push(Tuple.Create(cur.Item1 + str[cur.Item3], new List<long>(cur.Item2), cur.Item3 + 1)); s.Push(Tuple.Create(str[cur.Item3].ToString(), new List<long>(cur.Item2) { cur.Item1.toLong() }, cur.Item3 + 1)); } } } } class Time { public int[] M = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; public int[] D = { 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; public Time() { D[1] = 28; } public Time(int y) { D[1] = isLeapYear(y) ? 29 : 28; } public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } #endregion #region Data class AssociativeArray<T> : IEnumerable { public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(T a) { if (!conK(a)) dic[a] = 0; dic[a]++; } public void Add(params T[] a) { a.Length.REP(i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { a.Length.REP(i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => MaxK(); public T MinKey => MinK(); public T MaxK() { var maxV = MaxVal; return dic.First(d => d.Value == maxV).Key; } public T MinK() { var minV = MinVal; return dic.First(d => d.Value == minV).Key; } public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } public T[] ValueSortedKey(bool inc = true) { // test return (inc ? (dic.OrderBy(kp => kp.Value)) : (dic.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } //:sort->array } class Index { public int[] Comp(int[] bef) { int[] aft = new int[bef.Length]; var tmp = bef.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); aft = bef.Select(v => tmp[v]).ToArray(); return aft; } } class TreeDis { // TODO:shortestPath public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; g.Length.REP(i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class ShortestPath { public long INF = (long)1e15; protected int I = -1; protected int V; protected int E; public long[] cost; public List<Tuple<int, long>>[] Adj; protected bool isNonDir = true; public void Init(int n) { I = n + 1; V = n; Adj = new List<Tuple<int, long>>[I]; I.REP(i => Adj[i] = new List<Tuple<int, long>>()); } public void AddPath(int f, int t, long c) { E++; if (isNonDir) { Adj[f].Add(Tuple.Create(t, c)); Adj[t].Add(Tuple.Create(f, c)); } else { Adj[f].Add(Tuple.Create(t, c)); } } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } } class Dijkstra : ShortestPath { //隣接対応後検証不足,有向とか public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; var pq = new PQueue<Tuple<int, long>>(); pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost) while (pq.Count > 0) { var cur = pq.Dequeue(); if (cost[cur.Item1] < cur.Item2) continue; Adj[cur.Item1].Count.REP(i => { var tmp = Adj[cur.Item1][i]; if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) { cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2; pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1])); } }); } return cost[t]; } } class BellmanFord : ShortestPath { private bool[] neg; public BellmanFord() {} public BellmanFord(bool isNonDir) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; neg = new bool[I]; for (int i = 0; i < I - 1; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) cost[cur.Item1] = cost[j] + cur.Item2; })); } for (int i = 0; i < I; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) { cost[cur.Item1] = cost[j] + cur.Item2; neg[cur.Item1] = true; } if (neg[j]) neg[cur.Item1] = true; })); } return cost[t]; } public bool loopExist() { return neg[I - 1]; } } class WarshallFloyd { //そのうちAdjとどっちがいいか...TODO:ジェネリック private int E; private int INF = (int)1e9; public long[,] G; public void Init(int n) { E = n + 1; G = new long[E, E]; G.Set(INF); E.REP(i => G[i, i] = 0); } public void AddPath(int f, int t, long c) { G[f, t] = c; G[t, f] = c; } public void AddPath(int[] f, int[] t) { f.Length.REP(i => AddPath(f[i], t[i], 1)); } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } public void Run() { G = MinCostArr(); } public long[,] MinCostArr() { E.REP(i => E.REP( j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k])))); return G; } } class UnionFind { public long[] parent; public long[] depth; private int I; public void Init(int n) { I = n + 1; parent = new long[I]; depth = new long[I]; I.REP(i => parent[i] = i); } public long Find(long x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(long x, long y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(int a, int b) { return Find(a) == Find(b); } public long Size(int x) { return depth[Find(x)]; } } class Kruskal : ShortestPath { // TODO:test, public long Run() { var L = Adj.Select((l, i) => Tuple.Create(i, l[i].Item1, l[i].Item2)) .OrderBy(t => t.Item3) .ToList(); // var li = new List<Tuple<int, int, long>>(); // I.REP(i =>{ foreach (var t in Adj[i]) li.Add(Tuple.Create(i, t.Item1, // t.Item2));}); li = li.OrderBy(t => t.Item3).ToList();//li = // li.OrderByDescending(t => t.Item3).ToList(); var uf = new UnionFind(); uf.Init(V); long ret = 0; foreach (var t in L) { if (!uf.Same(t.Item1, t.Item2)) { ret += t.Item3; uf.Unite(t.Item1, t.Item2); } } return ret; } } #endregion #region Ex static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static long toLong(this string s) { long n; return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0; } public static long toLong(this char c) { return toLong(c.ToString()); } public static long toLong(this char[] c) { return toLong(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); } public static bool Odd(this int v) { return v % 2 != 0; } public static bool Odd(this long v) { return v % 2 != 0; } public static void REP(this int v, Action<int> act) { for (int i = 0; i < v; ++i) act(i); } public static void REPR(this int v, Action<int> act) { for (int i = v - 1; i >= 0; --i) act(i); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static T[] SortR<T>(this T[] a) { Array.Sort(a); Array.Reverse(a); return a; } public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v)); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class IEnumerableEx { // } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { //////////////////////////////////////////////////////////// string s; int K; void Solve() { io.i(out s, out K); char[] ans = s.ToCharArray(); s.Length.REP(i => { if (ans[i] != 'a' && ans[i] + K > 'z') { K -= 'z' - ans[i] + 1; ans[i] = 'a'; } }); int last = ans[ans.Length - 1] + K % ('z' - 'a' + 1); if (last > 'z') last -= (char)('z' - 'a' + 1); ans[ans.Length - 1] = (char)last; io.o(ans.toString()); } //////////////////////////////////////////////////////////// public static void Main() { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // cannot use break,continue,goto void FOR(int a, int b, Action<int> act) { for (int i = a; i < b; ++i) act(i); } void FORR(int a, int b, Action<int> act) { for (int i = a - 1; i >= b; --i) act(i); } #endregion //////////////////////////////////////////////////////////// } #region default class IO { TYPE tp; string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); tp = new TYPE(); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return tp.suitType<T>(String); } public void i<T>(out T v) { v = tp.suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; i++) a[i] = tp.suitType<T>(String); } public void ini<T, U>(out T[] a, out U[] b, int n) { a = new T[n]; b = new U[n]; for (int i = 0; i < n; i++) { a[i] = i<T>(); b[i] = i<U>(); } } public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) { a = new T[n]; b = new U[n]; c = new V[n]; for (int i = 0; i < n; i++) { a[i] = i<T>(); b[i] = i<U>(); c[i] = i<V>(); } } 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++) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void o<T>(T[,] a) { a.GetLength(0).REP(i => { a.GetLength(1).REP(j => or(a[i, j] + " ")); br(); }); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { o(connect<T>(a)); } public void or<T>(T a) { Console.Write(a); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } private string connect<T>(params T[] s) { return string.Join(" ", s); } } class TYPE { public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } public T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } public T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size; private int type; // type=0->min public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { public long mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { long ret = 1; for (long i = 1; i <= n; i++) ret = (ret * i) % mod; return ret; } public long ModC(long n, long r) { if (r == 0 || n == r) return 1; if (n == 0) return 0; if (n < 0 || n < r) throw new ArgumentException("n,r invalid"); else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long[,] C(int N) { long[,] Co = new long[N + 1, N + 1]; (N + 1).REP(i => (i + 1).REP(j => Co[i, j] = (j == 0 || j == i) ? 1L : Co[i - 1, j - 1] + Co[i - 1, j])); return Co; } public long DupC(long n, long r) { return ModC(n + r - 1, r); } public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, n) => GCD(v, n)); } public T Max<T>(params T[] a) { return a.Max(); } public T Min<T>(params T[] a) { return a.Min(); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int[] DigArr(int n) { int[] ret = new int[Digit(n)]; ret.Length.REP(i => ret[i] = DigVal(n, i + 1)); return ret; } public long DigArr2Num(IEnumerable<int> enu) { return enu.Aggregate((v, n) => v * 10 + n); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public long Tousa(long a, long d, long n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, long n) { return n * (2 * a + (n - 1) * d) / 2; } public long[] enuDivsor(long N) { var ret = new SortedSet<long>(); for (long i = 1; i * i <= N; i++) if (N % i == 0) { ret.Add(i); ret.Add(N / i); } return ret.ToArray(); } public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<List<int>>(); Arr.Length.REPR(i => s.Push(new List<int>() { i })); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) { var ret = new List<int>(); cur.ForEach(X => ret.Add(Arr[X])); yield return ret.ToArray(); } else Arr.Length.REPR(i => { if (!cur.Contains(i)) s.Push(new List<int>(cur) { i }); }); } } public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<List<int>>(); Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] })); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) yield return cur.ToArray(); else Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] })); } } public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<long[]> enuPart(string str) { var s = new Stack<Tuple<string, List<long>, int>>(); s.Push(Tuple.Create(str[0].ToString(), new List<long>(), 1)); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item3 >= str.Length) yield return (new List<long>(cur.Item2) { cur.Item1.toLong() }) .ToArray(); else { s.Push(Tuple.Create(cur.Item1 + str[cur.Item3], new List<long>(cur.Item2), cur.Item3 + 1)); s.Push(Tuple.Create(str[cur.Item3].ToString(), new List<long>(cur.Item2) { cur.Item1.toLong() }, cur.Item3 + 1)); } } } } class Time { public int[] M = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; public int[] D = { 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; public Time() { D[1] = 28; } public Time(int y) { D[1] = isLeapYear(y) ? 29 : 28; } public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } #endregion #region Data class AssociativeArray<T> : IEnumerable { public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(T a) { if (!conK(a)) dic[a] = 0; dic[a]++; } public void Add(params T[] a) { a.Length.REP(i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { a.Length.REP(i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => MaxK(); public T MinKey => MinK(); public T MaxK() { var maxV = MaxVal; return dic.First(d => d.Value == maxV).Key; } public T MinK() { var minV = MinVal; return dic.First(d => d.Value == minV).Key; } public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } public T[] ValueSortedKey(bool inc = true) { // test return (inc ? (dic.OrderBy(kp => kp.Value)) : (dic.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } //:sort->array } class Index { public int[] Comp(int[] bef) { int[] aft = new int[bef.Length]; var tmp = bef.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); aft = bef.Select(v => tmp[v]).ToArray(); return aft; } } class TreeDis { // TODO:shortestPath public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; g.Length.REP(i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class ShortestPath { public long INF = (long)1e15; protected int I = -1; protected int V; protected int E; public long[] cost; public List<Tuple<int, long>>[] Adj; protected bool isNonDir = true; public void Init(int n) { I = n + 1; V = n; Adj = new List<Tuple<int, long>>[I]; I.REP(i => Adj[i] = new List<Tuple<int, long>>()); } public void AddPath(int f, int t, long c) { E++; if (isNonDir) { Adj[f].Add(Tuple.Create(t, c)); Adj[t].Add(Tuple.Create(f, c)); } else { Adj[f].Add(Tuple.Create(t, c)); } } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } } class Dijkstra : ShortestPath { //隣接対応後検証不足,有向とか public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; var pq = new PQueue<Tuple<int, long>>(); pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost) while (pq.Count > 0) { var cur = pq.Dequeue(); if (cost[cur.Item1] < cur.Item2) continue; Adj[cur.Item1].Count.REP(i => { var tmp = Adj[cur.Item1][i]; if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) { cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2; pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1])); } }); } return cost[t]; } } class BellmanFord : ShortestPath { private bool[] neg; public BellmanFord() {} public BellmanFord(bool isNonDir) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; neg = new bool[I]; for (int i = 0; i < I - 1; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) cost[cur.Item1] = cost[j] + cur.Item2; })); } for (int i = 0; i < I; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) { cost[cur.Item1] = cost[j] + cur.Item2; neg[cur.Item1] = true; } if (neg[j]) neg[cur.Item1] = true; })); } return cost[t]; } public bool loopExist() { return neg[I - 1]; } } class WarshallFloyd { //そのうちAdjとどっちがいいか...TODO:ジェネリック private int E; private int INF = (int)1e9; public long[,] G; public void Init(int n) { E = n + 1; G = new long[E, E]; G.Set(INF); E.REP(i => G[i, i] = 0); } public void AddPath(int f, int t, long c) { G[f, t] = c; G[t, f] = c; } public void AddPath(int[] f, int[] t) { f.Length.REP(i => AddPath(f[i], t[i], 1)); } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } public void Run() { G = MinCostArr(); } public long[,] MinCostArr() { E.REP(i => E.REP( j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k])))); return G; } } class UnionFind { public long[] parent; public long[] depth; private int I; public void Init(int n) { I = n + 1; parent = new long[I]; depth = new long[I]; I.REP(i => parent[i] = i); } public long Find(long x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(long x, long y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(int a, int b) { return Find(a) == Find(b); } public long Size(int x) { return depth[Find(x)]; } } class Kruskal : ShortestPath { // TODO:test, public long Run() { var L = Adj.Select((l, i) => Tuple.Create(i, l[i].Item1, l[i].Item2)) .OrderBy(t => t.Item3) .ToList(); // var li = new List<Tuple<int, int, long>>(); // I.REP(i =>{ foreach (var t in Adj[i]) li.Add(Tuple.Create(i, t.Item1, // t.Item2));}); li = li.OrderBy(t => t.Item3).ToList();//li = // li.OrderByDescending(t => t.Item3).ToList(); var uf = new UnionFind(); uf.Init(V); long ret = 0; foreach (var t in L) { if (!uf.Same(t.Item1, t.Item2)) { ret += t.Item3; uf.Unite(t.Item1, t.Item2); } } return ret; } } #endregion #region Ex static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static long toLong(this string s) { long n; return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0; } public static long toLong(this char c) { return toLong(c.ToString()); } public static long toLong(this char[] c) { return toLong(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); } public static bool Odd(this int v) { return v % 2 != 0; } public static bool Odd(this long v) { return v % 2 != 0; } public static void REP(this int v, Action<int> act) { for (int i = 0; i < v; ++i) act(i); } public static void REPR(this int v, Action<int> act) { for (int i = v - 1; i >= 0; --i) act(i); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static T[] SortR<T>(this T[] a) { Array.Sort(a); Array.Reverse(a); return a; } public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v)); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class IEnumerableEx { // } #endregion }
[["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 12, 16, 31, 16, 31, 16, 31, 252, 0, 104], ["-", 12, 16, 31, 16, 31, 16, 31, 252, 0, 253], ["-", 15, 16, 12, 16, 31, 16, 31, 16, 17, 33], ["-", 12, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 0, 28, 0, 218, 8, 196, 0, 57, 0, 25], ["-", 0, 218, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 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], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["-", 64, 196, 0, 1, 0, 11, 12, 252, 0, 253], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 28, 0, 218, 8, 196, 0, 57, 0, 25], ["+", 0, 218, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 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], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 252, 0, 104], ["+", 64, 196, 0, 1, 0, 11, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
7,501
40
using System; namespace codefestival_2016_qualA_c { class Program { static void Main() { char[] s = Console.ReadLine().ToCharArray(); long k = long.Parse(Console.ReadLine()); for (int i = 0; i < s.Length - 1; i++) { if (s[i] + k > 'z') { k -= 'z' + 1 - s[i]; s[i] = 'a'; } } k %= 26; long x = s[s.Length - 1] + k; if (x > 'z') x -= 26; s[s.Length - 1] = (char)x; Console.WriteLine(s); } } }
using System; namespace codefestival_2016_qualA_c { class Program { static void Main() { char[] s = Console.ReadLine().ToCharArray(); long k = long.Parse(Console.ReadLine()); for (int i = 0; i < s.Length - 1; i++) { if (s[i] != 'a' && s[i] + k > 'z') { k -= 'z' + 1 - s[i]; s[i] = 'a'; } } k %= 26; long x = s[s.Length - 1] + k; if (x > 'z') x -= 26; s[s.Length - 1] = (char)x; Console.WriteLine(s); } } }
[["+", 8, 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, 7, 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, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73]]
8
155
9
using System; using System.Linq; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; using System.Diagnostics; class Program { static void Main() { char[] s = Console.ReadLine().ToCharArray(); long k = long.Parse(Console.ReadLine()); long remain = k; for (int i = 0; i < s.Length; i++) { int gap = 'z' - s[i] + 1; if (gap <= remain) { s[i] = 'a'; remain -= gap; } if (remain == 0) break; } s[s.Length - 1] = (char)(s[s.Length - 1] + remain % 26); for (int i = 0; i < s.Length; i++) { Console.Write(s[i]); } Console.WriteLine(); } }
using System; using System.Linq; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; using System.Diagnostics; class Program { static void Main() { char[] s = Console.ReadLine().ToCharArray(); long k = long.Parse(Console.ReadLine()); long remain = k; for (int i = 0; i < s.Length; i++) { if (s[i] == 'a') continue; int gap = 'z' - s[i] + 1; if (gap <= remain) { s[i] = 'a'; remain -= gap; } if (remain == 0) break; } s[s.Length - 1] = (char)(s[s.Length - 1] + remain % 26); for (int i = 0; i < s.Length; i++) { Console.Write(s[i]); } Console.WriteLine(); } }
[["+", 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, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 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, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
202
13
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; namespace tes { class contest { static void Main(string[] args) { var s = Console.ReadLine(); var num = int.Parse(Console.ReadLine()); var c = s.ToArray(); for (int i = 0; i < c.Length; i++) { int need = 26 - (c[i] - 'a'); if (num >= need) { c[i] = 'a'; num -= need; } if (i == c.Length - 1 && num > 0) { if (num >= 26) num %= 26; c[i] = (char)(c[i] + num); } } Console.WriteLine(new string(c)); } } }
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; namespace tes { class contest { static void Main(string[] args) { var s = Console.ReadLine(); var num = int.Parse(Console.ReadLine()); var c = s.ToArray(); for (int i = 0; i < c.Length; i++) { if (c[i] == 'a' && i != c.Length - 1) continue; int need = 26 - (c[i] - 'a'); if (num >= need) { c[i] = 'a'; num -= need; } if (i == c.Length - 1 && num > 0) { if (num >= 26) num %= 26; c[i] = (char)(c[i] + num); } } Console.WriteLine(new string(c)); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 252, 0, 104], ["+", 0, 57, 15, 16, 31, 16, 12, 252, 0, 253], ["+", 0, 7, 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, 79], ["+", 15, 16, 12, 16, 12, 16, 31, 214, 205, 22], ["+", 15, 16, 12, 16, 12, 16, 31, 214, 0, 131], ["+", 15, 16, 12, 16, 12, 16, 31, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
192
21
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; char[] inpt = Reader.ReadLine().ToArray(); long cnt = long.Parse(Reader.ReadLine()); for (int i = 0; i < inpt.Length; i++) { if (cnt == 0) { break; } int diff = 'z' - inpt[i]; if (cnt > diff) { inpt[i] = 'a'; cnt -= (diff + 1); } } if (cnt > 0) { cnt = cnt % 26; inpt[inpt.Length - 1] = (char)((int)inpt[inpt.Length - 1] + cnt); } Console.WriteLine(string.Join(string.Empty, inpt)); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" a 25 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; char[] inpt = Reader.ReadLine().ToArray(); long cnt = long.Parse(Reader.ReadLine()); for (int i = 0; i < inpt.Length; i++) { if (cnt == 0) { break; } if (inpt[i] == 'a') { continue; } int diff = 'z' - inpt[i]; if (cnt > diff) { inpt[i] = 'a'; cnt -= (diff + 1); } } if (cnt > 0) { cnt = cnt % 26; inpt[inpt.Length - 1] = (char)((int)inpt[inpt.Length - 1] + cnt); } Console.WriteLine(string.Join(string.Empty, inpt)); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" a 1000000000 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 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, 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], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
8
295
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ini; for (int i = 0; i < m; ++i) update(i, ini); } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public T look(int i) { return tree[i + n - 1]; } // [s, t] public T run(int s, int t) { return query(s, t + 1, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } namespace Codeforces { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); char[] input_arr = input.ToCharArray(); for (int i = 0; i < input.Length; i++) { if ((26 - (input_arr[i] - 'a')) <= k) { k -= (26 - (input_arr[i] - 'a')); input_arr[i] = 'a'; } if (i == input.Length - 1) { input_arr[i] = (char)(((input_arr[i] - 'a') + k) % 26 + 'a'); } } foreach (char c in input_arr) Console.Write(c); Console.WriteLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ini; for (int i = 0; i < m; ++i) update(i, ini); } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public T look(int i) { return tree[i + n - 1]; } // [s, t] public T run(int s, int t) { return query(s, t + 1, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } namespace Codeforces { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); char[] input_arr = input.ToCharArray(); for (int i = 0; i < input.Length; i++) { if (i != input.Length - 1 && input_arr[i] == 'a') continue; if ((26 - (input_arr[i] - 'a')) <= k) { k -= (26 - (input_arr[i] - 'a')); input_arr[i] = 'a'; if (k == 0) break; } if (i == input.Length - 1) { input_arr[i] = (char)(((input_arr[i] - 'a') + k) % 26 + 'a'); } } foreach (char c in input_arr) Console.Write(c); Console.WriteLine(); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 205, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 0, 131], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 7, 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, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 104], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253], ["+", 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, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 93, 0, 94]]
8
655
29
using System; using System.Collections.Generic; using System.Linq; using System.IO; class Program { const int M = 1000000007; const double eps = 1e-9; static int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var sc = new Scan(); var s = sc.Str; int k = sc.Int; int cnt = 0; for (int i = 0; i < s.Length; i++) { cnt += ('a' + 26 - s[i]) % 26; if (cnt > k) { int c2 = k - cnt + ('a' + 26 - s[i]) % 26; for (int j = i; j < s.Length; j++) { if (j == s.Length - 1) { sw.Write((char)(s[j] + c2 % 26)); } else if (('a' + 26 - s[j]) % 26 <= c2) { sw.Write("a"); c2 -= ('a' + 26 - s[j]) % 26; } else { sw.Write(s[j]); } } sw.WriteLine(); sw.Flush(); return; } if (i == s.Length - 1) { sw.Write((char)('a' + (k - cnt) % 26)); } else sw.Write("a"); } sw.WriteLine(); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static void swap<T>(IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG<T>(params T[] a) { Console.WriteLine(string.Join(" ", a)); } static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); } static T[] copy<T>(IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public int[] IntArrWithSep(char sep) { return Str.Split(sep).Select(int.Parse).ToArray(); } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } T cv<T>(string inp) { if (typeof(T).Equals(typeof(int))) return (T)Convert.ChangeType(int.Parse(inp), typeof(T)); if (typeof(T).Equals(typeof(long))) return (T)Convert.ChangeType(long.Parse(inp), typeof(T)); if (typeof(T).Equals(typeof(double))) return (T)Convert.ChangeType(double.Parse(inp), typeof(T)); if (typeof(T).Equals(typeof(char))) return (T)Convert.ChangeType(inp[0], typeof(T)); return (T)Convert.ChangeType(inp, typeof(T)); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } class mymath { static int Mod = 1000000007; public void setMod(int m) { Mod = m; } public bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public bool[] sieve(int n) { var isp = new bool[n + 1]; for (int i = 2; i <= n; i++) isp[i] = true; for (int i = 2; i * i <= n; i++) if (isp[i]) for (int j = i * i; j <= n; j += i) isp[j] = false; return isp; } public List<int> getprimes(int n) { var prs = new List<int>(); var isp = sieve(n); for (int i = 2; i <= n; i++) if (isp[i]) prs.Add(i); return prs; } public long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public long[][] powmat(long[][] A, long n) { if (n == 0) return E(A.Length); var t = powmat(A, n / 2); if ((n & 1) == 0) return mulmat(t, t); return mulmat(mulmat(t, t), A); } public long[] mulmat(long[][] A, long[] x) { int n = A.Length, m = x.Length; var ans = new long[n]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ans[i] = (ans[i] + x[j] * A[i][j]) % Mod; return ans; } public long[][] mulmat(long[][] A, long[][] B) { int n = A.Length, m = B[0].Length, l = B.Length; var ans = new long [n][]; for (int i = 0; i < n; i++) { ans[i] = new long[m]; for (int j = 0; j < m; j++) for (int k = 0; k < l; k++) ans[i][j] = (ans[i][j] + A[i][k] * B[k][j]) % Mod; } return ans; } public long[] addmat(long[] x, long[] y) { int n = x.Length; var ans = new long[n]; for (int i = 0; i < n; i++) ans[i] = (x[i] + y[i]) % Mod; return ans; } public long[][] addmat(long[][] A, long[][] B) { int n = A.Length, m = A[0].Length; var ans = new long [n][]; for (int i = 0; i < n; i++) ans[i] = addmat(A[i], B[i]); return ans; } public long powmod(long a, long b) { if (a >= Mod) return powmod(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = powmod(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public long inv(long a) { return powmod(a, Mod - 2); } public long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } public long lcm(long a, long b) { return a * (b / gcd(a, b)); } public long Comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; var numerator = new int[r]; var denominator = new int[r]; for (int k = 0; k < r; k++) { numerator[k] = n - r + k + 1; denominator[k] = k + 1; } for (int p = 2; p <= r; p++) { int pivot = denominator[p - 1]; if (pivot > 1) { int offset = (n - r) % p; for (int k = p - 1; k < r; k += p) { numerator[k - offset] /= pivot; denominator[k] /= pivot; } } } long result = 1; for (int k = 0; k < r; k++) if (numerator[k] > 1) result = result * numerator[k] % Mod; return result; } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; class Program { const int M = 1000000007; const double eps = 1e-9; static int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var sc = new Scan(); var s = sc.Str; int k = sc.Int; int cnt = 0; for (int i = 0; i < s.Length; i++) { cnt += ('a' + 26 - s[i]) % 26; if (cnt > k) { int c2 = k - cnt + ('a' + 26 - s[i]) % 26; for (int j = i; j < s.Length; j++) { if (j == s.Length - 1) { sw.Write((char)((s[j] - 'a' + c2) % 26 + 'a')); } else if (('a' + 26 - s[j]) % 26 <= c2) { sw.Write("a"); c2 -= ('a' + 26 - s[j]) % 26; } else { sw.Write(s[j]); } } sw.WriteLine(); sw.Flush(); return; } if (i == s.Length - 1) { sw.Write((char)('a' + (k - cnt) % 26)); } else sw.Write("a"); } sw.WriteLine(); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static void swap<T>(IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG<T>(params T[] a) { Console.WriteLine(string.Join(" ", a)); } static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); } static T[] copy<T>(IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public int[] IntArrWithSep(char sep) { return Str.Split(sep).Select(int.Parse).ToArray(); } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } T cv<T>(string inp) { if (typeof(T).Equals(typeof(int))) return (T)Convert.ChangeType(int.Parse(inp), typeof(T)); if (typeof(T).Equals(typeof(long))) return (T)Convert.ChangeType(long.Parse(inp), typeof(T)); if (typeof(T).Equals(typeof(double))) return (T)Convert.ChangeType(double.Parse(inp), typeof(T)); if (typeof(T).Equals(typeof(char))) return (T)Convert.ChangeType(inp[0], typeof(T)); return (T)Convert.ChangeType(inp, typeof(T)); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } class mymath { static int Mod = 1000000007; public void setMod(int m) { Mod = m; } public bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public bool[] sieve(int n) { var isp = new bool[n + 1]; for (int i = 2; i <= n; i++) isp[i] = true; for (int i = 2; i * i <= n; i++) if (isp[i]) for (int j = i * i; j <= n; j += i) isp[j] = false; return isp; } public List<int> getprimes(int n) { var prs = new List<int>(); var isp = sieve(n); for (int i = 2; i <= n; i++) if (isp[i]) prs.Add(i); return prs; } public long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public long[][] powmat(long[][] A, long n) { if (n == 0) return E(A.Length); var t = powmat(A, n / 2); if ((n & 1) == 0) return mulmat(t, t); return mulmat(mulmat(t, t), A); } public long[] mulmat(long[][] A, long[] x) { int n = A.Length, m = x.Length; var ans = new long[n]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) ans[i] = (ans[i] + x[j] * A[i][j]) % Mod; return ans; } public long[][] mulmat(long[][] A, long[][] B) { int n = A.Length, m = B[0].Length, l = B.Length; var ans = new long [n][]; for (int i = 0; i < n; i++) { ans[i] = new long[m]; for (int j = 0; j < m; j++) for (int k = 0; k < l; k++) ans[i][j] = (ans[i][j] + A[i][k] * B[k][j]) % Mod; } return ans; } public long[] addmat(long[] x, long[] y) { int n = x.Length; var ans = new long[n]; for (int i = 0; i < n; i++) ans[i] = (x[i] + y[i]) % Mod; return ans; } public long[][] addmat(long[][] A, long[][] B) { int n = A.Length, m = A[0].Length; var ans = new long [n][]; for (int i = 0; i < n; i++) ans[i] = addmat(A[i], B[i]); return ans; } public long powmod(long a, long b) { if (a >= Mod) return powmod(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = powmod(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public long inv(long a) { return powmod(a, Mod - 2); } public long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } public long lcm(long a, long b) { return a * (b / gcd(a, b)); } public long Comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; var numerator = new int[r]; var denominator = new int[r]; for (int k = 0; k < r; k++) { numerator[k] = n - r + k + 1; denominator[k] = k + 1; } for (int p = 2; p <= r; p++) { int pivot = denominator[p - 1]; if (pivot > 1) { int offset = (n - r) % p; for (int k = p - 1; k < r; k += p) { numerator[k - offset] /= pivot; denominator[k] /= pivot; } } } long result = 1; for (int k = 0; k < r; k++) if (numerator[k] > 1) result = result * numerator[k] % Mod; return result; } }
[["+", 51, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 31, 23, 0, 16, 31, 16, 12, 252, 0, 104], ["+", 31, 23, 0, 16, 31, 16, 12, 252, 0, 253], ["+", 51, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 28, 0, 74, 51, 23, 0, 16, 17, 72], ["+", 0, 74, 51, 23, 0, 16, 12, 252, 0, 104], ["+", 0, 74, 51, 23, 0, 16, 12, 252, 0, 253]]
8
2,466
10
using System; using System.Linq; using System.Linq.Expressions; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using System.Numerics; using Number = System.Int64; namespace Program { public class Solver { public void Solve() { var r = sc.Integer(); var c = sc.Integer(); var G = Enumerate(r + c, x => new List<KeyValuePair<int, long>>()); var n = sc.Integer(); for (int i = 0; i < n; i++) { var p = sc.Integer() - 1; var q = sc.Integer() - 1 + r; var x = sc.Integer(); G[p].Add(new KeyValuePair<int, Number>(q, x)); G[q].Add(new KeyValuePair<int, Number>(p, x)); } var used = Enumerate(r + c, x => long.MinValue); var ok = true; long a, b; a = b = long.MaxValue; Action<int, long> dfs = null; dfs = (pos, val) => { if (pos < r) a = Math.Min(a, val); else b = Math.Min(b, val); used[pos] = val; foreach (var to in G[pos]) { if (used[to.Key] == long.MinValue) dfs(to.Key, to.Value - val); else if (used[to.Key] != to.Value - val) ok = false; } }; for (int i = 0; i < r + c; i++) { if (used[i] != long.MinValue) continue; a = b = long.MaxValue; dfs(i, 0); ok &= Math.Min(a, b) >= 0; } Debug.WriteLine(used.AsJoinedString()); if (ok) IO.Printer.Out.WriteLine("Yes"); else IO.Printer.Out.WriteLine("No"); } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion
using System; using System.Linq; using System.Linq.Expressions; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using System.Numerics; using Number = System.Int64; namespace Program { public class Solver { public void Solve() { var r = sc.Integer(); var c = sc.Integer(); var G = Enumerate(r + c, x => new List<KeyValuePair<int, long>>()); var n = sc.Integer(); for (int i = 0; i < n; i++) { var p = sc.Integer() - 1; var q = sc.Integer() - 1 + r; var x = sc.Integer(); G[p].Add(new KeyValuePair<int, Number>(q, x)); G[q].Add(new KeyValuePair<int, Number>(p, x)); } var used = Enumerate(r + c, x => long.MinValue); var ok = true; long a, b; a = b = long.MaxValue; Action<int, long> dfs = null; dfs = (pos, val) => { if (pos < r) a = Math.Min(a, val); else b = Math.Min(b, val); used[pos] = val; foreach (var to in G[pos]) { if (used[to.Key] == long.MinValue) dfs(to.Key, to.Value - val); else if (used[to.Key] != to.Value - val) ok = false; } }; for (int i = 0; i < r + c; i++) { if (used[i] != long.MinValue) continue; a = b = 1L << 60; dfs(i, 0); ok &= a + b >= 0; } Debug.WriteLine(used.AsJoinedString()); if (ok) IO.Printer.Out.WriteLine("Yes"); else IO.Printer.Out.WriteLine("No"); } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion
[["-", 0, 1, 0, 11, 12, 11, 12, 214, 205, 199], ["-", 0, 1, 0, 11, 12, 11, 12, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 11, 12, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 11, 12, 16, 31, 203], ["+", 0, 1, 0, 11, 12, 11, 12, 16, 17, 151], ["+", 0, 1, 0, 11, 12, 11, 12, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 11, 12, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 11, 12, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 16, 31, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["-", 0, 11, 12, 16, 31, 213, 3, 4, 0, 25]]
8
1,516
13
using System; using System.Linq; namespace ABC045 { class B { static void Main(string[] args) { var sa = Console.ReadLine().ToList(); var sb = Console.ReadLine().ToList(); var sc = Console.ReadLine().ToList(); char c = sa[0]; sa.RemoveAt(0); // Console.WriteLine(string.Join(',', sa)); for (int i = 0; 0 <= sa.Count && 0 <= sb.Count && 0 <= sc.Count; i++) { if (c == 'a' && sa.Count == 0) { Console.WriteLine('A'); return; } if (c == 'b' && sb.Count == 0) { Console.WriteLine('B'); return; } if (c == 'c' && sc.Count == 0) { Console.WriteLine('C'); return; } if (c == 'a') { c = sa[0]; sa.RemoveAt(0); } if (c == 'b') { c = sb[0]; sb.RemoveAt(0); } if (c == 'c') { c = sc[0]; sc.RemoveAt(0); } } } } }
using System; using System.Linq; namespace ABC045 { class B { static void Main(string[] args) { var sa = Console.ReadLine().ToList(); var sb = Console.ReadLine().ToList(); var sc = Console.ReadLine().ToList(); char c = sa[0]; sa.RemoveAt(0); // Console.WriteLine(string.Join(',', sa)); for (int i = 0; 0 <= sa.Count && 0 <= sb.Count && 0 <= sc.Count; i++) { if (c == 'a' && sa.Count == 0) { Console.WriteLine('A'); return; } if (c == 'b' && sb.Count == 0) { Console.WriteLine('B'); return; } if (c == 'c' && sc.Count == 0) { Console.WriteLine('C'); return; } if (0 < sa.Count && c == 'a') { c = sa[0]; sa.RemoveAt(0); } if (0 < sb.Count && c == 'b') { c = sb[0]; sb.RemoveAt(0); } if (0 < sc.Count && c == 'c') { c = sc[0]; sc.RemoveAt(0); } } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
265
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B_016_45 { internal class Program { private static void Main(string[] args) { new Logic_B().Start(); } public class Logic_B { public void Start() { var A = Console.ReadLine(); var B = Console.ReadLine(); var C = Console.ReadLine(); var Aindex = 0; var Bindex = 0; var Cindex = 0; var turnNum = Math.Max(Math.Max(A.Length, B.Length), C.Length); var winner = string.Empty; var card = 'a'; for (int i = 0; i <= turnNum * 3; i++) { Console.Write(card.ToString() + " "); if (card == 'a' && Aindex == A.Length) { winner = "A"; break; } else if (card == 'b' && Bindex == B.Length) { winner = "B"; break; } else if (card == 'c' && Cindex == C.Length) { winner = "C"; break; } switch (card) { case 'a': card = A[Aindex]; Aindex++; break; case 'b': card = B[Bindex]; Bindex++; break; case 'c': card = C[Cindex]; Cindex++; break; default: break; } } Console.WriteLine(winner); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B_016_45 { internal class Program { private static void Main(string[] args) { // new Logic_A().Start(); new Logic_B().Start(); Console.ReadLine(); } public class Logic_B { public void Start() { var A = Console.ReadLine(); var B = Console.ReadLine(); var C = Console.ReadLine(); var Aindex = 0; var Bindex = 0; var Cindex = 0; var turnNum = Math.Max(Math.Max(A.Length, B.Length), C.Length); var winner = string.Empty; var card = 'a'; for (int i = 0; i <= turnNum * 3; i++) { // Console.Write(card.ToString() + " "); if (card == 'a' && Aindex == A.Length) { winner = "A"; break; } else if (card == 'b' && Bindex == B.Length) { winner = "B"; break; } else if (card == 'c' && Cindex == C.Length) { winner = "C"; break; } switch (card) { case 'a': card = A[Aindex]; Aindex++; break; case 'b': card = B[Bindex]; Bindex++; break; case 'c': card = C[Cindex]; Cindex++; break; default: break; } } Console.WriteLine(winner); } } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
325
21
using System; using System.IO; public class CodeFile1 { public static void Main() { string a_hand = Console.ReadLine(); string b_hand = Console.ReadLine(); string c_hand = Console.ReadLine(); turn(a_hand, b_hand, c_hand, 0, 0, 0, "a"); } public static void turn(string a_hand, string b_hand, string c_hand, int a, int b, int c, string who) { if (who == "a") { if (a + 1 == a_hand.Length) { Console.WriteLine("A"); } else turn(a_hand, b_hand, c_hand, a + 1, b, c, a_hand[a + 1].ToString()); } if (who == "b") { if (b + 1 == b_hand.Length) Console.WriteLine("B"); else turn(a_hand, b_hand, c_hand, a, b + 1, c, b_hand[b + 1].ToString()); } if (who == "c") { if (c + 1 == c_hand.Length) Console.WriteLine("C"); else turn(a_hand, b_hand, c_hand, a, b, c + 1, c_hand[c + 1].ToString()); } } }
using System; using System.IO; public class CodeFile1 { public static void Main() { string a_hand = Console.ReadLine(); string b_hand = Console.ReadLine(); string c_hand = Console.ReadLine(); turn(a_hand, b_hand, c_hand, 0, 0, 0, "a"); } public static void turn(string a_hand, string b_hand, string c_hand, int a, int b, int c, string who) { if (who == "a") { if (a == a_hand.Length) { Console.WriteLine("A"); } else turn(a_hand, b_hand, c_hand, a + 1, b, c, a_hand[a].ToString()); } if (who == "b") { if (b == b_hand.Length) Console.WriteLine("B"); else turn(a_hand, b_hand, c_hand, a, b + 1, c, b_hand[b].ToString()); } if (who == "c") { if (c == c_hand.Length) Console.WriteLine("C"); else turn(a_hand, b_hand, c_hand, a, b, c + 1, c_hand[c].ToString()); } } }
[["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
271
12