buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { var N = IO.GetInt(); var A = IO.GetIntList(); var B = IO.GetIntList(); var C = IO.GetIntList(); var ans = 0; for (int i = 0; i < N; i++) { ans += B[A[i] - 1]; if (A[i + 1] - A[i] == 1) ans += C[i]; } Console.WriteLine(ans); } } static class IO { static public string GetString() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { var N = IO.GetInt(); var A = IO.GetIntList(); var B = IO.GetIntList(); var C = IO.GetIntList(); var ans = 0; for (int i = 0; i < N; i++) { ans += B[A[i] - 1]; if (i == N - 1) break; if (A[i + 1] - A[i] == 1) ans += C[A[i] - 1]; } Console.WriteLine(ans); } } static class IO { static public string GetString() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
391
15
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var num = int.Parse(Console.ReadLine()); var a = ReadList(); var b = ReadList(); var c = ReadList(); c.Add(0); int satisfy = 0; for (int i = 0; i < num; i++) { satisfy += b[a[i] - 1]; if (i != num - 1) { satisfy += c[a[i] - 1]; } } Console.WriteLine(satisfy); } public static List<int> ReadList() { var a_text = Console.ReadLine().Split(' '); return a_text.Select(x => int.Parse(x)).ToList(); } }
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var num = int.Parse(Console.ReadLine()); var a = ReadList(); var b = ReadList(); var c = ReadList(); c.Add(0); int satisfy = 0; int before = 10000; for (int i = 0; i < num; i++) { satisfy += b[a[i] - 1]; if (before == a[i] - 1) { satisfy += c[a[i] - 2]; } before = a[i]; } Console.WriteLine(satisfy); } public static List<int> ReadList() { var a_text = Console.ReadLine().Split(' '); return a_text.Select(x => int.Parse(x)).ToList(); } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
178
21
using System; using System.Collections.Generic; using System.Linq; namespace abc140_b { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var arrayA = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var arrayB = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var arrayC = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var sum = 0; var prev = -1; foreach (var a in arrayA) { var index = a - 1; var b = arrayB[index]; var c = 0; if (index == prev + 1) { c = arrayC[index - 1]; } sum += b + c; prev = index; } Console.WriteLine(sum); } } }
using System; using System.Linq; namespace abc140_b { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var arrayA = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var arrayB = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var arrayC = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var sum = 0; var prev = -10; foreach (var a in arrayA) { var index = a - 1; var b = arrayB[index]; var c = 0; if (index == prev + 1) { c = arrayC[index - 1]; } sum += b + c; prev = index; } Console.WriteLine(sum); } } }
[["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203]]
8
205
9
using System; using System.Linq; namespace ABC140B { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var Bs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var Cs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var ans = 0; var bef = 0; for (var i = 1; i <= N; i++) { var A = As[i - 1]; ans += Bs[A - 1]; ; if (bef == A - 1) ans += Cs[bef - 1]; bef = A; } Console.WriteLine(ans); } } }
using System; using System.Linq; namespace ABC140B { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); var Bs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var Cs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var ans = 0; var bef = int.MinValue; for (var i = 0; i < N; i++) { var A = As[i]; ans += Bs[A]; if (bef == A - 1) ans += Cs[bef]; bef = A; } Console.WriteLine(ans); } } }
[["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 260, 0, 35]]
8
202
17
using System; namespace ABC140 { class B { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Console.WriteLine(Math.Pow(N, 3)); int[] A = new int[N]; int[] B = new int[N]; int[] C = new int[N]; string[] input = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { A[i] = int.Parse(input[i]); } input = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { B[i] = int.Parse(input[i]); } input = Console.ReadLine().Split(' '); for (int i = 0; i < N - 1; i++) { C[i] = int.Parse(input[i]); } int count = B[A[0] - 1]; for (int i = 1; i < N; i++) { if (A[i] == A[i - 1] + 1) { count += B[A[i] - 1] + C[A[i] - 2]; } else { count += B[A[i] - 1]; } } Console.WriteLine(count); } } }
using System; namespace ABC140 { class B { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] A = new int[N]; int[] B = new int[N]; int[] C = new int[N]; string[] input = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { A[i] = int.Parse(input[i]); } input = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { B[i] = int.Parse(input[i]); } input = Console.ReadLine().Split(' '); for (int i = 0; i < N - 1; i++) { C[i] = int.Parse(input[i]); } int count = B[A[0] - 1]; for (int i = 1; i < N; i++) { if (A[i] == A[i - 1] + 1) { count += B[A[i] - 1] + C[A[i] - 2]; } else { count += B[A[i] - 1]; } } Console.WriteLine(count); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
317
14
using System; using System.Collections.Generic; using System.Linq; namespace Buffet { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(x => int.Parse(x)); var B = Console.ReadLine().Split().Select(x => int.Parse(x)); var C = Console.ReadLine().Split().Select(x => int.Parse(x)); var score = 0; var prevCooking = 0; foreach (var a in A.Select((x, i) => new { Cooking = x, Index = i })) { score += B.ElementAt(a.Cooking - 1); if ((a.Cooking - 1) == prevCooking && a.Cooking > 0 && a.Cooking <= C.Count()) { score += C.ElementAt(a.Cooking - 1); } prevCooking = a.Cooking; } Console.WriteLine(score); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Buffet { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(x => int.Parse(x)); var B = Console.ReadLine().Split().Select(x => int.Parse(x)); var C = Console.ReadLine().Split().Select(x => int.Parse(x)); var score = 0; var prevCooking = 0; foreach (var a in A.Select((x, i) => new { Cooking = x, Index = i })) { score += B.ElementAt(a.Cooking - 1); if ((a.Cooking - 1) == prevCooking) { if (prevCooking > 0) { score += C.ElementAt(prevCooking - 1); } } prevCooking = a.Cooking; } Console.WriteLine(score); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["-", 15, 16, 31, 16, 12, 16, 31, 214, 205, 22], ["-", 15, 16, 31, 16, 12, 16, 31, 214, 0, 131], ["-", 15, 16, 31, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 15, 16, 12, 16, 12, 213, 63, 214, 205, 22], ["-", 15, 16, 12, 16, 12, 213, 63, 214, 0, 131], ["-", 15, 16, 12, 16, 12, 213, 63, 214, 141, 22], ["-", 15, 16, 12, 16, 12, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
231
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static int[] A; static int[] B; static int[] C; static void INPUT() { N = NextInt(); A = LineInt(); B = LineInt(); C = LineInt(); } static void OUTPUT() { var ans = B.Sum(); var prev = -1; foreach (var i in A.Select(__ => __ - 1).ToArray()) { ans += (i == prev + 1) ? C[prev] : 0; prev = i; } Console.WriteLine(ans); } static void Main(string[] args) { #if DEBUG TESTINPUT(); INPUT(); #else INPUT(); #endif OUTPUT(); } static void TESTINPUT() { N = 1000000007; } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static int[] A; static int[] B; static int[] C; static void INPUT() { N = NextInt(); A = LineInt(); B = LineInt(); C = LineInt(); } static void OUTPUT() { var ans = B.Sum(); var prev = int.MinValue; foreach (var i in A.Select(__ => __ - 1).ToArray()) { ans += (i == prev + 1) ? C[prev] : 0; prev = i; } Console.WriteLine(ans); } static void Main(string[] args) { #if DEBUG TESTINPUT(); INPUT(); #else INPUT(); #endif OUTPUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
[["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
518
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.JSC_2019_qual { class C { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { long n = ReadLong(); string s = Read(); long mask = 1000000000 + 7; long pats = 1; long remain = 0; for (int i = 0; i < 2 * n; i++) { if (s[i] == 'B') { if (remain % 2 == 1) { pats *= remain; pats %= mask; remain--; } else { remain++; } } else { if (remain % 2 == 1) { remain++; } else { if (remain == 0) { WriteLine(0); return; } else { pats *= remain; pats %= mask; remain--; } } } } for (long i = 1; i <= n; i++) { pats *= i; pats %= mask; } WriteLine(pats); } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.JSC_2019_qual { class C { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { long n = ReadLong(); string s = Read(); long mask = 1000000000 + 7; long pats = 1; long remain = 0; for (int i = 0; i < 2 * n; i++) { if (s[i] == 'B') { if (remain % 2 == 1) { pats *= remain; pats %= mask; remain--; } else { remain++; } } else { if (remain % 2 == 1) { remain++; } else { if (remain == 0) { WriteLine(0); return; } else { pats *= remain; pats %= mask; remain--; } } } } if (remain > 0) { WriteLine(0); return; } for (long i = 1; i <= n; i++) { pats *= i; pats %= mask; } WriteLine(pats); } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 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, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
448
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static int[,] ans; static void Main(string[] args) { Scanner cin = new Scanner(); int n = cin.Int(); ans = new int[n, n]; calc(1, 0, n); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { sb.Append($"ans[i, j] "); } sb.AppendLine(" "); } Console.WriteLine(sb.ToString()); } static void calc(int level, int s, int e) { int c = (e - s) / 2; for (int i = s; i < c; ++i) { for (int j = c; j < e; ++j) { ans[i, j] = level; } } if (c - s > 0 && e - c > 0) { calc(level + 1, s, c); calc(level + 1, c, e); } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { 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] = Int() + add; } return Array; } public long Long() { 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] = Long() + add; } return Array; } public double Double() { 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] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static int[,] ans; static void Main(string[] args) { Scanner cin = new Scanner(); int n = cin.Int(); ans = new int[n, n]; Calc(1, 0, n); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { sb.Append($"{ans[i, j] } "); } sb.AppendLine(" "); } Console.WriteLine(sb.ToString()); } static void Calc(int level, int s, int e) { int c = (e - s) / 2 + s; for (int i = s; i < c; ++i) { for (int j = c; j < e; ++j) { ans[i, j] = level; } } if (c - s > 1) { Calc(level + 1, s, c); } if (e - c > 1) { Calc(level + 1, c, e); } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { 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] = Int() + add; } return Array; } public long Long() { 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] = Long() + add; } return Array; } public double Double() { 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] = Double() + add; } return Array; } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["+", 0, 28, 0, 283, 0, 284, 0, 204, 205, 22], ["+", 0, 283, 0, 284, 0, 204, 206, 207, 0, 70], ["+", 0, 284, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 283, 0, 284, 0, 204, 206, 207, 0, 21], ["+", 0, 283, 0, 284, 0, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45]]
8
631
40
using System; namespace newEx { class Program { static void Main(string[] args) { // string[] l = Console.ReadLine().Split(' '); // int p = int.Parse(l[0]); // int q = int.Parse(l[1]); // int r = int.Parse(l[2]); string l = Console.ReadLine(); int r = int.Parse(l); l = Console.ReadLine(); Console.WriteLine(Solve(r, l)); } static string Solve(int a, string s) //修正200630 { if (a >= 3200) { Console.WriteLine(s); return s;   //修正200629 } else // if (a < 3200) { Console.WriteLine("red"); return "red";   //修正200629 // return"red"; //修正200629 } } } }
using System; namespace newEx { class Program { static void Main(string[] args) { // string[] l = Console.ReadLine().Split(' '); // int p = int.Parse(l[0]); // int q = int.Parse(l[1]); // int r = int.Parse(l[2]); string l = Console.ReadLine(); int r = int.Parse(l); l = Console.ReadLine(); Console.WriteLine(Solve(r, l)); } static string Solve(int a, string s) //修正200630 { if (a >= 3200) { // Console.WriteLine(s); return s;   //修正200629 } else // if (a < 3200) { // Console.WriteLine("red"); return "red";   //修正200629 // return"red"; //修正200629 } } } }
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
8
119
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC138A { class Program { static void Main(string[] args) { int a; String s; a = int.Parse(Console.ReadLine()); s = Console.ReadLine(); char[] cs = s.ToCharArray(); if (a >= 3200) Console.WriteLine(s); else Console.WriteLine("red"); Console.WriteLine(a); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC138A { class Program { static void Main(string[] args) { int a; String s; a = int.Parse(Console.ReadLine()); s = Console.ReadLine(); char[] cs = s.ToCharArray(); if (a >= 3200) Console.WriteLine(s); else Console.WriteLine("red"); Console.ReadKey(); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131]]
8
120
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); if (a >= 3200) { Console.WriteLine("Pink"); } else { Console.WriteLine("Red"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); string s = Console.ReadLine(); if (a < 3200) { Console.WriteLine("red"); } else { Console.WriteLine(s); } } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
106
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_138A { class Program { static void Main(string[] args) { int a; a = int.Parse(Console.ReadLine()); if (a >= 3200) Console.WriteLine("pink"); else Console.WriteLine("red"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_138A { class Program { static void Main(string[] args) { int a; a = int.Parse(Console.ReadLine()); String s = Console.ReadLine(); if (a < 3200) Console.WriteLine("red"); else Console.WriteLine(s); Console.ReadKey(); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
93
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC138A { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); string n; n = Console.ReadLine(); if (a < 3200) Console.WriteLine(n); else Console.WriteLine("red"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC138A { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); string n; n = Console.ReadLine(); if (a < 3200) Console.WriteLine("red"); else Console.WriteLine(n); Console.ReadKey(); } } }
[["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
100
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; var a = x[0]; string s = sc.Str; //ここまで } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; var a = x[0]; string s = sc.Str; if (a >= 3200) wr.wri(s); else wr.wri("red"); //ここまで } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 75, 1, 0, 35]]
8
534
23
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); int n = cin.NextInt(); var a = cin.ArrayInt(n); long prod = 1; for (int i = 0; i < n; i++) { prod *= a[i]; } long sum = 0; for (int i = 0; i < n; i++) { sum += prod / a[i]; } Console.WriteLine((double)prod / (double)sum); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); int n = cin.NextInt(); var a = cin.ArrayInt(n); double prod = 1; for (int i = 0; i < n; i++) { prod *= a[i]; } double sum = 0; for (int i = 0; i < n; i++) { sum += prod / a[i]; } Console.WriteLine(prod / sum); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 12, 74, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 12, 74, 39, 199], ["-", 3, 4, 0, 28, 0, 16, 12, 74, 0, 25]]
8
540
10
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { public class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); var s = Console.ReadLine().Split(' '); double x = 0; for (int i = 0; i < a; i++) { x += (double)1 / int.Parse(s[i]); } Console.WriteLine((1 / x).ToString("G5")); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { public class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); var s = Console.ReadLine().Split(' '); double x = 0; for (int i = 0; i < a; i++) { x += (double)1 / int.Parse(s[i]); } Console.WriteLine((1 / x)); } } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
121
7
using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { int num; Double sum = 0, len = 1; int.TryParse(Console.ReadLine(), out num); foreach (string x in Regex.Split(Console.ReadLine(), @"\s+")) { sum += Convert.ToDouble(x); len *= Convert.ToDouble(x); }; Console.WriteLine("{0}", len / sum); } }
using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { int num; Double sum = 0; int.TryParse(Console.ReadLine(), out num); foreach (string x in Regex.Split(Console.ReadLine(), @"\s+")) { sum += 1 / Convert.ToDouble(x); }; Console.WriteLine("{0}", 1.0 / sum); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 250]]
8
103
17
using System; using System.Linq; namespace Main { class Program { static void Main(string[] args) { int i; var temp = 0.0; var n = int.Parse(Console.ReadLine()); var A_temp = Console.ReadLine().Split(); var a = new double[n]; for (i = 0; i < n; i++) { a[i] = double.Parse(Console.ReadLine()); } for (i = 0; i < n; i++) { temp += (1 / a[i]); } Console.WriteLine(1 / temp); } } }
using System; using System.Linq; namespace Main { class Program { static void Main(string[] args) { int i; var temp = 0.0; var n = int.Parse(Console.ReadLine()); var A_temp = Console.ReadLine().Split(' '); var a = new double[n]; for (i = 0; i < n; i++) { a[i] = double.Parse(A_temp[i]); } for (i = 0; i < n; i++) { temp += (1 / a[i]); } Console.WriteLine(1 / temp); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
8
137
12
using System; using System.Collections.Generic; // list用 using System.Text.RegularExpressions; //正規表現用 using System.Text; // StringBuilder用 using System.Collections; //ハッシュテーブル用 using System.Linq; //デリゲータの使い方をマスターしたい class Program { Hashtable ht = new Hashtable(); static List<int> s = new List<int>(); static float result; static int K; StringBuilder strresult = new StringBuilder(""); // Append(str ○○)関数で文字を追加していく static long tmpre; static void Main() { // Modular mo = new // Modular();//素数で割った余りを出せで使う★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)()内は初期値 // Node no = new // Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける // Permutation pe = new // Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。 // Treap tr = new // Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。 // delegate int // CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名※()いらないを入れる。 // PriorityQueue pr = new // PriorityQueue<>(評価式);//優先度付キュー★Enqueue()で格納、Dequeue()で取りだし。引数は評価式(大と小のどちらが優先か)。 Read1(); Read2(K); tmpre = 1; for (int i = 1; i <= K; i++) { tmpre = tmpre * s[i - 1]; } long waruall = 0; long waru = 1; for (int j = 1; j <= K; j++) { waru = 1; for (int i = 1; i <= K; i++) { if (i != j) { waru = waru * s[i - 1]; } } waruall += waru; } result = (float)tmpre / (float)waruall; Console.WriteLine(result.ToString()); } static void Read1() { string tmp = Console.ReadLine(); K = int.Parse(tmp); } static void Read2(int kosuu) { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < kosuu; i++) { s.Add(int.Parse(tmp[i])); } } }
using System; using System.Collections.Generic; // list用 using System.Text.RegularExpressions; //正規表現用 using System.Text; // StringBuilder用 using System.Collections; //ハッシュテーブル用 using System.Linq; //デリゲータの使い方をマスターしたい class Program { Hashtable ht = new Hashtable(); static List<double> s = new List<double>(); static double result; static int K; StringBuilder strresult = new StringBuilder(""); // Append(str ○○)関数で文字を追加していく static double tmpre; static void Main() { // Modular mo = new // Modular();//素数で割った余りを出せで使う★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)()内は初期値 // Node no = new // Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける // Permutation pe = new // Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。 // Treap tr = new // Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。 // delegate int // CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名※()いらないを入れる。 // PriorityQueue pr = new // PriorityQueue<>(評価式);//優先度付キュー★Enqueue()で格納、Dequeue()で取りだし。引数は評価式(大と小のどちらが優先か)。 Read1(); Read2(K); tmpre = 1; for (int i = 1; i <= K; i++) { tmpre = tmpre * s[i - 1]; } double waruall = 0; double waru = 1; for (int j = 1; j <= K; j++) { waru = 1; for (int i = 1; i <= K; i++) { if (i != j) { waru = waru * s[i - 1]; } } waruall += waru; } result = tmpre / waruall; Console.WriteLine(result.ToString()); } static void Read1() { string tmp = Console.ReadLine(); K = int.Parse(tmp); } static void Read2(int kosuu) { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < kosuu; i++) { s.Add(double.Parse(tmp[i])); } } }
[["-", 0, 124, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 124, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 12, 74, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 12, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199]]
8
321
20
using System; using System.Linq; using System.Collections.Generic; public class AtCoderC { static void Main() { int n = int.Parse(Console.ReadLine()); int[] b = new int[n - 1]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { b[i] = int.Parse(words[i]); } } int[] a = new int[n]; a[0] = b[0]; for (int i = 1; i < n; i++) { a[i] = Math.Max(b[i - 1], b[i]); } Console.WriteLine(a.Sum()); } }
using System; using System.Linq; using System.Collections.Generic; public class AtCoderC { static void Main() { int n = int.Parse(Console.ReadLine()); int[] b = new int[n - 1]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n - 1; i++) { b[i] = int.Parse(words[i]); } } int[] a = new int[n]; a[0] = b[0]; for (int i = 1; i < n - 1; i++) { a[i] = Math.Min(b[i - 1], b[i]); } a[n - 1] = b[n - 2]; Console.WriteLine(a.Sum()); } }
[["+", 0, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 0, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
178
20
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int n = ReadLineInt(); int[] bList = ReadLineIntArray(); int[] aList = new int[n]; for (int i = 0; i < n; i++) { if (i == 0) { aList[i] = bList[i]; continue; } if (i == n - 1) { aList[i] = bList[i - 1]; continue; } aList[i] = Math.Min(bList[i - 1], bList[i]); } for (int i = 0; i < n; i++) { Console.WriteLine(aList[i]); } Console.WriteLine(aList.Sum()); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int n = ReadLineInt(); int[] bList = ReadLineIntArray(); int[] aList = new int[n]; for (int i = 0; i < n; i++) { if (i == 0) { aList[i] = bList[i]; continue; } if (i == n - 1) { aList[i] = bList[i - 1]; continue; } aList[i] = Math.Min(bList[i - 1], bList[i]); } Console.WriteLine(aList.Sum()); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } }
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
659
26
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var N = int.Parse(input[0]); var K = int.Parse(input[1]); var S = Console.ReadLine().ToCharArray(); var before = ""; var now = ""; var ans = 0; var single = 0; for (var i = 0; i < N; i++) { now = S[i].ToString(); if (now == "L" && before == "R") { ans += 2; } if (i == 0 && now == "L") { ans += 1; single += 1; } if (i == N - 1 && now == "R") { ans += 1; single += 1; } before = now; } ans = ans - (K - single) * 2; if (ans == single) { ans = 0; } else if (ans > single) { ans = ans - single * 2; } else { ans = 0; } Console.WriteLine(N - ans); Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var N = int.Parse(input[0]); var K = int.Parse(input[1]); var S = Console.ReadLine().ToCharArray(); var before = ""; var now = ""; var ans = 0; var single = 0; for (var i = 0; i < N; i++) { now = S[i].ToString(); if (now == "L" && before == "R") { ans += 2; } if (i == 0 && now == "L") { ans += 1; single += 1; } if (i == N - 1 && now == "R") { ans += 1; single += 1; } before = now; } ans = ans - (K - single) * 2; if (ans == single) { ans = 0; } else if (ans > single) { ans = ans - single * 2; } else { ans = 0; } Console.WriteLine(ans == 0 ? N - 1 : N - ans); Console.ReadLine(); } }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102]]
8
267
8
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 NK = Sarray(); var N = NK[0]; var K = NK[1]; var S = ReadLine(); var ans = 0L; var hanNum = 0L; for (var i = 0; i < N - 1; ++i) { if (S[i] == S[i + 1]) ++ans; else ++hanNum; } var kanou = hanNum / 2; var hosei = Min(kanou, K) * 2; if (kanou < K) ++hosei; if (0 == hanNum) hosei = 0; WriteLine(ans + hosei); // 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 NK = Sarray(); var N = NK[0]; var K = NK[1]; var S = ReadLine(); var ans = 0L; var hanNum = 0L; for (var i = 0; i < N - 1; ++i) { if (S[i] == S[i + 1]) ++ans; else ++hanNum; } var kanou = hanNum / 2; var hosei = K * 2; if (kanou < K) ++hosei; WriteLine(Min(N - 1, ans + hosei)); // Out.Flush(); } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 213, 63, 22], ["-", 0, 212, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 212, 0, 16, 31, 213, 3, 4, 0, 21], ["-", 0, 212, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 241, 0, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
254
22
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder { class Program { static long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); } static List<long> Slist() { return ReadLine().Trim().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { var NK = Sarray(); var N = NK[0]; var K = NK[1]; var S = ReadLine(); long revnum = 0; long point = 0; for (var i = 0; i < N - 1; ++i) { if (S[i] == S[i + 1]) ++point; else ++revnum; } if (0 == revnum) { WriteLine(point); return; } --revnum; var num = Math.Min(K, revnum); var ans = num * 2 + point; if (revnum < K) ++ans; WriteLine(ans); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder { class Program { static long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); } static List<long> Slist() { return ReadLine().Trim().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { var NK = Sarray(); var N = NK[0]; var K = NK[1]; var S = ReadLine(); long revnum = 0; long point = 0; for (var i = 0; i < N - 1; ++i) { if (S[i] == S[i + 1]) ++point; else ++revnum; } var num = Math.Min(K * 2, revnum); var ans = num + point; WriteLine(ans); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 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, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 1, 0, 241, 0, 68], ["-", 0, 195, 8, 196, 0, 1, 0, 241, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 64, 1, 0, 241, 0, 29], ["-", 8, 196, 0, 57, 64, 1, 0, 241, 0, 22]]
8
249
31
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderD { static void Main() { int n; int k; { var line = Console.ReadLine(); var words = line.Split(' '); n = int.Parse(words[0]); k = int.Parse(words[1]); } string s = Console.ReadLine(); int answer = 0; string before = s.Substring(0, 1); for (int i = 1; i < n; i++) { if (before.Equals(s.Substring(i, 1))) { answer++; } else { before = s.Substring(i, 1); } } int unique = n - answer; if (unique % 2 == 1) { answer += Math.Min(k, unique / 2) * 2; } else { if (unique / 2 > k) { answer += k * 2; } else if (unique / 2 == k) { answer += 2 * (k - 1) + 1; } else { answer += 2 * (unique - 1) + 1; } } Console.WriteLine(answer); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderD { static void Main() { int n; int k; { var line = Console.ReadLine(); var words = line.Split(' '); n = int.Parse(words[0]); k = int.Parse(words[1]); } string s = Console.ReadLine(); int answer = 0; string before = s.Substring(0, 1); for (int i = 1; i < n; i++) { if (before.Equals(s.Substring(i, 1))) { answer++; } else { before = s.Substring(i, 1); } } int unique = n - answer; if (unique % 2 == 1) { answer += Math.Min(k, unique / 2) * 2; } else { if (unique / 2 > k) { answer += k * 2; } else { answer = n - 1; } } Console.WriteLine(answer); } }
[["-", 0, 57, 75, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 57, 75, 196, 0, 57, 75, 57, 0, 24], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 85], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["-", 75, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["-", 75, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["-", 0, 57, 75, 196, 0, 57, 75, 57, 0, 25], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 203], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 0, 11, 12, 16, 31, 16, 12, 23, 0, 24], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 16, 12, 23, 0, 25], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 57, 75, 196, 0, 57, 75, 57, 0, 95], ["-", 75, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["-", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
8
258
33
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Procon { static void Main(string[] agrs) { int N = Int(); int K = Int(); char[] S = Chars(); int ret = 0; int num = 1; int tmp = 1; for (int i = 0; i < N - 1; i++) { if (S[i] == S[i + 1]) { tmp++; } else { ret += tmp - 1; tmp = 1; num++; } } ret += tmp - 1; if (K < num - 1) { Console.WriteLine(ret + K * 2); return; } Console.WriteLine(N - 1); } static string String() => Scanner.nextString(); static int Int() => int.Parse(Scanner.nextString()); static long Long() => long.Parse(Scanner.nextString()); static double Double() => double.Parse(Scanner.nextString()); static char[] Chars() => String().ToCharArray(); static string[] Strings() => Console.ReadLine().Split(' '); static int[] Ints() => Strings().Select(v => int.Parse(v)).ToArray(); static long[] Longs() => Strings().Select(v => long.Parse(v)).ToArray(); static double[] Doubles() => Strings().Select(v => double.Parse(v)).ToArray(); const int M = 1000000007; } class PriorityQueue<T> where T : IComparable<T> { public T[] heap; public int size; public int sign; public PriorityQueue(int N, bool descend = false) { heap = new T[N]; sign = 1; if (descend) sign = -1; } public int Compare(T x, T y) { return x.CompareTo(y) * sign; } public void Push(T x) { int i = size++; while (i > 0) { int p = (i - 1) / 2; if (Compare(x, heap[p]) >= 0) { break; } heap[i] = heap[p]; i = p; } heap[i] = x; } public T Pop() { T ret = heap[0]; T x = heap[--size]; int i = 0; while (i * 2 + 1 < size) { int a = i * 2 + 1; int b = i * 2 + 2; if (b < size && Compare(heap[a], heap[b]) > 0) { a = b; } if (Compare(heap[a], x) >= 0) { break; } heap[i] = heap[a]; i = a; } heap[i] = x; return ret; } public int Count() { return size; } } class Scanner { static string[] s = new string[0]; static int i = 0; static int max_i = 0; static public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } return s[i++]; } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Procon { static void Main(string[] agrs) { int N = Int(); int K = Int(); char[] S = Chars(); int ret = 0; int num = 1; int tmp = 1; for (int i = 0; i < N - 1; i++) { if (S[i] == S[i + 1]) { tmp++; } else { ret += tmp - 1; tmp = 1; num++; } } ret += tmp - 1; Console.WriteLine(Math.Min((ret + K * 2), N - 1)); } static string String() => Scanner.nextString(); static int Int() => int.Parse(Scanner.nextString()); static long Long() => long.Parse(Scanner.nextString()); static double Double() => double.Parse(Scanner.nextString()); static char[] Chars() => String().ToCharArray(); static string[] Strings() => Console.ReadLine().Split(' '); static int[] Ints() => Strings().Select(v => int.Parse(v)).ToArray(); static long[] Longs() => Strings().Select(v => long.Parse(v)).ToArray(); static double[] Doubles() => Strings().Select(v => double.Parse(v)).ToArray(); const int M = 1000000007; } class PriorityQueue<T> where T : IComparable<T> { public T[] heap; public int size; public int sign; public PriorityQueue(int N, bool descend = false) { heap = new T[N]; sign = 1; if (descend) sign = -1; } public int Compare(T x, T y) { return x.CompareTo(y) * sign; } public void Push(T x) { int i = size++; while (i > 0) { int p = (i - 1) / 2; if (Compare(x, heap[p]) >= 0) { break; } heap[i] = heap[p]; i = p; } heap[i] = x; } public T Pop() { T ret = heap[0]; T x = heap[--size]; int i = 0; while (i * 2 + 1 < size) { int a = i * 2 + 1; int b = i * 2 + 2; if (b < size && Compare(heap[a], heap[b]) > 0) { a = b; } if (Compare(heap[a], x) >= 0) { break; } heap[i] = heap[a]; i = a; } heap[i] = x; return ret; } public int Count() { return size; } } class Scanner { static string[] s = new string[0]; static int i = 0; static int max_i = 0; static public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } return s[i++]; } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
763
24
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { partial class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } static void Main(string[] args) { //↓ var nk = ReadIntArray(); var n = nk[0]; var k = nk[1]; var s = Console.ReadLine(); var h = 0; var prev = ' '; var flip = 0; for (int i = 0; i < n; i++) { var c = s[i]; if (prev == c) { h++; } else { flip++; prev = c; } } var fc = Math.Min(k, (flip - 1) / 2); var rest = Math.Max(k - fc, 0); Console.WriteLine(h + fc * 2 + (rest > 0 ? 1 : 0)); //↑ } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { partial class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } static void Main(string[] args) { //↓ var nk = ReadIntArray(); var n = nk[0]; var k = nk[1]; var s = Console.ReadLine(); var h = 0; var prev = ' '; var flip = 0; for (int i = 0; i < n; i++) { var c = s[i]; if (prev == c) { h++; } else { flip++; prev = c; } } var fc = Math.Min(Math.Min(k, (flip - 1) / 2), k); var rest = Math.Max(k - fc, 0); Console.WriteLine(h + fc * 2 + ((rest > 0 && flip % 2 == 0) ? 1 : 0)); //↑ } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 16, 12, 23, 0, 41, 15, 23, 0, 24], ["+", 12, 23, 0, 41, 15, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 15, 23, 0, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 23, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 17, 60], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 41, 15, 23, 0, 25]]
8
1,472
15
namespace AtCoder { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Util; class AtCoder { /*------------------------------------------------------------------*/ void Solve() { int N, K; string S; io.i(out N, out K, out S); if (N == 1) { 0.Prt(); } else { var nonChain = S.ToCharArray().Pairwise().Count(tup => tup.Item1 != tup.Item2); var take2 = nonChain / 2; // var take1 = nonChain % 2; var ans = N - 1 - Max(nonChain - 2 * take2, 0); ans.Prt(); } } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] _) => new AtCoder().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Util { public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static IEnumerable<TResult> ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, Func<T1, T2, TResult> f = null) { using (var e1 = xs.GetEnumerator()) using ( var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext()) yield return f(e1.Current, e2.Current); } public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs, IEnumerable<T2> ys) => ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y)); public static IEnumerable<TResult> ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) { using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using ( var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) yield return f(e1.Current, e2.Current, e3.Current); } public static IEnumerable<Tuple<T1, T2, T3>> ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z)); public static bool ODD(int x) => x % 2 != 0; public static bool ODD(long x) => x % 2L != 0L; public static int SUM(params int[] xs) => xs.Sum(); public static long SUM(params long[] xs) => xs.Sum(); public struct IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public class Counts<T> : Dictionary<T, int> { public Counts() {} public Counts(params T[] xs) : this() { Add(xs); } public new int this[T key] { get { int v; return this.TryGetValue(key, out v) ? v : 0; } } public void Add(T key) { if (!base.ContainsKey(key)) base.Add(key, 0); base[key]++; } public void Add(params T[] xs) => xs.Iter(Add); public void SortByCount(bool isAsc) => (isAsc ? (this.OrderBy(kp => kp.Value)) : (this.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key); } public class PriorityQueue<T> where T : IComparable<T> { private List<T> heap; private readonly bool isAsc; private int size; public T Peek => heap[0]; public int Count => size; public bool Any => size > 0; public bool Empty => !Any; public IEnumerable<T> Values => heap; public PriorityQueue(bool isAsc = true) { this.isAsc = isAsc; size = 0; heap = new List<T>(); } public void Enqueue(T item) { heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) / 2; if (Compare(heap[p], item) <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = item; } public T Dequeue() { var ret = heap[0]; var x = 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; } private int Compare(T x, T y) => isAsc ? x.CompareTo(y) : y.CompareTo(x); } } static class Ex { public static Tuple<IEnumerable<T>, IEnumerable<T>> Split<T>(this IEnumerable<T> xs, Func<T, bool> f) { var ys = xs.Where(f); var zs = xs.Where(x => !f(x)); return Tuple.Create(ys, zs); } public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static IEnumerable<IndexedItem<T>> Indexed<T>(this IEnumerable<T> xs) => xs.Select((x, idx) => new IndexedItem<T>(idx, x)); public static IEnumerable<T> UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val); public static IEnumerable<Tuple<T, T>> Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1)); } }
namespace AtCoder { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Util; class AtCoder { /*------------------------------------------------------------------*/ void Solve() { int N, K; string S; io.i(out N, out K, out S); if (N == 1) { 0.Prt(); } else { var nonChain = S.ToCharArray().Pairwise().Count(tup => tup.Item1 != tup.Item2); var ans = N - 1 - Max(nonChain - 2 * K, 0); ans.Prt(); } } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] _) => new AtCoder().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Util { public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static IEnumerable<TResult> ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, Func<T1, T2, TResult> f = null) { using (var e1 = xs.GetEnumerator()) using ( var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext()) yield return f(e1.Current, e2.Current); } public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs, IEnumerable<T2> ys) => ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y)); public static IEnumerable<TResult> ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) { using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using ( var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) yield return f(e1.Current, e2.Current, e3.Current); } public static IEnumerable<Tuple<T1, T2, T3>> ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z)); public static bool ODD(int x) => x % 2 != 0; public static bool ODD(long x) => x % 2L != 0L; public static int SUM(params int[] xs) => xs.Sum(); public static long SUM(params long[] xs) => xs.Sum(); public struct IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public class Counts<T> : Dictionary<T, int> { public Counts() {} public Counts(params T[] xs) : this() { Add(xs); } public new int this[T key] { get { int v; return this.TryGetValue(key, out v) ? v : 0; } } public void Add(T key) { if (!base.ContainsKey(key)) base.Add(key, 0); base[key]++; } public void Add(params T[] xs) => xs.Iter(Add); public void SortByCount(bool isAsc) => (isAsc ? (this.OrderBy(kp => kp.Value)) : (this.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key); } public class PriorityQueue<T> where T : IComparable<T> { private List<T> heap; private readonly bool isAsc; private int size; public T Peek => heap[0]; public int Count => size; public bool Any => size > 0; public bool Empty => !Any; public IEnumerable<T> Values => heap; public PriorityQueue(bool isAsc = true) { this.isAsc = isAsc; size = 0; heap = new List<T>(); } public void Enqueue(T item) { heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) / 2; if (Compare(heap[p], item) <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = item; } public T Dequeue() { var ret = heap[0]; var x = 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; } private int Compare(T x, T y) => isAsc ? x.CompareTo(y) : y.CompareTo(x); } } static class Ex { public static Tuple<IEnumerable<T>, IEnumerable<T>> Split<T>(this IEnumerable<T> xs, Func<T, bool> f) { var ys = xs.Where(f); var zs = xs.Where(x => !f(x)); return Tuple.Create(ys, zs); } public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static IEnumerable<IndexedItem<T>> Indexed<T>(this IEnumerable<T> xs) => xs.Select((x, idx) => new IndexedItem<T>(idx, x)); public static IEnumerable<T> UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val); public static IEnumerable<Tuple<T, T>> Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1)); } }
[["-", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["-", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22]]
8
2,674
9
using System; using System.Collections.Generic; using System.Linq; namespace Test01 { class Program { static void Main(string[] args) { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = input[0]; int K = input[1]; string S = Console.ReadLine(); int cnt_hap = 0; int cnt_rl = 0; for (int i = 1; i < N; i++) { if (S[i] == S[i - 1]) cnt_hap++; if (S[i - 1] == 'R' && S[i] == 'L') cnt_rl++; } if (cnt_rl >= K) cnt_hap += 2 * K; else cnt_hap += 2 * cnt_rl + 1; Console.WriteLine(cnt_hap); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Test01 { class Program { static void Main(string[] args) { int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = input[0]; int K = input[1]; string S = Console.ReadLine(); int cnt_hap = 0; int cnt_rl = 0; for (int i = 1; i < N; i++) { if (S[i] == S[i - 1]) cnt_hap++; if (S[i - 1] == 'R' && S[i] == 'L') cnt_rl++; } Console.WriteLine(Math.Min(cnt_hap + 2 * K, N - 1)); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 1, 0, 11, 0, 202, 0, 107], ["-", 75, 1, 0, 11, 12, 16, 31, 16, 31, 203], ["-", 75, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 75, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 0, 57, 75, 1, 0, 11, 12, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 195, 8, 196, 0, 57, 75, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
189
32
using System; using System.Collections.Generic; using System.Linq; public class ABC0140_A4v1 { private static void Main(string[] args) { var inputs = new List<string>() { Console.ReadLine().Trim(), Console.ReadLine().Trim(), }; Prepare(inputs); } private static void Prepare(List<string> inputs) { var ints = inputs[0].Split().Select(x => int.Parse(x)).ToArray(); var numOfDirections = ints[0]; var numOfTrials = ints[1]; var directions = inputs[1]; Compute(numOfDirections, numOfTrials, directions); } private static void Compute(int numOfDirections, int numOfTrials, string directions) { var initialHappiness = 0; for (var index = 0; index < numOfDirections - 1; index++) { if (directions[index] == directions[index + 1]) initialHappiness++; } var happiness = initialHappiness + (2 * numOfTrials); if (happiness > numOfDirections - 1) { if ((numOfDirections - initialHappiness) % 2 == 0) happiness = numOfDirections; else happiness = numOfDirections - 1; } OutputAnswer(happiness.ToString()); } private static void OutputAnswer(string text) => Console.WriteLine(text); }
using System; using System.Collections.Generic; using System.Linq; public class ABC0140_A4v1 { private static void Main(string[] args) { var inputs = new List<string>() { Console.ReadLine().Trim(), Console.ReadLine().Trim(), }; Prepare(inputs); } private static void Prepare(List<string> inputs) { var ints = inputs[0].Split().Select(x => int.Parse(x)).ToArray(); var numOfDirections = ints[0]; var numOfTrials = ints[1]; var directions = inputs[1]; Compute(numOfDirections, numOfTrials, directions); } private static void Compute(int numOfDirections, int numOfTrials, string directions) { var happiness = 0; for (var index = 0; index < numOfDirections - 1; index++) { if (directions[index] == directions[index + 1]) happiness++; } happiness += 2 * numOfTrials; var answer = Math.Min(happiness, numOfDirections - 1); OutputAnswer(answer.ToString()); } private static void OutputAnswer(string text) => Console.WriteLine(text); }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["-", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["-", 64, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 57, 75, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 57, 75, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22]]
8
269
17
using System; using System.Collections.Generic; using System.Linq; public class ABC0140_A4v1 { private static void Main(string[] args) { var inputs = new List<string>() { Console.ReadLine().Trim(), Console.ReadLine().Trim(), }; Prepare(inputs); } private static void Prepare(List<string> inputs) { var ints = inputs[0].Split().Select(x => int.Parse(x)).ToArray(); var numOfDirections = ints[0]; var numOfTrials = ints[1]; var directions = inputs[1]; Compute(numOfDirections, numOfTrials, directions); } private static void Compute(int numOfDirections, int numOfTrials, string directions) { var initialHappiness = 0; for (var index = 0; index < numOfDirections - 1; index++) { if (directions[index] == directions[index + 1]) initialHappiness++; } var happiness = initialHappiness + (2 * numOfTrials); if (happiness > numOfDirections - 1) { if ((numOfDirections - initialHappiness) % 2 == 0) happiness = numOfDirections; else happiness = numOfDirections - 1; } OutputAnswer(happiness.ToString()); } private static void OutputAnswer(string text) => Console.WriteLine(text); }
using System; using System.Collections.Generic; using System.Linq; public class ABC0140_A4v1 { private static void Main(string[] args) { var inputs = new List<string>() { Console.ReadLine().Trim(), Console.ReadLine().Trim(), }; Prepare(inputs); } private static void Prepare(List<string> inputs) { var ints = inputs[0].Split().Select(x => int.Parse(x)).ToArray(); var numOfDirections = ints[0]; var numOfTrials = ints[1]; var directions = inputs[1]; Compute(numOfDirections, numOfTrials, directions); } private static void Compute(int numOfDirections, int numOfTrials, string directions) { var initialHappiness = 0; for (var index = 0; index < numOfDirections - 1; index++) { if (directions[index] == directions[index + 1]) initialHappiness++; } var happiness = initialHappiness + (2 * numOfTrials); if (happiness > numOfDirections - 1) { happiness = numOfDirections - 1; } OutputAnswer(happiness.ToString()); } private static void OutputAnswer(string text) => Console.WriteLine(text); }
[["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["-", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95]]
8
269
17
using System; using System.Linq; using System.Collections.Generic; class ProgramD { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); string s = Console.ReadLine(); List<int> LR = new List<int>(); int count = 1; for (int i = 1; i < n; i++) { string si = s.Substring(i, 1); string si_p = s.Substring(i - 1, 1); if (si != si_p) { LR.Add(count); count = 1; } else count++; if (i == n - 1) LR.Add(count); } long ans = LR.Sum() - LR.Count(); long LRlen = LR.Count(); for (int i = 0; i < k; i++) { if (LRlen == 2) { ans += 1; break; } else if ((LRlen == 1)) { break; } else { ans += 2; LRlen -= 2; } } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class ProgramD { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); string s = Console.ReadLine(); List<int> LR = new List<int>(); int count = 1; for (int i = 1; i < n; i++) { string si = s.Substring(i, 1); string si_p = s.Substring(i - 1, 1); if (si != si_p) { LR.Add(count); count = 1; } else { count++; } if (i == n - 1) LR.Add(count); } long ans = LR.Sum() - LR.Count(); long LRlen = LR.Count(); for (int i = 0; i < k; i++) { if (LRlen == 2) { ans += 1; break; } else if ((LRlen == 1)) { break; } else { ans += 2; LRlen -= 2; } } if (ans >= n) ans = n - 1; Console.WriteLine(ans); } }
[["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
267
14
using System; using System.Linq; namespace abc140_d { static class Program { static void Main(string[] args) { var items = Console.ReadLine().ToIntArray(); // 人数 var n = items[0]; // 回転させる回数 var k = items[1]; // 向いている方向 var s = Console.ReadLine(); // 向いている方向が同じ人たちの列が最も長くなるところを回転させたい // →よくよく考えたら、(両端以外なら)どの場所を入れ替えても、幸福の増加量は+2では? // →一個飛ばしで、前から順々に入れ替えていくのが一番いい // もともとの合計値 var sum = 0L; // 直前のグループの末尾インデックス var prev = 0; // グループの総数 var count = 0; for (int i = 1; i < s.Length; i++) { if (s[i - 1] != s[i]) { sum += i - prev - 1; prev = i; count++; } } sum += s.Length - prev - 1; count++; // 各グループ数ごとの、最大回転数は下記の通り // グループ数 1 : 0回 o // グループ数 2 : 1回 ox // グループ数 3 : 1回 oxo // グループ数 4 : 2回 oxox // グループ数 5 : 2回 oxoxo // グループ数 6 : 3回 oxoxox // グループ数 7 : 3回 oxoxoxo var max = count - 1 - count % 2; if (k > max) { k = max; } sum += k * 2; Console.WriteLine($"{sum}"); } static int ToInteger(this string s) { return int.Parse(s); } static int[] ToIntArray(this string s, char separator = ' ') { return s.Split(separator).Select(m => m.ToInteger()).ToArray(); } } }
using System; using System.Linq; namespace abc140_d { static class Program { static void Main(string[] args) { var items = Console.ReadLine().ToIntArray(); // 人数 var n = items[0]; // 回転させる回数 var k = items[1]; // 向いている方向 var s = Console.ReadLine(); // 向いている方向が同じ人たちの列が最も長くなるところを回転させたい // →よくよく考えたら、(両端以外なら)どの場所を入れ替えても、幸福の増加量は+2では? // →一個飛ばしで、前から順々に入れ替えていくのが一番いい // もともとの合計値 var sum = 0L; // 直前のグループの末尾インデックス var prev = 0; // グループの総数 var count = 0; for (int i = 1; i < s.Length; i++) { if (s[i - 1] != s[i]) { sum += i - prev - 1; prev = i; count++; } } sum += s.Length - prev - 1; count++; // 各グループ数ごとの、最大回転数は下記の通り // グループ数 1 : 0回 o +0 // グループ数 2 : 1回 ox +1 // グループ数 3 : 1回 oxo +2 // グループ数 4 : 2回 oxox +2+1 // グループ数 5 : 2回 oxoxo // グループ数 6 : 3回 oxoxox // グループ数 7 : 3回 oxoxoxo var max = count / 2; if (k < max) { sum += k * 2; } else { sum += max * 2; // グループが偶数だったら、両端を回転するので、増加量が-1になることに注意 if (count % 2 == 0) { sum -= 1; } } Console.WriteLine($"{sum}"); } static int ToInteger(this string s) { return int.Parse(s); } static int[] ToIntArray(this string s, char separator = ' ') { return s.Split(separator).Select(m => m.ToInteger()).ToArray(); } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
260
33
using System; namespace D { class Program { static void Main(string[] args) { var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = NK[0]; var K = NK[1]; var S = Console.ReadLine(); var happiness = 0; if (S[0] == 'R' && S[1] == 'R') happiness++; if (S[N - 1] == 'L' && S[N - 2] == 'L') happiness++; for (int i = 1; i < N - 1; i++) { if (S[i] == 'L' && S[i - 1] == 'L') happiness++; if (S[i] == 'R' && S[i + 1] == 'R') happiness++; } Console.WriteLine(Math.Min(N - 1, happiness + 2 * K)); } } }
using System; namespace D { class Program { static void Main(string[] args) { Console.WriteLine((solver())); } static int solver() { var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = NK[0]; var K = NK[1]; var S = Console.ReadLine(); if (N == 1) return 0; var happiness = 0; if (S[0] == 'R' && S[1] == 'R') happiness++; if (S[N - 1] == 'L' && S[N - 2] == 'L') happiness++; for (int i = 1; i < N - 1; i++) { if (S[i] == 'L' && S[i - 1] == 'L') happiness++; if (S[i] == 'R' && S[i + 1] == 'R') happiness++; } return Math.Min(N - 1, happiness + 2 * K); } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 23, 0, 213, 63, 22], ["+", 0, 28, 0, 23, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 23, 0, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
215
33
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { // 各種変数の読み込み var its = Readints(); int n = its[0]; int k = its[1]; var muki = ReadLR(); int hap = 0; if (muki[0] & muki[1]) { hap++; } if (!muki[muki.Length - 1] & !muki[muki.Length - 2]) { hap++; } for (int i = 1; i < muki.Length - 1; i++) { bool isok = muki[i] ? muki[i + 1] : !muki[i - 1]; if (isok) { hap++; } } int lrcount = 0; int rlcount = 0; for (int i = 1; i < muki.Length; i++) { if (muki[i] & !muki[i - 1]) { lrcount++; } else if (!muki[i] & muki[i - 1]) { rlcount++; } } int fixnum = Math.Min(lrcount, rlcount); if (k > fixnum && lrcount != rlcount) { hap += fixnum * 2 + 1; } else { hap += Math.Min(k, fixnum) * 2; } /* for (int i = 0; i < k; i++) { var lr = SearchLR(muki); var rl = SearchRL(muki); if (lr < muki.Length | rl < muki.Length) { if (lr < muki.Length && rl < muki.Length) { hap += 2; } else { lr = Math.Min(lr, rl); rl = muki.Length; hap += 1; } int a = Math.Min(lr, rl); int b = Math.Max(lr, rl); int apbm1 = a + b - 1; for (int j = a; j < b; j++) { muki[apbm1 - j] = !muki[j]; } } else { break; } } */ Console.WriteLine(hap); #if DEBUG Console.ReadKey(); #endif } private static bool[] ReadLR() { var s = Console.ReadLine().ToCharArray(); var output = new bool[s.Length]; for (int i = 0; i < s.Length; i++) { output[i] = s[i] == 'R'; } return output; } private static int SearchLR(bool[] lr) { // LRとなっている箇所を見つけてRのインデックスを返す int i = 0; while (lr[i]) { i++; if (i == lr.Length) { return i; } } while (!lr[i]) { i++; if (i == lr.Length) { return i; } } return i; } private static int SearchRL(bool[] lr) { // RLとなっている箇所を見つけてLのインデックスを返す int i = 0; while (!lr[i]) { i++; if (i == lr.Length) { return i; } } while (lr[i]) { i++; if (i == lr.Length) { return i; } } return i; } private static int Readint() { // 1行に1つのintが入力されたのを読む return int.Parse(Console.ReadLine()); } private static int[] Readints() { // 1行に複数のintが入力されたのを読む var s = Console.ReadLine().Split(' '); var output = new int[s.Length]; for (int i = 0; i < s.Length; i++) { output[i] = int.Parse(s[i]); } return output; } private static int[][] Readints(int n, bool transpose = false) { // n行それぞれにintが入力されたのを読む // output[行番号][列番号]で返す。 // transposeがtrueのときは、output[列番号][行番号]で返す。 var s = Console.ReadLine().Split(' '); int rownum = s.Length; if (transpose) { var outputs = new int [rownum][]; for (int j = 0; j < rownum; j++) { outputs[j] = new int[n]; } for (int i = 0; i < s.Length; i++) { outputs[i][0] = int.Parse(s[i]); } for (int l = 1; l < n; l++) { var temps = Console.ReadLine().Split(' '); for (int i = 0; i < rownum; i++) { outputs[i][l] = int.Parse(temps[i]); } } return outputs; } else { var outputs = new int [n][]; outputs[0] = new int[rownum]; for (int i = 0; i < s.Length; i++) { outputs[0][i] = int.Parse(s[i]); } for (int l = 1; l < n; l++) { outputs[l] = new int[rownum]; var temps = Console.ReadLine().Split(' '); for (int i = 0; i < rownum; i++) { outputs[l][i] = int.Parse(temps[i]); } } return outputs; } } private int[] Minusone(int[] x) { var output = new int[x.Length]; for (int i = 0; i < x.Length; i++) { output[i] = x[i] - 1; } return output; } // 元の配列をソートして、ソート後の各要素の、元のインデックスを返す private static int[] SortwithIndex(double[] data) { var index = new int[data.Length]; for (int i = 0; i < data.Length; i++) { index[i] = i; } QSort(data, index, 0, data.Length - 1); return index; } private static void QSort(double[] data, int[] index, int low, int high) { // 要素数が1以下の領域ができた場合、その領域は確定とする。 if (high - low < 1) return; // 1. ピボットとして一つ選びそれをPとする。 var P = data[(low + high + 1) / 2]; // 2. 左から順に値を調べ、P以上のものを見つけたらその位置をiとする。 // 3. 右から順に値を調べ、P以下のものを見つけたらその位置をjとする。 // 4. // iがjより左にあるのならばその二つの位置を入れ替え、2に戻る。ただし、次の2での探索はiの一つ右、次の3での探索はjの一つ左から行う。 int i = low - 1; int j = high + 1; while (Scan(data, P, ref i, ref j)) { Swap(data, index, i, j); } // 5. // 2に戻らなかった場合、iの左側を境界に分割を行って2つの領域に分け、そのそれぞれに対して再帰的に1からの手順を行う。 QSort(data, index, low, i - 1); QSort(data, index, i, high); } private static bool Scan(double[] data, double P, ref int i, ref int j) { while (data[++i] < P) ; while (data[--j] > P) ; return i < j; } private static void Swap(double[] data, int[] index, int i, int j) { var temp = data[i]; data[i] = data[j]; data[j] = temp; var temp2 = index[i]; index[i] = index[j]; index[j] = temp2; } } }
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { // 各種変数の読み込み var its = Readints(); int n = its[0]; int k = its[1]; var muki = ReadLR(); if (n == 1) { Console.WriteLine(0); } else { int hap = 0; if (muki[0] & muki[1]) { hap++; } if (!muki[muki.Length - 1] & !muki[muki.Length - 2]) { hap++; } for (int i = 1; i < muki.Length - 1; i++) { bool isok = muki[i] ? muki[i + 1] : !muki[i - 1]; if (isok) { hap++; } } int lrcount = 0; int rlcount = 0; for (int i = 1; i < muki.Length; i++) { if (muki[i] & !muki[i - 1]) { lrcount++; } else if (!muki[i] & muki[i - 1]) { rlcount++; } } int fixnum = Math.Min(lrcount, rlcount); if (k > fixnum && lrcount != rlcount) { hap += fixnum * 2 + 1; } else { hap += Math.Min(k, fixnum) * 2; } Console.WriteLine(hap); } #if DEBUG Console.ReadKey(); #endif } private static bool[] ReadLR() { var s = Console.ReadLine().ToCharArray(); var output = new bool[s.Length]; for (int i = 0; i < s.Length; i++) { output[i] = s[i] == 'R'; } return output; } private static int SearchLR(bool[] lr) { // LRとなっている箇所を見つけてRのインデックスを返す int i = 0; while (lr[i]) { i++; if (i == lr.Length) { return i; } } while (!lr[i]) { i++; if (i == lr.Length) { return i; } } return i; } private static int SearchRL(bool[] lr) { // RLとなっている箇所を見つけてLのインデックスを返す int i = 0; while (!lr[i]) { i++; if (i == lr.Length) { return i; } } while (lr[i]) { i++; if (i == lr.Length) { return i; } } return i; } private static int Readint() { // 1行に1つのintが入力されたのを読む return int.Parse(Console.ReadLine()); } private static int[] Readints() { // 1行に複数のintが入力されたのを読む var s = Console.ReadLine().Split(' '); var output = new int[s.Length]; for (int i = 0; i < s.Length; i++) { output[i] = int.Parse(s[i]); } return output; } private static int[][] Readints(int n, bool transpose = false) { // n行それぞれにintが入力されたのを読む // output[行番号][列番号]で返す。 // transposeがtrueのときは、output[列番号][行番号]で返す。 var s = Console.ReadLine().Split(' '); int rownum = s.Length; if (transpose) { var outputs = new int [rownum][]; for (int j = 0; j < rownum; j++) { outputs[j] = new int[n]; } for (int i = 0; i < s.Length; i++) { outputs[i][0] = int.Parse(s[i]); } for (int l = 1; l < n; l++) { var temps = Console.ReadLine().Split(' '); for (int i = 0; i < rownum; i++) { outputs[i][l] = int.Parse(temps[i]); } } return outputs; } else { var outputs = new int [n][]; outputs[0] = new int[rownum]; for (int i = 0; i < s.Length; i++) { outputs[0][i] = int.Parse(s[i]); } for (int l = 1; l < n; l++) { outputs[l] = new int[rownum]; var temps = Console.ReadLine().Split(' '); for (int i = 0; i < rownum; i++) { outputs[l][i] = int.Parse(temps[i]); } } return outputs; } } private int[] Minusone(int[] x) { var output = new int[x.Length]; for (int i = 0; i < x.Length; i++) { output[i] = x[i] - 1; } return output; } // 元の配列をソートして、ソート後の各要素の、元のインデックスを返す private static int[] SortwithIndex(double[] data) { var index = new int[data.Length]; for (int i = 0; i < data.Length; i++) { index[i] = i; } QSort(data, index, 0, data.Length - 1); return index; } private static void QSort(double[] data, int[] index, int low, int high) { // 要素数が1以下の領域ができた場合、その領域は確定とする。 if (high - low < 1) return; // 1. ピボットとして一つ選びそれをPとする。 var P = data[(low + high + 1) / 2]; // 2. 左から順に値を調べ、P以上のものを見つけたらその位置をiとする。 // 3. 右から順に値を調べ、P以下のものを見つけたらその位置をjとする。 // 4. // iがjより左にあるのならばその二つの位置を入れ替え、2に戻る。ただし、次の2での探索はiの一つ右、次の3での探索はjの一つ左から行う。 int i = low - 1; int j = high + 1; while (Scan(data, P, ref i, ref j)) { Swap(data, index, i, j); } // 5. // 2に戻らなかった場合、iの左側を境界に分割を行って2つの領域に分け、そのそれぞれに対して再帰的に1からの手順を行う。 QSort(data, index, low, i - 1); QSort(data, index, i, high); } private static bool Scan(double[] data, double P, ref int i, ref int j) { while (data[++i] < P) ; while (data[--j] > P) ; return i < j; } private static void Swap(double[] data, int[] index, int i, int j) { var temp = data[i]; data[i] = data[j]; data[j] = temp; var temp2 = index[i]; index[i] = index[j]; index[j] = temp2; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,312
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); public static void Main() { int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = nk[0]; int K = nk[1]; string S = Console.ReadLine(); List<int> len = new List<int>(); char look = S[0]; int count = 1; for (int i = 1; i < S.Length; i++) { if (look == S[i]) { count++; } else { look = S[i]; len.Add(count); count = 1; } } len.Add(count); int maxlength = len[0] + len[1] + len[2]; int maxcenter = 1; int sum = maxlength; int saved = 0; for (int i = 0; i < len.Count; i++) { saved += len[i] - 1; } if (len.Count / 2 > K) { saved += 2 * K; } else { saved = N - 1; } Console.WriteLine(saved); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); public static void Main() { int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = nk[0]; int K = nk[1]; string S = Console.ReadLine(); List<int> len = new List<int>(); char look = S[0]; int count = 1; for (int i = 1; i < S.Length; i++) { if (look == S[i]) { count++; } else { look = S[i]; len.Add(count); count = 1; } } len.Add(count); int saved = 0; for (int i = 0; i < len.Count; i++) { saved += len[i] - 1; } if (len.Count / 2 > K) { saved += 2 * K; } else { saved = N - 1; } Console.WriteLine(saved); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 212, 0, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["-", 0, 212, 0, 16, 31, 16, 12, 204, 205, 22], ["-", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
276
28
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string T = Console.ReadLine(); int a = 0; for (int i = 1; i < 3; i++) { if (S[1] == T[1]) { a++; } } Console.WriteLine(a); Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string t = Console.ReadLine(); int a = 0; for (int i = 0; i < 3; i++) { if (s[i] == t[i]) { a++; } } Console.WriteLine(a); Console.Read(); } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
115
16
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var S = ReadLine(); var T = ReadLine(); int cnt = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (S[i] == T[j]) { cnt++; } } } WriteLine(cnt); } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var S = ReadLine(); var T = ReadLine(); int cnt = 0; for (int i = 0; i < 3; i++) { if (S[i] == T[i]) { cnt++; } } WriteLine(cnt); } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
[["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
906
18
using System; class Program { static void Main(string[] args) { int n = 0; string[] yohou = Console.ReadLine().Split(' '); string[] tenki = Console.ReadLine().Split(' '); for (int i = 0; i < 3; i++) { if (yohou[i] == tenki[i]) n++; } Console.WriteLine(n); } }
using System; class Program { static void Main(string[] args) { int n = 0; string yohou = Console.ReadLine(); string tenki = Console.ReadLine(); for (int i = 0; i < 3; i++) { if (yohou[i] == tenki[i]) n++; } Console.WriteLine(n); } }
[["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24]]
8
97
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; int n = x[0]; var h = sc.IntArr; int ans = 0; int now = 0; for (int i = 0; i < n - 1; ++i) { if (h[i + 1] < h[i]) { ans = Math.Max(ans, now); now = 0; } now++; } wr.wri(ans); } } 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; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; int n = x[0]; var h = sc.IntArr; int ans = 0; int now = 0; for (int i = 0; i < n - 1; ++i) { if (h[i + 1] > h[i]) { ans = Math.Max(ans, now); now = 0; } else now++; if (i == n - 2) ans = Math.Max(ans, now); } wr.wri(ans); } } 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; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
979
22
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; private const int MAX = 100001; static long[] fac = new long[MAX]; static long[] finv = new long[MAX]; static long[] inv = new long[MAX]; static void Solve() { var n = Input.NextInt(); var h = Input.NextInt(n); long ans = 0; long cur = 0; for (int i = n - 1; i >= 1; --i) { if (h[i - 1] >= h[i]) { cur++; } else { ans = Math.Max(ans, cur); cur = 0; } } Console.WriteLine(ans); } #region よく使う便利関数 static void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long COM(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } 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]; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.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; private const int MAX = 100001; static long[] fac = new long[MAX]; static long[] finv = new long[MAX]; static long[] inv = new long[MAX]; static void Solve() { var n = Input.NextInt(); var h = Input.NextInt(n); long ans = 0; long cur = 0; for (int i = n - 1; i >= 1; --i) { if (h[i - 1] >= h[i]) { cur++; } else { ans = Math.Max(ans, cur); cur = 0; } } ans = Math.Max(ans, cur); Console.WriteLine(ans); } #region よく使う便利関数 static void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long COM(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } 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]; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
2,358
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); long n = cin.Long(); long ans = (n - 1) * (n - 2) / 2; Console.WriteLine(ans); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { 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] = Int() + add; } return Array; } public long Long() { 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] = Long() + add; } return Array; } public double Double() { 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] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); long n = cin.Long(); long ans = n * (n - 1) / 2; Console.WriteLine(ans); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { 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] = Int() + add; } return Array; } public long Long() { 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] = Long() + add; } return Array; } public double Double() { 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] = Double() + add; } return Array; } } }
[["-", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 212, 0, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203]]
8
449
6
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Myon { public Myon() {} public static int Main() { cin = new Scanner(); new Myon().calc(); return 0; } static Scanner cin; // メンバ変数--- long N; // ------------- void calc() { N = cin.nextInt(); long ret = ((N - 1) * N) / 2; write(ret); } void write(string v) { Console.WriteLine(v); } void write(int v) { Console.WriteLine(v); } void write(double v) { Console.WriteLine(v); } int Pow(int x, int y) { return (int)Math.Pow(double.Parse(x.ToString()), double.Parse(y.ToString())); } double Pow(double x, double y) { return Math.Pow(x, y); } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Myon { public Myon() {} public static int Main() { cin = new Scanner(); new Myon().calc(); return 0; } static Scanner cin; // メンバ変数--- long N; // ------------- void calc() { N = cin.nextInt(); long ret = ((N - 1) * N) / 2; write(ret); } void write(string v) { Console.WriteLine(v); } void write(int v) { Console.WriteLine(v); } void write(double v) { Console.WriteLine(v); } void write(long v) { Console.WriteLine(v); } int Pow(int x, int y) { return (int)Math.Pow(double.Parse(x.ToString()), double.Parse(y.ToString())); } double Pow(double x, double y) { return Math.Pow(x, y); } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
[["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46]]
8
573
15
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { long n = long.Parse(ReadLine()); decimal divide = n / 2; long sum = (long)(divide * (2 + (n - 1))); WriteLine(sum - n); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { long n = long.Parse(ReadLine()); decimal divide = (decimal)(n / 2D); long ans = (long)(divide * (1 + n)); WriteLine(ans - n); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 200, 0, 212, 0, 74, 51, 23, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 250], ["+", 0, 200, 0, 212, 0, 74, 51, 23, 0, 25], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 51, 23, 0, 16, 12, 23, 0, 16, 31, 203], ["+", 51, 23, 0, 16, 12, 23, 0, 16, 31, 203], ["-", 0, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["-", 12, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 12, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 74, 51, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
102
17
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using static System.Math; namespace NewCompetitionProgramming { public class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { Solve(); } } public static void Solve() { var n = GetString().ToLong(); var count = 0L; for (long i = n - 1; i >= 1; i--) { count += i % (i + 1); } CWrite(count); } static void CWrite<T>(T str) => Console.WriteLine(str); static string GetString() => Console.ReadLine(); static T[] GetArray<T>() { var t = typeof(T); var str = Console.ReadLine(); if (t == typeof(string)) { return (T[])(object)str.Split(); } if (t == typeof(int)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(long)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(double)) { return (T[])(object)str.ToNumArray<T>(); } throw new NotSupportedException($"{t} is not supported."); } } class SetConsole : IDisposable { readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); public SetConsole() { sw.AutoFlush = false; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } } static class ExtentionsLibrary { public static T[] CopyArray<T>(this T[] array) { var newArray = new T[array.Length]; Array.Copy(array, newArray, array.Length); return newArray; } public static T[,] CopyTwoDimensionalArray<T>(this T[,] dArray) { var firstDimentionLength = dArray.GetLength(0); var secondDimentionLength = dArray.GetLength(1); var newDArray = new T[firstDimentionLength, secondDimentionLength]; Array.Copy(dArray, newDArray, firstDimentionLength * secondDimentionLength); return newDArray; } public static T[] ToNumArray<T>(this string str) { var t = typeof(T); if (t == typeof(int)) { return (T[])(object)str.Split().Select(int.Parse).ToArray(); } if (t == typeof(long)) { return (T[])(object)str.Split().Select(long.Parse).ToArray(); } if (t == typeof(double)) { return (T[])(object)str.Split().Select(double.Parse).ToArray(); } throw new NotSupportedException(); } public static int ToInt(this string str) => int.Parse(str); public static int ToInt(this char chr) => int.Parse(chr.ToString()); public static long ToLong(this string str) => long.Parse(str); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using static System.Math; namespace NewCompetitionProgramming { public class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { Solve(); } } public static void Solve() { var n = GetString().ToLong(); CWrite((n - 1) * (1 + (n - 1)) / 2); } static void CWrite<T>(T str) => Console.WriteLine(str); static string GetString() => Console.ReadLine(); static T[] GetArray<T>() { var t = typeof(T); var str = Console.ReadLine(); if (t == typeof(string)) { return (T[])(object)str.Split(); } if (t == typeof(int)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(long)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(double)) { return (T[])(object)str.ToNumArray<T>(); } throw new NotSupportedException($"{t} is not supported."); } } class SetConsole : IDisposable { readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); public SetConsole() { sw.AutoFlush = false; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } } static class ExtentionsLibrary { public static T[] CopyArray<T>(this T[] array) { var newArray = new T[array.Length]; Array.Copy(array, newArray, array.Length); return newArray; } public static T[,] CopyTwoDimensionalArray<T>(this T[,] dArray) { var firstDimentionLength = dArray.GetLength(0); var secondDimentionLength = dArray.GetLength(1); var newDArray = new T[firstDimentionLength, secondDimentionLength]; Array.Copy(dArray, newDArray, firstDimentionLength * secondDimentionLength); return newDArray; } public static T[] ToNumArray<T>(this string str) { var t = typeof(T); if (t == typeof(int)) { return (T[])(object)str.Split().Select(int.Parse).ToArray(); } if (t == typeof(long)) { return (T[])(object)str.Split().Select(long.Parse).ToArray(); } if (t == typeof(double)) { return (T[])(object)str.Split().Select(double.Parse).ToArray(); } throw new NotSupportedException(); } public static int ToInt(this string str) => int.Parse(str); public static int ToInt(this char chr) => int.Parse(chr.ToString()); public static long ToLong(this string str) => long.Parse(str); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 24], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 31, 203], ["+", 31, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
694
37
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var seqA = new int [n + 1][]; for (int i = 1; i < seqA.Length; ++i) { seqA[i] = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } var numGames = (n * (n - 1)) / 2; var adjList = new int [numGames + 1][]; for (int i = 1; i < adjList.Length; ++i) { adjList[i] = new int[2]; } Func<int, int, int> gameId = (_x, _y) => 0; gameId = (x, y) => x < y ? y - x + numGames - (n - x + 1) * (n - x) / 2 : gameId(y, x); var unplayableAtFirstDay = new List<int>(); for (int i = 1; i < seqA.Length; ++i) { for (int j = 1; j < seqA[i].Length; ++j) { int h = gameId(i, seqA[i][j]); int t = gameId(i, seqA[i][j - 1]); unplayableAtFirstDay.Add(h); for (int k = 0; k < adjList[t].Length; ++k) { if (adjList[t][k] > 0) { continue; } adjList[t][k] = h; break; } } } adjList[0] = unplayableAtFirstDay.ToArray(); var day = adjList[0].Length > 0 ? Dfs(E.Repeat(int.MinValue, adjList.Length).ToArray(), adjList, new bool[adjList.Length], 0, 1) : -1; Console.WriteLine(day); } static int Dfs(int[] memo, int[][] adjList, bool[] path, int t, int d) { if (path[t]) { return memo[t] = -1; } if (memo[t] != int.MinValue) { return memo[t]; } var r = d; path[t] = true; for (int i = 0; i < adjList[t].Length; ++i) { int h = adjList[t][i]; if (h < 1) { break; } var rr = Dfs(memo, adjList, path, h, d + 1); if (rr < 0) { r = rr; break; } r = Math.Max(r, rr); } path[t] = false; return memo[t] = r; } }
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var seqA = new int [n + 1][]; for (int i = 1; i < seqA.Length; ++i) { seqA[i] = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } var numGames = (n * (n - 1)) / 2; var adjList = new int [numGames + 1][]; for (int i = 1; i < adjList.Length; ++i) { adjList[i] = new int[2]; } Func<int, int, int> gameId = (_x, _y) => 0; gameId = (x, y) => x < y ? y - x + numGames - (n - x + 1) * (n - x) / 2 : gameId(y, x); var unplayableAtFirstDay = new List<int>(); for (int i = 1; i < seqA.Length; ++i) { for (int j = 1; j < seqA[i].Length; ++j) { int h = gameId(i, seqA[i][j]); int t = gameId(i, seqA[i][j - 1]); unplayableAtFirstDay.Add(h); for (int k = 0; k < adjList[t].Length; ++k) { if (adjList[t][k] > 0) { continue; } adjList[t][k] = h; break; } } } adjList[0] = unplayableAtFirstDay.ToArray(); var day = adjList[0].Length > 0 ? Dfs(E.Repeat(int.MinValue, adjList.Length).ToArray(), adjList, new bool[adjList.Length], 0) : -1; Console.WriteLine(day); } static int Dfs(int[] memo, int[][] adjList, bool[] path, int t) { if (path[t]) { return memo[t] = -1; } if (memo[t] != int.MinValue) { return memo[t]; } var r = 1; path[t] = true; for (int i = 0; i < adjList[t].Length; ++i) { int h = adjList[t][i]; if (h < 1) { break; } var rr = Dfs(memo, adjList, path, h); if (rr < 0) { r = rr; break; } r = Math.Max(r, rr + 1); } path[t] = false; return memo[t] = r; } }
[["-", 0, 212, 0, 41, 64, 213, 3, 4, 0, 21], ["-", 0, 41, 64, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
614
13
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { int N = GetInt(); int[,] A = new int[N, N - 1]; for (int i = 0; i < N; i++) for (int j = 0; j < N - 1; j++) A[i, j] = GetInt() - 1; var dict = new Dictionary<int, int>(); int cnt = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { dict[i * N + j] = cnt; cnt++; } } var adj = Enumerable.Range(0, cnt).Select(_ => new List<int>()).ToArray(); for (int i = 0; i < N; i++) { for (int j = 0; j < N - 2; j++) { int v = dict[Math.Min(i, A[i, j]) * N + Math.Max(i, A[i, j])]; int u = dict[Math.Min(i, A[i, j + 1]) * N + Math.Max(i, A[i, j + 1])]; adj[v].Add(u); } } var tpl = tplSort(adj); if (tpl.Count != cnt) { Console.WriteLine(-1); return; } long[] dp = new long[cnt]; for (int v = 0; v < cnt; v++) foreach (int u in adj[v]) dp[u] = Math.Max(dp[u], dp[v] + 1); Console.WriteLine(dp.Max() + 1); } private List<int> tplSort(List<int>[] adj) { int N = adj.Length; int[] deg = new int[N]; for (int v = 0; v < N; v++) { foreach (int u in adj[v]) deg[u]++; } var res = new List<int>(); var queue = new Queue<int>(); for (int v = 0; v < N; v++) if (deg[v] == 0) queue.Enqueue(v); while (queue.Count > 0) { int v = queue.Dequeue(); res.Add(v); foreach (int u in adj[v]) { deg[u]--; if (deg[u] == 0) queue.Enqueue(u); } } return res; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { int N = GetInt(); int[,] A = new int[N, N - 1]; for (int i = 0; i < N; i++) for (int j = 0; j < N - 1; j++) A[i, j] = GetInt() - 1; var dict = new Dictionary<int, int>(); int cnt = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { dict[i * N + j] = cnt; cnt++; } } var adj = Enumerable.Range(0, cnt).Select(_ => new List<int>()).ToArray(); for (int i = 0; i < N; i++) { for (int j = 0; j < N - 2; j++) { int v = dict[Math.Min(i, A[i, j]) * N + Math.Max(i, A[i, j])]; int u = dict[Math.Min(i, A[i, j + 1]) * N + Math.Max(i, A[i, j + 1])]; adj[v].Add(u); } } var tpl = tplSort(adj); if (tpl.Count != cnt) { Console.WriteLine(-1); return; } long[] dp = new long[cnt]; for (int i = 0; i < cnt; i++) { int v = tpl[i]; foreach (int u in adj[v]) dp[u] = Math.Max(dp[u], dp[v] + 1); } Console.WriteLine(dp.Max() + 1); } private List<int> tplSort(List<int>[] adj) { int N = adj.Length; int[] deg = new int[N]; for (int v = 0; v < N; v++) { foreach (int u in adj[v]) deg[u]++; } var res = new List<int>(); var queue = new Queue<int>(); for (int v = 0; v < N; v++) if (deg[v] == 0) queue.Enqueue(v); while (queue.Count > 0) { int v = queue.Dequeue(); res.Add(v); foreach (int u in adj[v]) { deg[u]--; if (deg[u] == 0) queue.Enqueue(u); } } return res; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); }
[["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
909
16
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int[,] matrix = new int[n, n - 1]; //行列 long answer = 0; for (int i = 0; i < n; i++) //それぞれの行 { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (int j = 0; j < n - 1; j++) matrix[i, j] = nums[j] - 1; //行の全ての成分 } int[] checkedCount = new int[n]; bool[] looked = new bool[n]; int lookedSum = 0; bool todayChecked = false; while (true) { todayChecked = false; for (int i = 0; i < n; i++) { looked[i] = false; } for (int i = 0; i < n; i++) { if (checkedCount[i] == n - 1 || looked[i]) continue; looked[i] = true; int partnerNum = matrix[i, checkedCount[i]]; if (checkedCount[partnerNum] == n - 1) continue; if (matrix[partnerNum, checkedCount[partnerNum]] == i && !looked[partnerNum]) { looked[partnerNum] = true; checkedCount[i]++; checkedCount[partnerNum]++; todayChecked = true; lookedSum++; // Console.WriteLine(i+" "+answer+" "+partnerNum); } } if (!todayChecked || answer > 100000) break; answer++; } if (lookedSum == n * (n - 1) / 2) Console.WriteLine(answer); else Console.WriteLine(1); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int[,] matrix = new int[n, n - 1]; //行列 long answer = 0; for (int i = 0; i < n; i++) //それぞれの行 { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (int j = 0; j < n - 1; j++) matrix[i, j] = nums[j] - 1; //行の全ての成分 } int[] checkedCount = new int[n]; bool[] looked = new bool[n]; int lookedSum = 0; bool todayChecked = false; while (true) { todayChecked = false; for (int i = 0; i < n; i++) { looked[i] = false; } for (int i = 0; i < n; i++) { if (checkedCount[i] == n - 1 || looked[i]) continue; looked[i] = true; int partnerNum = matrix[i, checkedCount[i]]; if (checkedCount[partnerNum] == n - 1) continue; if (matrix[partnerNum, checkedCount[partnerNum]] == i && !looked[partnerNum]) { looked[partnerNum] = true; checkedCount[i]++; checkedCount[partnerNum]++; todayChecked = true; lookedSum++; // Console.WriteLine(i+" "+answer+" "+partnerNum); } } if (!todayChecked || answer > 100000) break; answer++; } if (lookedSum == n * (n - 1) / 2) Console.WriteLine(answer); else if (answer == 100001) Console.WriteLine(499500); else Console.WriteLine(-1); } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33]]
8
368
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using CS = System.Runtime.CompilerServices; // using System.Diagnostics; using static System.Math; using ll = System.Int64; using static Contest_F.Lib_IO; using static Contest_F.Lib_Minifunc; namespace Contest_F { public static class Entry { public static void Main() { checked { long n; Lib_IO.rm(out n); P<double, double>[] xy; rl(n, out xy); P<double, double, ll>[] rt = new P<double, double, ll>[2 * n]; for (int i = 0; i < n; i++) { var r = Sqrt(xy[i].A * xy[i].A + xy[i].B * xy[i].B); var t = Atan2(xy[i].B, xy[i].A); rt[2 * i] = new P<double, double, ll>(r, t, i); rt[2 * i + 1] = new P<double, double, ll>(r, t + PI * 2.0, i); } rt.sort(2); int j = 0; P<double, double> sum = new P<double, double>(0, 0); while (rt[j].B < rt[0].B + PI) { sum.A += xy[rt[j].C].A; sum.B += xy[rt[j].C].B; j++; } double ans = Sqrt(sum.A * sum.A + sum.B * sum.B); for (int i = 1; i < n; i++) { sum.A -= xy[rt[i - 1].C].A; sum.B -= xy[rt[i - 1].C].B; while (rt[j].B < rt[i].B + PI) { sum.A += xy[rt[j].C].A; sum.B += xy[rt[j].C].B; j++; } chmax(ref ans, Sqrt(sum.A * sum.A + sum.B * sum.B)); } Lib_IO.wm(ans); } } } #region BaseModule public static class Lib_Minifunc { public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 [CS.MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [CS.MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) swap1(ref a, ref b); } // b の方が小さければ交換 [CS.MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { bool r; if (r = (a.CompareTo(b) == 1)) a = b; return r; } // b の方が小さければ a を更新 [CS.MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { bool r; if (r = (a.CompareTo(b) == -1)) a = b; return r; } // b の方が大きければ a を更新 [CS.MethodImpl(256)] public static bool inside(long i, long n) => (0 <= i && i < n); [CS.MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x, w) && inside(y, h)); [CS.MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable { T m = a[0]; for (int i = 1; i < a.Length; i++) chmin(ref m, a[i]); return m; } [CS.MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable { T m = a[0]; for (int i = 1; i < a.Length; i++) chmax(ref m, a[i]); return m; } [CS.MethodImpl(256)] public static long mod(long a, long m = MOD1) { var v = a % m; return (v < 0 ? (m < 0 ? v - m : v + m) : v); } [CS.MethodImpl(256)] public static long ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0) ? a / b : a / b + 1); // 整数商の切り上げ [CS.MethodImpl(256)] public static long round(double a) => Convert.ToInt64(a); // 四捨五入 public static string YES(bool a) => a ? "YES" : "NO"; public static string yes(bool a) => a ? "Yes" : "No"; [CS.MethodImpl(256)] public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b); [CS.MethodImpl(256)] public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b, c); [CS.MethodImpl(256)] public static P<T, U, V, W> initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d); public static T[] initc<T>(long l1) where T : new() { var m = new T[l1]; for (int i = 0; i < m.Length; i++) m[i] = new T(); return m; } // new制約は遅い public static int[] range(long s, long c) => Enumerable.Range((int)s, (int)c).ToArray(); [CS.MethodImpl(256)] public static T[] inita<T>(long l1, T v = default(T)) => Enumerable.Repeat(v, (int)l1).ToArray(); public static T[][] inita<T>(long l1, long l2, T v = default(T)) { var m = new T[l1][]; for (int i = 0; i < m.Length; i++) m[i] = inita(l2, v); return m; } public static void shift(this IList<int> l, int o) { for (int i = 0; i < l.Count; i++) l[i] += o; } public static void shift(this IList<long> l, long o) { for (int i = 0; i < l.Count; i++) l[i] += o; } [CS.MethodImpl(256)] public static bool initd<T, U>(this IDictionary<T, U> d, T k, U v = default(U)) { if (d.ContainsKey(k)) { return false; } else { d[k] = v; return true; } } public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null) where T : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.CompareTo(y)); break; case -1: Array.Sort(a, (x, y) => y.CompareTo(x)); break; default: break; } } public static void sort<T, U>(this P<T, U>[] a, int o, Comparison<P<T, U>> f = null) where T : IComparable where U : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; default: break; } } public static void sort<T, U, V>(this P<T, U, V>[] a, int o, Comparison<P<T, U, V>> f = null) where T : IComparable where U : IComparable where V : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; case 3: Array.Sort(a, (x, y) => x.C.CompareTo(y.C)); break; case -3: Array.Sort(a, (x, y) => y.C.CompareTo(x.C)); break; default: break; } } public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o, Comparison<P<T, U, V, W>> f = null) where T : IComparable where U : IComparable where V : IComparable where W : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; case 3: Array.Sort(a, (x, y) => x.C.CompareTo(y.C)); break; case -3: Array.Sort(a, (x, y) => y.C.CompareTo(x.C)); break; case 4: Array.Sort(a, (x, y) => x.D.CompareTo(y.D)); break; case -4: Array.Sort(a, (x, y) => y.D.CompareTo(x.D)); break; default: break; } } } public struct P<T, U> { public T A; public U B; public P(T a, U b) { A = a; B = b; } public static implicit operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B); public static implicit operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value); } public struct P<T, U, V> { public T A; public U B; public V C; public P(T a, U b, V c) { A = a; B = b; C = c; } } public struct P<T, U, V, W> { public T A; public U B; public V C; public W D; public P(T a, U b, V c, W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {} public Prt(System.IO.Stream s, Encoding e) : base(s, e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] { ' ' }; [CS.MethodImpl(256)] static bool eq<T, U>() => typeof(T).Equals(typeof(U)); [CS.MethodImpl(256)] static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); [CS.MethodImpl(256)] static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T, U>(out T a, out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T, U, V>(out T a, out U b, out V c) { var z = rm<T, U>(out a, out b); c = cv<V>(z[2]); return z; } public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) { var z = rm<T, U, V>(out a, out b, out c); d = cv<W>(z[3]); return z; } public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var z = rm<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(z[4]); return z; } public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries); a = new T[z.Length]; for (int i = 0; i < a.Length; i++) a[i] = cv<T>(z[i]); return z; } public static string[][] rl<T>(long n, out T[] a) { a = new T[n]; var y = new string[n][]; for (int i = 0; i < n; i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T, U>(long n, out P<T, U>[] a) { a = new P<T, U>[n]; var y = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; y[i] = rm(out o, out p); a[i] = new P<T, U>(o, p); } return y; } public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) { a = new P<T, U, V>[n]; var y = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; y[i] = rm(out o, out p, out q); a[i] = new P<T, U, V>(o, p, q); } return y; } public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) { a = new P<T, U, V, W>[n]; var y = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; y[i] = rm(out o, out p, out q, out r); a[i] = new P<T, U, V, W>(o, p, q, r); } return y; } public static string[][] rx<T>(long n, out T[][] a) { a = new T[n][]; var y = new string[n][]; for (int i = 0; i < n; i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act) { sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [CS.MethodImpl(256)] static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(() => { for (int i = 0; i < a.Length - 1; i++) Console.Write(wfm(a[i].GetType()) + " ", a[i]); Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); } public static void wl<T>(IList<T> a) { wwp(() => { var f = wfm(typeof(T)); if (a.Count == 0) { Console.WriteLine(); } else { foreach (T x in a) Console.WriteLine(f, x); } }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(() => { var f = wfm(typeof(T)); var g = f + s; foreach (var b in a) { if (b.Count == 0) { Console.WriteLine(); } else { for (int i = 0; i < b.Count - 1; i++) Console.Write(g, b[i]); Console.WriteLine(f, b[b.Count - 1]); } } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using CS = System.Runtime.CompilerServices; // using System.Diagnostics; using static System.Math; using ll = System.Int64; using static Contest_F.Lib_IO; using static Contest_F.Lib_Minifunc; namespace Contest_F { public static class Entry { public static void Main() { checked { long n; Lib_IO.rm(out n); P<double, double>[] xy; rl(n, out xy); P<double, double, ll>[] rt = new P<double, double, ll>[2 * n]; for (int i = 0; i < n; i++) { var r = Sqrt(xy[i].A * xy[i].A + xy[i].B * xy[i].B); var t = Atan2(xy[i].B, xy[i].A); rt[2 * i] = new P<double, double, ll>(r, t, i); rt[2 * i + 1] = new P<double, double, ll>(r, t + PI * 2.0, i); } rt.sort(2); int j = 0; P<double, double> sum = new P<double, double>(0, 0); double ans = 0.0; while (rt[j].B < rt[0].B + PI) { sum.A += xy[rt[j].C].A; sum.B += xy[rt[j].C].B; j++; chmax(ref ans, Sqrt(sum.A * sum.A + sum.B * sum.B)); } for (int i = 1; i < n; i++) { sum.A -= xy[rt[i - 1].C].A; sum.B -= xy[rt[i - 1].C].B; chmax(ref ans, Sqrt(sum.A * sum.A + sum.B * sum.B)); while (rt[j].B < rt[i].B + PI) { sum.A += xy[rt[j].C].A; sum.B += xy[rt[j].C].B; j++; chmax(ref ans, Sqrt(sum.A * sum.A + sum.B * sum.B)); } } Lib_IO.wm(ans); } } } #region BaseModule public static class Lib_Minifunc { public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 [CS.MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [CS.MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) swap1(ref a, ref b); } // b の方が小さければ交換 [CS.MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { bool r; if (r = (a.CompareTo(b) == 1)) a = b; return r; } // b の方が小さければ a を更新 [CS.MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { bool r; if (r = (a.CompareTo(b) == -1)) a = b; return r; } // b の方が大きければ a を更新 [CS.MethodImpl(256)] public static bool inside(long i, long n) => (0 <= i && i < n); [CS.MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x, w) && inside(y, h)); [CS.MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable { T m = a[0]; for (int i = 1; i < a.Length; i++) chmin(ref m, a[i]); return m; } [CS.MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable { T m = a[0]; for (int i = 1; i < a.Length; i++) chmax(ref m, a[i]); return m; } [CS.MethodImpl(256)] public static long mod(long a, long m = MOD1) { var v = a % m; return (v < 0 ? (m < 0 ? v - m : v + m) : v); } [CS.MethodImpl(256)] public static long ceil(long a, long b) => (a % b == 0 || (a < 0 && 0 < b) || (0 < a && b < 0) ? a / b : a / b + 1); // 整数商の切り上げ [CS.MethodImpl(256)] public static long round(double a) => Convert.ToInt64(a); // 四捨五入 public static string YES(bool a) => a ? "YES" : "NO"; public static string yes(bool a) => a ? "Yes" : "No"; [CS.MethodImpl(256)] public static P<T, U> initp<T, U>(T a, U b) => new P<T, U>(a, b); [CS.MethodImpl(256)] public static P<T, U, V> initp<T, U, V>(T a, U b, V c) => new P<T, U, V>(a, b, c); [CS.MethodImpl(256)] public static P<T, U, V, W> initp<T, U, V, W>(T a, U b, V c, W d) => new P<T, U, V, W>(a, b, c, d); public static T[] initc<T>(long l1) where T : new() { var m = new T[l1]; for (int i = 0; i < m.Length; i++) m[i] = new T(); return m; } // new制約は遅い public static int[] range(long s, long c) => Enumerable.Range((int)s, (int)c).ToArray(); [CS.MethodImpl(256)] public static T[] inita<T>(long l1, T v = default(T)) => Enumerable.Repeat(v, (int)l1).ToArray(); public static T[][] inita<T>(long l1, long l2, T v = default(T)) { var m = new T[l1][]; for (int i = 0; i < m.Length; i++) m[i] = inita(l2, v); return m; } public static void shift(this IList<int> l, int o) { for (int i = 0; i < l.Count; i++) l[i] += o; } public static void shift(this IList<long> l, long o) { for (int i = 0; i < l.Count; i++) l[i] += o; } [CS.MethodImpl(256)] public static bool initd<T, U>(this IDictionary<T, U> d, T k, U v = default(U)) { if (d.ContainsKey(k)) { return false; } else { d[k] = v; return true; } } public static void sort<T>(this T[] a, int o = 1, Comparison<T> f = null) where T : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.CompareTo(y)); break; case -1: Array.Sort(a, (x, y) => y.CompareTo(x)); break; default: break; } } public static void sort<T, U>(this P<T, U>[] a, int o, Comparison<P<T, U>> f = null) where T : IComparable where U : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; default: break; } } public static void sort<T, U, V>(this P<T, U, V>[] a, int o, Comparison<P<T, U, V>> f = null) where T : IComparable where U : IComparable where V : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; case 3: Array.Sort(a, (x, y) => x.C.CompareTo(y.C)); break; case -3: Array.Sort(a, (x, y) => y.C.CompareTo(x.C)); break; default: break; } } public static void sort<T, U, V, W>(this P<T, U, V, W>[] a, int o, Comparison<P<T, U, V, W>> f = null) where T : IComparable where U : IComparable where V : IComparable where W : IComparable { switch (o) { case 0: Array.Sort(a, f); break; case 1: Array.Sort(a, (x, y) => x.A.CompareTo(y.A)); break; case -1: Array.Sort(a, (x, y) => y.A.CompareTo(x.A)); break; case 2: Array.Sort(a, (x, y) => x.B.CompareTo(y.B)); break; case -2: Array.Sort(a, (x, y) => y.B.CompareTo(x.B)); break; case 3: Array.Sort(a, (x, y) => x.C.CompareTo(y.C)); break; case -3: Array.Sort(a, (x, y) => y.C.CompareTo(x.C)); break; case 4: Array.Sort(a, (x, y) => x.D.CompareTo(y.D)); break; case -4: Array.Sort(a, (x, y) => y.D.CompareTo(x.D)); break; default: break; } } } public struct P<T, U> { public T A; public U B; public P(T a, U b) { A = a; B = b; } public static implicit operator KeyValuePair<T, U>(P<T, U> a) => new KeyValuePair<T, U>(a.A, a.B); public static implicit operator P<T, U>(KeyValuePair<T, U> a) => new P<T, U>(a.Key, a.Value); } public struct P<T, U, V> { public T A; public U B; public V C; public P(T a, U b, V c) { A = a; B = b; C = c; } } public struct P<T, U, V, W> { public T A; public U B; public V C; public W D; public P(T a, U b, V c, W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s, new UTF8Encoding(false, true)) {} public Prt(System.IO.Stream s, Encoding e) : base(s, e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] { ' ' }; [CS.MethodImpl(256)] static bool eq<T, U>() => typeof(T).Equals(typeof(U)); [CS.MethodImpl(256)] static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); [CS.MethodImpl(256)] static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T, U>(out T a, out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T, U, V>(out T a, out U b, out V c) { var z = rm<T, U>(out a, out b); c = cv<V>(z[2]); return z; } public static string[] rm<T, U, V, W>(out T a, out U b, out V c, out W d) { var z = rm<T, U, V>(out a, out b, out c); d = cv<W>(z[3]); return z; } public static string[] rm<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var z = rm<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(z[4]); return z; } public static string[] rm<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var z = rm<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp, StringSplitOptions.RemoveEmptyEntries); a = new T[z.Length]; for (int i = 0; i < a.Length; i++) a[i] = cv<T>(z[i]); return z; } public static string[][] rl<T>(long n, out T[] a) { a = new T[n]; var y = new string[n][]; for (int i = 0; i < n; i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T, U>(long n, out P<T, U>[] a) { a = new P<T, U>[n]; var y = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; y[i] = rm(out o, out p); a[i] = new P<T, U>(o, p); } return y; } public static string[][] rl<T, U, V>(long n, out P<T, U, V>[] a) { a = new P<T, U, V>[n]; var y = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; y[i] = rm(out o, out p, out q); a[i] = new P<T, U, V>(o, p, q); } return y; } public static string[][] rl<T, U, V, W>(long n, out P<T, U, V, W>[] a) { a = new P<T, U, V, W>[n]; var y = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; y[i] = rm(out o, out p, out q, out r); a[i] = new P<T, U, V, W>(o, p, q, r); } return y; } public static string[][] rx<T>(long n, out T[][] a) { a = new T[n][]; var y = new string[n][]; for (int i = 0; i < n; i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act) { sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [CS.MethodImpl(256)] static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(() => { for (int i = 0; i < a.Length - 1; i++) Console.Write(wfm(a[i].GetType()) + " ", a[i]); Console.WriteLine(wfm(a[a.Length - 1].GetType()), a[a.Length - 1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[] { a }, " "); } public static void wl<T>(IList<T> a) { wwp(() => { var f = wfm(typeof(T)); if (a.Count == 0) { Console.WriteLine(); } else { foreach (T x in a) Console.WriteLine(f, x); } }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(() => { var f = wfm(typeof(T)); var g = f + s; foreach (var b in a) { if (b.Count == 0) { Console.WriteLine(); } else { for (int i = 0; i < b.Count - 1; i++) Console.Write(g, b[i]); Console.WriteLine(f, b[b.Count - 1]); } } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["+", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["+", 8, 196, 0, 287, 0, 196, 0, 197, 0, 35], ["-", 0, 287, 0, 196, 0, 52, 8, 196, 0, 46], ["-", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 52, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 275], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 287, 0, 196, 0, 52, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["+", 0, 28, 0, 16, 12, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 16, 12, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 52, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 52, 8, 196, 0, 46]]
8
4,535
41
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; namespace AtCoder { class AC { // const int MOD = 1000000007; const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new IO_ShortCut(); int N = Int; var pts = new List<Tuple<double, double>>(); for (int i = 0; i < N; i++) { double x, y; Input(out x, out y); pts.Add(new Tuple<double, double>(x, y)); } pts.Sort((x, y) => { var dif = Atan2(x.Item2, x.Item1) - Atan2(y.Item2, y.Item1); return dif == 0 ? 0 : (dif > 0 ? 1 : -1); }); double ans = 0; for (var i = 0; i < N; i++) { for (var j = i; j < N; j++) { double nx = 0; double ny = 0; for (var k = i; k <= j; k++) { nx += pts[k].Item1; ny += pts[k].Item2; } ans = Max(ans, Sqrt(nx * nx + ny * ny)); } } OutL(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } static class IO_ShortCut { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) => (T)Convert.ChangeType(input, typeof(T)); public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) => (long)Pow(a, b); } class Modulo { private int M; private readonly long[] m_facs; public long Mul(long a, long b) { return ((a * b) % M); } public Modulo(long n, int m) { M = m; m_facs = new long[n + 1]; m_facs[0] = 1; for (long i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public long Fac(long n) { return m_facs[n]; } public long Pow(long a, long m) { switch (m) { case 0: return 1L; case 1: return a; default: long p1 = Pow(a, m / 2); long p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public long Div(long a, long b) { return Mul(a, Pow(b, M - 2)); } public long Ncr(long n, long r) { if (n < r) { return 0; } if (n == r) { return 1; } long res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; namespace AtCoder { class AC { // const int MOD = 1000000007; const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new IO_ShortCut(); int N = Int; var pts = new List<Tuple<double, double>>(); for (int i = 0; i < N; i++) { double x, y; Input(out x, out y); pts.Add(new Tuple<double, double>(x, y)); } pts.Sort((x, y) => { var dif = Atan2(x.Item2, x.Item1) - Atan2(y.Item2, y.Item1); return dif == 0 ? 0 : (dif > 0 ? 1 : -1); }); double ans = 0; for (var i = 0; i < N; i++) { for (var j = 1; j <= N; j++) { double nx = 0, ny = 0; for (var k = i; k < i + j; k++) { nx += pts[k % N].Item1; ny += pts[k % N].Item2; } ans = Max(ans, Sqrt(nx * nx + ny * ny)); } } OutL(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } static class IO_ShortCut { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) => (T)Convert.ChangeType(input, typeof(T)); public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) => (long)Pow(a, b); } class Modulo { private int M; private readonly long[] m_facs; public long Mul(long a, long b) { return ((a * b) % M); } public Modulo(long n, int m) { M = m; m_facs = new long[n + 1]; m_facs[0] = 1; for (long i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public long Fac(long n) { return m_facs[n]; } public long Pow(long a, long m) { switch (m) { case 0: return 1L; case 1: return a; default: long p1 = Pow(a, m / 2); long p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public long Div(long a, long b) { return Mul(a, Pow(b, M - 2)); } public long Ncr(long n, long r) { if (n < r) { return 0; } if (n == r) { return 1; } long res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 109], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
8
1,515
15
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var n = sc.I; var h = new double [n << 1][]; var b = new bool [n][]; for (int i = 0; i < n; i++) { var e = sc.Ia; b[i] = new bool[n]; h[i] = new double[] { e[0], e[1], Atan2(e[1], e[0]) * 180 / PI + 180 }; h[i + n] = new double[] { e[0], e[1], Atan2(e[1], e[0]) * 180 / PI + 540 }; } Array.Sort(h, (u, v) => u[2].CompareTo(v[2])); double p1 = 0, p2 = 0, ans = 0; for (int i = 0, j = 0; i < n; i++) { while (h[i][2] + 180 > h[j][2]) { p1 += h[j][0]; p2 += h[j][1]; j++; } ans = Max(ans, Sqrt(p1 * p1 + p2 * p2)); p1 -= h[i][0]; p2 -= h[i][1]; } Console.WriteLine("{0}", ans); } } public 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(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var n = sc.I; var h = new double [n << 1][]; var b = new bool [n][]; for (int i = 0; i < n; i++) { var e = sc.Ia; b[i] = new bool[n]; h[i] = new double[] { e[0], e[1], Atan2(e[1], e[0]) * 180 / PI + 180 }; h[i + n] = new double[] { e[0], e[1], Atan2(e[1], e[0]) * 180 / PI + 540 }; } Array.Sort(h, (u, v) => u[2].CompareTo(v[2])); double ans = 0; for (int i = 0; i < n; i++) { double p1 = 0, p2 = 0; for (int j = i; h[i][2] + 180 >= h[j][2]; j++) { p1 += h[j][0]; p2 += h[j][1]; ans = Max(ans, Sqrt(p1 * p1 + p2 * p2)); } p1 -= h[i][0]; p2 -= h[i][1]; } Console.WriteLine("{0}", ans); } } public 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(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 0, 21], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 7, 8, 196, 0, 52, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
8
1,175
38
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long m = sc.NextLong(); long d = sc.NextLong(); long answer = 0; for (int i = 10; i <= d; i++) { if ((i / 10) * (i % 10) <= m) { 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(); long m = sc.NextLong(); long d = sc.NextLong(); long answer = 0; for (int i = 10; i <= d; i++) { long d1 = i % 10; long d10 = i / 10; if (d1 >= 2 && d10 >= 2 && d10 * d1 <= m) { 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, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 15, 16, 31, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22]]
8
401
32
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; var M = x[0]; var D = x[1]; int ans = 0; for (int i = 1; i <= M; ++i) { for (int j = 1; j <= D; ++j) { int d1 = j % 10; int d10 = j - d1; if (i == d1 * d10) ans++; } } wr.wri(ans); } } 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; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; var M = x[0]; var D = x[1]; int ans = 0; for (int i = 1; i <= M; ++i) { for (int j = 1; j <= D; ++j) { int d1 = j % 10; int d10 = (j - d1) / 10; if (i == (d1 * d10) && (d1 >= 2) && (d10 >= 2)) ans++; } } wr.wri(ans); } } 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; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 15, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 20], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 20], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
8
980
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace jsc2019_A { class Program { static void Main(string[] args) { var MD = Console.ReadLine().Split().Select(int.Parse).ToArray(); var M = MD[0]; var D = MD[1]; var ans = 0; for (int i = 1; i <= M; i++) { var f = Factorial(i); foreach (var item in f) { var v = 10 * item.Item1 + item.Item2; if (v <= D && v < 100) { ans++; } } } Console.WriteLine(ans); } public static List<Tuple<int, int>> Factorial(int i) { var ret = new List<Tuple<int, int>>(); for (int n = 2; n < i; n++) { if (i % n == 0 && i / 2 >= 2) { ret.Add(new Tuple<int, int>(n, i / n)); } } return ret; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace jsc2019_A { class Program { static void Main(string[] args) { var MD = Console.ReadLine().Split().Select(int.Parse).ToArray(); var M = MD[0]; var D = MD[1]; var ans = 0; for (int i = 1; i <= M; i++) { var f = Factorial(i); foreach (var item in f) { var v = 10 * item.Item1 + item.Item2; if (item.Item1 >= 10 || item.Item2 >= 10) continue; if (v <= D && v < 100) { ans++; } } } Console.WriteLine(ans); } public static List<Tuple<int, int>> Factorial(int i) { var ret = new List<Tuple<int, int>>(); for (int n = 2; n < i; n++) { if (i % n == 0 && i / 2 >= 2) { ret.Add(new Tuple<int, int>(n, i / n)); } } return ret; } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 210, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24]]
8
248
16
using System; class Program { static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(' '); int M = int.Parse(input1[0]); int D = int.Parse(input1[1]); int count = 0; int d1 = 0; int d10 = 0; for (int i = 1; i <= M; i++) { for (int j = 10; j <= D; j++) { if (j % 10 == 0) continue; d1 = j % 10; d10 = j / 10; if (d1 < 2) continue; if (d10 < 2) continue; } } Console.WriteLine(count); } }
using System; class Program { static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(' '); int M = int.Parse(input1[0]); int D = int.Parse(input1[1]); int count = 0; int d1 = 0; int d10 = 0; for (int i = 1; i <= M; i++) { for (int j = 10; j <= D; j++) { if (j % 10 == 0) continue; d1 = j % 10; d10 = j / 10; if (d1 < 2) continue; if (d10 < 2) continue; if (d1 * d10 == i) { count++; } } } Console.WriteLine(count); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
154
13
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { var md = ReadInts(); var ans = 0; for (int i = 1; i <= md[0]; i++) { for (int d = 22; d <= md[1]; d++) { var a = d.ToString(); // WriteLine(a); if (int.Parse(a[0].ToString()) >= 2 && int.Parse(a[1].ToString()) >= 2) { if (int.Parse(a[0].ToString()) * int.Parse(a[1].ToString()) == i) { WriteLine(i + "月" + d + "日"); ans++; } } } } WriteLine(ans); } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } public static bool IsPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } //最大公約数 public static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { var reminder = a % b; a = b; b = reminder; } return a; } //最小公倍数 public static int Lcm(int a, int b) { return a * b / Gcd(a, b); } //文字数を数える public static int CountChar(string s, char c) { return s.Length - s.Replace(c.ToString(), "").Length; } public static void debuglist(List<int> x) { foreach (var item in x) { WriteLine(item); } } public static void debuglist(List<string> x) { foreach (var item in x) { WriteLine(item); } } public static void debugarray(int[] x) { foreach (var item in x) { WriteLine(item); } } public static void debugarray(string[] x) { foreach (var item in x) { WriteLine(item); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { var md = ReadInts(); var ans = 0; for (int i = 1; i <= md[0]; i++) { for (int d = 22; d <= md[1]; d++) { var a = d.ToString(); // WriteLine(a); if (int.Parse(a[0].ToString()) >= 2 && int.Parse(a[1].ToString()) >= 2) { if (int.Parse(a[0].ToString()) * int.Parse(a[1].ToString()) == i) { ans++; } } } } WriteLine(ans); } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } public static bool IsPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } //最大公約数 public static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { var reminder = a % b; a = b; b = reminder; } return a; } //最小公倍数 public static int Lcm(int a, int b) { return a * b / Gcd(a, b); } //文字数を数える public static int CountChar(string s, char c) { return s.Length - s.Replace(c.ToString(), "").Length; } public static void debuglist(List<int> x) { foreach (var item in x) { WriteLine(item); } } public static void debuglist(List<string> x) { foreach (var item in x) { WriteLine(item); } } public static void debugarray(int[] x) { foreach (var item in x) { WriteLine(item); } } public static void debugarray(string[] x) { foreach (var item in x) { WriteLine(item); } } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 17, 72], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
686
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JSC2019 { class Program { static void Main(string[] args) { int[] md = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] mdd = new int[3]; int ans = 0; for (int i = 4; i <= md[0]; i++) { for (int j = 22; j <= md[1]; j++) { if (i == (j / 10) * (j % 10)) { ans++; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JSC2019 { class Program { static void Main(string[] args) { int[] md = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] mdd = new int[3]; int ans = 0; for (int i = 4; i <= md[0]; i++) { for (int j = 22; j <= md[1]; j++) { if (j % 10 <= 1) { } else if (i == (j / 10) * (j % 10)) { ans++; } } } Console.WriteLine(ans); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24]]
8
154
11
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG // MyDebugger.MakeTestCase("../TextFile2.txt"); MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); int m = int.Parse(spl[0]); int d = int.Parse(spl[1]); long c = 0; for (int i = 4; i <= m; i++) { for (int j = 22; j <= d; j++) { int d10 = j / 10; int d1 = j % 10; if (d10 * d1 == i) c++; } } return c; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG // MyDebugger.MakeTestCase("../TextFile2.txt"); MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); int m = int.Parse(spl[0]); int d = int.Parse(spl[1]); long c = 0; for (int i = 4; i <= m; i++) { for (int j = 22; j <= d; j++) { int d10 = j / 10; int d1 = j % 10; if (d10 < 2 || d1 < 2) continue; if (d10 * d1 == i) c++; } } return c; } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22]]
8
203
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProgramingStudying2 { class Program { static void Main(string[] args) { var nk = Console.ReadLine().Split(); var n = int.Parse(nk[0]); var k = long.Parse(nk[1]); var a = Console.ReadLine().Split().Select(int.Parse).ToList(); var ans1 = 0L; var ans2 = 0L; const long INF = (long)1000000007; // k個の部分列の中ごとにある転倒のカウント for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { ans1++; } } } Console.WriteLine(ans1); ans1 = ans1 * k % INF; //部分列間にある転倒のカウント for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] > a[j]) { ans2++; } } } Console.WriteLine(ans2); if (k % 2 == 0) { ans2 = ans2 * k / 2 % INF; ans2 = ans2 * (k - 1) % INF; } else { ans2 = ans2 * (k - 1) / 2 % INF; ans2 = ans2 * k % INF; } Console.WriteLine((ans1 + ans2) % INF); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProgramingStudying2 { class Program { static void Main(string[] args) { var nk = Console.ReadLine().Split(); var n = int.Parse(nk[0]); var k = long.Parse(nk[1]); var a = Console.ReadLine().Split().Select(int.Parse).ToList(); var ans1 = 0L; var ans2 = 0L; const long INF = (long)1000000007; // k個の部分列の中ごとにある転倒のカウント for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { ans1++; } } } ans1 = ans1 * k % INF; //部分列間にある転倒のカウント for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] > a[j]) { ans2++; } } } if (k % 2 == 0) { ans2 = ans2 * k / 2 % INF; ans2 = ans2 * (k - 1) % INF; } else { ans2 = ans2 * (k - 1) / 2 % INF; ans2 = ans2 * k % INF; } Console.WriteLine((ans1 + ans2) % INF); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
317
14
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; public static class P { public static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); long k = nk[1]; var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); long res = 0; for (int i = 0; i < a.Length; i++) { var cur = (long)a.Skip(i).Count(x => x < a[i]) * k + ((long)a.Count(x => x < a[i])) * (k * (k - 1) / 2); res += cur % 1000000007; res %= 1000000007; } Console.WriteLine(res); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; public static class P { public static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); long k = nk[1]; var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); long res = 0; for (int i = 0; i < a.Length; i++) { var cur = a.Skip(i).Count(x => x < a[i]) * k + a.Count(x => x < a[i]) * ((k * (k - 1) / 2) % 1000000007); res += cur % 1000000007; res %= 1000000007; } Console.WriteLine(res); } }
[["-", 0, 212, 0, 16, 31, 16, 31, 74, 0, 24], ["-", 0, 212, 0, 16, 31, 16, 31, 74, 39, 199], ["-", 0, 212, 0, 16, 31, 16, 31, 74, 0, 25], ["-", 0, 212, 0, 16, 12, 16, 31, 23, 0, 24], ["-", 0, 16, 12, 16, 31, 23, 0, 74, 0, 24], ["-", 0, 16, 12, 16, 31, 23, 0, 74, 39, 199], ["-", 0, 16, 12, 16, 31, 23, 0, 74, 0, 25], ["-", 31, 23, 0, 74, 51, 213, 3, 4, 0, 25], ["+", 0, 212, 0, 16, 12, 16, 12, 23, 0, 24], ["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 12, 203]]
8
228
12
using System; namespace pro { class MainClass { public static void Main() { string[] str1 = Console.ReadLine().Split(' '); int n = int.Parse(str1[0]); long k = int.Parse(str1[1]); int[] a = new int[n]; string[] str2 = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { a[i] = int.Parse(str2[i]); } int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] > a[j]) { count++; } } } int count1 = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { count1++; } } } long sum = 0; sum = (long)(count * (k * k / 2.0 % (long)(Math.Pow(10, 9) + 7) - k / 2)); sum = (sum + count1 * k % (long)(Math.Pow(10, 9) + 7)) % (long)(Math.Pow(10, 9) + 7); Console.WriteLine(sum); } } }
using System; namespace pro { class MainClass { public static void Main() { string[] str1 = Console.ReadLine().Split(' '); int n = int.Parse(str1[0]); long k = int.Parse(str1[1]); int[] a = new int[n]; string[] str2 = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { a[i] = int.Parse(str2[i]); } int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (a[i] > a[j]) { count++; } } } int count1 = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) { count1++; } } } long sum = 0; checked { sum = count * ((k * k - k) / 2 % (long)(Math.Pow(10, 9) + 7)); sum = (sum + count1 * k % (long)(Math.Pow(10, 9) + 7)) % (long)(Math.Pow(10, 9) + 7); Console.WriteLine(sum); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 1, 0, 11, 12, 74, 51, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["-", 12, 23, 0, 16, 31, 16, 31, 16, 12, 250], ["+", 12, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 16, 31, 16, 12, 74, 51, 23, 0, 25], ["-", 51, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["-", 0, 16, 12, 23, 0, 16, 12, 16, 17, 85], ["-", 0, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46]]
8
324
18
using System; using System.Collections.Generic; // list用 using System.Text.RegularExpressions; //正規表現用 using System.Text; // StringBuilder用 using System.Collections; //ハッシュテーブル用 using System.Linq; class Program { Hashtable ht = new Hashtable(); static List<long> s = new List<long>(); static long result; static long K, N; static int M = 1000000007; //素数 StringBuilder strresult = new StringBuilder(""); // Append(str ○○)関数で文字を追加していく static void Main() { // Modular mo = new // Modular(0);//素数で割った余りを出せで使う★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)カッコ内が初期値 // Node no = new // Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける // Permutation pe = new // Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。 // Treap tr = new // Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。 // delegate int // CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名を入れる。 // PriorityQueue pr = new // PriorityQueue<>(評価式);//優先度付キュー★Enqueue()で格納、Dequeue()で取りだし。引数は評価式(大と小のどちらが優先か)。 Read1(); Read2(N); long[] check2 = new long[N]; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { if (s[i] > s[j]) { check2[i]++; } } } for (int i = 0; i < N; i++) { result = (result + (check2[i] * K)) % M; } long[] check = new long[N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (s[i] > s[j]) { check[i]++; } } } //ワンセットの中に何個自分以上がある? for (int i = 0; i < N; i++) { result = (result + (long)((check[i] * K * (K - 1)) / (long)2)) % M; } // result=(long)mo; Console.WriteLine(result.ToString()); } static void Read1() { string[] tmp = Console.ReadLine().Split(' '); N = long.Parse(tmp[0]); K = long.Parse(tmp[1]); } static void Read2(long kosuu) { string[] tmp = Console.ReadLine().Split(' '); for (long i = 0; i < kosuu; i++) { s.Add(long.Parse(tmp[i])); } } static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } } class Modular { private const int M = 1000000007; //素数 private long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } }
using System; using System.Collections.Generic; // list用 using System.Text.RegularExpressions; //正規表現用 using System.Text; // StringBuilder用 using System.Collections; //ハッシュテーブル用 using System.Linq; class Program { Hashtable ht = new Hashtable(); static List<long> s = new List<long>(); static decimal result; static int K, N; static int M = 1000000007; //素数 StringBuilder strresult = new StringBuilder(""); // Append(str ○○)関数で文字を追加していく static void Main() { // Modular mo = new // Modular(0);//素数で割った余りを出せで使う★使い方:Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる(powべき乗、Fac累乗、nCr組み合わせも関数として存在)カッコ内が初期値 // Node no = new // Node<>();//UnionFind★Find関数で根っこの値を返す(根っこの値が一緒なら同グループ)、Unite関数で二つの木をくっつける // Permutation pe = new // Permutation<>();//配列&リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。 // Treap tr = new // Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。 // delegate int // CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名を入れる。 // PriorityQueue pr = new // PriorityQueue<>(評価式);//優先度付キュー★Enqueue()で格納、Dequeue()で取りだし。引数は評価式(大と小のどちらが優先か)。 Read1(); Read2(N); int[] check2 = new int[N]; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { if (s[i] > s[j]) { check2[i]++; } } } for (int i = 0; i < N; i++) { result = (result + ((decimal)check2[i] * (decimal)K)) % M; } int[] check = new int[N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (s[i] > s[j]) { check[i]++; } } } //ワンセットの中に何個自分以上がある? for (int i = 0; i < N; i++) { result = (result + (((decimal)check[i] * (decimal)K * ((decimal)K - 1)) / 2)) % M; } // result=(long)mo; Console.WriteLine(result.ToString()); } static void Read1() { string[] tmp = Console.ReadLine().Split(' '); N = int.Parse(tmp[0]); K = int.Parse(tmp[1]); } static void Read2(int kosuu) { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < kosuu; i++) { s.Add(int.Parse(tmp[i])); } } static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } } class Modular { private const int M = 1000000007; //素数 private long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 31, 74, 39, 199], ["+", 0, 16, 12, 23, 0, 16, 31, 74, 0, 25], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 0, 25], ["-", 12, 16, 31, 23, 0, 16, 12, 74, 39, 199], ["-", 12, 16, 31, 23, 0, 16, 12, 74, 0, 25], ["+", 31, 23, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 31, 23, 0, 16, 31, 16, 31, 74, 0, 25], ["+", 31, 23, 0, 16, 31, 16, 12, 74, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 12, 74, 39, 199], ["+", 31, 23, 0, 16, 31, 16, 12, 74, 0, 25], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["-", 12, 74, 51, 23, 0, 16, 12, 74, 0, 24], ["-", 12, 74, 51, 23, 0, 16, 12, 74, 39, 199], ["-", 12, 74, 51, 23, 0, 16, 12, 74, 0, 25], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199]]
8
902
41
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { int N = NextInt(); long K = NextLong(); int[] A = LineInt(); long ans = 0; for (int i = 0; i < N; i++) { //以降出現数 long cou = 0; for (int j = 0; j < N; j++) if (A[i] > A[j]) cou++; long box = (K - 1) * K / 2; ans += box * cou; cou = 0; for (int j = i + 1; j < N; j++) if (A[i] > A[j]) cou++; ans += cou * (K); ans %= MOD; } Console.WriteLine(ans); } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { int N = NextInt(); long K = NextLong(); int[] A = LineInt(); long ans = 0; for (int i = 0; i < N; i++) { //以降出現数 long cou = 0; for (int j = 0; j < N; j++) if (A[i] > A[j]) cou++; long box = ((K - 1) * K / 2) % MOD; ans += (box * cou) % MOD; cou = 0; for (int j = i + 1; j < N; j++) if (A[i] > A[j]) cou++; ans += cou * (K); ans %= MOD; } Console.WriteLine(ans); } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
[["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
567
8
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Sc_out; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 3; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var th = new Thread(Run, 1 << 26); th.Start(); th.Join(); // Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; // Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { var N = Cin.Int; var S = Cin.Str; ModInt ans = 1; int lef = 0; for (var i = 0; i < 2 * N; i++) { if (S[i] == 'B' ^ (lef % 2 == 1)) { lef++; } else { if (lef == 0) { OutL(0); return; } ans *= lef; lef--; } } ans *= Fac(N); OutL(ans.value); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class PrimeList { private bool[] isprime; private List<int> primelist; public PrimeList(int n) { if (n < 2) { return; } primelist = new List<int>(); isprime = new bool[n + 1]; for (var i = 0; i <= n; i++) { isprime[i] = i != 0 && i != 1; } for (var i = 2; i <= n; i++) { if (!isprime[i]) { continue; } primelist.Add(i); int c = i; while (c + i <= n) { c += i; isprime[c] = false; } } } public bool IsPrime(int n) { return isprime[n]; } public List<int> GetPrimeList() { return primelist; } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } public class SegmentTree<T> { // 1-indexed type int n; T[] Tree; Func<T, T, T> f; T ex; int L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { ex = exvalue; f = fun; n = 1; while (n < size) n <<= 1; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue, T[] initial) { ex = exvalue; n = 1; while (n < size) n <<= 1; f = fun; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = (n <= i && i <= n + initial.Length - 1) ? initial[i - n] : ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Set_All() { for (var i = n - 1; i >= 1; i--) Tree[i] = f(Tree[i << 1], Tree[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Assign(int idx, T nxt) => Tree[idx + n] = nxt; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int idx) { int now = idx + n; while (now > 1) { now >>= 1; Tree[now] = f(Tree[now << 1], Tree[now << 1 | 1]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update(int idx, T nxt) { Assign(idx, nxt); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update_func(int idx, T y) { Assign(idx, f(Peek(idx), y)); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query_Fold(int l, int r) { int L = n + l; int R = n + r; T vL = ex, vR = ex; while (L < R) { if (L % 2 == 1) { vL = f(vL, Tree[L]); L++; } if (R % 2 == 1) { vR = f(Tree[R - 1], vR); R--; } L >>= 1; R >>= 1; } return f(vL, vR); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Peek(int idx) => Tree[idx + n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Display(int len) { for (var i = 0; i < len; i++) Console.Write($"{Tree[i + n]} "); Console.WriteLine(); } } public class UnionFind { private int[] parent; private int[] rank; private int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } public int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } } static class Sc_out { public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Sc_out; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 3; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var th = new Thread(Run, 1 << 26); th.Start(); th.Join(); // Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; // Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { var N = Cin.Int; var S = Cin.Str; ModInt ans = 1; int lef = 0; for (var i = 0; i < 2 * N; i++) { if (S[i] == 'B' ^ (lef % 2 == 1)) { lef++; } else { if (lef == 0) { OutL(0); return; } ans *= lef; lef--; } } if (lef != 0) { OutL(0); return; } ans *= Fac(N); OutL(ans.value); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class PrimeList { private bool[] isprime; private List<int> primelist; public PrimeList(int n) { if (n < 2) { return; } primelist = new List<int>(); isprime = new bool[n + 1]; for (var i = 0; i <= n; i++) { isprime[i] = i != 0 && i != 1; } for (var i = 2; i <= n; i++) { if (!isprime[i]) { continue; } primelist.Add(i); int c = i; while (c + i <= n) { c += i; isprime[c] = false; } } } public bool IsPrime(int n) { return isprime[n]; } public List<int> GetPrimeList() { return primelist; } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } public class SegmentTree<T> { // 1-indexed type int n; T[] Tree; Func<T, T, T> f; T ex; int L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { ex = exvalue; f = fun; n = 1; while (n < size) n <<= 1; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue, T[] initial) { ex = exvalue; n = 1; while (n < size) n <<= 1; f = fun; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = (n <= i && i <= n + initial.Length - 1) ? initial[i - n] : ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Set_All() { for (var i = n - 1; i >= 1; i--) Tree[i] = f(Tree[i << 1], Tree[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Assign(int idx, T nxt) => Tree[idx + n] = nxt; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int idx) { int now = idx + n; while (now > 1) { now >>= 1; Tree[now] = f(Tree[now << 1], Tree[now << 1 | 1]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update(int idx, T nxt) { Assign(idx, nxt); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update_func(int idx, T y) { Assign(idx, f(Peek(idx), y)); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query_Fold(int l, int r) { int L = n + l; int R = n + r; T vL = ex, vR = ex; while (L < R) { if (L % 2 == 1) { vL = f(vL, Tree[L]); L++; } if (R % 2 == 1) { vR = f(Tree[R - 1], vR); R--; } L >>= 1; R >>= 1; } return f(vL, vR); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Peek(int idx) => Tree[idx + n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Display(int len) { for (var i = 0; i < len; i++) Console.Write($"{Tree[i + n]} "); Console.WriteLine(); } } public class UnionFind { private int[] parent; private int[] rank; private int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } public int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } } static class Sc_out { public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
3,454
15
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var n = ni(); var s = ns(); bool flip = false; int level = 0; int mod = 1000000007; long ans = 1; for (int i = 1; i <= n; i++) { ans *= i; ans %= mod; } foreach (var c in s) { if ((c == 'B') ^ flip) { level++; } else { ans *= level--; ans %= mod; } flip ^= true; } cout.WriteLine(ans); } } // PREWRITEN CODE BEGINS FROM HERE static public class StringExtensions { static public string JoinToString<T>(this IEnumerable<T> source, string separator = " ") { return string.Join(separator, source); } } internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; private readonly TextWriter cerr; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; cerr = Console.Error; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } #if DEBUG internal static class LinqPadExtension { public static string TextDump<T>(this T obj) { if (obj is IEnumerable) return (obj as IEnumerable).Cast<object>().JoinToString().Dump(); else return obj.ToString().Dump(); } public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); } } #endif public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var n = ni(); var s = ns(); bool flip = false; int level = 0; int mod = 1000000007; long ans = 1; for (int i = 1; i <= n; i++) { ans *= i; ans %= mod; } foreach (var c in s) { if ((c == 'B') ^ flip) { level++; } else { ans *= level--; ans %= mod; } flip ^= true; } if (level != 0) ans = 0; cout.WriteLine(ans); } } // PREWRITEN CODE BEGINS FROM HERE static public class StringExtensions { static public string JoinToString<T>(this IEnumerable<T> source, string separator = " ") { return string.Join(separator, source); } } internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; private readonly TextWriter cerr; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; cerr = Console.Error; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } #if DEBUG internal static class LinqPadExtension { public static string TextDump<T>(this T obj) { if (obj is IEnumerable) return (obj as IEnumerable).Cast<object>().JoinToString().Dump(); else return obj.ToString().Dump(); } public static T Dump<T>(this T obj) { return LINQPad.Extensions.Dump(obj); } } #endif public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
1,273
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A { class Program { /// <summary> /// The main entry point for the application /// </summary> [STAThread] public static void Main(string[] args) { string[] str_s = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得 string[] str_t = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得 int c = 0; for (int i = 0; i < 3; i++) { if (str_s[i] == str_t[i]) { c++; } } Console.Write("{0}", c); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A { class Program { /// <summary> /// The main entry point for the application /// </summary> [STAThread] public static void Main(string[] args) { string str_s = Console.ReadLine(); // 2つ以上のスペース区切り入力の取得 str_s.ToList(); string str_t = Console.ReadLine(); // 2つ以上のスペース区切り入力の取得 str_t.ToList(); int c = 0; for (int i = 0; i < 3; i++) { if (str_s[i] == str_t[i]) { c++; } } Console.Write("{0}", c); } } }
[["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
140
18
using System; using System.Linq; namespace ABC139 { class Program { static void Main() { var S = Console.ReadLine(); var T = Console.ReadLine(); var ans = 0; for (int i = 0; i < 3; i++) if (S[i] == T[i]) ans++; } } }
using System; using System.Linq; namespace ABC139 { class Program { static void Main() { var S = Console.ReadLine(); var T = Console.ReadLine(); var ans = 0; for (int i = 0; i < 3; i++) if (S[i] == T[i]) ans++; Console.WriteLine(ans); } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
75
7
using System; using System.Linq; class A { static void Main() { var s = Console.ReadLine(); var t = Console.ReadLine(); Console.WriteLine(new int [s.Length].Count(i => s[i] == t[i])); } }
using System; using System.Linq; class A { static void Main() { var s = Console.ReadLine(); var t = Console.ReadLine(); Console.WriteLine(Enumerable.Range(0, s.Length).Count(i => s[i] == t[i])); } }
[["-", 0, 28, 0, 213, 63, 214, 205, 227, 0, 228], ["-", 0, 213, 63, 214, 205, 227, 39, 224, 39, 199], ["-", 63, 214, 205, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["-", 63, 214, 205, 227, 39, 224, 225, 226, 0, 73], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25]]
8
65
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0031 { class Program { static void Main(string[] args) { var str = Console.ReadLine(); int A = int.Parse(str.Split(' ')[0]); int B = int.Parse(str.Split(' ')[1]); int result = 0; int t = 1; while (true) { result++; t = (t - 1); t += A; if (B <= t) { break; } } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0031 { class Program { static void Main(string[] args) { var str = Console.ReadLine(); int A = int.Parse(str.Split(' ')[0]); int B = int.Parse(str.Split(' ')[1]); int result = 0; int t = 1; while (t < B) { result++; t = (t - 1); t += A; } Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46]]
8
143
14
using System; class main { static void Main(string[] args) { string[] s = Console.ReadLine().Split(" "); int tap = int.Parse(s[0]) - 1; int sockets = int.Parse(s[1]); for (int i = 1; i != 0; i++) { if (tap * i + 1 >= sockets) { Console.Write(i); break; } } } }
using System; class main { static void Main(string[] args) { string[] s = Console.ReadLine().Split(" "); int tap = int.Parse(s[0]) - 1; int sockets = int.Parse(s[1]); if (sockets == 1) { Console.Write("0"); return; } for (int i = 1; i != 0; i++) { if (tap * i + 1 >= sockets) { Console.Write(i); break; } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
101
19
using System; using System.Linq; namespace b { class Program { static void Main(string[] args) { var ln = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var a = ln[0]; var b = ln[1]; decimal ans = 1; if (a < b) { decimal x = b - a; ans += Math.Ceiling(x / (a - 1)); } Console.WriteLine(ans); } } }
using System; using System.Linq; namespace b { class Program { static void Main(string[] args) { var ln = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var a = ln[0]; var b = ln[1]; decimal ans = 0; if (b > 1) { ans = 1; if (a < b) { decimal x = b - a; ans += Math.Ceiling(x / (a - 1)); } } Console.WriteLine(ans); } } }
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
117
12
using System; namespace Sample { class Sample { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int count = B - A; int ans = 1; while (count > 0) { count++; ans++; count = count - A; } Console.WriteLine(ans); } } }
using System; namespace Sample { class Sample { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int count = B - A; int ans; if (B == 1) { ans = 0; } else { ans = 1; while (count > 0) { count++; ans++; count = count - A; } } Console.WriteLine(ans); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 52, 8, 196, 0, 46]]
8
105
17
using System; using System.Collections.Generic; using System.Linq; namespace competitive_programming { public class Program { static void Main(string[] args) { var sep = ' '; var cin = new ConsoleInput(Console.In, sep); var program = new Program(); program.Solve(cin); } private void Solve(ConsoleInput cin) { var a = cin.ReadInt; var b = cin.ReadInt; var x = (int)((b - 1) / (a - 1) + 1); Console.WriteLine(x); } } internal class ConsoleInput { private readonly System.IO.TextReader stream; private readonly char separator = ' '; private readonly Queue<string> inputStream = new Queue<string>(); public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this.separator = separator; this.stream = stream; } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } string[] tmp = stream.ReadLine().Split(separator); foreach (string v in tmp) { inputStream.Enqueue(v); } return inputStream.Dequeue(); } } public string ReadLine => stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => 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 class SegmentTree { private readonly int _n; private readonly int _N; private readonly int[] _values; public SegmentTree(int n) { _n = n; _N = 1; while (_N < _n) _N *= 2; _values = new int[_N]; } public SegmentTree(int n, int init = int.MaxValue) : this(n) { for (var i = 0; i < _N; ++i) _values[i] = init; } public void Update(int i, int value) { int idx = i + _N - 1; _values[idx] = value; while (idx > 0) { idx = parent(idx); _values[idx] = Math.Min(_values[lchild(idx)], _values[rchild(idx)]); } } public int Find(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = _N; if (r <= a || b <= l) return int.MaxValue; if (a <= l && r <= b) return _values[k]; int lvalue = Find(a, b, lchild(k), l, (l + r) / 2); int rvalue = Find(a, b, rchild(k), (l + r) / 2, r); return Math.Min(lvalue, rvalue); } private int parent(int i) => (int)((i - 1) / 2); private int lchild(int i) => 2 * i + 1; private int rchild(int i) => 2 * i + 2; } }
using System; using System.Collections.Generic; using System.Linq; namespace competitive_programming { public class Program { static void Main(string[] args) { var sep = ' '; var cin = new ConsoleInput(Console.In, sep); var program = new Program(); program.Solve(cin); } private void Solve(ConsoleInput cin) { var a = cin.ReadInt; var b = cin.ReadInt; var x = Util.DivideFloor(b - 1, a - 1); Console.WriteLine(x); } } internal static class Util { internal static int DivideFloor(int a, int b) => (a + b - 1) / b; } internal class ConsoleInput { private readonly System.IO.TextReader stream; private readonly char separator = ' '; private readonly Queue<string> inputStream = new Queue<string>(); public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this.separator = separator; this.stream = stream; } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } string[] tmp = stream.ReadLine().Split(separator); foreach (string v in tmp) { inputStream.Enqueue(v); } return inputStream.Dequeue(); } } public string ReadLine => stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => 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 class SegmentTree { private readonly int _n; private readonly int _N; private readonly int[] _values; public SegmentTree(int n) { _n = n; _N = 1; while (_N < _n) _N *= 2; _values = new int[_N]; } public SegmentTree(int n, int init = int.MaxValue) : this(n) { for (var i = 0; i < _N; ++i) _values[i] = init; } public void Update(int i, int value) { int idx = i + _N - 1; _values[idx] = value; while (idx > 0) { idx = parent(idx); _values[idx] = Math.Min(_values[lchild(idx)], _values[rchild(idx)]); } } public int Find(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = _N; if (r <= a || b <= l) return int.MaxValue; if (a <= l && r <= b) return _values[k]; int lvalue = Find(a, b, lchild(k), l, (l + r) / 2); int rvalue = Find(a, b, rchild(k), (l + r) / 2, r); return Math.Min(lvalue, rvalue); } private int parent(int i) => (int)((i - 1) / 2); private int lchild(int i) => 2 * i + 1; private int rchild(int i) => 2 * i + 2; } }
[["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 200, 0, 212, 0, 74, 51, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 51, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 74, 51, 23, 0, 16, 31, 16, 17, 85], ["-", 51, 23, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 17, 72], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 74, 51, 23, 0, 25], ["+", 0, 209, 8, 201, 0, 235, 8, 201, 0, 46], ["+", 0, 209, 8, 201, 0, 235, 0, 251, 0, 305], ["+", 0, 209, 8, 201, 0, 235, 0, 251, 0, 115], ["+", 0, 208, 0, 209, 8, 201, 0, 235, 0, 269], ["+", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["+", 0, 209, 8, 201, 0, 235, 8, 201, 0, 45], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 305], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 306, 0, 221], ["+", 0, 195, 8, 306, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 8, 306, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 8, 306, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 195, 8, 306, 0, 16, 31, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 306, 0, 16, 17, 85], ["+", 8, 201, 0, 195, 8, 306, 0, 16, 12, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 0, 35]]
8
781
42
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.B { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var inputs = ReadLongs(); var A = inputs[0]; var B = inputs[1]; for (int i = 0;; i++) { if (i == 0 && B == 1) { return 0; } else if (i == 1 && A >= B) { return 1; } else if (A * i - 1 >= B) { return i; } } return null; } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.B { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var inputs = ReadLongs(); var A = inputs[0]; var B = inputs[1]; for (int i = 0;; i++) { if (i == 0 && B == 1) { return 0; } else if (i == 1 && A >= B) { return 1; } else if ((A - 1) * i + 1 >= B) { return i; } } } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["-", 75, 57, 75, 57, 15, 16, 31, 16, 17, 33], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 72], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 215], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35]]
8
264
9
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramB { static void Main() { int a = NextInt, b = NextInt; System.Console.WriteLine((b - 1) / a + 1); } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramB { static void Main() { int a = NextInt, b = NextInt; int tmp = 1, count = 0; while (tmp < b) { tmp = tmp - 1 + a; count++; } System.Console.WriteLine(count); } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 31, 16, 31, 23, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 85], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
289
38
using System; class c { static void Main() { var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int a = ab[0], b = ab[1]; Console.WriteLine((b + 1) / (a - 1)); } }
using System; class c { static void Main() { var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int a = ab[0], b = ab[1]; Console.WriteLine(Math.Ceiling((decimal)(b - 1) / (a - 1))); } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 74, 51, 23, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
68
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace tapp { class Program { static void Main(string[] args) { string num = Console.ReadLine(); String[] input = num.Split(' '); int A = Convert.ToInt32(input[0]); int B = Convert.ToInt32(input[1]); Console.WriteLine(Math.Ceiling((double)((B - 1) / (A - 1)))); { Console.Read(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace tapp { class Program { static void Main(string[] args) { string num = Console.ReadLine(); String[] input = num.Split(' '); int A = Convert.ToInt32(input[0]); int B = Convert.ToInt32(input[1]); double ans = Math.Ceiling((double)(B - 1) / (A - 1)); Console.WriteLine(ans); { Console.Read(); } } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
130
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp21 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = Convert.ToInt32(input[0]); int b = Convert.ToInt32(input[1]); int i = 1; int c = 0; while (a * i < b) { c = a * i - 1; i++; } Console.WriteLine(i); Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp21 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = Convert.ToInt32(input[0]); int b = Convert.ToInt32(input[1]); int i = 1; int c = 0; while (i < b) { i = i + a - 1; c++; } Console.WriteLine(c); Console.Read(); } } }
[["-", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 52, 15, 16, 31, 16, 17, 48], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
134
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc139_b { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int tap = 0; //最小で必要な電源タップ数 int plug = 1;   //電源プラグの差込口 while (plug < b) { plug = plug + a - 1; //使えるプラグ数(plug)=残りの差込口(plug)+新しい電源タップ(a)-使用プラグ(1) tap++; if (plug == b) { Console.WriteLine(tap); } else if (plug > b) { Console.WriteLine(tap); } } Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc139_b { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int tap = 0; //最小で必要な電源タップ数 int plug = 1;   //電源プラグの差込口 while (plug < b) { plug = plug + a - 1; //使えるプラグ数(plug)=残りの差込口(plug)+新しい電源タップ(a)-使用プラグ(1) tap++; } Console.WriteLine(tap); Console.ReadLine(); } } }
[["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 95], ["-", 0, 52, 8, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 52, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["-", 0, 52, 8, 196, 0, 57, 75, 57, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
8
160
24
using System; namespace B { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); double cnt = Math.Ceiling((double)B / A); Console.WriteLine(cnt); Console.Read(); } } }
using System; namespace B { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); double cnt = Math.Ceiling((double)(B - 1) / (A - 1)); Console.WriteLine(cnt); Console.Read(); } } }
[["+", 0, 28, 0, 16, 31, 74, 51, 23, 0, 24], ["+", 0, 16, 31, 74, 51, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 74, 51, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 74, 51, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
94
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc139_b { class Program { static void Main(string[] args) { string[] kazu = Console.ReadLine().Split(' '); int A = int.Parse(kazu[0]); int B = int.Parse(kazu[1]); int consent = 1; int tap = 0; for (int i = 0; consent < B; i++) { if (consent < B) { consent = consent - 1 + A; tap = tap + 1; if (consent >= B) { Console.WriteLine(tap); } } } Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc139_b { class Program { static void Main(string[] args) { string[] kazu = Console.ReadLine().Split(' '); int A = int.Parse(kazu[0]); int B = int.Parse(kazu[1]); int consent = 1; int tap = 0; for (int i = 0; consent <= B; i++) { if (consent < B) { consent = consent - 1 + A; tap = tap + 1; if (consent > B) { Console.WriteLine(tap); } } else if (consent == B) { Console.WriteLine(tap); break; } } Console.Read(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 57, 75, 57, 64, 196, 0, 93, 0, 35]]
8
159
22
using System; class Prog { static void Main() { int[] ls = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int a = ls[0]; int b = ls[1]; int i = 0; while (a + (a - 1) * i - b < 0) { i++; } Console.WriteLine(i + 1); } }
using System; class Prog { static void Main() { int[] ls = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int a = ls[0]; int b = ls[1]; int i = 0; while (a + (a - 1) * i - b < 0) { i++; } if (b != 1) { Console.WriteLine(i + 1); } else { Console.WriteLine(0); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
92
18
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var AB = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var ans = 0; for (var i = 0; i < AB[1]; i++) { if (!(((ans * AB[0])) - ((0 < ans) ? ans - 1 : 0) < AB[1])) break; ans++; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var AB = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); var ans = 0; if (AB[1] == 1) { Console.WriteLine(0); return; } for (var i = 0; i < AB[1]; i++) { if (!(((ans * AB[0])) - ((0 < ans) ? ans - 1 : 0) < AB[1])) break; ans++; } Console.WriteLine(ans); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
156
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_solve { class Program { public const ulong mod = 1000000007; static void Main(string[] args) { var ab = Input3(); var ans = 1; var sct = ab[0]; while (sct < ab[1]) { sct += ab[0] - 1; ans++; } Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } static public long[] Input3() { string[] data = Console.ReadLine().Split(); long[] res = new long[data.LongLength]; for (long i = 0; i < data.LongLength; i++) { res[i] = long.Parse(data[i]); } return res; } public static long Choose(long n, long a) { long x = 1; long y = 1; for (long i = 0; i < a; i++) { x *= n - i; y *= i + 1; } return x / y; } public static long Gcd(long a, long b) { long x = Math.Max(a, b); long y = Math.Min(a, b); if (x % y == 0) return y; else return Gcd(y, x % y); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_solve { class Program { public const ulong mod = 1000000007; static void Main(string[] args) { var ab = Input3(); var ans = 1; var sct = ab[0]; while (sct < ab[1]) { sct += ab[0] - 1; ans++; } if (ab[1] == 1) ans = 0; Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } static public long[] Input3() { string[] data = Console.ReadLine().Split(); long[] res = new long[data.LongLength]; for (long i = 0; i < data.LongLength; i++) { res[i] = long.Parse(data[i]); } return res; } public static long Choose(long n, long a) { long x = 1; long y = 1; for (long i = 0; i < a; i++) { x *= n - i; y *= i + 1; } return x / y; } public static long Gcd(long a, long b) { long x = Math.Max(a, b); long y = Math.Min(a, b); if (x % y == 0) return y; else return Gcd(y, x % y); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
333
13
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.IO.Pipes; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorders { public class Program { static void Main(string[] args) { var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int a = ab[0]; int b = ab[1]; if (b <= a) { Console.WriteLine(1); } else { int c = b - a; int ans = (c + a - 2) / (a - 1) + 1; Console.WriteLine(ans); } } } }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.IO.Pipes; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorders { public class Program { static void Main(string[] args) { var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int a = ab[0]; int b = ab[1]; if (b == 1) { Console.WriteLine(0); return; } if (b <= a) { Console.WriteLine(1); } else { int c = b - a; int ans = (c + a - 2) / (a - 1) + 1; Console.WriteLine(ans); } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
8
168
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); int a = cin.Int(); int b = cin.Int(); int ans = 0; while (ans * (a - 1) + a < b) { ++ans; } Console.WriteLine(ans + 1); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { 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] = Int() + add; } return Array; } public long Long() { 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] = Long() + add; } return Array; } public double Double() { 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] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); int a = cin.Int(); int b = cin.Int(); if (b == 1) { Console.WriteLine(0); return; } int ans = 0; while (ans * (a - 1) + a < b) { ++ans; } Console.WriteLine(ans + 1); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { 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] = Int() + add; } return Array; } public long Long() { 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] = Long() + add; } return Array; } public double Double() { 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] = Double() + add; } return Array; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
467
17
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200410.abc139_b.Cin; using static _20200410.abc139_b.Util; // using Pair = System.ValueTuple<long, long>; /// <summary> /// abc139 /// B - Power Socket /// https://atcoder.jp/contests/abc139/tasks/abc139_b /// </summary> namespace _20200410.abc139_b { public class Program { public static void Main(string[] args) { int A = ri; int B = ri; int A2 = A - 1; int ans = (B + A2 - 1) / A2; if (B % A2 == 1) ans--; Console.WriteLine(ans); } } /// <summary> /// 競プロライブラリ /// https://github.com/ha2ne2/ABC/tree/master/Lib /// </summary> public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long val) { Value = val % MOD; if (Value < 0) Value += MOD; } private static Mint Ctor(long val) { return new Mint() { Value = val }; } public static Mint operator +(Mint a, Mint b) { long res = a.Value + b.Value; if (res > MOD) res -= MOD; return Ctor(res); } public static Mint operator -(Mint a, Mint b) { long res = a.Value - b.Value; if (res < 0) res += MOD; return Ctor(res); } public static Mint operator *(Mint a, Mint b) { long res = a.Value * b.Value; if (res > MOD) res %= MOD; return Ctor(res); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object obj) { return obj is Mint && Value == ((Mint)obj).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public override string ToString() { return Value.ToString(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long n) { if (n == 0) return new Mint(1); Mint b = Pow(a, n >> 1); b *= b; if ((n & 1) == 1) b *= a; return b; } public static Mint Inv(Mint n) { long a = n.Value; long b = MOD; long x = 1; long u = 0; while (b != 0) { long k = a / b; long _x = u; u = x - k * u; x = _x; long _a = a; a = b; b = _a - (k * b); } return new Mint(x); } public bool Equals(Mint other) { return Value == other.Value; } public int CompareTo(Mint other) { return Comparer<long>.Default.Compare(Value, other.Value); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { private V DefaultValue; private static Func<V> CreateInstance = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V defaultValue) { DefaultValue = defaultValue; } new public V this[K i] { get { V v; if (TryGetValue(i, out v)) { return v; } else { return base[i] = DefaultValue != null ? DefaultValue : CreateInstance(); } } set { base[i] = value; } } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static string ReadString() { return Next(); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { Tokens = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long N) { a = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[,] ReadIntTable(int h, int w) { Tokens = null; int[,] ret = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadInt(); } } return ret; } public static long[,] ReadLongTable(long h, long w) { Tokens = null; long[,] ret = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadLong(); } } return ret; } public static char[,] ReadCharTable(int h, int w) { Tokens = null; char[,] res = new char[h, w]; for (int i = 0; i < h; i++) { string s = ReadString(); for (int j = 0; j < w; j++) { res[i, j] = s[j]; } } return res; } private static string[] Tokens; private static int Pointer; private static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { if (Console.IsOutputRedirected) return; var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } public static long GCD(long a, long b) { while (b != 0) { long _a = a; a = b; b = _a % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } public static long[] Accumulate(long[] array) { long[] acc = new long[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } public static double[] Accumulate(double[] array) { double[] acc = new double[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200410.abc139_b.Cin; using static _20200410.abc139_b.Util; // using Pair = System.ValueTuple<long, long>; /// <summary> /// abc139 /// B - Power Socket /// https://atcoder.jp/contests/abc139/tasks/abc139_b /// </summary> namespace _20200410.abc139_b { public class Program { public static void Main(string[] args) { int A = ri; int B = ri; int A2 = A - 1; int ans = (B + A2 - 1) / A2; if (B - A2 * (ans - 1) == 1) ans--; Console.WriteLine(ans); } } /// <summary> /// 競プロライブラリ /// https://github.com/ha2ne2/ABC/tree/master/Lib /// </summary> public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long val) { Value = val % MOD; if (Value < 0) Value += MOD; } private static Mint Ctor(long val) { return new Mint() { Value = val }; } public static Mint operator +(Mint a, Mint b) { long res = a.Value + b.Value; if (res > MOD) res -= MOD; return Ctor(res); } public static Mint operator -(Mint a, Mint b) { long res = a.Value - b.Value; if (res < 0) res += MOD; return Ctor(res); } public static Mint operator *(Mint a, Mint b) { long res = a.Value * b.Value; if (res > MOD) res %= MOD; return Ctor(res); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object obj) { return obj is Mint && Value == ((Mint)obj).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public override string ToString() { return Value.ToString(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long n) { if (n == 0) return new Mint(1); Mint b = Pow(a, n >> 1); b *= b; if ((n & 1) == 1) b *= a; return b; } public static Mint Inv(Mint n) { long a = n.Value; long b = MOD; long x = 1; long u = 0; while (b != 0) { long k = a / b; long _x = u; u = x - k * u; x = _x; long _a = a; a = b; b = _a - (k * b); } return new Mint(x); } public bool Equals(Mint other) { return Value == other.Value; } public int CompareTo(Mint other) { return Comparer<long>.Default.Compare(Value, other.Value); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { private V DefaultValue; private static Func<V> CreateInstance = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V defaultValue) { DefaultValue = defaultValue; } new public V this[K i] { get { V v; if (TryGetValue(i, out v)) { return v; } else { return base[i] = DefaultValue != null ? DefaultValue : CreateInstance(); } } set { base[i] = value; } } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static string ReadString() { return Next(); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { Tokens = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long N) { a = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[,] ReadIntTable(int h, int w) { Tokens = null; int[,] ret = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadInt(); } } return ret; } public static long[,] ReadLongTable(long h, long w) { Tokens = null; long[,] ret = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadLong(); } } return ret; } public static char[,] ReadCharTable(int h, int w) { Tokens = null; char[,] res = new char[h, w]; for (int i = 0; i < h; i++) { string s = ReadString(); for (int j = 0; j < w; j++) { res[i, j] = s[j]; } } return res; } private static string[] Tokens; private static int Pointer; private static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { if (Console.IsOutputRedirected) return; var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } public static long GCD(long a, long b) { while (b != 0) { long _a = a; a = b; b = _a % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } public static long[] Accumulate(long[] array) { long[] acc = new long[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } public static double[] Accumulate(double[] array) { double[] acc = new double[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["+", 15, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
8
2,416
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_Cs { public class Program { public static void Main() { decimal[] vs = Console.ReadLine().Split().Select(decimal.Parse).ToArray(); decimal ans = 1; if (vs[0] < vs[1]) { ans = 1 + Math.Ceiling((vs[1] - vs[0]) / (vs[0] - 1)); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_Cs { public class Program { public static void Main() { decimal[] vs = Console.ReadLine().Split().Select(decimal.Parse).ToArray(); decimal ans = 0; if (vs[1] > 1) { ans = 1; } if (vs[0] < vs[1]) { ans = 1 + Math.Ceiling((vs[1] - vs[0]) / (vs[0] - 1)); } Console.WriteLine(ans); } } }
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
126
15
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var A = items[0]; var B = items[1]; var kuchi = 0; var count = 0; while (kuchi < B) { count++; kuchi += (count == 1) ? A : A - 1; } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray(); var A = items[0]; var B = items[1]; var kuchi = 1; var count = 0; while (kuchi < B) { count++; kuchi += A - 1; } Console.WriteLine(count); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 1, 0, 11, 12, 41, 15, 23, 0, 24], ["-", 0, 11, 12, 41, 15, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 41, 15, 23, 0, 16, 17, 60], ["-", 0, 11, 12, 41, 15, 23, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 41, 15, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 64, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102]]
8
207
10
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(); var A = int.Parse(input[0]); var B = int.Parse(input[1]); var sum = 0; var ans = 0; while (true) { sum += A; ans++; if (sum >= B) { Console.WriteLine(ans); return; } sum--; } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(); var A = int.Parse(input[0]); var B = int.Parse(input[1]); if (B <= 1) { Console.WriteLine(0); return; } var sum = 0; var ans = 0; while (true) { sum += A; ans++; if (sum >= B) { Console.WriteLine(ans); return; } sum--; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
112
17
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] ab = ReadLineIntArray(); int rtn = 1; int n = ab[1] - ab[0]; while (n > 0) { n -= ab[0] - 1; rtn++; } Console.WriteLine(rtn); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] ab = ReadLineIntArray(); if (ab[1] == 1) { Console.WriteLine(0); } else { int rtn = 1; int n = ab[1] - ab[0]; while (n > 0) { n -= ab[0] - 1; rtn++; } Console.WriteLine(rtn); } } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
711
7
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int m = 0; static int r = 0; static int c = 0; static int x = 0; static int y = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static bool flg2 = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static int mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } #endregion static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); Solve(); Console.Out.Flush(); } static int[] used; public static void Solve() { int a = Int(); int b = Int(); cnt = 1; sum = a; while (sum < b) { cnt++; sum += a - 1; } Cnt(); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int m = 0; static int r = 0; static int c = 0; static int x = 0; static int y = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static bool flg2 = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static int mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } #endregion static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); Solve(); Console.Out.Flush(); } static int[] used; public static void Solve() { int a = Int(); int b = Int(); if (b == 1) { wl(0); return; } cnt = 1; sum = a; while (sum < b) { cnt++; sum += a - 1; } Cnt(); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,276
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // using ProCon.Util; namespace ProCon { class Program { static void Main(string[] args) { AC139B(); } static void AC139B() { // https://atcoder.jp/contests/abc139/tasks var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = input[0]; // a口の電源タップ var b = input[1]; // B口以上の未使用口 var x = 0; //必要な電源タップの個数 if (a > b) { x = 1; } else { x = (b - a) % (a - 1) == 0 ? (b - a) / (a - 1) + 1 : (b - a) / (a - 1) + 2; } Console.WriteLine(x); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // using ProCon.Util; namespace ProCon { class Program { static void Main(string[] args) { AC139B(); } static void AC139B() { // https://atcoder.jp/contests/abc139/tasks var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = input[0]; // a口の電源タップ var b = input[1]; // B口以上の未使用口 var x = 0; //必要な電源タップの個数 if (b == 1) { x = 0; } else if (a > b) { x = 1; } else { x = (b - a) % (a - 1) == 0 ? (b - a) / (a - 1) + 1 : (b - a) / (a - 1) + 2; } Console.WriteLine(x); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
8
173
13
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var A = l[0]; var B = l[1]; int ret = 0; while (B > 0) { if (A >= B) { B -= A; } else { B -= A - 1; } ret++; } Console.WriteLine(ret); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var A = l[0]; var B = l[1]; int ret = 0; if (B == 1) { Console.WriteLine(ret); return; } while (B > 0) { if (A >= B) { B -= A; } else { B -= A - 1; } ret++; } Console.WriteLine(ret); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
149
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp10 { class Program { static void MainA(string[] args) { Console.WriteLine( Console.ReadLine() .ToCharArray() .Zip(Console.ReadLine().ToCharArray(), (x, y) => x == y) .Count(x => x)); } static void Main() { var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var ans = arr[1] == arr[0] ? 1 : arr[1] / arr[0] + 1; Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp10 { class Program { static void MainA(string[] args) { Console.WriteLine( Console.ReadLine() .ToCharArray() .Zip(Console.ReadLine().ToCharArray(), (x, y) => x == y) .Count(x => x)); } static void Main() { var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var ans = (arr[1] - 1 + arr[0] - 2) / (arr[0] - 1); Console.WriteLine(ans); } } }
[["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 0, 200, 0, 212, 0, 41, 15, 16, 17, 60], ["-", 0, 212, 0, 41, 15, 16, 12, 204, 205, 22], ["-", 0, 41, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 41, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["-", 0, 200, 0, 212, 0, 41, 75, 16, 17, 72], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
8
164
19
using System; namespace AtCoder { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int tmp = 0; int ans = 0; while (true) { ans += 1; tmp = ans * (A - 1) + 1; if (tmp >= B) break; } Console.WriteLine(ans); } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int tmp = 0; int ans = 0; while (true) { tmp = ans * (A - 1) + 1; if (tmp >= B) break; ans += 1; } Console.WriteLine(ans); } } }
[["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203]]
8
113
8
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var AB = ReadSplitInt(); var A = AB[0]; var B = AB[1]; var sum = A; var ans = 1; while (sum < B) { sum += (A - 1); ans++; } Println(ans); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static void YESOrNO(bool e) => Println(e ? "YES" : "NO"); static void YesOrNo(bool e) => Println(e ? "Yes" : "No"); static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a / Gcd(a, b) * b; static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var AB = ReadSplitLong(); var A = AB[0]; var B = AB[1]; var kuchi = 1L; var ans = 0; while (kuchi < B) { kuchi--; kuchi += A; ans++; } Println(ans); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static void YESOrNO(bool e) => Println(e ? "YES" : "NO"); static void YesOrNo(bool e) => Println(e ? "Yes" : "No"); static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a / Gcd(a, b) * b; static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25]]
8
730
19
using System; namespace ABC139 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int count = 1; for (int i = A; i < B; i += (A - 1)) { count++; } Console.WriteLine(count); } } }
using System; namespace ABC139 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int count = 1; for (int i = A; i < B; i += (A - 1)) { count++; } if (B != 1) Console.WriteLine(count); else Console.WriteLine(0); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
99
14
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); for (int i = 1;; i++) { int n = a * i - (i - 1); if (b <= n) { Console.WriteLine(i); return; } } } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int i = 0; for (i = 0;; i++) { int n = (a * i) - (i - 1); if (b <= n) { break; } } Console.WriteLine(i); } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 7, 10, 11, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
105
18