buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { var (i, o, t, j, l, s, z) = cin.ReadValue<long, long, long, long, long, long, long>(); long ans = i / 2 * 2 + o + j / 2 * 2 + t / 2 * 2; if (i > 0 && j > 0 && l > 0) Chmax(ref ans, (i - 1) / 2 * 2 + o + (j - 1) / 2 * 2 + (l - 1) / 2 * 2 + 3); Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.C { static class Program { public static void Solve(Scanner cin) { var (i, o, t, j, l, s, z) = cin.ReadValue<long, long, long, long, long, long, long>(); long ans = i / 2 * 2 + o + j / 2 * 2 + l / 2 * 2; if (i > 0 && j > 0 && l > 0) Chmax(ref ans, (i - 1) / 2 * 2 + o + (j - 1) / 2 * 2 + (l - 1) / 2 * 2 + 3); Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["-", 0, 212, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 16, 31, 16, 31, 22]]
8
2,740
2
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Diagnostics; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var minos = Console.ReadLine().Split().Select(int.Parse).ToArray(); var I = minos[0]; var O = minos[1]; var J = minos[3]; var L = minos[4]; long res = (I / 2 + J / 2 + L / 2) * 2; if (J != 0 && L != 0 && I != 0) res = Max(res, ((I - 1) / 2 + (J - 1) / 2 + (L - 1) / 2) * 2 + 3); res += O; Console.WriteLine(res); } }
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Diagnostics; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var minos = Console.ReadLine().Split().Select(long.Parse).ToArray(); var I = minos[0]; var O = minos[1]; var J = minos[3]; var L = minos[4]; long res = (I / 2 + J / 2 + L / 2) * 2; if (J != 0 && L != 0 && I != 0) res = Max(res, ((I - 1) / 2 + (J - 1) / 2 + (L - 1) / 2) * 2 + 3); res += O; Console.WriteLine(res); } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
228
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var ar = Input.ar; var res = ar[1]; res += ar[0] / 2 * 2; res += ar[3] / 2 * 2; res += ar[4] / 2 * 2; res += 3 * ToInt32(ar[0] % 2 == 1 && ar[3] % 2 == 1 && ar[4] % 2 == 1); var r = ar[1]; if (ar[0] > 0 && ar[3] > 0 && ar[4] > 0) { r += 3; ar[0]--; ar[3]--; ar[4]--; } r += ar[0] / 2 * 2; r += ar[3] / 2 * 2; r += ar[4] / 2 * 2; WriteLine(Max(res, r)); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[][] ar2D(int num) => Enumerable.Repeat(0, num).Select(_ => ar).ToArray(); public static long[][] arL2D(int num) => Enumerable.Repeat(0, num).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var ar = Input.arL; var res = ar[1]; res += ar[0] / 2 * 2; res += ar[3] / 2 * 2; res += ar[4] / 2 * 2; res += 3 * ToInt32(ar[0] % 2 == 1 && ar[3] % 2 == 1 && ar[4] % 2 == 1); var r = ar[1]; if (ar[0] > 0 && ar[3] > 0 && ar[4] > 0) { r += 3; ar[0]--; ar[3]--; ar[4]--; } r += ar[0] / 2 * 2; r += ar[3] / 2 * 2; r += ar[4] / 2 * 2; WriteLine(Max(res, r)); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[][] ar2D(int num) => Enumerable.Repeat(0, num).Select(_ => ar).ToArray(); public static long[][] arL2D(int num) => Enumerable.Repeat(0, num).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
635
2
using System; using System.Collections.Generic; using System.Linq; class Program { const int mod = 1000000007; const long o = 1; static void Main() { Sc sc = new Sc(); int[] a = sc.Ia; long b = a[1], c = a[1]; c += (a[0] & -2) + (a[3] & -2) + (a[4] & -2); if (a[0] % 2 == 1 && a[3] % 2 == 1 && a[4] % 2 == 1) { c++; } if (a[0] > 0 && a[3] > 0 && a[4] > 0) { a[3]--; a[4]--; a[0]--; b += 3; } b += (a[0] & -2) + (a[3] & -2) + (a[4] & -2); Console.WriteLine("{0}", Math.Max(c, b)); } } class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { const int mod = 1000000007; const long o = 1; static void Main() { Sc sc = new Sc(); long[] a = sc.La; long b = a[1], c = a[1]; c += (a[0] & -2) + (a[3] & -2) + (a[4] & -2); if (a[0] % 2 == 1 && a[3] % 2 == 1 && a[4] % 2 == 1) { c++; } if (a[0] > 0 && a[3] > 0 && a[4] > 0) { a[3]--; a[4]--; a[0]--; b += 3; } b += (a[0] & -2) + (a[3] & -2) + (a[4] & -2); Console.WriteLine("{0}", Math.Max(c, b)); } } class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
423
4
using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray(); long ret = x[1]; long[] a = new long[] { x[0], x[3], x[4] }; long aret = 0; aret += a[0] / 2 * 2; aret += a[1] / 2 * 2; aret += a[2] / 2 * 2; long[] b = new long[] { x[0] - 1, x[3] - 1, x[4] - 1 }; if (b.Min() >= 0) { long bret = 0; bret += b[0] / 2 * 2; bret += b[1] / 2 * 2; bret += b[2] / 2 * 2; Console.WriteLine(ret + Math.Max(aret, (bret + 1))); } else { Console.WriteLine(ret + aret); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray(); long ret = x[1]; long[] a = new long[] { x[0], x[3], x[4] }; long aret = 0; aret += a[0] / 2 * 2; aret += a[1] / 2 * 2; aret += a[2] / 2 * 2; long[] b = new long[] { x[0] - 1, x[3] - 1, x[4] - 1 }; if (b.Min() >= 0) { long bret = 0; bret += b[0] / 2 * 2; bret += b[1] / 2 * 2; bret += b[2] / 2 * 2; Console.WriteLine(ret + Math.Max(aret, (bret + 3))); } else { Console.WriteLine(ret + aret); } } } }
[["-", 3, 4, 0, 28, 0, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 23, 0, 16, 12, 203]]
8
246
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Threading; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { public Program() {} static void Main(string[] args) { new Program().prog(); } Scanner cin; const int MOD = 1000000007; const int INF = int.MaxValue - 10; const long INFL = long.MaxValue - 10; const double EPS = 1e-8; const double PI = 3.1415926536; int[,] dir8; int[,] dir4; void prog() { cin = new Scanner(); dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } }; dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } }; int I = cin.nextInt(); int O = cin.nextInt(); int T = cin.nextInt(); int J = cin.nextInt(); int L = cin.nextInt(); long ans1 = O; long ans2 = O; ans1 += (I / 2) * 2 + (J / 2) * 2 + (L / 2) * 2; if (I >= 1 && J >= 1 && L >= 1) { I--; J--; L--; ans2 += 3 + (I / 2) * 2 + (J / 2) * 2 + (L / 2) * 2; } Console.WriteLine(Math.Max(ans1, ans2)); } } 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.IO; using System.Threading; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { public Program() {} static void Main(string[] args) { new Program().prog(); } Scanner cin; const int MOD = 1000000007; const int INF = int.MaxValue - 10; const long INFL = long.MaxValue - 10; const double EPS = 1e-8; const double PI = 3.1415926536; int[,] dir8; int[,] dir4; void prog() { cin = new Scanner(); dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } }; dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } }; long I = cin.nextInt(); long O = cin.nextInt(); int T = cin.nextInt(); long J = cin.nextInt(); long L = cin.nextInt(); long ans1 = O; long ans2 = O; ans1 += (I / 2) * 2 + (J / 2) * 2 + (L / 2) * 2; if (I >= 1 && J >= 1 && L >= 1) { I--; J--; L--; ans2 += 3 + (I / 2) * 2 + (J / 2) * 2 + (L / 2) * 2; } Console.WriteLine(Math.Max(ans1, ans2)); } } 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()); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
556
8
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 I = int.Parse(str[0]); long O = int.Parse(str[1]); long J = int.Parse(str[3]); long L = int.Parse(str[4]); long count = I / 2 * 2 + O + J / 2 * 2 + L / 2 * 2; if (I >= 1 && J >= 1 && L >= 1) { count = Math.Max(count, 3 + (I - 1) / 2 * 2 + 0 + (J - 1) / 2 * 2 + (L - 1) / 2 * 2); } sb.Append(count + "\n"); } }
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); long I = int.Parse(str[0]); long O = int.Parse(str[1]); long J = int.Parse(str[3]); long L = int.Parse(str[4]); long count = I / 2 * 2 + O + J / 2 * 2 + L / 2 * 2; if (I >= 1 && J >= 1 && L >= 1) { count = Math.Max(count, 3 + (I - 1) / 2 * 2 + O + (J - 1) / 2 * 2 + (L - 1) / 2 * 2); } sb.Append(count + "\n"); } }
[["-", 0, 28, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 12, 22]]
8
245
2
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); // I, O, T, J, L, S, Z this.ICount = inpt[0]; this.OCount = inpt[1]; this.JCount = inpt[3]; this.LCount = inpt[4]; long ans = Math.Max(this.GetVal(1), this.GetVal(0)) + this.OCount; Console.WriteLine(ans); } private long GetVal(long join3) { long tmp = Math.Min(ICount, Math.Min(join3, Math.Min(this.JCount, this.ICount))); long ans = tmp * 3; long remainI = this.ICount - tmp; long remainJ = this.JCount - tmp; long remainL = this.LCount - tmp; ans += (remainI / 2) * 2; ans += (remainJ / 2) * 2; ans += (remainL / 2) * 2; return ans; } private long OCount = 0; private long ICount = 0; private long JCount = 0; private long LCount = 0; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 0 0 10 0 0 0 0 "; 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; long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); // I, O, T, J, L, S, Z this.ICount = inpt[0]; this.OCount = inpt[1]; this.JCount = inpt[3]; this.LCount = inpt[4]; long ans = Math.Max(this.GetVal(1), this.GetVal(0)) + this.OCount; Console.WriteLine(ans); } private long GetVal(long join3) { long tmp = Math.Min(ICount, Math.Min(join3, Math.Min(this.JCount, this.LCount))); long ans = tmp * 3; long remainI = this.ICount - tmp; long remainJ = this.JCount - tmp; long remainL = this.LCount - tmp; ans += (remainI / 2) * 2; ans += (remainJ / 2) * 2; ans += (remainL / 2) * 2; return ans; } private long OCount = 0; private long ICount = 0; private long JCount = 0; private long LCount = 0; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 0 0 10 0 0 0 0 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
8
377
2
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); // static Scan sc = new ScanCHK(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var a = sc.LongArr; long i = a[0], o = a[1], j = a[3], l = a[4]; long m = Min(i, j, l); i -= m; j -= m; l -= m; long k = o + m + i / 2 * 2 + j / 2 * 2 + l / 2 * 2; if (m > 0) { --m; ++i; ++j; ++l; k = Math.Max(k, o + m + i / 2 * 2 + j / 2 * 2 + l / 2 * 2); } Prt(k); 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 string con<T>(this IEnumerable<T> a) => a.con(" "); public static string con<T>(this IEnumerable<T> a, string s) => string.Join(s, a); 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 double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => 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 / gcd(a, b) * b; public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); // static Scan sc = new ScanCHK(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var a = sc.LongArr; long i = a[0], o = a[1], j = a[3], l = a[4]; long m = Min(i, j, l); i -= m; j -= m; l -= m; long k = o + m * 3 + i / 2 * 2 + j / 2 * 2 + l / 2 * 2; if (m > 0) { --m; ++i; ++j; ++l; k = Math.Max(k, o + m * 3 + i / 2 * 2 + j / 2 * 2 + l / 2 * 2); } Prt(k); 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 string con<T>(this IEnumerable<T> a) => a.con(" "); public static string con<T>(this IEnumerable<T> a, string s) => string.Join(s, a); 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 double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => 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 / gcd(a, b) * b; public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
[["+", 31, 16, 31, 16, 31, 16, 12, 16, 17, 48], ["+", 31, 16, 31, 16, 31, 16, 12, 16, 12, 203]]
8
3,009
4
using System; namespace abc050A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); string B = (str[1]); int C = int.Parse(str[2]); if (B == "+") Console.WriteLine(A + C); else Console.WriteLine(A + C); } } }
using System; namespace abc050A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); string B = (str[1]); int C = int.Parse(str[2]); if (B == "+") Console.WriteLine(A + C); else Console.WriteLine(A - C); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
101
2
using System; using static System.Console; using static System.Math; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Template { static void Main(string[] args) { var data = IO.ReadStrArr(); if (data[1] == "+") WriteLine(int.Parse(data[0]) + int.Parse(data[1])); else WriteLine(int.Parse(data[0]) - int.Parse(data[1])); } } public class IO { public static string ReadStr() => Console.ReadLine(); public static string[] ReadStrArr() => ReadStr().Split(' '); public static int ReadInt() => int.Parse(ReadStr()); public static int[] ReadIntArr() => Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); public static double ReadDouble() => double.Parse(ReadStr()); public static double[] ReadDoubleArr() => Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); public static long ReadLong() => long.Parse(ReadStr()); public static long[] ReadLongArr() => Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } }
using System; using static System.Console; using static System.Math; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Template { static void Main(string[] args) { var data = IO.ReadStrArr(); if (data[1] == "+") WriteLine(int.Parse(data[0]) + int.Parse(data[2])); else WriteLine(int.Parse(data[0]) - int.Parse(data[2])); } } public class IO { public static string ReadStr() => Console.ReadLine(); public static string[] ReadStrArr() => ReadStr().Split(' '); public static int ReadInt() => int.Parse(ReadStr()); public static int[] ReadIntArr() => Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); public static double ReadDouble() => double.Parse(ReadStr()); public static double[] ReadDoubleArr() => Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); public static long ReadLong() => long.Parse(ReadStr()); public static long[] ReadLongArr() => Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
304
4
using System; using System.Linq; class Program { static void Main(string[] args) { var AopB = Console.ReadLine().Split(' ').ToList(); Console.WriteLine(AopB[1] == "+" ? int.Parse(AopB[0]) + int.Parse(AopB[1]) : int.Parse(AopB[0]) - int.Parse(AopB[1])); } }
using System; using System.Linq; class Program { static void Main(string[] args) { var AopB = Console.ReadLine().Split(' ').ToList(); Console.WriteLine(AopB[1] == "+" ? int.Parse(AopB[0]) + int.Parse(AopB[2]) : int.Parse(AopB[0]) - int.Parse(AopB[2])); } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
97
4
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var input = Console.ReadLine().Split(' ').ToList(); if (input[1] == "+") { Console.WriteLine(int.Parse(input[0]) + int.Parse(input[2])); } else { Console.WriteLine(int.Parse(input[0]) + int.Parse(input[2])); } } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var input = Console.ReadLine().Split(' ').ToList(); if (input[1] == "+") { Console.WriteLine(int.Parse(input[0]) + int.Parse(input[2])); } else { Console.WriteLine(int.Parse(input[0]) - int.Parse(input[2])); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
112
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var ans = "NO"; var S = cin.ReadLine; var end = 0; for (var i = S.Length; true; i = i) { if (0 <= i - 5 && (S.Substring(i - 5, 5) == "dream" || S.Substring(i - 5, 5) == "erase")) { i = i - 5; } else if (0 <= i - 6 && (S.Substring(i - 6, 6) == "dreamer" || S.Substring(i - 6, 6) == "eraser")) { i = i - 6; } else if (0 <= i - 7 && (S.Substring(i - 7, 67) == "dreamer")) { i = i - 7; } else { end = i; break; } } if (end == 0) { ans = "YES"; } WriteLine(ans.ToString()); } } 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) { var ans = "NO"; var S = cin.ReadLine; var end = 0; for (var i = S.Length; true; i = i) { if (0 <= i - 5 && (S.Substring(i - 5, 5) == "dream" || S.Substring(i - 5, 5) == "erase")) { i = i - 5; } else if (0 <= i - 6 && (S.Substring(i - 6, 6) == "dreamer" || S.Substring(i - 6, 6) == "eraser")) { i = i - 6; } else if (0 <= i - 7 && (S.Substring(i - 7, 7) == "dreamer")) { i = i - 7; } else { end = i; break; } } if (end == 0) { ans = "YES"; } WriteLine(ans.ToString()); } } 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, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 203]]
8
623
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var divide = new String[] { "dream", "dreamer", "erase", "eraser" }; // 入力 String input = Console.ReadLine(); String inputR = new String(input.Reverse().ToArray()); var divideR = new String[4]; for (int i = 0; i < 4; i++) { divideR[i] = new String(divide[i].Reverse().ToArray()); } Boolean can = true; for (int i = 0; i < input.Length;) { // 4つの文字列のいずれかで一致するか Boolean can2 = false; for (int j = 0; j < 4; j++) { String d = divideR[j]; if ((i + d.Length) <= inputR.Length) { if (inputR.Substring(i, d.Length) == d) { can2 = true; i += d.Length; } } } if (!can2) { can = false; break; } } // 結果出力 if (can) { Console.WriteLine("YES"); } else { Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var divide = new String[] { "dream", "dreamer", "erase", "eraser" }; // 入力 String input = Console.ReadLine(); String inputR = new String(input.Reverse().ToArray()); var divideR = new String[4]; for (int i = 0; i < 4; i++) { divideR[i] = new String(divide[i].Reverse().ToArray()); } Boolean can = true; for (int i = 0; i < input.Length;) { // 4つの文字列のいずれかで一致するか Boolean can2 = false; for (int j = 0; j < 4; j++) { String d = divideR[j]; if ((i + d.Length) <= inputR.Length) { if (inputR.Substring(i, d.Length) == d) { can2 = true; i += d.Length; } } } if (!can2) { can = false; break; } } // 結果出力 if (can) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
264
2
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 = new string(ReadLine().Reverse().ToArray()); var b = 0; var match = new string[] { new string("dreamer".Reverse().ToArray()), new string("dream".Reverse().ToArray()), new string("eraser".Reverse().ToArray()), new string("erase".Reverse().ToArray()), }; while (b < S.Length) { var flag = false; foreach (var m in match) { if (S.Length - m.Length < b) continue; if (S.Substring(b, m.Length) == m) { flag = true; b += m.Length; break; } } if (!flag) { WriteLine("No"); return; } } WriteLine("Yes"); // 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 = new string(ReadLine().Reverse().ToArray()); var b = 0; var match = new string[] { new string("dreamer".Reverse().ToArray()), new string("dream".Reverse().ToArray()), new string("eraser".Reverse().ToArray()), new string("erase".Reverse().ToArray()), }; while (b < S.Length) { var flag = false; foreach (var m in match) { if (S.Length - m.Length < b) continue; if (S.Substring(b, m.Length) == m) { flag = true; b += m.Length; break; } } if (!flag) { WriteLine("NO"); return; } } WriteLine("YES"); // Out.Flush(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
308
4
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { var s = Console.ReadLine(); var reg = new Regex("^(dream|dreamer|erase|eraser)+$"); if (reg.IsMatch(s)) { Console.WriteLine("YES"); } else { 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() { return Tuple.Create(this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int> ReadTup3() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int, int> ReadTup4() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt(), this.ReadInt()); } 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<int, int>[] ReadTupArray(int n) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(); } return array; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { var s = Console.ReadLine(); var reg = new Regex("^(dream|dreamer|erase|eraser)+$"); if (reg.IsMatch(s)) { Console.WriteLine("YES"); } else { 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() { return Tuple.Create(this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int> ReadTup3() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int, int> ReadTup4() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt(), this.ReadInt()); } 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<int, int>[] ReadTupArray(int n) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(); } return array; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
908
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var S = sc.ReadStr(); S = new string(S.Reverse().ToArray()); var dream = new string("dream".Reverse().ToArray()); var dreamer = new string("dreamer".Reverse().ToArray()); var erase = new string("erase".Reverse().ToArray()); var eraser = new string("eraser".Reverse().ToArray()); var ok = true; for (int i = 0; i < S.Length; i++) { if (i + 5 - 1 < S.Length && S.Substring(i, 5) == dream) i += 4; else if (i + 7 - 1 < S.Length && S.Substring(i, 7) == dreamer) i += 6; else if (i + 5 - 1 < S.Length && S.Substring(i, 5) == erase) i += 4; else if (i + 6 - 1 < S.Length && S.Substring(i, 6) == eraser) i += 5; else { ok = false; break; } } Console.WriteLine(ok ? "Yes" : "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 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; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var S = sc.ReadStr(); S = new string(S.Reverse().ToArray()); var dream = new string("dream".Reverse().ToArray()); var dreamer = new string("dreamer".Reverse().ToArray()); var erase = new string("erase".Reverse().ToArray()); var eraser = new string("eraser".Reverse().ToArray()); var ok = true; for (int i = 0; i < S.Length; i++) { if (i + 5 - 1 < S.Length && S.Substring(i, 5) == dream) i += 4; else if (i + 7 - 1 < S.Length && S.Substring(i, 7) == dreamer) i += 6; else if (i + 5 - 1 < S.Length && S.Substring(i, 5) == erase) i += 4; else if (i + 6 - 1 < S.Length && S.Substring(i, 6) == eraser) i += 5; else { ok = false; break; } } Console.WriteLine(ok ? "YES" : "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 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; } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
802
4
using System; using System.Text; public class A { public static void Main() { StringBuilder sb = new StringBuilder(Console.ReadLine()); sb.Replace("eracer", ""); sb.Replace("erace", ""); sb.Replace("dreamer", ""); sb.Replace("dream", ""); if (sb.ToString() == "") { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; using System.Text; public class A { public static void Main() { StringBuilder sb = new StringBuilder(Console.ReadLine()); sb.Replace("eraser", ""); sb.Replace("erase", ""); sb.Replace("dreamer", ""); sb.Replace("dream", ""); if (sb.ToString() != "") { Console.WriteLine("NO"); } else { Console.WriteLine("YES"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79]]
8
116
10
using System; using System.Collections; using System.Collections.Generic; namespace 練習問題 { class Program { static void Main(string[] args) { List<int> pattern = new List<int>(); var sw = new System.Diagnostics.Stopwatch(); string s = ""; debug Debug = new debug(); if (args.Length == 0) { Debug.FlagFalse(); s = Console.ReadLine(); } else { Debug.FlagTrue(); if (args[0] == "1") { s = "erasedream"; } else if (args[0] == "2") { s = "dreameraser"; } else if (args[0] == "3") { s = "dreamerer"; } } string startS = s; string t = ""; sw.Start(); // 2秒以内ですねスタート while (startS != t) { if (s.Length >= 5) { if (s.Substring(s.Length - 5, 5) == "dream") { s = s.Substring(0, s.Length - 5); continue; } if (s.Length >= 7) { if (s.Substring(s.Length - 7, 7) == "dreamer") { s = s.Substring(0, s.Length - 7); continue; } } if (s.Substring(s.Length - 5, 5) == "erase") { s = s.Substring(0, s.Length - 5); continue; } if (s.Length >= 6) { if (s.Substring(s.Length - 6, 6) == "eraser") { s = s.Substring(0, s.Length - 6); continue; } } Console.WriteLine("No"); break; Debug.Log(s); } else if (s == "") { Console.WriteLine("Yes"); break; } else if (s.Length < 1) { Console.WriteLine("No"); break; } } // Console.WriteLine(s); sw.Stop(); TimeSpan ts = sw.Elapsed; // Console.WriteLine($"{ts}"); } static int intPow(int target, int kaisu) { int startTarget = target; for (int i = 1; i < kaisu; i++) { target *= startTarget; } return target; } static void bubble_sort(List<List<int>> a) { int count = 0; for (int i = 0; i < a.Count; i++) { for (int j = 0; j < a.Count - i - 1; j++) { // if (a[j] == a[a.Count - 1]){ // continue; // } count++; if (a[j][1] > a[j + 1][1]) { int localsave = 0; localsave = a[j + 1][1]; a[j + 1][1] = a[j][1]; a[j][1] = localsave; localsave = a[j][0]; a[j][0] = a[j + 1][0]; a[j + 1][0] = localsave; } } // debug(a,"途中" + i); } // debug(a,"result"); // Console.WriteLine("回数"+count); for (int i = 0; i < a.Count; i++) { Console.WriteLine(a[i][0] + " " + a[i][1]); } } /* 標準入力と標準出力が使えるかのチェック static void echo() { string echotest = Console.ReadLine(); Console.WriteLine(echotest); } static void HelloWorld(){ Console.WriteLine("Hello World!"); } */ } public class debug { //宣言時は、「 debug Debug = new debug(); 」推奨 bool debug_flag = true; public void Log(string str) { if (debug_flag == true) { Console.WriteLine(str); } } public void Log(int str) { if (debug_flag == true) { Console.WriteLine(str); } } public void Log(float str) { if (debug_flag == true) { Console.WriteLine(str); } } public void Log(object obj) { if (debug_flag == true) { Console.WriteLine(obj); } } public void Log(int[] arr) { if (debug_flag == true) { Console.WriteLine(string.Join(",", arr)); } } public void Log(string[] arr) { if (debug_flag == true) { Console.WriteLine(string.Join(",", arr)); } } public void Log(List<int> arr) { if (debug_flag == true) { string shuturyoku = ""; for (int i = 0; i < arr.Count; i++) { shuturyoku += arr[i] + ","; } Console.WriteLine(shuturyoku.TrimEnd(',')); } } public void Log(List<string> arr) { if (debug_flag == true) { string shuturyoku = ""; for (int i = 0; i < arr.Count; i++) { shuturyoku += arr[i] + ","; } Console.WriteLine(shuturyoku.TrimEnd(',')); } } public void Log(List<float> arr) { if (debug_flag == true) { string shuturyoku = ""; for (int i = 0; i < arr.Count; i++) { shuturyoku += arr[i] + ","; } Console.WriteLine(shuturyoku.TrimEnd(',')); } } public void Log() { if (debug_flag == true) { Console.WriteLine("アタイイレナサイ"); } } public void FlagFalse() { debug_flag = false; } public void FlagTrue() { debug_flag = true; } } }
using System; using System.Collections; using System.Collections.Generic; namespace 練習問題 { class Program { static void Main(string[] args) { List<int> pattern = new List<int>(); var sw = new System.Diagnostics.Stopwatch(); string s = ""; debug Debug = new debug(); if (args.Length == 0) { Debug.FlagFalse(); s = Console.ReadLine(); } else { Debug.FlagTrue(); if (args[0] == "1") { s = "erasedream"; } else if (args[0] == "2") { s = "dreameraser"; } else if (args[0] == "3") { s = "dreamerer"; } } string startS = s; string t = ""; sw.Start(); // 2秒以内ですねスタート while (startS != t) { if (s.Length >= 5) { if (s.Substring(s.Length - 5, 5) == "dream") { s = s.Substring(0, s.Length - 5); continue; } if (s.Length >= 7) { if (s.Substring(s.Length - 7, 7) == "dreamer") { s = s.Substring(0, s.Length - 7); continue; } } if (s.Substring(s.Length - 5, 5) == "erase") { s = s.Substring(0, s.Length - 5); continue; } if (s.Length >= 6) { if (s.Substring(s.Length - 6, 6) == "eraser") { s = s.Substring(0, s.Length - 6); continue; } } Console.WriteLine("NO"); break; Debug.Log(s); } else if (s == "") { Console.WriteLine("YES"); break; } else if (s.Length < 1) { Console.WriteLine("NO"); break; } } // Console.WriteLine(s); sw.Stop(); TimeSpan ts = sw.Elapsed; // Console.WriteLine($"{ts}"); } static int intPow(int target, int kaisu) { int startTarget = target; for (int i = 1; i < kaisu; i++) { target *= startTarget; } return target; } static void bubble_sort(List<List<int>> a) { int count = 0; for (int i = 0; i < a.Count; i++) { for (int j = 0; j < a.Count - i - 1; j++) { // if (a[j] == a[a.Count - 1]){ // continue; // } count++; if (a[j][1] > a[j + 1][1]) { int localsave = 0; localsave = a[j + 1][1]; a[j + 1][1] = a[j][1]; a[j][1] = localsave; localsave = a[j][0]; a[j][0] = a[j + 1][0]; a[j + 1][0] = localsave; } } // debug(a,"途中" + i); } // debug(a,"result"); // Console.WriteLine("回数"+count); for (int i = 0; i < a.Count; i++) { Console.WriteLine(a[i][0] + " " + a[i][1]); } } /* 標準入力と標準出力が使えるかのチェック static void echo() { string echotest = Console.ReadLine(); Console.WriteLine(echotest); } static void HelloWorld(){ Console.WriteLine("Hello World!"); } */ } public class debug { //宣言時は、「 debug Debug = new debug(); 」推奨 bool debug_flag = true; public void Log(string str) { if (debug_flag == true) { Console.WriteLine(str); } } public void Log(int str) { if (debug_flag == true) { Console.WriteLine(str); } } public void Log(float str) { if (debug_flag == true) { Console.WriteLine(str); } } public void Log(object obj) { if (debug_flag == true) { Console.WriteLine(obj); } } public void Log(int[] arr) { if (debug_flag == true) { Console.WriteLine(string.Join(",", arr)); } } public void Log(string[] arr) { if (debug_flag == true) { Console.WriteLine(string.Join(",", arr)); } } public void Log(List<int> arr) { if (debug_flag == true) { string shuturyoku = ""; for (int i = 0; i < arr.Count; i++) { shuturyoku += arr[i] + ","; } Console.WriteLine(shuturyoku.TrimEnd(',')); } } public void Log(List<string> arr) { if (debug_flag == true) { string shuturyoku = ""; for (int i = 0; i < arr.Count; i++) { shuturyoku += arr[i] + ","; } Console.WriteLine(shuturyoku.TrimEnd(',')); } } public void Log(List<float> arr) { if (debug_flag == true) { string shuturyoku = ""; for (int i = 0; i < arr.Count; i++) { shuturyoku += arr[i] + ","; } Console.WriteLine(shuturyoku.TrimEnd(',')); } } public void Log() { if (debug_flag == true) { Console.WriteLine("アタイイレナサイ"); } } public void FlagFalse() { debug_flag = false; } public void FlagTrue() { debug_flag = true; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
1,140
6
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); // int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); //文字列の反転 var tmp = new string(s.Reverse().ToArray()); var c1 = "maerd"; var c2 = "remaerd"; var c3 = "esare"; var c4 = "resare"; StringBuilder t1 = new StringBuilder(""); bool ok = true; while (tmp.Length > 0) { if (tmp.StartsWith(c1)) { tmp = tmp.Remove(0, c1.Length); t1.Append(c1); } else if (tmp.StartsWith(c2)) { tmp = tmp.Remove(0, c2.Length); t1.Append(c2); } else if (tmp.StartsWith(c3)) { tmp = tmp.Remove(0, c3.Length); t1.Append(c3); } else if (tmp.StartsWith(c4)) { tmp = tmp.Remove(0, c4.Length); t1.Append(c4); } else { ok = false; break; } } // 出力 var t2 = new string(s.Reverse().ToArray()); var ans = "YES"; if (t1.ToString() != t2) { ans = "No"; } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); // int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray(); //文字列の反転 var tmp = new string(s.Reverse().ToArray()); var c1 = "maerd"; var c2 = "remaerd"; var c3 = "esare"; var c4 = "resare"; StringBuilder t1 = new StringBuilder(""); bool ok = true; while (tmp.Length > 0) { if (tmp.StartsWith(c1)) { tmp = tmp.Remove(0, c1.Length); t1.Append(c1); } else if (tmp.StartsWith(c2)) { tmp = tmp.Remove(0, c2.Length); t1.Append(c2); } else if (tmp.StartsWith(c3)) { tmp = tmp.Remove(0, c3.Length); t1.Append(c3); } else if (tmp.StartsWith(c4)) { tmp = tmp.Remove(0, c4.Length); t1.Append(c4); } else { ok = false; break; } } // 出力 var t2 = new string(s.Reverse().ToArray()); var ans = "YES"; if (t1.ToString() != t2) { ans = "NO"; } Console.WriteLine(ans); } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
309
2
using System; namespace oasobi { static class MainClass { public static void Main() { string S = Console.ReadLine(); string firstreplaced = S.Replace("dream", "A").Replace("erase", "T"); string secondreplaced = firstreplaced.Replace("Aer", "G").Replace("Tr", "C"); string final = secondreplaced.Replace("A", "") .Replace("T", "") .Replace("G", "") .Replace("C", ""); if (final == "") { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; namespace oasobi { static class MainClass { public static void Main() { string S = Console.ReadLine(); string firstreplaced = S.Replace("dream", "A").Replace("erase", "T"); string secondreplaced = firstreplaced.Replace("Aer", "G").Replace("Tr", "C"); string final = secondreplaced.Replace("A", "") .Replace("T", "") .Replace("G", "") .Replace("C", ""); if (final == "") { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
158
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; // static int N; static string ss, S; public static void Input() { var cin = new Scanner(); ss = Console.ReadLine(); S = Swap(ss); } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); string ans = "Yes"; int res = S.Length; int st = 0; string[] c = { "maerd", "remaerd", "esare", "resare" }; while (res > 0) { if (res >= 5) { if (c.Contains(S.Substring(st, 5))) { res -= 5; st += 5; continue; } } if (res >= 6) { if (c.Contains(S.Substring(st, 6))) { res -= 6; st += 6; continue; } } if (res >= 7) { if (c.Contains(S.Substring(st, 7))) { res -= 7; st += 7; continue; } } ans = "No"; break; } Console.WriteLine(ans); // Console.Out.Flush(); } public static string Swap(string str) { var rs = new StringBuilder(); var swapstr = str.ToCharArray(); for (var i = 0; i < str.Length; i++) { rs.Append(swapstr[str.Length - 1 - i]); } return rs.ToString(); } } public class Scanner { 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; } } public class Graph {} }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; // static int N; static string ss, S; public static void Input() { var cin = new Scanner(); ss = Console.ReadLine(); S = Swap(ss); } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); string ans = "YES"; int res = S.Length; int st = 0; string[] c = { "maerd", "remaerd", "esare", "resare" }; while (res > 0) { if (res >= 5) { if (c.Contains(S.Substring(st, 5))) { res -= 5; st += 5; continue; } } if (res >= 6) { if (c.Contains(S.Substring(st, 6))) { res -= 6; st += 6; continue; } } if (res >= 7) { if (c.Contains(S.Substring(st, 7))) { res -= 7; st += 7; continue; } } ans = "NO"; break; } Console.WriteLine(ans); // Console.Out.Flush(); } public static string Swap(string str) { var rs = new StringBuilder(); var swapstr = str.ToCharArray(); for (var i = 0; i < str.Length; i++) { rs.Append(swapstr[str.Length - 1 - i]); } return rs.ToString(); } } public class Scanner { 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; } } public class Graph {} }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
446
4
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var s = cin.next(); var words = new string[] { "dream", "dreamer", "erase", "eraser" }; var queue = new Queue<int>(); queue.Enqueue(0); while (queue.Count > 0) { var pop = queue.Dequeue(); if (pop == s.Length) { Console.WriteLine("Yes"); return; } foreach (var word in words) { if (pop + word.Length > s.Length) continue; var sub = s.Substring(pop, word.Length); if (sub.Equals(word)) { queue.Enqueue(pop + word.Length); } } } Console.WriteLine("No"); } } class Point { public int x { get; set; } public int y { get; set; } public int t { get; set; } } static class C { public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long UpperBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] < key) l = mid + 1; else r = mid; } return l; } } static class Subsequence { /// <summary> /// 最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.LowerBound(dp, a[i])] = a[i]; } return C.LowerBound(dp, long.MaxValue - 1); } /// <summary> /// 重複を許さない最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long UniqueLIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.UpperBound(dp, a[i])] = a[i]; } return C.UpperBound(dp, long.MaxValue - 1); } } 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; } } #region ModInt public class ModInt { public static long Mod; public long num; public ModInt(long n, int mod = (int)1e9 + 7) { num = n; Mod = mod; } 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); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } 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); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var s = cin.next(); var words = new string[] { "dream", "dreamer", "erase", "eraser" }; var queue = new Queue<int>(); queue.Enqueue(0); while (queue.Count > 0) { var pop = queue.Dequeue(); if (pop == s.Length) { Console.WriteLine("YES"); return; } foreach (var word in words) { if (pop + word.Length > s.Length) continue; var sub = s.Substring(pop, word.Length); if (sub.Equals(word)) { queue.Enqueue(pop + word.Length); } } } Console.WriteLine("NO"); } } class Point { public int x { get; set; } public int y { get; set; } public int t { get; set; } } static class C { public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } public static long UpperBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] < key) l = mid + 1; else r = mid; } return l; } } static class Subsequence { /// <summary> /// 最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.LowerBound(dp, a[i])] = a[i]; } return C.LowerBound(dp, long.MaxValue - 1); } /// <summary> /// 重複を許さない最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long UniqueLIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.UpperBound(dp, a[i])] = a[i]; } return C.UpperBound(dp, long.MaxValue - 1); } } 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; } } #region ModInt public class ModInt { public static long Mod; public long num; public ModInt(long n, int mod = (int)1e9 + 7) { num = n; Mod = mod; } 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); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } 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); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
1,261
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC049C_Daydream { class Program { static void Main(string[] args) { char[] c = Console.ReadLine().ToArray(); Array.Reverse(c); string s = new string(c); string[] words = new string[] { "maerd", "remaerd", "esare", "resare" }; bool flag = true; for (int i = 0; i < s.Length; i++) { bool flag2 = false; foreach (var w in words) { if (s.Length - i < w.Length) { continue; } else if (s.Substring(i, w.Length) == w) { flag2 = true; i += w.Length; } } if (!flag2) { flag = false; break; } } if (flag) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC049C_Daydream { class Program { static void Main(string[] args) { char[] c = Console.ReadLine().ToArray(); Array.Reverse(c); string s = new string(c); string[] words = new string[] { "maerd", "remaerd", "esare", "resare" }; bool flag = true; for (int i = 0; i < s.Length;) { bool flag2 = false; foreach (var w in words) { if (s.Length - i < w.Length) { continue; } else if (s.Substring(i, w.Length) == w) { flag2 = true; i += w.Length; } } if (!flag2) { flag = false; break; } } if (flag) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
[["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29]]
8
225
2
namespace AtCoder.ABC.C049 { using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.IO; using AtCoder.ABC.IO; public class C049 { public void Solve(Parser parser, Printer printer) { char[] s = parser.Scan().ToArray(); Array.Reverse(s); bool got = Solve(new string(s)); var ans = got ? "Yes" : "No"; printer.Write(ans); printer.WriteLine(); printer.Flush(); } private bool Solve(string r) { string[] keywords = new string[] { "maerd", "remaerd", "esare", "resare", }; while (r != "") { string contains = ""; foreach (var keyword in keywords) { if (r.StartsWith(keyword)) { contains = keyword; } } if (contains == "") { return false; } r = r.Substring(contains.Length); } return true; } } static class Program { static void Main(string[] args) { var i = new Parser(Console.OpenStandardInput()); var o = new Printer(Console.OpenStandardOutput()); new C049().Solve(i, o); } } } namespace AtCoder.ABC.IO { #region IO using System; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Globalization; public class Parser { public Parser(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; } } public IEnumerable<Parser> Take(int n) { return Enumerable.Range(1, n).Select(_ => this); } 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); } } public 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) {} 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()); } } #endregion }
namespace AtCoder.ABC.C049 { using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.IO; using AtCoder.ABC.IO; public class C049 { public void Solve(Parser parser, Printer printer) { char[] s = parser.Scan().ToArray(); Array.Reverse(s); bool got = Solve(new string(s)); var ans = got ? "YES" : "NO"; printer.Write(ans); printer.WriteLine(); printer.Flush(); } private bool Solve(string r) { string[] keywords = new string[] { "maerd", "remaerd", "esare", "resare", }; while (r != "") { string contains = ""; foreach (var keyword in keywords) { if (r.StartsWith(keyword)) { contains = keyword; } } if (contains == "") { return false; } r = r.Substring(contains.Length); } return true; } } static class Program { static void Main(string[] args) { var i = new Parser(Console.OpenStandardInput()); var o = new Printer(Console.OpenStandardOutput()); new C049().Solve(i, o); } } } namespace AtCoder.ABC.IO { #region IO using System; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Globalization; public class Parser { public Parser(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; } } public IEnumerable<Parser> Take(int n) { return Enumerable.Range(1, n).Select(_ => this); } 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); } } public 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) {} 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()); } } #endregion }
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
1,117
4
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static void Main(string[] args) { string s = Console.ReadLine(); while (s.Length >= 5) { int pos = s.Length; string ss = s.Substring(pos - 5, 5); if (ss.CompareTo("erase") == 0 || ss.CompareTo("dream") == 0) { s = s.Substring(0, pos - 5); continue; } if (pos >= 7) { ss = s.Substring(pos - 7, 7); if (ss.CompareTo("dreamer") == 0) { s = s.Substring(0, pos - 7); continue; } } if (pos >= 6) { ss = s.Substring(pos - 6, 6); if (ss.CompareTo("eraser") == 0) { s = s.Substring(0, pos - 6); continue; } } Console.WriteLine("No"); return; } if (s.Length != 0) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static void Main(string[] args) { string s = Console.ReadLine(); while (s.Length >= 5) { int pos = s.Length; string ss = s.Substring(pos - 5, 5); if (ss.CompareTo("erase") == 0 || ss.CompareTo("dream") == 0) { s = s.Substring(0, pos - 5); continue; } if (pos >= 7) { ss = s.Substring(pos - 7, 7); if (ss.CompareTo("dreamer") == 0) { s = s.Substring(0, pos - 7); continue; } } if (pos >= 6) { ss = s.Substring(pos - 6, 6); if (ss.CompareTo("eraser") == 0) { s = s.Substring(0, pos - 6); continue; } } Console.WriteLine("NO"); return; } if (s.Length != 0) { Console.WriteLine("NO"); return; } Console.WriteLine("YES"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
268
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Beg049C { class Program { static void Main(string[] args) { var dividers = new string[4] { "dream", "dreamer", "erase", "eraser" }; var s = Console.ReadLine(); var n = s.Length; var dp = new int[n + 1]; dp[0] = 1; for (int i = 0; i < n; i++) { if (dp[i] == 1) { foreach (var div in dividers) { if (n - i >= div.Length && s.Substring(i, div.Length) == div) dp[i + div.Length] = 1; } } } var ans = dp[n] == 1 ? "Yes" : "No"; Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Beg049C { class Program { static void Main(string[] args) { var dividers = new string[4] { "dream", "dreamer", "erase", "eraser" }; var s = Console.ReadLine(); var n = s.Length; var dp = new int[n + 1]; dp[0] = 1; for (int i = 0; i < n; i++) { if (dp[i] == 1) { foreach (var div in dividers) { if (n - i >= div.Length && s.Substring(i, div.Length) == div) dp[i + div.Length] = 1; } } } var ans = dp[n] == 1 ? "YES" : "NO"; Console.WriteLine(ans); } } }
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
201
4
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { // 文字列の入力 var s = Console.ReadLine(); var targetList = new List<string>() { "dream", "dreamer", "erase", "eraser" }; // 逆さから読むとかぶらない・・・ s = string.Join("", s.Reverse()); targetList = targetList.Select(x => string.Join("", x.Reverse())).ToList(); var hitFlag = true; for (int i = 0; i < s.Length;) { var flag2 = false; foreach (var word in targetList) { if (s.Length - i < word.Length) continue; else if (s.Substring(i, word.Length) == word) { i += word.Length; flag2 = true; break; } } if (!flag2) { hitFlag = false; break; } } if (hitFlag) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { // 文字列の入力 var s = Console.ReadLine(); var targetList = new List<string>() { "dream", "dreamer", "erase", "eraser" }; // 逆さから読むとかぶらない・・・ s = string.Join("", s.Reverse()); targetList = targetList.Select(x => string.Join("", x.Reverse())).ToList(); var hitFlag = true; for (int i = 0; i < s.Length;) { var flag2 = false; foreach (var word in targetList) { if (s.Length - i < word.Length) continue; else if (s.Substring(i, word.Length) == word) { i += word.Length; flag2 = true; break; } } if (!flag2) { hitFlag = false; break; } } if (hitFlag) Console.WriteLine("YES"); else Console.WriteLine("NO"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
227
4
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace NotFounds { public class Program { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var S = cin.Read.Reverse(); var words = new string[] { "maerd", "remaerd", "esare", "resare" }; var flag = true; for (int i = 0; i < S.Length;) { var flag2 = false; foreach (var x in words) if (S.Length - i < x.Length) continue; else if (S.Substring(i, x.Length) == x) { flag2 = true; i += x.Length; } if (!flag2) { WriteLine(i); flag = false; break; } } if (flag) WriteLine("YES"); else WriteLine("NO"); } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace NotFounds { public class Program { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var S = cin.Read.Reverse(); var words = new string[] { "maerd", "remaerd", "esare", "resare" }; var flag = true; for (int i = 0; i < S.Length;) { var flag2 = false; foreach (var x in words) if (S.Length - i < x.Length) continue; else if (S.Substring(i, x.Length) == x) { flag2 = true; i += x.Length; } if (!flag2) { flag = false; break; } } if (flag) WriteLine("YES"); else WriteLine("NO"); } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 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, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
718
5
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var s = Console.ReadLine(); Console.WriteLine(Calculation.Calc(s) ? "YES" : "NO"); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { internal static bool Calc(string s) { while (s.Length > 0) { if (s.Length >= 5 && (s.Right(5) == "erase" || s.Right(5) == "dream")) { s = s.Left(s.Length - 5); } if (s.Length >= 6 && s.Right(6) == "eraser") { s = s.Left(s.Length - 6); } if (s.Length >= 7 && s.Right(7) == "dreamer") { s = s.Left(s.Length - 7); } return false; } return true; } } static class RootedTreeNodesFactory { public class RootedTreeNode { public int Id { get; } public int Parent { get; } public int Depth { get; set; } int[] Childs { get; } public RootedTreeNode(int id, int parent, int[] childs) { this.Id = id; this.Parent = parent; this.Childs = childs; } } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static long[] ReadNTimesAsLong(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => long.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>計数ソート</summary> public static int[] CountingSort(int[] aArr, int k) { int[] b, c; var n = aArr.Length; b = new int[n]; c = Enumerable.Repeat(0, k + 1).ToArray(); for (int i = 0; i < n; i++) { c[aArr[i]]++; } for (int i = 1; i <= k; i++) { c[i] += c[i - 1]; } for (int i = n - 1; i >= 0; i--) { b[c[aArr[i]] - 1] = aArr[i]; c[aArr[i]]--; } return b; } } /// <summary>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>拡張メソッドs</summary> static class Extention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } public static string Left(this string str, int length) { return str.Substring(0, length); } public static string Right(this string str, int length) { return str.Substring(str.Length - length, length); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var s = Console.ReadLine(); Console.WriteLine(Calculation.Calc(s) ? "YES" : "NO"); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class Calculation { internal static bool Calc(string s) { while (s.Length > 0) { if (s.Length >= 5 && (s.Right(5) == "erase" || s.Right(5) == "dream")) { s = s.Left(s.Length - 5); continue; } if (s.Length >= 6 && s.Right(6) == "eraser") { s = s.Left(s.Length - 6); continue; } if (s.Length >= 7 && s.Right(7) == "dreamer") { s = s.Left(s.Length - 7); continue; } return false; } return true; } } static class RootedTreeNodesFactory { public class RootedTreeNode { public int Id { get; } public int Parent { get; } public int Depth { get; set; } int[] Childs { get; } public RootedTreeNode(int id, int parent, int[] childs) { this.Id = id; this.Parent = parent; this.Childs = childs; } } } static class Quick { internal static void Calculate(int[] ts) { QuickSort(ts, 0, ts.Count() - 1); } private static void QuickSort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); QuickSort(ts, p, q - 1); QuickSort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static long[] ReadNTimesAsLong(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => long.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } static class WriteLib { public static void Write<T>(IEnumerable<T> ts) { ts.ToList().ForEach(s => Console.WriteLine(s)); } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(int a, int n, int mod = 1000000007) { var res = 1; while (n > 0) { if ((n & 1) == 1) { res = (int)(Math.BigMul(res % mod, a) % mod); // resにaをかける } a = (int)(Math.Pow(a % mod, 2) % mod); // 次のaはa^2 n >>= 1; } return res; } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>計数ソート</summary> public static int[] CountingSort(int[] aArr, int k) { int[] b, c; var n = aArr.Length; b = new int[n]; c = Enumerable.Repeat(0, k + 1).ToArray(); for (int i = 0; i < n; i++) { c[aArr[i]]++; } for (int i = 1; i <= k; i++) { c[i] += c[i - 1]; } for (int i = n - 1; i >= 0; i--) { b[c[aArr[i]] - 1] = aArr[i]; c[aArr[i]]--; } return b; } } /// <summary>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>DeepCopyするクラス</summary> class DeepCopier { BinaryFormatter b = new BinaryFormatter(); public T DeepCopy<T>(T obj) { T result; using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } } static class MergeSort { public static long[] Sort(long[] arr) { return Sort(arr, 0, arr.Count()); } // rightは+1されていることに注意 private static long[] Merge(long[] sArr, int left, int mid, int right) { var n1 = mid - left; var n2 = right - mid; var lArr = new long[n1 + 1]; var rArr = new long[n2 + 1]; for (int i = 0; i < n1; i++) { lArr[i] = sArr[left + i]; } lArr[n1] = int.MaxValue; for (int i = 0; i < n2; i++) { rArr[i] = sArr[mid + i]; } rArr[n2] = int.MaxValue; int l = 0, r = 0; for (int k = left; k < right; k++) { if (lArr[l] <= rArr[r]) { sArr[k] = lArr[l]; l++; } else { sArr[k] = rArr[r]; r++; } } return sArr; // 要素数はright - left } private static long[] Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; sArr = Sort(sArr, left, mid); sArr = Sort(sArr, mid, right); sArr = Merge(sArr, left, mid, right); } return sArr; } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>拡張メソッドs</summary> static class Extention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } public static string Left(this string str, int length) { return str.Substring(0, length); } public static string Right(this string str, int length) { return str.Substring(str.Length - length, length); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
3,396
6
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { string s = ReadLine(); WriteLine(s.Replace("eraser", "") .Replace("erase", "") .Replace("dreamer", "") .Replace("dream", "") == "" ? "Yes" : "No"); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { string s = ReadLine(); WriteLine(s.Replace("eraser", "") .Replace("erase", "") .Replace("dreamer", "") .Replace("dream", "") == "" ? "YES" : "NO"); } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
110
4
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { string s = Console.ReadLine(); int i = 0; while (i < s.Length) { string subs = s.Substring(i, 5); if (subs == "dream") { i += 5; if (i < s.Length - 2 && s.Substring(i, 2) == "er") { if (!(i < s.Length - 3 && s.Substring(i, 3) == "era")) { i += 2; } } } else if (subs == "erase") { i += 5; if (i < s.Length - 1 && s.Substring(i, 1) == "r") i++; } else { break; } } if (i == s.Length) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } // Main(); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { string s = Console.ReadLine(); int i = 0; while (i < s.Length - 4) { string subs = s.Substring(i, 5); if (subs == "dream") { i += 5; if (i < s.Length - 1 && s.Substring(i, 2) == "er") { if (!(i < s.Length - 2 && s.Substring(i, 3) == "era")) { i += 2; } } } else if (subs == "erase") { i += 5; if (i < s.Length && s.Substring(i, 1) == "r") i++; } else { break; } } if (i == s.Length) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } // Main(); } }
[["+", 8, 196, 0, 52, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 23, 0, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 23, 0, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33]]
8
211
8
using System; namespace arc065_a { class Program { static void Main(string[] args) { char[] a = Console.ReadLine().ToCharArray(); Array.Reverse(a); string s = new string(a); bool ret = true; while (s.Length != 0 && ret) { string x = s.Substring(0, 5); if (x == "maerd") s = s.Substring(5, s.Length - 5); else if (x == "esare") s = s.Substring(5, s.Length - 5); else if (x + s[6] == "resare") s = s.Substring(6, s.Length - 6); else if (x + s[6] + s[7] == "remaerd") s = s.Substring(7, s.Length - 7); else ret = false; } Console.WriteLine(ret ? "YES" : "NO"); } } }
using System; namespace arc065_a { class Program { static void Main(string[] args) { char[] a = Console.ReadLine().ToCharArray(); Array.Reverse(a); string s = new string(a); bool ret = true; while (s.Length != 0 && ret) { string x = s.Substring(0, 5); if (x == "maerd") s = s.Substring(5, s.Length - 5); else if (x == "esare") s = s.Substring(5, s.Length - 5); else if (x + s[5] == "resare") s = s.Substring(6, s.Length - 6); else if (x + s[5] + s[6] == "remaerd") s = s.Substring(7, s.Length - 7); else ret = false; } Console.WriteLine(ret ? "YES" : "NO"); } } }
[["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
212
6
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var input = Console.ReadLine().Split(' ').Select(x => x.Substring(1, 1)).ToList(); Console.WriteLine(input[0] + input[1] + input[2]); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var input = Console.ReadLine().Split(' ').Select(x => x.Substring(0, 1)).ToList(); Console.WriteLine(input[0] + input[1] + input[2]); } }
[["-", 0, 218, 8, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 218, 8, 213, 3, 4, 0, 28, 0, 203]]
8
80
2
using System; using System.Collections.Generic; class Program { static string InputPattern = "Input3"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("AtCoder Beginner Contest"); // ABC } else if (InputPattern == "Input2") { WillReturn.Add("AtCoder Snuke Contest"); // ASC } else if (InputPattern == "Input3") { WillReturn.Add("AtCoder X Contest"); // AXC } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); string s = InputList[0]; string[] wkArr = s.Split(' '); Array.ForEach(wkArr, A => Console.Write(A[0])); Console.WriteLine(); } }
using System; using System.Collections.Generic; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("AtCoder Beginner Contest"); // ABC } else if (InputPattern == "Input2") { WillReturn.Add("AtCoder Snuke Contest"); // ASC } else if (InputPattern == "Input3") { WillReturn.Add("AtCoder X Contest"); // AXC } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); string s = InputList[0]; string[] wkArr = s.Split(' '); Array.ForEach(wkArr, A => Console.Write(A[0])); Console.WriteLine(); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
8
199
2
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); long a = cin.NextLong(); long b = cin.NextLong(); long x = cin.NextLong(); Console.WriteLine(b / x - a / x + a % x == 0 ? 1 : 0); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); long a = cin.NextLong(); long b = cin.NextLong(); long x = cin.NextLong(); Console.WriteLine(b / x - a / x + (a % x == 0 ? 1 : 0)); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
[["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
498
2
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var a = cin.nextLong(); var b = cin.nextLong(); var x = cin.nextLong(); Console.WriteLine((b / x - a / x) * a % x == 0 ? 1 : 0); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); 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 int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } 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[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var a = cin.nextLong(); var b = cin.nextLong(); var x = cin.nextLong(); Console.WriteLine((b / x - a / x) + (a % x == 0 ? 1 : 0)); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); 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 int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } 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[] s) => new Solver().Solve(); } }
[["-", 0, 41, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
591
4
using System; using System.Collections.Generic; using System.Linq; using static AtCoder.Io; namespace AtCoder { class Program { static void Main() { var abx = ReadLongArray(); var a = abx[0]; var b = abx[1]; var x = abx[2]; Console.WriteLine($"{b / x - (a - 1) / x}"); } } public static class Io { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static long ReadLong() => long.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse); public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse); } }
using System; using System.Collections.Generic; using System.Linq; using static AtCoder.Io; namespace AtCoder { class Program { static void Main() { var abx = ReadLongArray(); var a = abx[0]; var b = abx[1]; var x = abx[2]; Console.WriteLine($"{b / x - a / x + (a % x == 0 ? 1 : 0)}"); } } public static class Io { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static long ReadLong() => long.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse); public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse); } }
[["+", 0, 284, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 284, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 284, 0, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 17, 72], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 12, 22], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 284, 0, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 284, 0, 16, 12, 23, 0, 41, 0, 102], ["+", 0, 284, 0, 16, 12, 23, 0, 41, 75, 203], ["-", 0, 283, 0, 284, 0, 16, 12, 16, 17, 85], ["-", 0, 283, 0, 284, 0, 16, 12, 16, 12, 22]]
8
251
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); long a = long.Parse(input[0]); long b = long.Parse(input[1]); long x = long.Parse(input[2]); int count = 0; if (a == 0) { Console.WriteLine(b / x - 1); } else Console.WriteLine(b / x - (a - 1) / x); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); long a = long.Parse(input[0]); long b = long.Parse(input[1]); long x = long.Parse(input[2]); int count = 0; if (a == 0) { Console.WriteLine(b / x + 1); } else Console.WriteLine(b / x - (a - 1) / x); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
143
2
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; public class Program { public static void Main() { string[] s = Console.ReadLine().Split(' '); long a = long.Parse(s[0]); long b = long.Parse(s[1]); long x = long.Parse(s[2]); long ans = 0; ans = (b / x) - ((a - 1) / x); if (a == 0) ans += 1; Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; public class Program { public static void Main() { string[] s = Console.ReadLine().Split(' '); long a = long.Parse(s[0]); long b = long.Parse(s[1]); long x = long.Parse(s[2]); long ans = 0; ans = (b / x) - (a / x); if (a % x == 0) ans += 1; Console.WriteLine(ans); } }
[["-", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["-", 12, 23, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 12, 16, 12, 23, 0, 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]]
8
132
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { String[] str = Console.ReadLine().Split(' '); long A = long.Parse(str[0]); long B = long.Parse(str[1]); long X = long.Parse(str[2]); long ans = 0; if (A != 0) { ans = ((B / X) - (A / X)); } else { ans = (B / X) + 1; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test { class Program { static void Main(string[] args) { String[] str = Console.ReadLine().Split(' '); long A = long.Parse(str[0]); long B = long.Parse(str[1]); long X = long.Parse(str[2]); long ans = 0; if (A != 0) { ans = ((B / X) - ((A - 1) / X)); } else { ans = (B / X) + 1; } Console.WriteLine(ans); } } }
[["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 25]]
8
152
4
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { Console.WriteLine(B / X - A / X + (B % X == 0 ? 1 : 0)); } long A, B, X; public Sol() { var d = rla(); A = d[0]; B = d[1]; X = d[2]; } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { Console.WriteLine(B / X - A / X + (A % X == 0 ? 1 : 0)); } long A, B, X; public Sol() { var d = rla(); A = d[0]; B = d[1]; X = d[2]; } 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)); } }
[["-", 12, 23, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 31, 22]]
8
348
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass { static void Main() { var nx = ReadLine().Split().Select(int.Parse).ToArray(); int N = nx[0]; long x = nx[1]; var r = ReadLine().Split().Select(long.Parse).ToArray(); var a = new long[N + 2]; for (int i = 0; i < N; i++) { a[i + 1] = r[i]; } long ans = 0; for (int i = 1; i < N + 1; i++) { long s = a[i - 1] + a[i + 1]; if (s > x) { a[i + 1] -= s - x; ans += s - x; } } WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass { static void Main() { var nx = ReadLine().Split().Select(int.Parse).ToArray(); int N = nx[0]; long x = nx[1]; var r = ReadLine().Split().Select(long.Parse).ToArray(); var a = new long[N + 2]; for (int i = 0; i < N; i++) { a[i + 1] = r[i]; } long ans = 0; for (int i = 0; i < N + 1; i++) { long s = a[i] + a[i + 1]; if (s > x) { a[i + 1] -= s - x; ans += s - x; } } WriteLine(ans); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
207
4
using System; using System.Diagnostics; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main() { string[] cin = Console.ReadLine().Split(); long n = long.Parse(cin[0]); long x = long.Parse(cin[1]); long[] a = Console.ReadLine().Split().Select(i => long.Parse(i)).ToArray(); long ans = 0; if (a[0] > x) { ans = a[0] - x; a[0] = x; } for (long i = 0; i < n - 1; i++) { if (a[i] + a[i + 1] > x) { long gap = a[i] + a[i + 1] - x; ans += gap; if (a[i + 1] <= gap) a[i + 1] -= gap; else { a[i] -= (gap - a[i + 1]); a[i + 1] = 0; } } } Console.WriteLine(ans); } }
using System; using System.Diagnostics; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main() { string[] cin = Console.ReadLine().Split(); long n = long.Parse(cin[0]); long x = long.Parse(cin[1]); long[] a = Console.ReadLine().Split().Select(i => long.Parse(i)).ToArray(); long ans = 0; if (a[0] > x) { ans = a[0] - x; a[0] = x; } for (long i = 0; i < n - 1; i++) { if (a[i] + a[i + 1] > x) { long gap = a[i] + a[i + 1] - x; ans += gap; if (a[i + 1] >= gap) a[i + 1] -= gap; else { a[i] -= (gap - a[i + 1]); a[i + 1] = 0; } } } Console.WriteLine(ans); } }
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20]]
8
252
2
using System; using System.Linq; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; class Program { static void Main() { var input = Console.ReadLine(); var equal = input[0] == input[input.Length - 1]; var even = input.Length % 2 == 0; Console.WriteLine(equal ^ even ? "First" : "Second"); } }
using System; using System.Linq; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; class Program { static void Main() { var input = Console.ReadLine(); var equal = input[0] == input[input.Length - 1]; var even = input.Length % 2 == 0; Console.WriteLine(equal ^ even ? "Second" : "First"); } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
95
4
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() { int N = cin.nextInt(); long x = cin.nextInt(); long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = cin.nextInt(); } long[] B = (long[])A.Clone(); Array.Reverse(B); long ans = Math.Min(calc2(N, x, A), calc2(N, x, B)); Console.WriteLine(ans); } long calc2(int N, long x, long[] A) { long ans = 0; for (int i = 1; i < N; i++) { long dec = A[i - 1] + A[i] - x; if (dec > 0) { ans += dec; long dec2 = Math.Max(dec, A[i]); A[i] -= dec2; } } return ans; } } 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() { int N = cin.nextInt(); long x = cin.nextInt(); long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = cin.nextInt(); } long[] B = (long[])A.Clone(); Array.Reverse(B); long ans = Math.Min(calc2(N, x, A), calc2(N, x, B)); Console.WriteLine(ans); } long calc2(int N, long x, long[] A) { long ans = 0; for (int i = 1; i < N; i++) { long dec = A[i - 1] + A[i] - x; if (dec > 0) { ans += dec; long dec2 = Math.Min(dec, A[i]); A[i] -= dec2; } } return ans; } } 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, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
507
2
using System; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; public class Program { static readonly int Mod = (int)1e9 + 7; public void Solve() { int N = Reader.Int(), K = Reader.Int(); long ans = 0; var div = Divisors(N); var num = new long[div.Length]; for (int a = 0; a < div.Length; a++) { for (int b = 0; b < a; b++) if (div[a] % div[b] == 0) num[a] -= num[b]; long pow = ModPower(K, (div[a] + 1) / 2, Mod); num[a] = (num[a] + pow % Mod + Mod) % Mod; if (div[a] % 2 == 0) ans += num[a] * (div[a] / 2) % Mod; else ans += num[a] * div[a] % Mod; } Console.WriteLine(ans % Mod); } long ModPower(long x, long n, long mod) // x ^ n { long res = 1; if ((x %= mod) < 0) x += mod; for (; n > 0; n >>= 1, x = x * x % mod) if ((n & 1) == 1) res = res * x % mod; return res; } static int[] Divisors(int n) { var divisors = new List<int>(); int sqrt = (int)Math.Sqrt(n); for (int i = 1; i <= sqrt; i++) if (n % i == 0) { divisors.Add(i); if (i * i != n) divisors.Add(n / i); } divisors.Sort(); return divisors.ToArray(); } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
using System; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; public class Program { static readonly int Mod = (int)1e9 + 7; public void Solve() { int N = Reader.Int(), K = Reader.Int(); long ans = 0; var div = Divisors(N); var num = new long[div.Length]; for (int a = 0; a < div.Length; a++) { for (int b = 0; b < a; b++) if (div[a] % div[b] == 0) num[a] -= num[b]; long pow = ModPower(K, (div[a] + 1) / 2, Mod); num[a] = ((num[a] + pow) % Mod + Mod) % Mod; if (div[a] % 2 == 0) ans += num[a] * (div[a] / 2) % Mod; else ans += num[a] * div[a] % Mod; } Console.WriteLine(ans % Mod); } long ModPower(long x, long n, long mod) // x ^ n { long res = 1; if ((x %= mod) < 0) x += mod; for (; n > 0; n >>= 1, x = x * x % mod) if ((n & 1) == 1) res = res * x % mod; return res; } static int[] Divisors(int n) { var divisors = new List<int>(); int sqrt = (int)Math.Sqrt(n); for (int i = 1; i <= sqrt; i++) if (n % i == 0) { divisors.Add(i); if (i * i != n) divisors.Add(n / i); } divisors.Sort(); return divisors.ToArray(); } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
[["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 25]]
8
935
2
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 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) - 1; answer %= mod; } else { memo--; if (memo < -1) answer += Math.Abs(memo) - 1; answer %= mod; } } 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 = new long [2 * n][]; //座標と種類 long memo = 0; 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とすると、改行なしで出力。 } }
[["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203]]
8
307
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int cnt = 0; bool[] used = new bool[N]; for (int j = 30; j >= 0; j--) { int gr = 0; for (int i = 0; i < N; i++) { gr ^= A[i]; } if (gr == 0) { Console.WriteLine(cnt); return; } if (((gr >> j) & 1) == 0) continue; int mask = 1 << j; bool chk = false; for (int i = 0; i < N; i++) { if (!used[i] && (A[i] & mask) == mask) { A[i]--; cnt++; chk = true; used[i] = true; break; } } if (!chk) { Console.WriteLine(-1); return; } } int gg = 0; for (int i = 0; i < N; i++) gg ^= A[i]; Console.WriteLine(gg == 0 ? cnt : -1); } int N; int[] A; public Sol() { N = ri(); A = new int[N]; for (int i = 0; i < N; i++) A[i] = 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() { int cnt = 0; bool[] used = new bool[N]; for (int j = 30; j >= 0; j--) { int gr = 0; for (int i = 0; i < N; i++) { gr ^= A[i]; } if (gr == 0) { Console.WriteLine(cnt); return; } if (((gr >> j) & 1) == 0) continue; int mask = 1 << j; bool chk = false; for (int i = 0; i < N; i++) { if (!used[i] && (A[i] % (mask << 1)) == mask) { A[i]--; cnt++; chk = true; used[i] = true; break; } } if (!chk) { Console.WriteLine(-1); return; } } int gg = 0; for (int i = 0; i < N; i++) gg ^= A[i]; Console.WriteLine(gg == 0 ? cnt : -1); } int N; int[] A; public Sol() { N = ri(); A = new int[N]; for (int i = 0; i < N; i++) A[i] = 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)); } }
[["-", 15, 16, 12, 16, 31, 23, 0, 16, 17, 67], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 109], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 151], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
554
6
using System; using System.Linq; namespace relay_a { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(x[0] * x[1] / (x[0] + x[1])); } } }
using System; using System.Linq; namespace relay_a { class Program { static void Main(string[] args) { double[] x = Console.ReadLine().Split().Select(double.Parse).ToArray(); Console.WriteLine(x[0] * x[1] / (x[0] + x[1])); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199]]
8
80
4
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Numerics; namespace contest { class contest { static void Main(string[] args) { string s = Console.ReadLine(); var cp = s.Reverse().ToArray(); bool ok = true; for (int i = 0; i < s.Length; i++) { if (!check(cp[i], s[i])) { ok = false; break; } } if (ok) Console.WriteLine("YES"); else Console.WriteLine("NO"); } public static bool check(char a, char b) { if (a == 'b' && b == 'd') return true; if (a == 'd' && b == 'b') return true; if (a == 'p' && b == 'q') return true; if (a == 'q' && b == 'p') return true; return false; } } }
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Numerics; namespace contest { class contest { static void Main(string[] args) { string s = Console.ReadLine(); var cp = s.Reverse().ToArray(); bool ok = true; for (int i = 0; i < s.Length; i++) { if (!check(cp[i], s[i])) { ok = false; break; } } if (ok) Console.WriteLine("Yes"); else Console.WriteLine("No"); } public static bool check(char a, char b) { if (a == 'b' && b == 'd') return true; if (a == 'd' && b == 'b') return true; if (a == 'p' && b == 'q') return true; if (a == 'q' && b == 'p') return true; return false; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
220
4
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() { var ca = S.ToCharArray(); Array.Reverse(ca); int N = ca.Length; for (int i = 0; i < N; i++) { if (ca[i] == 'd') ca[i] = 'b'; else if (ca[i] == 'b') ca[i] = 'd'; else if (ca[i] == 'p') ca[i] = 'p'; else if (ca[i] == 'q') ca[i] = 'q'; } var ns = new String(ca); Console.WriteLine(ns == S ? "Yes" : "No"); } String S; public Sol() { S = 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() { var ca = S.ToCharArray(); Array.Reverse(ca); int N = ca.Length; for (int i = 0; i < N; i++) { if (ca[i] == 'd') ca[i] = 'b'; else if (ca[i] == 'b') ca[i] = 'd'; else if (ca[i] == 'p') ca[i] = 'q'; else if (ca[i] == 'q') ca[i] = 'p'; } var ns = new String(ca); Console.WriteLine(ns == S ? "Yes" : "No"); } String S; public Sol() { S = 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)); } }
[["-", 75, 57, 64, 1, 0, 11, 12, 252, 0, 253], ["+", 75, 57, 64, 1, 0, 11, 12, 252, 0, 253]]
8
445
4
using System; using System.Collections.Generic; namespace relay_c { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); long x = (long)Math.Pow(2, n); LinkedList<int> a = new LinkedList<int>(); for (long i = 0; i < x; i++) a.AddLast(int.Parse(Console.ReadLine())); while (a.Count > 1) { var b = a.First.Value; a.RemoveFirst(); var c = a.First.Value; a.RemoveFirst(); a.AddLast(b == c ? b : Math.Abs(b - c)); } Console.WriteLine(a.First); } } }
using System; using System.Collections.Generic; namespace relay_c { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); long x = (long)Math.Pow(2, n); LinkedList<int> a = new LinkedList<int>(); for (long i = 0; i < x; i++) a.AddLast(int.Parse(Console.ReadLine())); while (a.Count > 1) { var b = a.First.Value; a.RemoveFirst(); var c = a.First.Value; a.RemoveFirst(); a.AddLast(b == c ? b : Math.Abs(b - c)); } Console.WriteLine(a.First.Value); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
8
171
2
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.CupCount = inpt[0]; int swapCount = inpt[1]; for (int i = 0; i < swapCount; i++) { int[] mv = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.Move.Add(i, mv); } SetAns(0, 1, true); SetAns(0, 2, false); Console.WriteLine(ans.Count); } private int CupCount; private Dictionary<int, int[]> Move = new Dictionary<int, int[]>(); private Dictionary<int, Dictionary<int, Dictionary<bool, bool>>> flags = new Dictionary<int, Dictionary<int, Dictionary<bool, bool>>>(); private Dictionary<int, bool> ans = new Dictionary<int, bool>(); private void SetAns(int idx, int pos, bool canMagicUse) { if (!flags.ContainsKey(idx)) { flags.Add(idx, new Dictionary<int, Dictionary<bool, bool>>()); } if (!flags[idx].ContainsKey(pos)) { flags[idx].Add(pos, new Dictionary<bool, bool>()); } if (flags[idx][pos].ContainsKey(canMagicUse)) { return; } flags[idx][pos][canMagicUse] = true; if (idx >= this.Move.Count) { this.ans[pos] = true; if (canMagicUse) { if (pos > 1) { this.ans[pos - 1] = true; } if (pos < this.CupCount) { this.ans[pos + 1] = true; } } return; } int currentPos = pos; if (Move[idx][0] == pos) { currentPos = Move[idx][1]; } else if (Move[idx][1] == pos) { currentPos = Move[idx][0]; } List<int> nextPos = new List<int>(); nextPos.Add(currentPos); if (canMagicUse) { if (currentPos > 1) { nextPos.Add(currentPos - 1); } if (currentPos < CupCount) { nextPos.Add(currentPos + 1); } } int nextIdx = this.GetNextIndex(idx, nextPos); this.SetAns(nextIdx, currentPos, canMagicUse); if (canMagicUse) { if (currentPos > 1) { this.SetAns(nextIdx, currentPos - 1, false); } if (currentPos < this.CupCount) { this.SetAns(nextIdx, currentPos + 1, false); } } } private int GetNextIndex(int currentIdx, List<int> pos) { for (int i = currentIdx; i < Move.Count; i++) { if (pos.Any(a => Move[i].Any(b => b == a))) { return i; } } return Move.Count; } public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 20 1 1 7 8 20 1 19 "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.CupCount = inpt[0]; int swapCount = inpt[1]; for (int i = 0; i < swapCount; i++) { int[] mv = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.Move.Add(i, mv); } SetAns(0, 1, true); SetAns(0, 2, false); Console.WriteLine(ans.Count); } private int CupCount; private Dictionary<int, int[]> Move = new Dictionary<int, int[]>(); private Dictionary<int, Dictionary<int, Dictionary<bool, bool>>> flags = new Dictionary<int, Dictionary<int, Dictionary<bool, bool>>>(); private Dictionary<int, bool> ans = new Dictionary<int, bool>(); private void SetAns(int idx, int pos, bool canMagicUse) { if (!flags.ContainsKey(idx)) { flags.Add(idx, new Dictionary<int, Dictionary<bool, bool>>()); } if (!flags[idx].ContainsKey(pos)) { flags[idx].Add(pos, new Dictionary<bool, bool>()); } if (flags[idx][pos].ContainsKey(canMagicUse)) { return; } flags[idx][pos][canMagicUse] = true; if (idx >= this.Move.Count) { this.ans[pos] = true; if (canMagicUse) { if (pos > 1) { this.ans[pos - 1] = true; } if (pos < this.CupCount) { this.ans[pos + 1] = true; } } return; } int currentPos = pos; if (Move[idx][0] == pos) { currentPos = Move[idx][1]; } else if (Move[idx][1] == pos) { currentPos = Move[idx][0]; } List<int> nextPos = new List<int>(); nextPos.Add(currentPos); if (canMagicUse) { if (currentPos > 1) { nextPos.Add(currentPos - 1); } if (currentPos < CupCount) { nextPos.Add(currentPos + 1); } } int nextIdx = this.GetNextIndex(idx, nextPos); this.SetAns(nextIdx, currentPos, canMagicUse); if (canMagicUse) { if (currentPos > 1) { this.SetAns(nextIdx, currentPos - 1, false); } if (currentPos < this.CupCount) { this.SetAns(nextIdx, currentPos + 1, false); } } } private int GetNextIndex(int currentIdx, List<int> pos) { for (int i = currentIdx + 1; i < Move.Count; i++) { if (pos.Any(a => Move[i].Any(b => b == a))) { return i; } } return Move.Count; } public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 20 1 1 7 8 20 1 19 "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
817
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long h = sc.NextLong(); long w = sc.NextLong(); string answer = ""; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { string str = sc.Next(); if (str == "snuke") { answer = ((char)('A' + i)).ToString() + (j + 1); } } } 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 h = sc.NextLong(); long w = sc.NextLong(); string answer = ""; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { string str = sc.Next(); if (str == "snuke") { answer = ((char)('A' + j)).ToString() + (i + 1); } } } 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(); } }
[["-", 205, 23, 0, 74, 51, 23, 0, 16, 12, 22], ["+", 205, 23, 0, 74, 51, 23, 0, 16, 12, 22], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22]]
8
441
4
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 h = sc.nextInt(); int w = sc.nextInt(); for (int y = 0; y < h; y++) { for (int x = 1; x <= w; x++) { string s = sc.next(); if (s == "snuke") { char c = (char)('A' + y); Console.WriteLine("{0}{1}", c, x); return; } } } } } } 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 h = sc.nextInt(); int w = sc.nextInt(); for (int y = 1; y <= h; y++) { for (int x = 0; x < w; x++) { string s = sc.next(); if (s == "snuke") { char c = (char)('A' + x); Console.WriteLine("{0}{1}", c, y); return; } } } } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 22], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
1,262
12
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } private const int MOD = 1000000007; static void Solve() { var n = Input.NextInt(); int y = 0; int sum = 0; for (int i = 1; i < n; ++i) { sum += i; if (sum >= n) { y = i; break; } } int remove = sum - n; for (int i = 1; i <= y; ++i) { if (i == remove) { continue; } Console.WriteLine(i); } } #region よく使う便利関数 static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static void Swap<T>(ref T x, ref T y) { T t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } private const int MOD = 1000000007; static void Solve() { var n = Input.NextInt(); int y = 0; int sum = 0; for (int i = 1; i <= n; ++i) { sum += i; if (sum >= n) { y = i; break; } } int remove = sum - n; for (int i = 1; i <= y; ++i) { if (i == remove) { continue; } Console.WriteLine(i); } } #region よく使う便利関数 static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static void Swap<T>(ref T x, ref T y) { T t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
1,596
2
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 m = sc.nextInt(); int[][] ls = new int [n][]; UnionFindTree u = new UnionFindTree(m); for (int i = 0; i < n; i++) { int ki = sc.nextInt(); ls[i] = sc.nextInt(ki); if (ki > 1) { for (int lang = 1; lang < ki; lang++) { u.UniteCategory(ls[i][0], ls[i][lang]); } } } bool ok = true; for (int man = 1; man < n; man++) { if (u.IsSameCategory(ls[0][0], ls[man][0]) == false) { ok = false; } } pr.WriteLine(ok); } } } 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 } } class UnionFindTree { int N; int[] parent, rank, size; public UnionFindTree(int capacity) { N = capacity; parent = new int[N]; rank = new int[N]; size = new int[N]; for (var i = 0; i < N; i++) { parent[i] = i; size[i] = 1; } } public int GetSize(int x) { return size[GetRootOf(x)]; } public int GetRootOf(int x) { return parent[x] == x ? x : parent[x] = GetRootOf(parent[x]); } public bool UniteCategory(int x, int y) { if ((x = GetRootOf(x)) == (y = GetRootOf(y))) return false; if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; } else { parent[y] = x; size[x] += size[y]; if (rank[x] == rank[y]) rank[x]++; } return true; } public bool IsSameCategory(int x, int y) { return GetRootOf(x) == GetRootOf(y); } }
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 m = sc.nextInt(); int[][] ls = new int [n][]; UnionFindTree u = new UnionFindTree(m + 1); for (int i = 0; i < n; i++) { int ki = sc.nextInt(); ls[i] = sc.nextInt(ki); if (ki > 1) { for (int lang = 1; lang < ki; lang++) { u.UniteCategory(ls[i][0], ls[i][lang]); } } } bool ok = true; for (int man = 1; man < n; man++) { if (u.IsSameCategory(ls[0][0], ls[man][0]) == false) { ok = false; } } pr.WriteLine(ok); } } } 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 } } class UnionFindTree { int N; int[] parent, rank, size; public UnionFindTree(int capacity) { N = capacity; parent = new int[N]; rank = new int[N]; size = new int[N]; for (var i = 0; i < N; i++) { parent[i] = i; size[i] = 1; } } public int GetSize(int x) { return size[GetRootOf(x)]; } public int GetRootOf(int x) { return parent[x] == x ? x : parent[x] = GetRootOf(parent[x]); } public bool UniteCategory(int x, int y) { if ((x = GetRootOf(x)) == (y = GetRootOf(y))) return false; if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; } else { parent[y] = x; size[x] += size[y]; if (rank[x] == rank[y]) rank[x]++; } return true; } public bool IsSameCategory(int x, int y) { return GetRootOf(x) == GetRootOf(y); } }
[["+", 0, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 12, 203]]
8
1,609
2
using System; using System.Linq; class Program { static long mod = (long)1e9 + 1; static void Main() { int[] inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = inputs[0], M = inputs[1]; if (N > M) { Console.WriteLine(0); return; } long[,,] dp = new long[M + 1, N, N]; dp[0, 0, N - 1] = 1; for (int n = 0; n < M; n++) { for (int s = 1; s <= N; s++) { for (int l = Math.Max(N - n - 1, 0); l < N; l++) { dp[n + 1, N - l - 1, l] += s * dp[n, s - 1, l] % mod; dp[n + 1, N - l - 1, l] %= mod; dp[n + 1, s - 1, l] += (N - s - l) * dp[n, s - 1, l] % mod; dp[n + 1, s - 1, l] %= mod; if (l > 0) { dp[n + 1, s - 1, l - 1] += l * dp[n, s - 1, l] % mod; dp[n + 1, s - 1, l - 1] %= mod; } } } } Console.WriteLine(dp[M, N - 1, 0]); } }
using System; using System.Linq; class Program { static long mod = (long)1e9 + 7; static void Main() { int[] inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = inputs[0], M = inputs[1]; if (N > M) { Console.WriteLine(0); return; } long[,,] dp = new long[M + 1, N, N]; dp[0, 0, N - 1] = 1; for (int n = 0; n < M; n++) { for (int s = 1; s <= N; s++) { for (int l = Math.Max(N - n - 1, 0); l < N; l++) { dp[n + 1, N - l - 1, l] += s * dp[n, s - 1, l] % mod; dp[n + 1, N - l - 1, l] %= mod; dp[n + 1, s - 1, l] += (N - s - l) * dp[n, s - 1, l] % mod; dp[n + 1, s - 1, l] %= mod; if (l > 0) { dp[n + 1, s - 1, l - 1] += l * dp[n, s - 1, l] % mod; dp[n + 1, s - 1, l - 1] %= mod; } } } } Console.WriteLine(dp[M, N - 1, 0]); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
346
2
using System; using System.Text; using System.Collections.Generic; class Solve { int H, W; string[,] s; public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Read(); Calc(); Console.Write(sb.ToString()); } void Calc() { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (s[i, j] == "snuke") { sb.Append((char)(i + 'A') + ""); sb.Append((int)(j + 1) + "\n"); } } } } void Read() { string[] str = Console.ReadLine().Split(' '); H = int.Parse(str[0]); W = int.Parse(str[1]); s = new string[H, W]; for (int i = 0; i < H; i++) { str = Console.ReadLine().Split(' '); for (int j = 0; j < W; j++) { s[i, j] = str[j]; } } } }
using System; using System.Text; using System.Collections.Generic; class Solve { int H, W; string[,] s; public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Read(); Calc(); Console.Write(sb.ToString()); } void Calc() { for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (s[i, j] == "snuke") { sb.Append((char)(j + 'A') + ""); sb.Append((int)(i + 1) + "\n"); } } } } void Read() { string[] str = Console.ReadLine().Split(' '); H = int.Parse(str[0]); W = int.Parse(str[1]); s = new string[H, W]; for (int i = 0; i < H; i++) { str = Console.ReadLine().Split(' '); for (int j = 0; j < W; j++) { s[i, j] = str[j]; } } } }
[["-", 0, 16, 31, 74, 51, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 74, 51, 23, 0, 16, 31, 22]]
8
298
4
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using static System.Console; using static System.Math; //using CS_Contest.Graph; using CS_Contest.Loop; using CS_Contest.Utils; using static Nakov.IO.Cin; using static CS_Contest.IO.IO; using static CS_Contest.Utils.MyMath; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; using ti3 = Tuple<int, int, int>; using ti2 = Tuple<int, int>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { int N = NextInt(), M = NextInt(); var uf = new UnionFind(N + M); N.REP(i => { NextIntList().Skip(1).Foreach(Li => { uf.Unite(Li - 1, i); }); }); (Generate.Seq(0,N).All(p=>uf.IsSameGroup(0,p))?"YES":"NO").WL(); } } public struct UnionFind { private readonly int[] _data; public UnionFind(int size) { _data = new int[size]; for (var i = 0; i < size; i++) _data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return x != y; if (_data[y] < _data[x]) { var tmp = y; y = x; x = tmp; } _data[x] += _data[y]; _data[y] = x; return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return _data[x] < 0 ? x : _data[x] = Root(_data[x]); } } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } } namespace CS_Contest.Loop { [DebuggerStepThrough] public static class Loop { public static void REP(this int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) { var i = 0; foreach (var item in ie) { act(i, item); i++; } } public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) { foreach (var item in ie) { act(item); } } } public class Generate { public static IEnumerable<int> Seq(int s, int e) => Seq(s, e, 1); public static IEnumerable<int> Seq(int s, int e, int a) { while (s != e) { yield return s; s += a; } } public static List<T> Repeat<T>(Func<int, T> result, int range) => Enumerable.Range(0, range).Select(result).ToList(); } } namespace CS_Contest.IO { using Li = List<int>; using Ll = List<long>; public static class IO { public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Li NextIntList(int n) => Enumerable.Repeat(0, n).Select(x => ReadLine()).Select(int.Parse).ToList(); public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList(); public static T Tee<T>(this T t, Func<T, string> formatter = null) { if (formatter == null) formatter = arg => arg.ToString(); formatter(t).WL(); return t; } public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL(); public static void W(this object @this) => Write(@this); } } namespace CS_Contest.Utils { using Li = List<int>; using Ll = List<long>; [DebuggerStepThrough] public static class Utils { public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly); public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2)); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static Map<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Map<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) { var enumerable = @this as T[] ?? @this.ToArray(); for (var i = 0; i < enumerable.Count(); i++) { if (i == at) continue; yield return enumerable.ElementAt(i); } } } public class Map<TKey, TValue> : Dictionary<TKey, TValue> { public Map() : base() { } public Map(int capacity) : base(capacity) { } public new TValue this[TKey index] { get { TValue v; return this.TryGetValue(index, out v) ? v : base[index] = default(TValue); } set { base[index] = value; } } } public static class MyMath { public static T EMin<T>(params T[] a) where T : IComparable<T> => a.Min(); public static T EMax<T>(params T[] a) where T : IComparable<T> => a.Max(); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using static System.Console; using static System.Math; //using CS_Contest.Graph; using CS_Contest.Loop; using CS_Contest.Utils; using static Nakov.IO.Cin; using static CS_Contest.IO.IO; using static CS_Contest.Utils.MyMath; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; using ti3 = Tuple<int, int, int>; using ti2 = Tuple<int, int>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { int N = NextInt(), M = NextInt(); var uf = new UnionFind(N + M); N.REP(i => { NextIntList().Skip(1).Foreach(Li => { uf.Unite(Li - 1 + N, i); }); }); (Generate.Seq(0,N).All(p=>uf.IsSameGroup(0,p))?"YES":"NO").WL(); } } public struct UnionFind { private readonly int[] _data; public UnionFind(int size) { _data = new int[size]; for (var i = 0; i < size; i++) _data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return x != y; if (_data[y] < _data[x]) { var tmp = y; y = x; x = tmp; } _data[x] += _data[y]; _data[y] = x; return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return _data[x] < 0 ? x : _data[x] = Root(_data[x]); } } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } } namespace CS_Contest.Loop { [DebuggerStepThrough] public static class Loop { public static void REP(this int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) { var i = 0; foreach (var item in ie) { act(i, item); i++; } } public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) { foreach (var item in ie) { act(item); } } } public class Generate { public static IEnumerable<int> Seq(int s, int e) => Seq(s, e, 1); public static IEnumerable<int> Seq(int s, int e, int a) { while (s != e) { yield return s; s += a; } } public static List<T> Repeat<T>(Func<int, T> result, int range) => Enumerable.Range(0, range).Select(result).ToList(); } } namespace CS_Contest.IO { using Li = List<int>; using Ll = List<long>; public static class IO { public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Li NextIntList(int n) => Enumerable.Repeat(0, n).Select(x => ReadLine()).Select(int.Parse).ToList(); public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList(); public static T Tee<T>(this T t, Func<T, string> formatter = null) { if (formatter == null) formatter = arg => arg.ToString(); formatter(t).WL(); return t; } public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL(); public static void W(this object @this) => Write(@this); } } namespace CS_Contest.Utils { using Li = List<int>; using Ll = List<long>; [DebuggerStepThrough] public static class Utils { public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly); public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2)); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static Map<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Map<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) { var enumerable = @this as T[] ?? @this.ToArray(); for (var i = 0; i < enumerable.Count(); i++) { if (i == at) continue; yield return enumerable.ElementAt(i); } } } public class Map<TKey, TValue> : Dictionary<TKey, TValue> { public Map() : base() { } public Map(int capacity) : base(capacity) { } public new TValue this[TKey index] { get { TValue v; return this.TryGetValue(index, out v) ? v : base[index] = default(TValue); } set { base[index] = value; } } } public static class MyMath { public static T EMin<T>(params T[] a) where T : IComparable<T> => a.Min(); public static T EMax<T>(params T[] a) where T : IComparable<T> => a.Max(); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
1,930
2
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int m = Console.ReadLine().Split().Select(int.Parse).ToArray()[1]; int[] a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray(); int[] moda = new int[m]; int[] paircount = new int[m]; int res = 0; int last = -10; for (int i = 0; i < a.Length; i++) { if (last == a[i]) { paircount[a[i] % m]++; last = -1; } else { last = a[i]; } moda[a[i] % m]++; } if (m % 2 == 0) { res += moda[m / 2 + 1] / 2; } res += moda[0] / 2; for (int i = 0; i < m / 2 - (m % 2 == 0 ? 1 : 0); i++) { res += Math.Min(moda[i + 1], moda[m - i - 1]); res += Math.Min((moda[i + 1] > moda[m - i - 1] ? paircount[i + 1] : paircount[m - i - 1]), Math.Abs(moda[i + 1] - moda[m - i - 1]) / 2); // Console.WriteLine(res); } Console.WriteLine(res); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int m = Console.ReadLine().Split().Select(int.Parse).ToArray()[1]; int[] a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray(); int[] moda = new int[m]; int[] paircount = new int[m]; int res = 0; int last = -10; for (int i = 0; i < a.Length; i++) { if (last == a[i]) { paircount[a[i] % m]++; last = -1; } else { last = a[i]; } moda[a[i] % m]++; } if (m % 2 == 0) { res += moda[m / 2] / 2; } res += moda[0] / 2; for (int i = 0; i < m / 2 - (m % 2 == 0 ? 1 : 0); i++) { res += Math.Min(moda[i + 1], moda[m - i - 1]); res += Math.Min((moda[i + 1] > moda[m - i - 1] ? paircount[i + 1] : paircount[m - i - 1]), Math.Abs(moda[i + 1] - moda[m - i - 1]) / 2); // Console.WriteLine(res); } Console.WriteLine(res); } }
[["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
342
2
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Numerics; namespace contest { class contest { static void Main(string[] args) { var num = Console.ReadLine().Split().Select(int.Parse).ToArray(); var card = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = num[0]; int m = num[1]; Array.Sort(card); var dic = new SortedDictionary<int, List<int>>(); for (int i = 0; i < n; i++) { int tmp = card[i] % m; if (!dic.Keys.Contains(tmp)) { dic[tmp] = new List<int>(); } dic[tmp].Add(card[i]); } int count = 0; var memo = new bool[m + 1]; foreach (var item in dic) { int tmp = item.Key; var setA = item.Value; if (memo[tmp]) continue; if (tmp == 0 || (m % 2 == 0 && tmp == m / 2)) { count += setA.Count() / 2; memo[tmp] = true; } else { int res = m - tmp; if (memo[res]) continue; if (dic.Keys.Contains(res)) { var setB = dic[res]; count += calc(setA, setB); memo[tmp] = true; memo[res] = true; } else { setA.Sort(); for (int j = 0; j < setA.Count(); j++) { if (setA[j] == setA[j + 1]) { count++; j++; } } memo[tmp] = true; } } } Console.WriteLine(count); } public static int calc(List<int> a, List<int> b) { int count = 0; if (a.Count() < b.Count()) { var tmp = new List<int>(a); a = new List<int>(b); b = new List<int>(tmp); } a.Sort(); // b.Sort(); int res = a.Count() - b.Count(); res /= 2; int cnt = 0; for (int i = 0; i < a.Count() - 1 && cnt < res; i++) { if (a[i] == a[i + 1]) { cnt++; i++; } } count = b.Count() + cnt; return count; } } }
using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Numerics; namespace contest { class contest { static void Main(string[] args) { var num = Console.ReadLine().Split().Select(int.Parse).ToArray(); var card = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = num[0]; int m = num[1]; Array.Sort(card); var dic = new SortedDictionary<int, List<int>>(); for (int i = 0; i < n; i++) { int tmp = card[i] % m; if (!dic.Keys.Contains(tmp)) { dic[tmp] = new List<int>(); } dic[tmp].Add(card[i]); } int count = 0; var memo = new bool[m + 1]; foreach (var item in dic) { int tmp = item.Key; var setA = item.Value; if (memo[tmp]) continue; if (tmp == 0 || (m % 2 == 0 && tmp == m / 2)) { count += setA.Count() / 2; memo[tmp] = true; } else { int res = m - tmp; if (memo[res]) continue; if (dic.Keys.Contains(res)) { var setB = dic[res]; count += calc(setA, setB); memo[tmp] = true; memo[res] = true; } else { setA.Sort(); for (int j = 0; j < setA.Count() - 1; j++) { if (setA[j] == setA[j + 1]) { count++; j++; } } memo[tmp] = true; } } } Console.WriteLine(count); } public static int calc(List<int> a, List<int> b) { int count = 0; if (a.Count() < b.Count()) { var tmp = new List<int>(a); a = new List<int>(b); b = new List<int>(tmp); } a.Sort(); // b.Sort(); int res = a.Count() - b.Count(); res /= 2; int cnt = 0; for (int i = 0; i < a.Count() - 1 && cnt < res; i++) { if (a[i] == a[i + 1]) { cnt++; i++; } } count = b.Count() + cnt; return count; } } }
[["+", 75, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 75, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
578
2
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; using System.Numerics; using System.Threading.Tasks; using System.Text.RegularExpressions; using Debug = System.Diagnostics.Debug; using System.Runtime.CompilerServices; using static System.Math; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var hw = Console.ReadLine().Split().Select(int.Parse).ToArray(); char[][] map = Enumerable.Repeat(0, hw[0]) .Select(_ => Console.ReadLine().ToArray()) .ToArray(); if (map[0][0] == '.') goto invalid; map[0][0] = '.'; int y = 0; int x = 0; while (x != hw[1] || y != hw[0]) { if (y + 1 < hw[0] && map[y + 1][x] == '#') { y++; map[y][x] = '.'; } else if (x + 1 < hw[1] && map[y][x + 1] == '#') { x++; map[y][x] = '.'; } else { break; } } if (map.All(a => a.All(b => b == '.'))) { Console.WriteLine("valid"); } invalid:; Console.WriteLine("invalid"); } }
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; using System.Numerics; using System.Threading.Tasks; using System.Text.RegularExpressions; using Debug = System.Diagnostics.Debug; using System.Runtime.CompilerServices; using static System.Math; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var hw = Console.ReadLine().Split().Select(int.Parse).ToArray(); char[][] map = Enumerable.Repeat(0, hw[0]) .Select(_ => Console.ReadLine().ToArray()) .ToArray(); if (map[0][0] == '.') goto invalid; map[0][0] = '.'; int y = 0; int x = 0; while (x != hw[1] || y != hw[0]) { if (y + 1 < hw[0] && map[y + 1][x] == '#') { y++; map[y][x] = '.'; } else if (x + 1 < hw[1] && map[y][x + 1] == '#') { x++; map[y][x] = '.'; } else { break; } } if (map.All(a => a.All(b => b == '.'))) { Console.WriteLine("Possible"); return; } invalid:; Console.WriteLine("Impossible"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
8
359
6
using System; using System.Text; using System.Linq; using System.Collections.Generic; public class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.H = inpt[0]; this.W = inpt[1]; StringBuilder mp = new StringBuilder(); for (int i = 0; i < this.H; i++) { mp.Append(Reader.ReadLine()); } this.Map = mp.ToString(); bool ans = this.GetAns(1, 0, 0); Console.WriteLine(ans ? "Possible" : "Impossible"); } private Dictionary<int, Dictionary<long, bool>> dic = new Dictionary<int, Dictionary<long, bool>>(); private bool GetAns(long flag, int r, int c) { int posKey = r * this.W + c; if (!dic.ContainsKey(posKey)) { dic.Add(posKey, new Dictionary<long, bool>()); } if (dic[posKey].ContainsKey(flag)) { return dic[posKey][flag]; } if (r == this.H - 1 && c == this.W - 1) { bool ans = true; for (int i = 0; i < this.Map.Length; i++) { bool f = (flag & (1 << i)) != 0; if (Map[i] == '#' && f) { continue; } else if (this.Map[i] == '.' && (!f)) { continue; } else { ans = false; break; } } this.dic[posKey][flag] = ans; return ans; } bool ret = false; if (c < this.W - 1) { int newIdx = r * this.W + (c + 1); if (this.Map[newIdx] == '#') { long newFlag = flag + (1 << newIdx); ret = ret | this.GetAns(newFlag, r, c + 1); } } if (r < this.H - 1 && (!ret)) { int newIdx = (r + 1) * this.W + c; if (this.Map[newIdx] == '#') { long newFlag = flag + (1 << newIdx); ret = ret | this.GetAns(newFlag, r + 1, c); } } this.dic[posKey][flag] = ret; return ret; } private int H; private int W; private string Map; public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 4 5 ##... .##.. ..##. ...## "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
using System; using System.Text; using System.Linq; using System.Collections.Generic; public class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.H = inpt[0]; this.W = inpt[1]; StringBuilder mp = new StringBuilder(); for (int i = 0; i < this.H; i++) { mp.Append(Reader.ReadLine()); } this.Map = mp.ToString(); bool ans = this.GetAns(1, 0, 0); Console.WriteLine(ans ? "Possible" : "Impossible"); } private Dictionary<int, Dictionary<long, bool>> dic = new Dictionary<int, Dictionary<long, bool>>(); private bool GetAns(long flag, int r, int c) { int posKey = r * this.W + c; if (!dic.ContainsKey(posKey)) { dic.Add(posKey, new Dictionary<long, bool>()); } if (dic[posKey].ContainsKey(flag)) { return dic[posKey][flag]; } if (r == this.H - 1 && c == this.W - 1) { bool ans = true; for (int i = 0; i < this.Map.Length; i++) { bool f = (flag & (1l << i)) != 0; if (Map[i] == '#' && f) { continue; } else if (this.Map[i] == '.' && (!f)) { continue; } else { ans = false; break; } } this.dic[posKey][flag] = ans; return ans; } bool ret = false; if (c < this.W - 1) { int newIdx = r * this.W + (c + 1); if (this.Map[newIdx] == '#') { long newFlag = flag + (1l << newIdx); ret = ret | this.GetAns(newFlag, r, c + 1); } } if (r < this.H - 1 && (!ret)) { int newIdx = (r + 1) * this.W + c; if (this.Map[newIdx] == '#') { long newFlag = flag + (1l << newIdx); ret = ret | this.GetAns(newFlag, r + 1, c); } } this.dic[posKey][flag] = ret; return ret; } private int H; private int W; private string Map; public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 4 5 ##... .##.. ..##. ...## "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
[["-", 31, 23, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 31, 203], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 203]]
8
683
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC037A { class Program { static void Main(string[] args) { string[] n = Console.ReadLine().Split(' '); int a = int.Parse(n[0]); int b = int.Parse(n[1]); int c = int.Parse(n[1]); if (a == (b + c)) Console.WriteLine("Yes"); else if (b == (a + c)) Console.WriteLine("Yes"); else if (c == (a + b)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC037A { class Program { static void Main(string[] args) { string[] n = Console.ReadLine().Split(' '); int a = int.Parse(n[0]); int b = int.Parse(n[1]); int c = int.Parse(n[2]); if (a == (b + c)) Console.WriteLine("Yes"); else if (b == (a + c)) Console.WriteLine("Yes"); else if (c == (a + b)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
172
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp44 { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(',').Select(int.Parse).ToArray(); Array.Sort(s); if (s[0] + s[1] == s[2]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp44 { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Array.Sort(s); if (s[0] + s[1] == s[2]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 205, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
120
2
using System; using System.Collections.Generic; using System.Linq; using static AtCoder.Io; namespace AtCoder { class Program { static void Main() { var abc = ReadIntArray(); Console.WriteLine(abc.Sum() / 2 == abc.Max() ? "Yes" : "No"); } } public static class Io { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static long ReadLong() => long.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse); public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse); } }
using System; using System.Collections.Generic; using System.Linq; using static AtCoder.Io; namespace AtCoder { class Program { static void Main() { var abc = ReadIntArray(); Console.WriteLine(abc.Sum() == abc.Max() * 2 ? "Yes" : "No"); } } public static class Io { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static long ReadLong() => long.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse); public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse); } }
[["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 85], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 48], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 203]]
8
233
4
using System; using System.Linq; using static System.Console; class program { static void Main() { var input = ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); input.Sort(); var sorted = input; if (sorted[0] + sorted[1] == sorted[2]) { WriteLine("yes"); } else { WriteLine("No"); } } }
using System; using System.Linq; using static System.Console; class program { static void Main() { var input = ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); input.Sort(); var sorted = input; if (sorted[0] + sorted[1] == sorted[2]) { WriteLine("Yes"); } else { WriteLine("No"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
102
2
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var abc = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); abc.Sort(); Console.WriteLine(abc[2] == abc[0] + abc[1] ? "YES" : "NO"); } } }
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var abc = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); abc.Sort(); Console.WriteLine(abc[2] == abc[0] + abc[1] ? "Yes" : "No"); } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
93
4
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var abc = Console.ReadLine().Split(); var a = int.Parse(abc[0]); var b = int.Parse(abc[1]); var c = int.Parse(abc[2]); if (b + c == a || a + c == b || b + c == c) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var abc = Console.ReadLine().Split(); var a = int.Parse(abc[0]); var b = int.Parse(abc[1]); var c = int.Parse(abc[2]); if (b + c == a || a + c == b || b + a == c) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22]]
8
125
2
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); input.Sort((x, y) => y - x); if (input[0] == input[1] + input[2]) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); input.Sort((a, b) => b - a); if (input[0] == input[1] + input[2]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
113
12
using System; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var nums = new int[3]; for (var i = 0; i < 3; i++) { nums[i] = Convert.ToInt32(input[i]); } Array.Sort(nums); var result = nums[0] + nums[1] == nums[2] ? "YES" : "NO"; Console.WriteLine(result); } }
using System; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var nums = new int[3]; for (var i = 0; i < 3; i++) { nums[i] = Convert.ToInt32(input[i]); } Array.Sort(nums); var result = nums[0] + nums[1] == nums[2] ? "Yes" : "No"; Console.WriteLine(result); } }
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
114
4
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(); int a, b, c; void solve() { a = cin.nextInt(); b = cin.nextInt(); c = cin.nextInt(); int[] candy = { a, b, c }; Array.Sort(candy); Array.Reverse(candy); bool isEnable = candy[0] == (candy[1] + candy[2]); Console.WriteLine(isEnable ? "YES" : "NO"); } 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 { private int mod = 1000000007; // 10^9+7 public int Mod { get; set; } public Mathf() {} public Mathf(int mod) { this.mod = mod; } 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; } } } }
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(); int a, b, c; void solve() { a = cin.nextInt(); b = cin.nextInt(); c = cin.nextInt(); int[] candy = { a, b, c }; Array.Sort(candy); Array.Reverse(candy); bool isEnable = candy[0] == (candy[1] + candy[2]); Console.WriteLine(isEnable ? "Yes" : "No"); } 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 { private int mod = 1000000007; // 10^9+7 public int Mod { get; set; } public Mathf() {} public Mathf(int mod) { this.mod = mod; } 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; } } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
547
4
using System; using System.Linq; public class Test { public static void Main() { string[] str = Console.ReadLine().Split(' '); int a, b, c; a = int.Parse(str[0]); b = int.Parse(str[1]); c = int.Parse(str[2]); if (a == b + c || b == a + c || c == a + b) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; using System.Linq; public class Test { public static void Main() { string[] str = Console.ReadLine().Split(' '); int a, b, c; a = int.Parse(str[0]); b = int.Parse(str[1]); c = int.Parse(str[2]); if (a == b + c || b == a + c || c == a + b) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
125
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC047A { class Program { static void Main(string[] args) { int a, b, c, d; string[] input = Console.ReadLine().Split(' '); a = int.Parse(input[0]); b = int.Parse(input[1]); c = int.Parse(input[2]); d = (a + b + c) / 2; if (a == d || b == d || c == d) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC047A { class Program { static void Main(string[] args) { float a, b, c, d; string[] input = Console.ReadLine().Split(' '); a = int.Parse(input[0]); b = int.Parse(input[1]); c = int.Parse(input[2]); d = (a + b + c) / 2; if (a == d || b == d || c == d) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
158
2
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; namespace atcorder2 { class Program { public static long Read() { return long.Parse(ReadLine()); } public static long[] Reads() { return ReadLine().Split().Select(long.Parse).ToArray(); } public static long gcd(long x, long y) { if (x < y) gcd(y, x); while (y != 0) { var z = x; x = y; y = z % y; } return x; } public static long C(long n, long k) { long x = 1; for (long i = 1; i <= k; i++) { x *= n - i + 1; x /= i; } return x; } static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var q = Reads(); var w = q[0]; var h = q[1]; var n = q[2]; long left = 0; long right = w; long up = h; long down = 0; for (int i = 0; i < n; i++) { q = Reads(); if (q[2] == 1) left = Math.Min(left, q[0]); if (q[2] == 2) right = Math.Max(right, q[0]); if (q[2] == 3) down = Math.Min(down, q[1]); if (q[2] == 4) up = Math.Max(up, q[1]); } if (left < right && down < up) WriteLine((right - left) * (up - down)); else WriteLine(0); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; namespace atcorder2 { class Program { public static long Read() { return long.Parse(ReadLine()); } public static long[] Reads() { return ReadLine().Split().Select(long.Parse).ToArray(); } public static long gcd(long x, long y) { if (x < y) gcd(y, x); while (y != 0) { var z = x; x = y; y = z % y; } return x; } public static long C(long n, long k) { long x = 1; for (long i = 1; i <= k; i++) { x *= n - i + 1; x /= i; } return x; } static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var q = Reads(); var w = q[0]; var h = q[1]; var n = q[2]; long left = 0; long right = w; long up = h; long down = 0; for (int i = 0; i < n; i++) { q = Reads(); if (q[2] == 1) left = Math.Max(left, q[0]); if (q[2] == 2) right = Math.Min(right, q[0]); if (q[2] == 3) down = Math.Max(down, q[1]); if (q[2] == 4) up = Math.Min(up, q[1]); } if (left < right && down < up) WriteLine((right - left) * (up - down)); else WriteLine(0); Console.Out.Flush(); } } }
[["-", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22]]
8
421
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int w = sc.NextInt(); int h = sc.NextInt(); int n = sc.NextInt(); bool[,] map = new bool[w, h]; for (int i = 0; i < n; i++) { int x = sc.NextInt(); int y = sc.NextInt(); int a = sc.NextInt(); for (int j = 0; j < w; j++) { for (int k = 0; k < h; k++) { switch (a) { case 1: if (j < x) { map[j, k] = true; } break; case 2: if (j > x) { map[j, k] = true; } break; case 3: if (k < y) { map[j, k] = true; } break; case 4: if (k > y) { map[j, k] = true; } break; } } } } int answer = 0; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (map[i, j] == false) { 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(); int w = sc.NextInt(); int h = sc.NextInt(); int n = sc.NextInt(); bool[,] map = new bool[w, h]; for (int i = 0; i < n; i++) { int x = sc.NextInt(); int y = sc.NextInt(); int a = sc.NextInt(); for (int j = 0; j < w; j++) { for (int k = 0; k < h; k++) { switch (a) { case 1: if (j < x) { map[j, k] = true; } break; case 2: if (j >= x) { map[j, k] = true; } break; case 3: if (k < y) { map[j, k] = true; } break; case 4: if (k >= y) { map[j, k] = true; } break; } } } } int answer = 0; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (map[i, j] == false) { 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(); } }
[["-", 8, 254, 0, 239, 0, 57, 15, 16, 17, 47], ["+", 8, 254, 0, 239, 0, 57, 15, 16, 17, 20]]
8
604
4
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[] WHN = Console.ReadLine().Split().Select(int.Parse).ToArray(); int xuplim = WHN[1]; int xdnlim = 0; int yuplim = WHN[0]; int ydnlim = 0; int[][] xyas = new int[WHN[2]][] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); foreach (int[] xya in xyas) { switch (xya[2]) { case 1: xdnlim = Math.Max(xdnlim, xya[0]); break; case 2: xuplim = Math.Min(xuplim, xya[0]); break; case 3: ydnlim = Math.Max(ydnlim, xya[1]); break; case 4: yuplim = Math.Min(yuplim, xya[1]); break; } } Console.WriteLine(Math.Max((xuplim - xdnlim), 0) * Math.Max((yuplim - ydnlim), 0)); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[] WHN = Console.ReadLine().Split().Select(int.Parse).ToArray(); int xuplim = WHN[0]; int xdnlim = 0; int yuplim = WHN[1]; int ydnlim = 0; int[][] xyas = new int[WHN[2]][] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); foreach (int[] xya in xyas) { switch (xya[2]) { case 1: xdnlim = Math.Max(xdnlim, xya[0]); break; case 2: xuplim = Math.Min(xuplim, xya[0]); break; case 3: ydnlim = Math.Max(ydnlim, xya[1]); break; case 4: yuplim = Math.Min(yuplim, xya[1]); break; } } Console.WriteLine(Math.Max((xuplim - xdnlim), 0) * Math.Max((yuplim - ydnlim), 0)); } }
[["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203]]
8
253
4
using System; using System.Linq; public class Hello { public static void Main() { int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int W = nums[0]; int H = nums[1]; int N = nums[2]; int minX = 0; int minY = 0; int maxX = Int32.MaxValue; int maxY = Int32.MaxValue; for (int i = 0; i < N; i++) { nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); switch (nums[2]) { case 1: minX = Math.Max(minX, nums[0]); break; case 2: maxX = Math.Min(maxX, nums[0]); break; case 3: minY = Math.Max(minY, nums[1]); break; case 4: maxY = Math.Min(maxY, nums[1]); break; default: break; } } int difX = maxX - minX; //横の長さ int difY = maxY - minY; //縦の長さ Console.WriteLine(difX >= 0 && difY >= 0 ? (difX * difY) : 0); } }
using System; using System.Linq; public class Hello { public static void Main() { int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int W = nums[0]; int H = nums[1]; int N = nums[2]; int minX = 0; int minY = 0; int maxX = W; int maxY = H; for (int i = 0; i < N; i++) { nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); switch (nums[2]) { case 1: minX = Math.Max(minX, nums[0]); break; case 2: maxX = Math.Min(maxX, nums[0]); break; case 3: minY = Math.Max(minY, nums[1]); break; case 4: maxY = Math.Min(maxY, nums[1]); break; default: break; } } int difX = maxX - minX; //横の長さ int difY = maxY - minY; //縦の長さ Console.WriteLine(difX >= 0 && difY >= 0 ? (difX * difY) : 0); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
266
8
// // using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var w = line[0]; var h = line[1]; var n = line[2]; var a1 = 0; var a2 = w; var a3 = 0; var a4 = h; for (var i = 0; i < n; i++) { line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var x = line[0]; var y = line[1]; var a = line[2]; switch (a) { case 1: a1 = Math.Max(a1, x); break; case 2: a2 = Math.Min(a2, x); break; case 3: a3 = Math.Min(a3, y); break; case 4: a4 = Math.Min(a4, y); break; default: break; } } var deltaX = Math.Max(0, a2 - a1); var deltaY = Math.Max(0, a4 - a3); Console.WriteLine(deltaY * deltaX); } }
// // using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var w = line[0]; var h = line[1]; var n = line[2]; var a1 = 0; var a2 = w; var a3 = 0; var a4 = h; for (var i = 0; i < n; i++) { line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var x = line[0]; var y = line[1]; var a = line[2]; switch (a) { case 1: a1 = Math.Max(a1, x); break; case 2: a2 = Math.Min(a2, x); break; case 3: a3 = Math.Max(a3, y); break; case 4: a4 = Math.Min(a4, y); break; default: break; } } var deltaX = Math.Max(0, a2 - a1); var deltaY = Math.Max(0, a4 - a3); Console.WriteLine(deltaY * deltaX); } }
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22]]
8
278
2
using System; using System.Linq; class Program { static void Main(string[] args) { int W = cin.ni(); int H = cin.ni(); int N = cin.ni(); int right = W; int left = 0; int top = H; int bottom = 0; for (int i = 0; i < N; i++) { int x = cin.ni(); int y = cin.ni(); int a = cin.ni(); switch (a) { case 1: left = Math.Max(left, x); break; case 2: right = Math.Min(right, x); break; case 3: bottom = Math.Max(bottom, x); break; case 4: top = Math.Min(top, y); break; default: break; } } right = Math.Max(right, left); top = Math.Max(top, bottom); Console.WriteLine((right - left) * (top - bottom)); } } public class cin { private static string[] s = new string[0]; private static int i = 0; private static char[] cs = new char[] { ' ' }; public static 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 static int ni() { return int.Parse(next()); } public static long nextLong() { return long.Parse(next()); } public static double nextDouble() { return double.Parse(next()); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int W = cin.ni(); int H = cin.ni(); int N = cin.ni(); int right = W; int left = 0; int top = H; int bottom = 0; for (int i = 0; i < N; i++) { int x = cin.ni(); int y = cin.ni(); int a = cin.ni(); switch (a) { case 1: left = Math.Max(left, x); break; case 2: right = Math.Min(right, x); break; case 3: bottom = Math.Max(bottom, y); break; case 4: top = Math.Min(top, y); break; default: break; } } right = Math.Max(right, left); top = Math.Max(top, bottom); Console.WriteLine((right - left) * (top - bottom)); } } public class cin { private static string[] s = new string[0]; private static int i = 0; private static char[] cs = new char[] { ' ' }; public static 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 static int ni() { return int.Parse(next()); } public static long nextLong() { return long.Parse(next()); } public static double nextDouble() { return double.Parse(next()); } }
[["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
8
391
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication19 { class Program { static void Main(string[] args) { var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (a[0] != a[1] && a[1] != a[2] && a[0] != a[1]) Console.WriteLine(3); if (a[0] == a[1] && a[1] == a[2]) Console.WriteLine(1); if ((a[0] == a[1] || a[1] == a[2] || a[0] == a[2]) && (a[1] != a[2] || a[1] != a[2] || a[0] != a[1])) Console.WriteLine(2); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication19 { class Program { static void Main(string[] args) { var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (a[0] != a[1] && a[1] != a[2] && a[0] != a[2]) Console.WriteLine(3); if (a[0] == a[1] && a[1] == a[2]) Console.WriteLine(1); else if ((a[0] == a[1] || a[1] == a[2] || a[0] == a[2]) && (a[1] != a[2] || a[1] != a[2] || a[0] != a[1])) Console.WriteLine(2); } } }
[["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
204
3
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(); string t = "CODEFESTIVAL201"; long answer = 0; for (int i = 0; i < 16; i++) { if (s[i] != t[i]) { 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(); string t = "CODEFESTIVAL2016"; long answer = 0; for (int i = 0; i < 16; i++) { if (s[i] != t[i]) { 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, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
8
395
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace CF2016B_A { class Program { static string a = "CODEFESTIVAL2016"; static int ans; static void Main(string[] args) { var t = ReadLine(); for (int i = 0; i < 16; i++) { if (a[i] == t[i]) { ans++; } } Console.WriteLine(ans); } static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace CF2016B_A { class Program { static string a = "CODEFESTIVAL2016"; static int ans; static void Main(string[] args) { var t = ReadLine(); for (int i = 0; i < 16; i++) { if (a[i] != t[i]) { ans++; } } Console.WriteLine(ans); } static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79]]
8
141
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long a = sc.NextLong(); long b = sc.NextLong(); string s = sc.Next(); long count = 0; long order = 1; for (int i = 0; i < n; i++) { if (s[i] == 'a') { if (count < a + b) { Console.WriteLine("YES"); count++; } else { Console.WriteLine("No"); } } else if (s[i] == 'b') { if (count < a + b && order <= b) { Console.WriteLine("YES"); count++; } else { Console.WriteLine("No"); } order++; } else { Console.WriteLine("No"); } } } 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 n = sc.NextLong(); long a = sc.NextLong(); long b = sc.NextLong(); string s = sc.Next(); long count = 0; long order = 1; for (int i = 0; i < n; i++) { if (s[i] == 'a') { if (count < a + b) { Console.WriteLine("Yes"); count++; } else { Console.WriteLine("No"); } } else if (s[i] == 'b') { if (count < a + b && order <= b) { Console.WriteLine("Yes"); count++; } else { Console.WriteLine("No"); } order++; } else { Console.WriteLine("No"); } } } 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, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
510
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace CF2016B_B { class Program { static int N, A, B; static int a, b; static void Main(string[] args) { var t = scan; N = t[0]; A = t[1]; B = t[2]; var S = ReadLine(); for (int i = 0; i < S.Length; i++) { if (S[i] == 'a') { if (a + b < A + B) { a++; Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } if (S[i] == 'b') { if (a + b < A + B && b < B) { b++; Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else Console.WriteLine("No"); } } static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace CF2016B_B { class Program { static int N, A, B; static int a, b; static void Main(string[] args) { var t = scan; N = t[0]; A = t[1]; B = t[2]; var S = ReadLine(); for (int i = 0; i < S.Length; i++) { if (S[i] == 'a') { if (a + b < A + B) { a++; Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else if (S[i] == 'b') { if (a + b < A + B && b < B) { b++; Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else Console.WriteLine("No"); } } static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
8
259
1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Threading; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { public Program() {} static void Main(string[] args) { new Program().prog(); } Scanner cin; const int MOD = 1000000007; const int INF = int.MaxValue; const double EPS = 1e-7; const double PI = 3.1415926536; void prog() { cin = new Scanner(); int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } }; int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } }; int N = cin.nextInt(); int A = cin.nextInt(); int B = cin.nextInt(); string str = cin.next(); int a = 0; int b = 0; bool[] yes = new bool[str.Length]; for (int i = 0; i < str.Length; i++) { yes[i] = false; } for (int i = 0; i < str.Length; i++) { if (str[i] == 'a') { a++; if (a <= A + B) { yes[i] = true; } } else if (str[i] == 'b') { b++; if (a <= A + B && b <= B) { yes[i] = true; a++; } } } for (int i = 0; i < str.Length; i++) { Console.WriteLine(yes[i] ? "Yes" : "No"); } } } 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.IO; using System.Threading; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { public Program() {} static void Main(string[] args) { new Program().prog(); } Scanner cin; const int MOD = 1000000007; const int INF = int.MaxValue; const double EPS = 1e-7; const double PI = 3.1415926536; void prog() { cin = new Scanner(); int[,] dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } }; int[,] dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } }; int N = cin.nextInt(); int A = cin.nextInt(); int B = cin.nextInt(); string str = cin.next(); int a = 0; int b = 0; bool[] yes = new bool[str.Length]; for (int i = 0; i < str.Length; i++) { yes[i] = false; } for (int i = 0; i < str.Length; i++) { if (str[i] == 'a') { a++; if (a <= A + B) { yes[i] = true; } } else if (str[i] == 'b') { b++; if (a < A + B && b <= B) { yes[i] = true; a++; } } } for (int i = 0; i < str.Length; i++) { Console.WriteLine(yes[i] ? "Yes" : "No"); } } } 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, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 18]]
8
604
2
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long answer = 0; string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long w = long.Parse(input[0]); long h = long.Parse(input[1]); long wMemo = h + 1; long hMemo = w + 1; long[][] pathArray = new long [w + h][]; for (long i = 0; i < w + h; i++) { pathArray[i] = new long[2]; // 0は横、1は縦 } for (long i = 0; i < w; i++) { pathArray[i][0] = long.Parse(Console.ReadLine()); pathArray[i][1] = 0; } for (long i = w; i < w + h; i++) { pathArray[w + i][0] = long.Parse(Console.ReadLine()); pathArray[w + i][1] = 1; } Array.Sort(pathArray, (a, b) => a[0].CompareTo(b[0])); for (long i = 0; i < w + h; i++) { if (pathArray[i][1] == 0) { hMemo--; answer += pathArray[i][0] * wMemo; } else { wMemo--; answer += pathArray[i][0] * hMemo; } } Console.WriteLine(answer); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long answer = 0; string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long w = long.Parse(input[0]); long h = long.Parse(input[1]); long wMemo = h + 1; long hMemo = w + 1; long[][] pathArray = new long [w + h][]; for (long i = 0; i < w + h; i++) { pathArray[i] = new long[2]; // 0は横、1は縦 } for (long i = 0; i < w; i++) { pathArray[i][0] = long.Parse(Console.ReadLine()); pathArray[i][1] = 0; } for (long i = w; i < w + h; i++) { pathArray[i][0] = long.Parse(Console.ReadLine()); pathArray[i][1] = 1; } Array.Sort(pathArray, (a, b) => a[0].CompareTo(b[0])); for (long i = 0; i < w + h; i++) { if (pathArray[i][1] == 0) { hMemo--; answer += pathArray[i][0] * wMemo; } else { wMemo--; answer += pathArray[i][0] * hMemo; } } Console.WriteLine(answer); } }
[["-", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 72]]
8
332
4
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 sc = new ScanCHK(); var se = new Search(); int h, w; sc.Multi(out h, out w); var pw = new long[w]; var ph = new long[h]; var wimos = new long[w + 1]; var himos = new long[h + 1]; for (int i = 0; i < w; i++) { pw[i] = sc.Int; } Array.Sort(pw); for (int i = 0; i < w; i++) { wimos[i + 1] = wimos[i] + pw[i]; } for (int i = 0; i < h; i++) { ph[i] = sc.Int; } Array.Sort(ph); for (int i = 0; i < h; i++) { himos[i + 1] = himos[i] + ph[i]; } long sum = 0; for (int i = 0; i < w; i++) { int m = se.UpperBound(ph, pw[i]); sum += himos[m] + pw[i] * (h - m + 1); } var a = sum + himos[h]; sw.WriteLine(a); 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 string con<T>(string sep, IEnumerable<T> a) { return string.Join(sep, a); } static string con<T>(IEnumerable<T> a) { return con(" ", a); } 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) { int n = a.Count; var ret = new T[n]; for (int i = 0; i < n; i++) ret[i] = a[i]; return ret; } } class ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); return s == s.Trim() ? s : ""; } } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public 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 { 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 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 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 long[] mulmat(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 long[][] mulmat(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] = mulmat(Bt, A[i]); return ret; } public long[] addmat(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 long[][] addmat(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = addmat(A[i], B[i]); return ret; } 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 ret = 1; for (int k = 0; k < r; k++) if (numerator[k] > 1) ret = ret * numerator[k] % Mod; return ret; } } class Search { // nより大きいの項のindexのうち最小のものを返す // n以下の項のindexのうち最大のもの+1を返す // そこに挿入 public int UpperBound<T>(IList<T> a, T n) where T : IComparable<T> { if (a.Count == 0) return 0; int l = 0, r = a.Count - 1; while (l < r) { int m = (l + r) >> 1; if (a[m].CompareTo(n) <= 0) { if (a[m + 1].CompareTo(n) > 0) return m + 1; l = m + 1; } else r = m - 1; } if (a[l].CompareTo(n) <= 0) return l + 1; return l; } // n未満の項のindexのうち最大のもの+1を返す // n以上の項のindexのうち最小のものを返す // そこに挿入 public int LowerBound<T>(IList<T> a, T n) where T : IComparable<T> { if (a.Count == 0) return 0; int l = 0, r = a.Count - 1; while (l < r) { int m = (l + r) >> 1; if (a[m].CompareTo(n) < 0) { if (a[m + 1].CompareTo(n) >= 0) return m + 1; l = m + 1; } else r = m - 1; } if (a[l].CompareTo(n) < 0) return l + 1; return l; } }
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 sc = new ScanCHK(); var se = new Search(); int h, w; sc.Multi(out w, out h); var pw = new long[w]; var ph = new long[h]; var wimos = new long[w + 1]; var himos = new long[h + 1]; for (int i = 0; i < w; i++) { pw[i] = sc.Int; } Array.Sort(pw); for (int i = 0; i < w; i++) { wimos[i + 1] = wimos[i] + pw[i]; } for (int i = 0; i < h; i++) { ph[i] = sc.Int; } Array.Sort(ph); for (int i = 0; i < h; i++) { himos[i + 1] = himos[i] + ph[i]; } long sum = 0; for (int i = 0; i < w; i++) { int m = se.UpperBound(ph, pw[i]); sum += himos[m] + pw[i] * (h - m + 1); } var a = sum + himos[h]; sw.WriteLine(a); 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 string con<T>(string sep, IEnumerable<T> a) { return string.Join(sep, a); } static string con<T>(IEnumerable<T> a) { return con(" ", a); } 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) { int n = a.Count; var ret = new T[n]; for (int i = 0; i < n; i++) ret[i] = a[i]; return ret; } } class ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); return s == s.Trim() ? s : ""; } } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public 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 { 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 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 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 long[] mulmat(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 long[][] mulmat(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] = mulmat(Bt, A[i]); return ret; } public long[] addmat(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 long[][] addmat(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = addmat(A[i], B[i]); return ret; } 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 ret = 1; for (int k = 0; k < r; k++) if (numerator[k] > 1) ret = ret * numerator[k] % Mod; return ret; } } class Search { // nより大きいの項のindexのうち最小のものを返す // n以下の項のindexのうち最大のもの+1を返す // そこに挿入 public int UpperBound<T>(IList<T> a, T n) where T : IComparable<T> { if (a.Count == 0) return 0; int l = 0, r = a.Count - 1; while (l < r) { int m = (l + r) >> 1; if (a[m].CompareTo(n) <= 0) { if (a[m + 1].CompareTo(n) > 0) return m + 1; l = m + 1; } else r = m - 1; } if (a[l].CompareTo(n) <= 0) return l + 1; return l; } // n未満の項のindexのうち最大のもの+1を返す // n以上の項のindexのうち最小のものを返す // そこに挿入 public int LowerBound<T>(IList<T> a, T n) where T : IComparable<T> { if (a.Count == 0) return 0; int l = 0, r = a.Count - 1; while (l < r) { int m = (l + r) >> 1; if (a[m].CompareTo(n) < 0) { if (a[m + 1].CompareTo(n) >= 0) return m + 1; l = m + 1; } else r = m - 1; } if (a[l].CompareTo(n) < 0) return l + 1; return l; } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
2,916
4
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 sc = new ScanCHK(); int n, a, b; sc.Multi(out n, out a, out b); int ans = 0; for (int i = 0; i < n; i++) { int t = sc.Int; if (t < a && b <= t) ++ans; } sw.WriteLine(ans); 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 string con<T>(IEnumerable<T> a) { return string.Join(" ", a); } 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 ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); return s == s.Trim() ? s : ""; } } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public 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 sc = new ScanCHK(); int n, a, b; sc.Multi(out n, out a, out b); int ans = 0; for (int i = 0; i < n; i++) { int t = sc.Int; if (t < a || b <= t) ++ans; } sw.WriteLine(ans); 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 string con<T>(IEnumerable<T> a) { return string.Join(" ", a); } 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 ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); return s == s.Trim() ? s : ""; } } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public 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; } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106]]
8
2,343
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace b { class Program { static void Main(string[] args) { int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = nk[0]; int k = nk[1]; int[] l = new int[26]; for (int i = 0; i < n; i++) { l[(Console.ReadLine()[0] - 'A')]++; } PriorityQueue<int> pq = new PriorityQueue<int>(CompareAccount); for (int i = 0; i < n; i++) { if (l[i] > 0) pq.Enqueue(l[i]); } int ans = 0; while (pq.Count >= k) { List<int> ls = new List<int>(); for (int i = 0; i < k; i++) { ls.Add(pq.Dequeue() - 1); } for (int i = 0; i < ls.Count; i++) { if (ls[i] > 0) pq.Enqueue(ls[i]); } ans++; } Console.WriteLine(ans); } static int CompareAccount(int x, int y) { if (x > y) return -1; // xがyより大きい else if (x < y) return 1; // xがyより小さい else // if (x == y) return 0; // xとyが等しい } } class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = 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; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace b { class Program { static void Main(string[] args) { int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = nk[0]; int k = nk[1]; int[] l = new int[26]; for (int i = 0; i < n; i++) { l[(Console.ReadLine()[0] - 'A')]++; } PriorityQueue<int> pq = new PriorityQueue<int>(CompareAccount); for (int i = 0; i < 26; i++) { if (l[i] > 0) pq.Enqueue(l[i]); } int ans = 0; while (pq.Count >= k) { List<int> ls = new List<int>(); for (int i = 0; i < k; i++) { ls.Add(pq.Dequeue() - 1); } for (int i = 0; i < ls.Count; i++) { if (ls[i] > 0) pq.Enqueue(ls[i]); } ans++; } Console.WriteLine(ans); } static int CompareAccount(int x, int y) { if (x > y) return -1; // xがyより大きい else if (x < y) return 1; // xがyより小さい else // if (x == y) return 0; // xとyが等しい } } class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = 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; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
706
2
using System; using System.Collections.Generic; namespace agc005_a { class Program { static void Main(string[] args) { string s = Console.ReadLine(); Stack<char> stack = new Stack<char>(); for (int i = 0; i < s.Length; i++) { if (s[i] == 'S') { stack.Push('S'); } else { if (stack == null) { stack.Push('T'); } else { if (stack.Peek() == 'S') { stack.Pop(); } else { stack.Push('T'); } } } } Console.WriteLine(stack.Count); } } }
using System; using System.Collections.Generic; namespace agc005_a { class Program { static void Main(string[] args) { string s = Console.ReadLine(); Stack<char> stack = new Stack<char>(); for (int i = 0; i < s.Length; i++) { if (s[i] == 'S') { stack.Push('S'); } else { if (stack.Count == 0) { stack.Push('T'); } else { if (stack.Peek() == 'S') { stack.Pop(); } else { stack.Push('T'); } } } } Console.WriteLine(stack.Count); } } }
[["+", 75, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 75, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 215], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203]]
8
156
4
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int cnt = 0; int cnt_max = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'T') { cnt++; } else { cnt--; } cnt_max = Math.Max(cnt, cnt_max); } Console.WriteLine(cnt_max); } }
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int cnt = 0; int cnt_max = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'T') { cnt++; } else { cnt--; } cnt_max = Math.Max(cnt, cnt_max); } Console.WriteLine(cnt_max * 2); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
95
2
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static long n = long.Parse(Console.ReadLine()); // long.Parseはstringをlongに変換。 static long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); static long[] positions = new long[n]; //それぞれの数字が左から何番目か static long[] bits = new long[n + 2]; static int middleNum = 0; static long answer = 0; static void Main() { for (int i = 0; i < n; i++) { positions[nums[i] - 1] = i; } for (int i = 0; i < n; i++) { middleNum = i; long leftCount = SearchLeft(0, positions[i]); long rightCount = SearchRight(0, n - 1 - positions[i]); // Console.WriteLine(leftCount+" "+rightCount +" "+ answer); answer += (i + 1) * (leftCount + 1) * (rightCount + 1); //数 × 数が加算される部分列の個数 BitAdd(positions[i] + 1, 1); //使用位置を1にする } Console.WriteLine(answer); } static void BitAdd(long i, long x) // BITでiだけにx加算 { while (i <= n) { bits[i] += x; i += i & -i; } } static long BitSum(long i) // BITでi以下の総和を計算 { long sum = 0; while (i > 0) { sum += bits[i]; i -= i & -i; } return sum; } static long SearchLeft(long min, long max) //二分探索法で最大値を求める { while (true) { long mid = min + (max - min) / 2; if (CheckLeft(mid)) min = mid; //さらに大きくても成り立つかも else max = mid; if (max - min <= 1) { if (CheckLeft(max)) { return max; //最大値で成り立つかの確認を優先 } else { return min; } break; } } } static long SearchRight(long min, long max) //二分探索法で最大値を求める { while (true) { long mid = min + (max - min) / 2; if (CheckRight(mid)) min = mid; //さらに大きくても成り立つかも else max = mid; if (max - min <= 1) { if (CheckRight(max)) { return max; //最大値で成り立つかの確認を優先 } else { return min; } break; } } } static bool CheckLeft(long testNum) { if (BitSum(middleNum) - BitSum(middleNum - testNum) == 0) return true; return false; } static bool CheckRight(long testNum) { if (BitSum(middleNum + 1 + testNum) - BitSum(middleNum + 1) == 0) return true; return false; } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static long n = long.Parse(Console.ReadLine()); // long.Parseはstringをlongに変換。 static long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); static long[] positions = new long[n]; //それぞれの数字が左から何番目か static long[] bits = new long[n + 2]; static long middleNum = 0; static long answer = 0; static void Main() { for (int i = 0; i < n; i++) { positions[nums[i] - 1] = i; } for (int i = 0; i < n; i++) { middleNum = positions[i]; long leftCount = SearchLeft(0, positions[i]); long rightCount = SearchRight(0, n - 1 - positions[i]); // Console.WriteLine(leftCount+" "+rightCount +" "+ answer); answer += (i + 1) * (leftCount + 1) * (rightCount + 1); //数 × 数が加算される部分列の個数 BitAdd(positions[i] + 1, 1); //使用位置を1にする } Console.WriteLine(answer); } static void BitAdd(long i, long x) // BITでiだけにx加算 { while (i <= n) { bits[i] += x; i += i & -i; } } static long BitSum(long i) // BITでi以下の総和を計算 { long sum = 0; while (i > 0) { sum += bits[i]; i -= i & -i; } return sum; } static long SearchLeft(long min, long max) //二分探索法で最大値を求める { while (true) { long mid = min + (max - min) / 2; if (CheckLeft(mid)) min = mid; //さらに大きくても成り立つかも else max = mid; if (max - min <= 1) { if (CheckLeft(max)) { return max; //最大値で成り立つかの確認を優先 } else { return min; } break; } } } static long SearchRight(long min, long max) //二分探索法で最大値を求める { while (true) { long mid = min + (max - min) / 2; if (CheckRight(mid)) min = mid; //さらに大きくても成り立つかも else max = mid; if (max - min <= 1) { if (CheckRight(max)) { return max; //最大値で成り立つかの確認を優先 } else { return min; } break; } } } static bool CheckLeft(long testNum) { if (BitSum(middleNum) - BitSum(middleNum - testNum) == 0) return true; return false; } static bool CheckRight(long testNum) { if (BitSum(middleNum + 1 + testNum) - BitSum(middleNum + 1) == 0) return true; return false; } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
8
537
5
using System; class Program { static void Main(string[] args) { // 整数の入力 String a = Console.ReadLine(); //出力 Console.WriteLine(a.Insert(3, " ")); } }
using System; class Program { static void Main(string[] args) { // 整数の入力 String a = Console.ReadLine(); //出力 Console.WriteLine(a.Insert(4, " ")); } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203]]
8
45
2
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.Contracts; using System.IO; using System.Linq; using System.Numerics; using System.Xml.Schema; using System.Threading; using System.Diagnostics.CodeAnalysis; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int BuildBitCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } 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); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } 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]); } 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]); } 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]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = 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]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { var S = GetStr().ToCharArray(); var K = GetInt(); for (int i = 0; i < S.Length; i++) { if (K < 26 - (S[i] - 'a')) continue; K -= 26 - (S[i] - 'a'); S[i] = 'a'; } S[S.Length - 1] = (char)((S[S.Length - 1] - 'a' + K) % 26 + 'a'); Console.WriteLine(new string(S)); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.Contracts; using System.IO; using System.Linq; using System.Numerics; using System.Xml.Schema; using System.Threading; using System.Diagnostics.CodeAnalysis; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int BuildBitCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } 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); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } 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]); } 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]); } 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]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = 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]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { var S = GetStr().ToCharArray(); var K = GetInt(); for (int i = 0; i < S.Length; i++) { if (K < 26 - (S[i] - 'a')) continue; K -= (26 - (S[i] - 'a')) % 26; S[i] = 'a'; } S[S.Length - 1] = (char)((S[S.Length - 1] - 'a' + K) % 26 + 'a'); Console.WriteLine(new string(S)); } } }
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
1,973
4
using System; namespace CF2016qA { class C { static void Main(string[] args) { string s = Console.ReadLine(); int K = int.Parse(Console.ReadLine()); char[] res = new char[s.Length]; for (int i = 0; i < s.Length; i++) { int x = 26 - (s[i] - 'a'); if (x <= K) { res[i] = 'a'; K -= x; } else { res[i] = s[i]; } } if (0 < K) { res[s.Length - 1] = (char)(res[s.Length - 1] + K % 26); } Console.WriteLine(res); } } }
using System; namespace CF2016qA { class C { static void Main(string[] args) { string s = Console.ReadLine(); int K = int.Parse(Console.ReadLine()); char[] res = new char[s.Length]; for (int i = 0; i < s.Length; i++) { int x = 26 - (s[i] - 'a'); if (x <= K) { res[i] = 'a'; K -= x % 26; } else { res[i] = s[i]; } } if (0 < K) { res[s.Length - 1] = (char)(res[s.Length - 1] + K % 26); } Console.WriteLine(res); } } }
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
168
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CF2016A_C { class Program { static char[] all = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; static void Main(string[] args) { var t = Console.ReadLine(); int K = scan[0]; int n = t.Length; int now = 0; char[] S = t.ToCharArray(); while (now < n) { var d = all.Length - all.TakeWhile(a => a != S[now]).Count(); if (S[now] != 'a' && d < K) { S[now] = 'a'; K -= d; } now++; } var noul = all.TakeWhile(a => a != S[n - 1]).Count(); // Console.WriteLine(noul); if (K > 0) { noul += K; noul %= all.Length; // Console.WriteLine(noul); S[n - 1] = all[noul]; } Console.WriteLine(S); } static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CF2016A_C { class Program { static char[] all = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; static void Main(string[] args) { var t = Console.ReadLine(); int K = scan[0]; int n = t.Length; int now = 0; char[] S = t.ToCharArray(); while (now < n) { int d = all.Length - all.TakeWhile(a => a != S[now]).Count(); if (S[now] != 'a' && d <= K) { S[now] = 'a'; K -= d; } now++; } int noul = all.TakeWhile(a => a != S[n - 1]).Count(); // Console.WriteLine(noul); if (K > 0) { noul += K; noul %= all.Length; // Console.WriteLine(noul); S[n - 1] = all[noul]; } Console.WriteLine(S); } static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
356
6