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.Text.RegularExpressions; namespace AtCoder { public class Program { static long mod = 1000000007; static int n; static double[] p; static double[,] dp; static void Main(string[] args) { n = int.Parse(Console.ReadLine()); p = Console.ReadLine().Split().Select(double.Parse).ToArray(); int cnt = n / 2 + 1; dp = new double[n + 1, cnt + 1]; for (int i = 0; i < p.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = -1; } } double ans = Compute(cnt, 0); // System.Diagnostics.Debug.WriteLine($""); // for (int j = 0; j < dp.GetLength(1); j++) { // for (int i = 0; i < dp.GetLength(0); i++) { // System.Diagnostics.Debug.Write($"{dp[i, j],6} "); // } // System.Diagnostics.Debug.WriteLine($""); //} Console.WriteLine(ans); } static double Compute(int cnt, int index) { if (dp[index, cnt] >= 0) { return dp[index, cnt]; } if (cnt == 0) { dp[index, cnt] = 1; return 1; } if (cnt > n - index) { dp[index, cnt] = 0; return 0; } double result = 0; // 表 result += p[index] * Compute(cnt - 1, index + 1); // 裏 result += (1 - p[index]) * Compute(cnt, index + 1); dp[index, cnt] = result; return result; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class Program { static int n; static double[] p; static double[,] dp; static void Main(string[] args) { n = int.Parse(Console.ReadLine()); p = Console.ReadLine().Split().Select(double.Parse).ToArray(); int cnt = n / 2 + 1; dp = new double[n + 1, cnt + 1]; for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = -1; } } double ans = Compute(cnt, 0); // System.Diagnostics.Debug.Write($" "); // for (int i = 0; i < dp.GetLength(0); i++) { // System.Diagnostics.Debug.Write($"{i,6} "); //} // System.Diagnostics.Debug.WriteLine($""); // for (int j = 0; j < dp.GetLength(1); j++) { // System.Diagnostics.Debug.Write($"{j}:"); // for (int i = 0; i < dp.GetLength(0); i++) { // System.Diagnostics.Debug.Write($"{dp[i, j],6} "); // } // System.Diagnostics.Debug.WriteLine($""); //} Console.WriteLine(ans); } static double Compute(int count, int index) { if (dp[index, count] >= 0) { return dp[index, count]; } if (count == 0) { return dp[index, count] = 1; } if (count > n - index) { return dp[index, count] = 0; } double result = 0; // 表 result += p[index] * Compute(count - 1, index + 1); // 裏 result += (1 - p[index]) * Compute(count, index + 1); return dp[index, count] = result; } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 115], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 37, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 37, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38]]
8
337
40
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // using System.Numerics; using System.Diagnostics; class Program { public void Slove() { int n = int.Parse(Console.ReadLine()); double[] coins = Console.ReadLine().Split().Select(double.Parse).ToArray(); double[] dp = new double[n / 2 + 2]; dp[0] = 1; foreach (var coin in coins) { double coinR = 1 - coin; foreach (int i in Enumerable.Range(0, n / 2 + 1) .Reverse() .SkipWhile(x => dp[x] == 0)) { dp[i + 1] += dp[i] * coin; dp[i] = dp[i] * coinR; } } Console.WriteLine(string.Join(",", dp)); Console.WriteLine(dp[n / 2 + 1]); } static void Main(string[] args) { var p = new Program(); p.Slove(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // using System.Numerics; using System.Diagnostics; class Program { public void Slove() { int n = int.Parse(Console.ReadLine()); double[] coins = Console.ReadLine().Split().Select(double.Parse).ToArray(); double[] dp = new double[n / 2 + 2]; dp[0] = 1; foreach (var coin in coins) { double coinR = 1 - coin; foreach (int i in Enumerable.Range(0, n / 2 + 1) .Reverse() .SkipWhile(x => dp[x] == 0)) { dp[i + 1] += dp[i] * coin; dp[i] = dp[i] * coinR; } } // Console.WriteLine(string.Join(",", dp)); Console.WriteLine(dp[n / 2 + 1]); } static void Main(string[] args) { var p = new Program(); p.Slove(); } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 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
239
16
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace J { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var counts = new int[3]; for (var i = 0; i < A.Length; i++) { counts[A[i] - 1]++; } var ep = 1.0 / N; var dp = new double[N + 1, N + 1, N + 1]; for (var i = 0; i <= N; i++) { for (var j = 0; j <= N; j++) { for (var k = 0; k <= N; k++) { var z = N - i - j - k; if (z < 0) break; if (z == N) continue; var x = 1 - z * ep; if (i > 0) dp[i, j, k] += dp[i - 1, j, k] * i * ep; if (j > 0) dp[i, j, k] += dp[i, j - 1, k] * j * ep; if (k > 0) dp[i, j, k] += dp[i, j, k - 1] * k * ep; dp[i, j, k] += 1; dp[i, j, k] /= x; } } } Console.WriteLine(dp[counts[0], counts[1], counts[2]]); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace J { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var counts = new int[3]; for (var i = 0; i < A.Length; i++) { counts[A[i] - 1]++; } var ep = 1.0 / N; var dp = new double[N + 1, N + 1, N + 1]; for (var k = 0; k <= N; k++) { for (var j = 0; j <= N; j++) { for (var i = 0; i <= N; i++) { var z = N - i - j - k; if (z < 0) break; if (z == N) continue; var x = 1 - z * ep; if (i > 0) dp[i, j, k] += dp[i - 1, j, k] * i * ep; if (j > 0) dp[i, j, k] += dp[i + 1, j - 1, k] * j * ep; if (k > 0) dp[i, j, k] += dp[i, j + 1, k - 1] * k * ep; dp[i, j, k] += 1; dp[i, j, k] /= x; } } } Console.WriteLine(dp[counts[0], counts[1], counts[2]]); } } }
[["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
418
16
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.DP { class EDPC_J { public static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var m = new int[3]; for (int i = 0; i < a.Length; i++) m[a[i] - 1]++; var dp = new double[m[2] + 1, m[1] + m[2] + 1, n + 1]; for (int i = 0; i <= m[2]; i++) { for (int j = 0; j <= m[1] + m[2] - i; j++) { for (int k = 0; k <= n - i - j; k++) { dp[i, j, k] = n; if (i > 0) dp[i, j, k] += dp[i - 1, j + 1, k] * i; if (j > 0) dp[i, j, k] += dp[i, j - 1, k + 1] * j; if (k > 0) dp[i, j, k] += dp[i, j, k - 1] * k; dp[i, j, k] /= i + j + k; } } } Console.WriteLine(dp[m[2], m[1], m[0]]); } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.DP { class EDPC_J { public static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var m = new int[3]; for (int i = 0; i < a.Length; i++) m[a[i] - 1]++; var dp = new double[m[2] + 1, m[1] + m[2] + 1, n + 1]; for (int i = 0; i <= m[2]; i++) { for (int j = 0; j <= m[1] + m[2] - i; j++) { for (int k = 0; k <= n - i - j; k++) { if (i + j + k == 0) { dp[i, j, k] = 0; continue; } dp[i, j, k] = n; if (i > 0) dp[i, j, k] += dp[i - 1, j + 1, k] * i; if (j > 0) dp[i, j, k] += dp[i, j - 1, k + 1] * j; if (k > 0) dp[i, j, k] += dp[i, j, k - 1] * k; dp[i, j, k] /= i + j + k; } } } Console.WriteLine(dp[m[2], m[1], m[0]]); } } }
[["+", 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, 72], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 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, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22]]
8
347
25
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class Program { static int n; static int k; static int[] a; static bool[] dp; static void Main(string[] args) { int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); n = vs[0]; k = vs[1]; a = Console.ReadLine().Split().Select(int.Parse).ToArray(); dp = new bool[k + 1]; for (int i = 1; i <= k; i++) { for (int j = 0; j < a.Length; j++) { if (i - a[j] >= 0) { dp[i] |= !dp[i - a[j]]; } } } // for (int i = 0; i < dp.Length; i++) { // System.Diagnostics.Debug.Write($"{(dp[i] ? "o" : "x")}, "); //} // System.Diagnostics.Debug.WriteLine($""); Console.WriteLine($"{(dp[k] ? "First" : "Second")}, "); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class Program { static long mod = 1000000007; static int n; static int k; static int[] a; static bool[] dp; static void Main(string[] args) { int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); n = vs[0]; k = vs[1]; a = Console.ReadLine().Split().Select(int.Parse).ToArray(); dp = new bool[k + 1]; for (int i = 1; i <= k; i++) { for (int j = 0; j < a.Length; j++) { if (i - a[j] >= 0) { dp[i] |= !dp[i - a[j]]; } } } Console.WriteLine(dp[k] ? "First" : "Second"); } } }
[["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["+", 0, 235, 8, 201, 0, 124, 0, 251, 0, 115], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 0, 28, 0, 283, 0, 284, 0, 23, 0, 24], ["-", 0, 284, 0, 23, 0, 41, 75, 5, 0, 62], ["-", 0, 28, 0, 283, 0, 284, 0, 23, 0, 25], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296]]
8
232
13
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; private const long INFINITY = 9223372036854775807; private struct Pair { public int x, y; } public static void Main() { int N = NextInt(); int K = NextInt(); int[] x = LineInt(); bool[] dp = new bool[K + 1]; for (int i = 0; i <= K; i++) dp[i] = false; for (int i = 0; i < N; i++) for (int j = x[i]; j <= K; j++) if (!dp[j - x[i]]) dp[j] = true; Console.WriteLine((dp[K] ? "First" : "Second")); } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; private const long INFINITY = 9223372036854775807; private struct Pair { public int x, y; } public static void Main() { int N = NextInt(); int K = NextInt(); int[] x = LineInt(); bool[] dp = new bool[K + 1]; for (int i = 0; i <= K; i++) dp[i] = false; for (int j = 1; j <= K; j++) for (int i = 0; i < N; i++) if (j >= x[i] && !dp[j - x[i]]) dp[j] = true; Console.WriteLine((dp[K] ? "First" : "Second")); } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
[["+", 8, 196, 0, 7, 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, 19], ["+", 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, 7, 0, 88], ["+", 0, 195, 8, 196, 0, 7, 8, 7, 0, 24], ["+", 8, 196, 0, 7, 8, 7, 10, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 8, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 7, 8, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 7, 10, 198, 39, 199], ["-", 8, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 7, 8, 57, 15, 16, 31, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 7, 8, 7, 0, 35], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 31, 22], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 7, 26, 223, 0, 22], ["-", 8, 196, 0, 7, 8, 7, 26, 223, 0, 29], ["-", 0, 195, 8, 196, 0, 7, 8, 7, 0, 25], ["-", 8, 196, 0, 7, 8, 7, 8, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 7, 8, 57, 0, 24], ["+", 0, 7, 8, 7, 8, 57, 15, 16, 17, 98]]
8
495
30
using System; class M { static void Main() { Func<int[]> read = () => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var h = read(); var a = read(); int n = h[0], k = h[1]; var dp = new int[n + 1, k + 1]; for (int i = 0; i <= n; i++) dp[i, 0] = 1; for (int j = 0; j <= k; j++) dp[0, j] = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= k; j++) dp[i, j] = (dp[i, j - 1] + dp[i - 1, j] - (j > a[i - 1] ? dp[i - 1, j - a[i - 1] - 1] : 0)) % 1000000007; Console.WriteLine(dp[n, k] - (k > 0 ? dp[n, k - 1] : 0)); } }
using System; class M { static void Main() { Func<int[]> read = () => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var h = read(); var a = read(); int n = h[0], k = h[1]; var dp = new long[n + 1, k + 1]; for (int i = 0; i <= n; i++) dp[i, 0] = 1; for (int j = 0; j <= k; j++) dp[0, j] = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= k; j++) dp[i, j] = MInt(dp[i, j - 1] + dp[i - 1, j] - (j > a[i - 1] ? dp[i - 1, j - a[i - 1] - 1] : 0)); Console.WriteLine(MInt(dp[n, k] - (k > 0 ? dp[n, k - 1] : 0))); } const int m = 1000000007; static long MInt(long x) => (x %= m) < 0 ? x + m : x; }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 8, 7, 8, 1, 0, 11, 12, 213, 63, 22], ["-", 8, 7, 8, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 7, 8, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 235, 8, 201, 0, 124, 0, 251, 0, 154], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 208, 0, 235, 8, 201, 0, 124, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 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, 306, 0, 221], ["+", 8, 306, 0, 41, 15, 16, 31, 23, 0, 24], ["+", 0, 41, 15, 16, 31, 23, 0, 11, 31, 22], ["+", 15, 16, 31, 23, 0, 11, 0, 202, 0, 132], ["+", 0, 41, 15, 16, 31, 23, 0, 11, 12, 22], ["+", 8, 306, 0, 41, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 306, 0, 41, 15, 16, 17, 18], ["+", 0, 195, 8, 306, 0, 41, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 306, 0, 41, 0, 101], ["+", 0, 195, 8, 306, 0, 41, 64, 16, 31, 22], ["+", 0, 195, 8, 306, 0, 41, 64, 16, 17, 72], ["+", 0, 195, 8, 306, 0, 41, 64, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 306, 0, 41, 0, 102], ["+", 8, 201, 0, 195, 8, 306, 0, 41, 75, 22], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 0, 35]]
8
251
36
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.DP { public class SegmentTree<T> { private readonly T ex; private readonly int n; private readonly int offset; private readonly T[] node; private readonly Func<T, T, T> func; public T this[int index] => node[offset + index]; public SegmentTree(int m, Func<T, T, T> func, T ex) { this.func = func; this.ex = ex; n = 1; while (n < m) n *= 2; offset = n - 1; node = new T[n * 2 - 1]; for (int i = 0; i < node.Length; i++) node[i] = ex; } public SegmentTree(int n, Func<T, T, T> operation, T init, T ex) : this(n, operation, ex) { for (int i = offset; i < offset + n; i++) node[i] = init; } public SegmentTree(T[] values, Func<T, T, T> operation, T ex) : this(values.Length, operation, ex) { Array.Copy(values, 0, node, offset, values.Length); UpdateTree(); } public void Assign(int i, T value) => node[offset + i] = value; public void AssignAndUpdate(int i, T value) { i += offset; node[i] = value; while (i > 0) { i = (i - 1) / 2; node[i] = func(node[2 * i + 1], node[2 * i + 2]); } } public void UpdateTree() { for (int i = offset - 1; i >= 0; i--) node[i] = func(node[2 * i + 1], node[2 * i + 2]); } public T Query(int head, int foot) => Query(head, foot, 0, 0, n); private T Query(int head, int foot, int k, int left, int right) { T leftValue = ex; T rightValue = ex; int d = offset; while (head < foot) { if ((head & 1) == 1) leftValue = func(leftValue, node[d + head++]); if ((foot & 1) == 0) rightValue = func(node[d + foot--], rightValue); head >>= 1; foot >>= 1; d >>= 1; } return func(func(leftValue, node[d + head]), rightValue); } } class EDPC_Q { public static void Main() { var n = int.Parse(Console.ReadLine()); var h = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); // i本目までの最大高さがjである場合についてdpを行う var dp = new long[n + 1]; var segmentTree = new SegmentTree<long>(n, (long x, long y) => Math.Max(x, y), 0, 0); for (int i = 0; i < n; i++) { var max = segmentTree.Query(0, h[i] - 1); segmentTree.AssignAndUpdate(h[i] - 1, max + a[i]); } Console.WriteLine(segmentTree.Query(0, n)); } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.DP { public class SegmentTree<T> { private readonly T ex; private readonly int n; private readonly int offset; private readonly T[] node; private readonly Func<T, T, T> func; public T this[int index] => node[offset + index]; public SegmentTree(int m, Func<T, T, T> func, T ex) { this.func = func; this.ex = ex; n = 1; while (n < m) n *= 2; offset = n - 1; node = new T[n * 2 - 1]; for (int i = 0; i < node.Length; i++) node[i] = ex; } public SegmentTree(int n, Func<T, T, T> operation, T init, T ex) : this(n, operation, ex) { for (int i = offset; i < offset + n; i++) node[i] = init; } public SegmentTree(T[] values, Func<T, T, T> operation, T ex) : this(values.Length, operation, ex) { Array.Copy(values, 0, node, offset, values.Length); UpdateTree(); } public void Assign(int i, T value) => node[offset + i] = value; public void AssignAndUpdate(int i, T value) { i += offset; node[i] = value; while (i > 0) { i = (i - 1) / 2; node[i] = func(node[2 * i + 1], node[2 * i + 2]); } } public void UpdateTree() { for (int i = offset - 1; i >= 0; i--) node[i] = func(node[2 * i + 1], node[2 * i + 2]); } public T Query(int head, int foot) { T leftValue = ex; T rightValue = ex; int d = offset; while (head < foot) { if ((head & 1) == 1) leftValue = func(leftValue, node[d + head++]); if ((foot & 1) == 0) rightValue = func(node[d + foot--], rightValue); head >>= 1; foot >>= 1; d >>= 1; } return func(func(leftValue, node[d + head]), rightValue); } } class EDPC_Q { public static void Main() { var n = int.Parse(Console.ReadLine()); var h = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); var dp = new long[n + 1]; var segmentTree = new SegmentTree<long>(n, (long x, long y) => Math.Max(x, y), 0, 0); for (int i = 0; i < n; i++) { var max = segmentTree.Query(0, h[i] - 1); segmentTree.AssignAndUpdate(h[i] - 1, max + a[i]); } Console.WriteLine(segmentTree.Query(0, n - 1)); } } }
[["-", 0, 235, 8, 201, 0, 195, 8, 306, 0, 221], ["-", 8, 201, 0, 195, 8, 306, 0, 213, 63, 22], ["-", 0, 195, 8, 306, 0, 213, 3, 4, 0, 24], ["-", 8, 306, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 195, 8, 306, 0, 213, 3, 4, 0, 21], ["-", 8, 306, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 195, 8, 306, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 0, 35], ["-", 0, 235, 8, 201, 0, 195, 0, 251, 0, 261], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 22], ["-", 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, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
762
35
using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Text; namespace AtCoder { public class Program { static void Main() { var cin = new Scanner(); string k = cin.Next(); int d = cin.Int(); int n = k.Length; var dpKa = new ModInt[n, d]; var dpMi = new ModInt[n, d]; int first = k[0] - '0'; for (int m = 0; m < 10; m++) { if (m < first) { dpKa[0, m % d] += 1; } else if (m == first) { dpMi[0, m % d] += 1; } } dpKa[0, 0] = 1; for (int i = 0; i < n - 1; i++) { int num = k[i + 1] - '0'; for (int j = 0; j < d; j++) { for (int m = 0; m < 10; m++) { int t = (j + m) % d; if (m < num) { dpKa[i + 1, t] += dpKa[i, j] + dpMi[i, j]; } else if (m == num) { dpMi[i + 1, t] += dpMi[i, j]; dpKa[i + 1, t] += dpKa[i, j]; } else { dpKa[i + 1, t] += dpKa[i, j]; } } } } ModInt ans = dpKa[n - 1, 0] + dpMi[n - 1, 0] - 1; Console.WriteLine(ans.Value); } } public struct ModInt { public static long P { get; set; } = (long)1e9 + 7; public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); } public static ModInt Pow(long value, long k) { long ret = 1; for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) { if ((k & 1) == 1) { ret = ret * value % P; } } return new ModInt(ret); } public static ModInt Inverse(ModInt value) { return Pow(value, P - 2); } public long Value; public ModInt(long value) { value %= P; if (value < 0) { value += P; } Value = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.Value += rhs.Value; if (lhs.Value >= P) { lhs.Value -= P; } return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.Value -= rhs.Value; if (lhs.Value < 0) { lhs.Value += P; } return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { return new ModInt(lhs.Value * rhs.Value % P); } public static ModInt operator /(ModInt lhs, ModInt rhs) { long exp = P - 2; while (exp > 0) { if (exp % 2 > 0) { lhs *= rhs; } rhs *= rhs; exp /= 2; } return lhs; } public static implicit operator ModInt(long n) { n %= P; if (n < 0) { n += P; } return new ModInt(n); } public override string ToString() { return Value.ToString(); } } public class HashMap<TKey, TValue> : Dictionary<TKey, TValue> { private readonly Func<TKey, TValue> initialzier_; public HashMap(Func<TKey, TValue> initialzier) : base() { initialzier_ = initialzier; } public HashMap(Func<TKey, TValue> initialzier, int capacity) : base(capacity) { initialzier_ = initialzier; } new public TValue this[TKey key] { get { if (ContainsKey(key) == false) { base[key] = initialzier_(key); } return base[key]; } set { base[key] = value; } } } public static class Helper { public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) > 0 ? value : target; public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) > 0) { target = value; onUpdated(value); } } public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) < 0 ? value : target; public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) < 0) { target = value; onUpdated(value); } } public static T[] Array<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToArray(); public static List<T> List<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToList(); public static T[,] Array2<T>(int n, int m, T init) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = init; } } return array; } public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = initializer(i, j); } } return array; } public static T[,,] Array3<T>(int n1, int n2, int n3, T init) { var array = new T[n1, n2, n3]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { array[i1, i2, i3] = init; } } } return array; } private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action) { for (int dn = 0; dn < 4; dn++) { int d4i = i + delta4_[dn]; int d4j = j + delta4_[dn + 1]; if ((uint)d4i < (uint)imax && (uint)d4j < (uint)jmax) { action(d4i, d4j); } } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string NextLine() => reader_(); public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.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[] 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[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Text; namespace AtCoder { public class Program { static void Main() { var cin = new Scanner(); string k = cin.Next(); int d = cin.Int(); int n = k.Length; var dpKa = new ModInt[n, d]; var dpMi = new ModInt[n, d]; int first = k[0] - '0'; for (int m = 0; m < 10; m++) { if (m < first) { dpKa[0, m % d] += 1; } else if (m == first) { dpMi[0, m % d] += 1; } } for (int i = 0; i < n - 1; i++) { int num = k[i + 1] - '0'; for (int j = 0; j < d; j++) { for (int m = 0; m < 10; m++) { int t = (j + m) % d; if (m < num) { dpKa[i + 1, t] += dpKa[i, j] + dpMi[i, j]; } else if (m == num) { dpMi[i + 1, t] += dpMi[i, j]; dpKa[i + 1, t] += dpKa[i, j]; } else { dpKa[i + 1, t] += dpKa[i, j]; } } } } ModInt ans = dpKa[n - 1, 0] + dpMi[n - 1, 0] - 1; Console.WriteLine(ans.Value); } } public struct ModInt { public static long P { get; set; } = (long)1e9 + 7; public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); } public static ModInt Pow(long value, long k) { long ret = 1; for (k %= P - 1; k > 0; k >>= 1, value = value * value % P) { if ((k & 1) == 1) { ret = ret * value % P; } } return new ModInt(ret); } public static ModInt Inverse(ModInt value) { return Pow(value, P - 2); } public long Value; public ModInt(long value) { value %= P; if (value < 0) { value += P; } Value = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.Value += rhs.Value; if (lhs.Value >= P) { lhs.Value -= P; } return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.Value -= rhs.Value; if (lhs.Value < 0) { lhs.Value += P; } return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { return new ModInt(lhs.Value * rhs.Value % P); } public static ModInt operator /(ModInt lhs, ModInt rhs) { long exp = P - 2; while (exp > 0) { if (exp % 2 > 0) { lhs *= rhs; } rhs *= rhs; exp /= 2; } return lhs; } public static implicit operator ModInt(long n) { n %= P; if (n < 0) { n += P; } return new ModInt(n); } public override string ToString() { return Value.ToString(); } } public class HashMap<TKey, TValue> : Dictionary<TKey, TValue> { private readonly Func<TKey, TValue> initialzier_; public HashMap(Func<TKey, TValue> initialzier) : base() { initialzier_ = initialzier; } public HashMap(Func<TKey, TValue> initialzier, int capacity) : base(capacity) { initialzier_ = initialzier; } new public TValue this[TKey key] { get { if (ContainsKey(key) == false) { base[key] = initialzier_(key); } return base[key]; } set { base[key] = value; } } } public static class Helper { public static void UpdateMin<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) > 0 ? value : target; public static void UpdateMin<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) > 0) { target = value; onUpdated(value); } } public static void UpdateMax<T>(ref T target, T value) where T : IComparable<T> => target = target.CompareTo(value) < 0 ? value : target; public static void UpdateMax<T>(ref T target, T value, Action<T> onUpdated) where T : IComparable<T> { if (target.CompareTo(value) < 0) { target = value; onUpdated(value); } } public static T[] Array<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToArray(); public static List<T> List<T>(int n, Func<int, T> init) => Enumerable.Range(0, n).Select(x => init(x)).ToList(); public static T[,] Array2<T>(int n, int m, T init) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = init; } } return array; } public static T[,] Array2<T>(int n, int m, Func<int, int, T> initializer) { var array = new T[n, m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { array[i, j] = initializer(i, j); } } return array; } public static T[,,] Array3<T>(int n1, int n2, int n3, T init) { var array = new T[n1, n2, n3]; for (int i1 = 0; i1 < n1; i1++) { for (int i2 = 0; i2 < n2; i2++) { for (int i3 = 0; i3 < n3; i3++) { array[i1, i2, i3] = init; } } } return array; } private static readonly int[] delta4_ = { 1, 0, -1, 0, 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void DoAt4(int i, int j, int imax, int jmax, Action<int, int> action) { for (int dn = 0; dn < 4; dn++) { int d4i = i + delta4_[dn]; int d4j = j + delta4_[dn + 1]; if ((uint)d4i < (uint)imax && (uint)d4j < (uint)jmax) { action(d4i, d4j); } } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private readonly Func<string> reader_; private string[] buf_; private int index_; public Scanner(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string NextLine() => reader_(); public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.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[] 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[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 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
2,038
9
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { int n = int.Parse(Console.ReadLine()); long mod = 1000000007; string s = Console.ReadLine(); long[,] dp = new long[n + 1, n]; long[,] sums = new long[n + 1, n + 1]; for (int i = 0; i < n; i++) { dp[1, i] = 1; sums[1, i + 1] = i + 1; } for (int i = 2; i <= n; i++) { for (int j = 0; j < n + 1 - i; j++) //左から0-indexで何番目を取るのか { if (s[i - 2] == '>') { dp[i, j] = sums[i - 1, n] - sums[i - 1, j + 1]; } else { dp[i, j] = sums[i - 1, j + 1]; } dp[i, j] %= mod; sums[i, j + 1] = sums[i, j] + dp[i, j]; sums[i, j + 1] %= mod; // Console.WriteLine(i+" "+j+" "+dp[i,j]); } for (int j = n + 1 - i; j < n; j++) { sums[i, j + 1] = sums[i, j]; } } Console.WriteLine(dp[n, 0]); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { int n = int.Parse(Console.ReadLine()); long mod = 1000000007; string s = Console.ReadLine(); long[,] dp = new long[n + 1, n]; long[,] sums = new long[n + 1, n + 1]; for (int i = 0; i < n; i++) { dp[1, i] = 1; sums[1, i + 1] = i + 1; } for (int i = 2; i <= n; i++) { for (int j = 0; j < n + 1 - i; j++) //左から0-indexで何番目を取るのか { if (s[i - 2] == '>') { dp[i, j] = sums[i - 1, n] - sums[i - 1, j + 1]; } else { dp[i, j] = sums[i - 1, j + 1]; } dp[i, j] += mod; dp[i, j] %= mod; sums[i, j + 1] = sums[i, j] + dp[i, j]; sums[i, j + 1] %= mod; // Console.WriteLine(i+" "+j+" "+dp[i,j]); } for (int j = n + 1 - i; j < n; j++) { sums[i, j + 1] = sums[i, j]; } } Console.WriteLine(dp[n, 0]); } }
[["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73]]
8
325
9
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; using vt = System.ValueTuple<int, int>; static class Program { const int mod = (int)1e9 + 7; static List<vt>[] li; static bool[] b; static int[] pa; static long[] dp; static long[][] dpl, dpr; static int p; const int ie = 1; static void Main() { Sc sc = new Sc(); var s = sc.Ia; int n = s[0], m = n - 1; p = s[1]; li = new List<vt>[n + 1]; b = new bool[n + 1]; dp = new long[n + 1]; dpl = new long [n + 1][]; dpr = new long [n + 1][]; pa = new int[n + 1]; for (int i = 1; i <= n; i++) { li[i] = new List<vt>(); li[i].Add((-1, -1)); } for (int i = 0; i < m; i++) { var e = sc.Ia; li[e[0]].Add((e[1], 1)); li[e[1]].Add((e[0], 1)); } int o = 1; Fu1(o, 0); Fu2(o, li[o][1].Item2); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= n; i++) { sb.Append(dp[i] + "\n"); } Console.Write(sb); } static void Fu2(int a, long g) { dp[a] = Fop(dp[a], g); for (int i = 1; i < li[a].Count; i++) { if (li[a][i].Item1 != pa[a]) { Fu2(li[a][i].Item1, Fop(Fop(dpl[a][i - 1], dpr[a][i + 1]), g) + li[a][i].Item2); } } } static void Fu1(int a, int o) { b[a] = true; pa[a] = o; dpl[a] = new long[li[a].Count]; dpr[a] = new long[li[a].Count + 1]; dpl[a][0] = dpr[a][li[a].Count] = ie; for (int i = 1; i < li[a].Count; i++) { if (!b[li[a][i].Item1]) { Fu1(li[a][i].Item1, a); dpl[a][i] = dpr[a][i] = dp[li[a][i].Item1] + li[a][i].Item2; } else { dpl[a][i] = dpr[a][i] = ie; } dpl[a][i] = Fop(dpl[a][i], dpl[a][i - 1]); } for (int i = li[a].Count - 1; i >= 0; i--) { dpr[a][i] = Fop(dpr[a][i], dpr[a][i + 1]); } dp[a] = dpl[a][li[a].Count - 1]; } static long Fop(long a, long b) { return a * b % p; } } 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(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.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; using vt = System.ValueTuple<int, int>; static class Program { const int mod = (int)1e9 + 7; static List<vt>[] li; static bool[] b; static int[] pa; static long[] dp; static long[][] dpl, dpr; static int p; const int ie = 1; static void Main() { Sc sc = new Sc(); var s = sc.Ia; int n = s[0], m = n - 1; p = s[1]; li = new List<vt>[n + 1]; b = new bool[n + 1]; dp = new long[n + 1]; dpl = new long [n + 1][]; dpr = new long [n + 1][]; pa = new int[n + 1]; for (int i = 1; i <= n; i++) { li[i] = new List<vt>(); li[i].Add((-1, -1)); } for (int i = 0; i < m; i++) { var e = sc.Ia; li[e[0]].Add((e[1], 1)); li[e[1]].Add((e[0], 1)); } int o = 1; Fu1(o, 0); Fu2(o, 1); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= n; i++) { sb.Append(dp[i] + "\n"); } Console.Write(sb); } static void Fu2(int a, long g) { dp[a] = Fop(dp[a], g); for (int i = 1; i < li[a].Count; i++) { if (li[a][i].Item1 != pa[a]) { Fu2(li[a][i].Item1, Fop(Fop(dpl[a][i - 1], dpr[a][i + 1]), g) + li[a][i].Item2); } } } static void Fu1(int a, int o) { b[a] = true; pa[a] = o; dpl[a] = new long[li[a].Count]; dpr[a] = new long[li[a].Count + 1]; dpl[a][0] = dpr[a][li[a].Count] = ie; for (int i = 1; i < li[a].Count; i++) { if (!b[li[a][i].Item1]) { Fu1(li[a][i].Item1, a); dpl[a][i] = dpr[a][i] = dp[li[a][i].Item1] + li[a][i].Item2; } else { dpl[a][i] = dpr[a][i] = ie; } dpl[a][i] = Fop(dpl[a][i], dpl[a][i - 1]); } for (int i = li[a].Count - 1; i >= 0; i--) { dpr[a][i] = Fop(dpr[a][i], dpr[a][i + 1]); } dp[a] = dpl[a][li[a].Count - 1]; } static long Fop(long a, long b) { return a * b % p; } } 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(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.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; } }
[["-", 0, 28, 0, 214, 205, 204, 205, 204, 205, 22], ["-", 0, 214, 205, 204, 205, 204, 206, 207, 0, 70], ["-", 205, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 214, 205, 204, 205, 204, 206, 207, 0, 73], ["-", 0, 28, 0, 214, 205, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 214, 205, 204, 206, 207, 0, 73], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
8
1,566
8
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; using System.Numerics; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Math; using Debug = System.Diagnostics.Debug; using LayoutKind = System.Runtime.InteropServices.LayoutKind; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { public static int Mod; static void Main() { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; Mod = nm[1]; List<int>[] neighbours = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray(); int[][] edges = Enumerable.Repeat(0, n - 1) .Select(_ => Console.ReadLine() .Split() .Select(x => int.Parse(x) - 1) .ToArray()) .ToArray(); ReRooting treeDP = new ReRooting(n, edges); Console.WriteLine( string.Join("\n", Enumerable.Range(0, n).Select(x => treeDP.Query(x)))); } } class ReRooting { public int NodeCount { get; private set; } int[][] Neighbours; int[][] IndexForNeighbours; long[] Res; long[][] dp; public ReRooting(int nodeCount, int[][] edges) { NodeCount = nodeCount; List<int>[] neighbours = new List<int>[nodeCount]; List<int>[] indexForNeighbours = new List<int>[nodeCount]; for (int i = 0; i < nodeCount; i++) { neighbours[i] = new List<int>(); indexForNeighbours[i] = new List<int>(); } for (int i = 0; i < edges.Length; i++) { var edge = edges[i]; indexForNeighbours[edge[0]].Add(neighbours[edge[1]].Count); indexForNeighbours[edge[1]].Add(neighbours[edge[0]].Count); neighbours[edge[0]].Add(edge[1]); neighbours[edge[1]].Add(edge[0]); } Neighbours = new int [nodeCount][]; IndexForNeighbours = new int [nodeCount][]; for (int i = 0; i < nodeCount; i++) { Neighbours[i] = neighbours[i].ToArray(); IndexForNeighbours[i] = indexForNeighbours[i].ToArray(); } dp = new long [Neighbours.Length][]; Res = new long[Neighbours.Length]; for (int i = 0; i < Neighbours.Length; i++) dp[i] = new long[Neighbours[i].Length]; Initialize(); } public long Query(int x) => Res[x]; private void Initialize() { int[] parents = new int[NodeCount]; int[] order = new int[NodeCount]; #region InitOrderedTree var index = 0; Stack<int> stack = new Stack<int>(); stack.Push(0); parents[0] = -1; while (stack.Count > 0) { var node = stack.Pop(); order[index++] = node; for (int i = 0; i < Neighbours[node].Length; i++) { var neighbour = Neighbours[node][i]; if (neighbour == parents[node]) continue; stack.Push(neighbour); parents[neighbour] = node; } } #endregion #region fromLeaf // DFSの逆順に辿ると、親に対して値を返すために必要な情報は既に集まっている。 for (int i = order.Length - 1; i >= 1; i--) { var node = order[i]; var parent = parents[node]; long accum = 1; int neighbourIndex = -1; for (int j = 0; j < Neighbours[node].Length; j++) { if (Neighbours[node][j] == parent) { neighbourIndex = j; continue; } //部分木の結果を累積 accum = (accum * dp[node][j]) % P.Mod; } //自ノードの値を作用させ、dpに保持させる dp[parent][IndexForNeighbours[node][neighbourIndex]] = accum + 1; } #endregion #region toLeaf //既にノードの値を出すために必要な情報は集まっているので、出す for (int i = 0; i < order.Length; i++) { var node = order[i]; long accum = 1; //尻からの累積 long[] accumsFromTail = new long[Neighbours[node].Length]; accumsFromTail[accumsFromTail.Length - 1] = 1; for (int j = accumsFromTail.Length - 1; j >= 1; j--) accumsFromTail[j - 1] = (accumsFromTail[j] * dp[node][j]) % P.Mod; //頭から累積をしながら配る for (int j = 0; j < accumsFromTail.Length; j++) { dp[Neighbours[node][j]][IndexForNeighbours[node][j]] = (accum * accumsFromTail[j]) % P.Mod + 1; accum = (accum * dp[node][j]) % P.Mod; } //累積し終えたものにノードの値を作用させたものが結果(今回はなし) Res[node] = accum; } #endregion } }
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; using System.Numerics; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Math; using Debug = System.Diagnostics.Debug; using LayoutKind = System.Runtime.InteropServices.LayoutKind; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { public static int Mod; static void Main() { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; Mod = nm[1]; List<int>[] neighbours = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray(); int[][] edges = Enumerable.Repeat(0, n - 1) .Select(_ => Console.ReadLine() .Split() .Select(x => int.Parse(x) - 1) .ToArray()) .ToArray(); ReRooting treeDP = new ReRooting(n, edges); Console.WriteLine( string.Join("\n", Enumerable.Range(0, n).Select(x => treeDP.Query(x)))); } } class ReRooting { public int NodeCount { get; private set; } int[][] Neighbours; int[][] IndexForNeighbours; long[] Res; long[][] dp; public ReRooting(int nodeCount, int[][] edges) { NodeCount = nodeCount; List<int>[] neighbours = new List<int>[nodeCount]; List<int>[] indexForNeighbours = new List<int>[nodeCount]; for (int i = 0; i < nodeCount; i++) { neighbours[i] = new List<int>(); indexForNeighbours[i] = new List<int>(); } for (int i = 0; i < edges.Length; i++) { var edge = edges[i]; indexForNeighbours[edge[0]].Add(neighbours[edge[1]].Count); indexForNeighbours[edge[1]].Add(neighbours[edge[0]].Count); neighbours[edge[0]].Add(edge[1]); neighbours[edge[1]].Add(edge[0]); } Neighbours = new int [nodeCount][]; IndexForNeighbours = new int [nodeCount][]; for (int i = 0; i < nodeCount; i++) { Neighbours[i] = neighbours[i].ToArray(); IndexForNeighbours[i] = indexForNeighbours[i].ToArray(); } dp = new long [Neighbours.Length][]; Res = new long[Neighbours.Length]; for (int i = 0; i < Neighbours.Length; i++) dp[i] = new long[Neighbours[i].Length]; if (NodeCount > 1) Initialize(); else Res[0] = 1; } public long Query(int x) => Res[x]; private void Initialize() { int[] parents = new int[NodeCount]; int[] order = new int[NodeCount]; #region InitOrderedTree var index = 0; Stack<int> stack = new Stack<int>(); stack.Push(0); parents[0] = -1; while (stack.Count > 0) { var node = stack.Pop(); order[index++] = node; for (int i = 0; i < Neighbours[node].Length; i++) { var neighbour = Neighbours[node][i]; if (neighbour == parents[node]) continue; stack.Push(neighbour); parents[neighbour] = node; } } #endregion #region fromLeaf // DFSの逆順に辿ると、親に対して値を返すために必要な情報は既に集まっている。 for (int i = order.Length - 1; i >= 1; i--) { var node = order[i]; var parent = parents[node]; long accum = 1; int neighbourIndex = -1; for (int j = 0; j < Neighbours[node].Length; j++) { if (Neighbours[node][j] == parent) { neighbourIndex = j; continue; } //部分木の結果を累積 accum = (accum * dp[node][j]) % P.Mod; } //自ノードの値を作用させ、dpに保持させる dp[parent][IndexForNeighbours[node][neighbourIndex]] = accum + 1; } #endregion #region toLeaf //既にノードの値を出すために必要な情報は集まっているので、出す for (int i = 0; i < order.Length; i++) { var node = order[i]; long accum = 1; //尻からの累積 long[] accumsFromTail = new long[Neighbours[node].Length]; accumsFromTail[accumsFromTail.Length - 1] = 1; for (int j = accumsFromTail.Length - 1; j >= 1; j--) accumsFromTail[j - 1] = (accumsFromTail[j] * dp[node][j]) % P.Mod; //頭から累積をしながら配る for (int j = 0; j < accumsFromTail.Length; j++) { dp[Neighbours[node][j]][IndexForNeighbours[node][j]] = (accum * accumsFromTail[j]) % P.Mod + 1; accum = (accum * dp[node][j]) % P.Mod; } //累積し終えたものにノードの値を作用させたものが結果(今回はなし) Res[node] = accum; } #endregion } }
[["+", 8, 201, 0, 263, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 263, 8, 196, 0, 57, 0, 24], ["+", 0, 263, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 263, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 263, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 263, 8, 196, 0, 57, 0, 25], ["+", 0, 263, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 263, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 11, 31, 204, 205, 22], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 12, 203]]
8
1,131
14
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; using System.Numerics; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Math; using Debug = System.Diagnostics.Debug; using LayoutKind = System.Runtime.InteropServices.LayoutKind; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { public static int Mod; static void Main() { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; Mod = nm[1]; List<int>[] neighbours = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray(); int[][] edges = Enumerable.Repeat(0, n - 1) .Select(_ => Console.ReadLine() .Split() .Select(x => int.Parse(x) - 1) .ToArray()) .ToArray(); ReRooting treeDP = new ReRooting(n, edges); Console.WriteLine( string.Join("\n", Enumerable.Range(0, n).Select(x => treeDP.Query(x)))); } } class ReRooting { int[][] Neighbours; int[][] IndexForNeighbours; long[] res; long[][] dp; int[] SearchState; public ReRooting(int nodeCount, int[][] edges) { List<int>[] neighbours = new List<int>[nodeCount]; List<int>[] indexForNeighbours = new List<int>[nodeCount]; for (int i = 0; i < nodeCount; i++) { neighbours[i] = new List<int>(); indexForNeighbours[i] = new List<int>(); } for (int i = 0; i < edges.Length; i++) { var edge = edges[i]; indexForNeighbours[edge[0]].Add(neighbours[edge[1]].Count); indexForNeighbours[edge[1]].Add(neighbours[edge[0]].Count); neighbours[edge[0]].Add(edge[1]); neighbours[edge[1]].Add(edge[0]); } Neighbours = new int [nodeCount][]; IndexForNeighbours = new int [nodeCount][]; for (int i = 0; i < nodeCount; i++) { Neighbours[i] = neighbours[i].ToArray(); IndexForNeighbours[i] = indexForNeighbours[i].ToArray(); } dp = new long [Neighbours.Length][]; SearchState = new int[Neighbours.Length]; res = new long[Neighbours.Length]; for (int i = 0; i < Neighbours.Length; i++) { dp[i] = new long[Neighbours[i].Length]; SearchState[i] = -2; } } public long Query(int x) { if (SearchState[x] != -1) DFS(x, -1); return res[x]; } public long Query(int x, int toIndex) { if (SearchState[x] != -1 && SearchState[x] != toIndex) DFS(x, Neighbours[x][toIndex]); return dp[Neighbours[x][toIndex]][IndexForNeighbours[x][toIndex]]; } private void DFS(int x, int parent) { Debug.Assert( SearchState[x] != -1 && (SearchState[x] == -2 || Neighbours[x][SearchState[x]] != parent)); long accum = 1; if (SearchState[x] == -2) { SearchState[x] = -1; for (int i = 0; i < Neighbours[x].Length; i++) { if (Neighbours[x][i] == parent) { SearchState[x] = i; continue; } var state = SearchState[Neighbours[x][i]]; if (state != -1 && state != IndexForNeighbours[x][i]) DFS(Neighbours[x][i], x); accum = (accum * dp[x][i]) % P.Mod; } if (SearchState[x] != -1) { dp[parent][IndexForNeighbours[x][SearchState[x]]] = accum + 1; return; } accum = 1; } else { var targetInd = SearchState[x]; var target = Neighbours[x][targetInd]; var targetState = SearchState[target]; if (targetState != -1 && targetState != IndexForNeighbours[x][targetInd]) DFS(Neighbours[x][targetInd], x); } long[] accumsFromTail = new long[Neighbours[x].Length]; accumsFromTail[accumsFromTail.Length - 1] = 1; for (int i = accumsFromTail.Length - 2; i >= 0; i--) accumsFromTail[i] = (accumsFromTail[i + 1] * dp[x][i + 1]) % 1000000007; for (int i = 0; i < accumsFromTail.Length; i++) { dp[Neighbours[x][i]][IndexForNeighbours[x][i]] = (accum * accumsFromTail[i]) % P.Mod + 1; accum = (accum * dp[x][i]) % P.Mod; } res[x] = accum; SearchState[x] = -1; } }
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; using System.Numerics; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Math; using Debug = System.Diagnostics.Debug; using LayoutKind = System.Runtime.InteropServices.LayoutKind; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { public static int Mod; static void Main() { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; Mod = nm[1]; List<int>[] neighbours = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray(); int[][] edges = Enumerable.Repeat(0, n - 1) .Select(_ => Console.ReadLine() .Split() .Select(x => int.Parse(x) - 1) .ToArray()) .ToArray(); ReRooting treeDP = new ReRooting(n, edges); Console.WriteLine( string.Join("\n", Enumerable.Range(0, n).Select(x => treeDP.Query(x)))); } } class ReRooting { int[][] Neighbours; int[][] IndexForNeighbours; long[] res; long[][] dp; int[] SearchState; public ReRooting(int nodeCount, int[][] edges) { List<int>[] neighbours = new List<int>[nodeCount]; List<int>[] indexForNeighbours = new List<int>[nodeCount]; for (int i = 0; i < nodeCount; i++) { neighbours[i] = new List<int>(); indexForNeighbours[i] = new List<int>(); } for (int i = 0; i < edges.Length; i++) { var edge = edges[i]; indexForNeighbours[edge[0]].Add(neighbours[edge[1]].Count); indexForNeighbours[edge[1]].Add(neighbours[edge[0]].Count); neighbours[edge[0]].Add(edge[1]); neighbours[edge[1]].Add(edge[0]); } Neighbours = new int [nodeCount][]; IndexForNeighbours = new int [nodeCount][]; for (int i = 0; i < nodeCount; i++) { Neighbours[i] = neighbours[i].ToArray(); IndexForNeighbours[i] = indexForNeighbours[i].ToArray(); } dp = new long [Neighbours.Length][]; SearchState = new int[Neighbours.Length]; res = new long[Neighbours.Length]; for (int i = 0; i < Neighbours.Length; i++) { dp[i] = new long[Neighbours[i].Length]; SearchState[i] = -2; } if (nodeCount <= 1) { res[0] = 1; SearchState[0] = -1; } } public long Query(int x) { if (SearchState[x] != -1) DFS(x, -1); return res[x]; } public long Query(int x, int toIndex) { if (SearchState[x] != -1 && SearchState[x] != toIndex) DFS(x, Neighbours[x][toIndex]); return dp[Neighbours[x][toIndex]][IndexForNeighbours[x][toIndex]]; } private void DFS(int x, int parent) { Debug.Assert( SearchState[x] != -1 && (SearchState[x] == -2 || Neighbours[x][SearchState[x]] != parent)); long accum = 1; if (SearchState[x] == -2) { SearchState[x] = -1; for (int i = 0; i < Neighbours[x].Length; i++) { if (Neighbours[x][i] == parent) { SearchState[x] = i; continue; } var state = SearchState[Neighbours[x][i]]; if (state != -1 && state != IndexForNeighbours[x][i]) DFS(Neighbours[x][i], x); accum = (accum * dp[x][i]) % P.Mod; } if (SearchState[x] != -1) { dp[parent][IndexForNeighbours[x][SearchState[x]]] = accum + 1; return; } accum = 1; } else { var targetInd = SearchState[x]; var target = Neighbours[x][targetInd]; var targetState = SearchState[target]; if (targetState != -1 && targetState != IndexForNeighbours[x][targetInd]) DFS(Neighbours[x][targetInd], x); } long[] accumsFromTail = new long[Neighbours[x].Length]; accumsFromTail[accumsFromTail.Length - 1] = 1; for (int i = accumsFromTail.Length - 2; i >= 0; i--) accumsFromTail[i] = (accumsFromTail[i + 1] * dp[x][i + 1]) % P.Mod; for (int i = 0; i < accumsFromTail.Length; i++) { dp[Neighbours[x][i]][IndexForNeighbours[x][i]] = (accum * accumsFromTail[i]) % P.Mod + 1; accum = (accum * dp[x][i]) % P.Mod; } res[x] = accum; SearchState[x] = -1; } }
[["+", 8, 201, 0, 263, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 263, 8, 196, 0, 57, 0, 24], ["+", 0, 263, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 263, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 263, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 263, 8, 196, 0, 57, 0, 25], ["+", 0, 263, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 235, 8, 201, 0, 263, 8, 196, 0, 46], ["-", 0, 7, 8, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 1, 0, 11, 12, 16, 12, 214, 205, 22], ["+", 8, 1, 0, 11, 12, 16, 12, 214, 0, 131], ["+", 8, 1, 0, 11, 12, 16, 12, 214, 141, 22]]
8
1,183
27
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var a = cin.ReadLong; var b = cin.ReadLong; var c = cin.ReadLong; var ans = Min(a + b, c) + b; WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public long poison(long x, long y) { var ans = Min(x, y); if (x < y) ans++; return ans; } public void Solve(ConsoleInput cin) { var a = cin.ReadLong; var b = cin.ReadLong; var c = cin.ReadLong; var ans = poison(a + b, c) + b; WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } } }
[["+", 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, 196, 0, 45], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 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], ["+", 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], ["+", 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, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["-", 0, 200, 0, 212, 0, 16, 31, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 213, 63, 22]]
8
503
36
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long h = sc.NextLong(); long w = sc.NextLong(); long answer = 0; for (long i = 0; i < n; i++) { long a = sc.NextLong(); long b = sc.NextLong(); if (a >= h && b >= w && (a == h || b == w)) { 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 n = sc.NextLong(); long h = sc.NextLong(); long w = sc.NextLong(); long answer = 0; for (long i = 0; i < n; i++) { long a = sc.NextLong(); long b = sc.NextLong(); if (a >= h && b >= w) { answer++; } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
8
432
10
using System; using System.Collections.Generic; using System.IO; using System.IO.Pipes; namespace Contest { class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; _separator = ' '; } private char _separator; private StreamReader _stream; private int _pos; private string[] _line; #region get a element public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(_separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region convert array private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region get row elements #region get array public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(_separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion #region get 2 ~4 elements public void GetRow(out string a, out string b) { a = Next(); b = Next(); } public void GetRow(out string a, out string b, out string c) { a = Next(); b = Next(); c = Next(); } public void GetRow(out string a, out string b, out string c, out string d) { a = Next(); b = Next(); c = Next(); d = Next(); } public void GetIntRow(out int a, out int b) { a = NextInt(); b = NextInt(); } public void GetIntRow(out int a, out int b, out int c) { a = NextInt(); b = NextInt(); c = NextInt(); } public void GetIntRow(out int a, out int b, out int c, out int d) { a = NextInt(); b = NextInt(); c = NextInt(); d = NextInt(); } public void GetLongRow(out long a, out long b) { a = NextLong(); b = NextLong(); } public void GetLongRow(out long a, out long b, out long c) { a = NextLong(); b = NextLong(); c = NextLong(); } public void GetLongRow(out long a, out long b, out long c, out long d) { a = NextLong(); b = NextLong(); c = NextLong(); d = NextLong(); } public void GetDoubleRow(out double a, out double b) { a = NextDouble(); b = NextDouble(); } public void GetDoubleRow(out double a, out double b, out double c) { a = NextDouble(); b = NextDouble(); c = NextDouble(); } public void GetDoubleRow(out double a, out double b, out double c, out double d) { a = NextDouble(); b = NextDouble(); c = NextDouble(); d = NextDouble(); } #endregion #endregion #region get 2 ~4 column elements public void GetColumn(int n, out string[] a) { a = new string[n]; for (int i = 0; i < n; i++) { a[i] = Next(); } } public void GetColumn(int n, out string[] a, out string[] b) { a = new string[n]; b = new string[n]; for (int i = 0; i < n; i++) { GetRow(out a[i], out b[i]); } } public void GetColumn(int n, out string[] a, out string[] b, out string[] c) { a = new string[n]; b = new string[n]; c = new string[n]; for (int i = 0; i < n; i++) { GetRow(out a[i], out b[i], out c[i]); } } public void GetColumn(int n, out string[] a, out string[] b, out string[] c, out string[] d) { a = new string[n]; b = new string[n]; c = new string[n]; d = new string[n]; for (int i = 0; i < n; i++) { GetRow(out a[i], out b[i], out c[i], out d[i]); } } public void GetIntColumn(int n, out int[] a) { string[] sa; GetColumn(n, out sa); a = ToIntArray(sa); } public void GetIntColumn(int n, out int[] a, out int[] b) { string[] sa, sb; GetColumn(n, out sa, out sb); a = ToIntArray(sa); b = ToIntArray(sb); } public void GetIntColumn(int n, out int[] a, out int[] b, out int[] c) { string[] sa, sb, sc; GetColumn(n, out sa, out sb, out sc); a = ToIntArray(sa); b = ToIntArray(sb); c = ToIntArray(sc); } public void GetIntColumn(int n, out int[] a, out int[] b, out int[] c, out int[] d) { string[] sa, sb, sc, sd; GetColumn(n, out sa, out sb, out sc, out sd); a = ToIntArray(sa); b = ToIntArray(sb); c = ToIntArray(sc); d = ToIntArray(sd); } public void GetLongColumn(int n, out long[] a) { string[] sa; GetColumn(n, out sa); a = ToLongArray(sa); } public void GetLongColumn(int n, out long[] a, out long[] b) { string[] sa, sb; GetColumn(n, out sa, out sb); a = ToLongArray(sa); b = ToLongArray(sb); } public void GetLongColumn(int n, out long[] a, out long[] b, out long[] c) { string[] sa, sb, sc; GetColumn(n, out sa, out sb, out sc); a = ToLongArray(sa); b = ToLongArray(sb); c = ToLongArray(sc); } public void GetLongColumn(int n, out long[] a, out long[] b, out long[] c, out long[] d) { string[] sa, sb, sc, sd; GetColumn(n, out sa, out sb, out sc, out sd); a = ToLongArray(sa); b = ToLongArray(sb); c = ToLongArray(sc); d = ToLongArray(sd); } public void GetDoubleColumn(int n, out double[] a) { string[] sa; GetColumn(n, out sa); a = ToDoubleArray(sa); } public void GetDoubleColumn(int n, out double[] a, out double[] b) { string[] sa, sb; GetColumn(n, out sa, out sb); a = ToDoubleArray(sa); b = ToDoubleArray(sb); } public void GetDoubleColumn(int n, out double[] a, out double[] b, out double[] c) { string[] sa, sb, sc; GetColumn(n, out sa, out sb, out sc); a = ToDoubleArray(sa); b = ToDoubleArray(sb); c = ToDoubleArray(sc); } public void GetDoubleColumn(int n, out double[] a, out double[] b, out double[] c, out double[] d) { string[] sa, sb, sc, sd; GetColumn(n, out sa, out sb, out sc, out sd); a = ToDoubleArray(sa); b = ToDoubleArray(sb); c = ToDoubleArray(sc); d = ToDoubleArray(sd); } #endregion #region get matrix public string[][] GetMatrix(int h) { string[][] result = new string[h][]; for (int i = 0; i < h; i++) { result[i] = Array(); } return result; } public int[][] GetIntMatrix(int h) { int[][] result = new int [h][]; for (int i = 0; i < h; i++) { result[i] = IntArray(); } return result; } public long[][] GetLongMatrix(int h) { long[][] result = new long [h][]; for (int i = 0; i < h; i++) { result[i] = LongArray(); } return result; } public double[][] GetDoubleMatrix(int h) { double[][] result = new double [h][]; for (int i = 0; i < h; i++) { result[i] = DoubleArray(); } return result; } public char[][] GetCharMatrix(int h) { char[][] result = new char [h][]; for (int i = 0; i < h; i++) { result[i] = Next().ToCharArray(); } return result; } #endregion } class Program { public void Solve() { var sc = new Scanner(); int N = sc.NextInt(); int H = sc.NextInt(); int W = sc.NextInt(); int cnt = 0; for (int i = 0; i < N; i++) { if (sc.NextInt() >= H && sc.NextInt() >= W) cnt++; } Console.WriteLine(cnt); } static void Main(string[] args) => new Program().Solve(); } }
using System; using System.Collections.Generic; using System.IO; using System.IO.Pipes; namespace Contest { class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; _separator = ' '; } private char _separator; private StreamReader _stream; private int _pos; private string[] _line; #region get a element public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(_separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region convert array private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region get row elements #region get array public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(_separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion #region get 2 ~4 elements public void GetRow(out string a, out string b) { a = Next(); b = Next(); } public void GetRow(out string a, out string b, out string c) { a = Next(); b = Next(); c = Next(); } public void GetRow(out string a, out string b, out string c, out string d) { a = Next(); b = Next(); c = Next(); d = Next(); } public void GetIntRow(out int a, out int b) { a = NextInt(); b = NextInt(); } public void GetIntRow(out int a, out int b, out int c) { a = NextInt(); b = NextInt(); c = NextInt(); } public void GetIntRow(out int a, out int b, out int c, out int d) { a = NextInt(); b = NextInt(); c = NextInt(); d = NextInt(); } public void GetLongRow(out long a, out long b) { a = NextLong(); b = NextLong(); } public void GetLongRow(out long a, out long b, out long c) { a = NextLong(); b = NextLong(); c = NextLong(); } public void GetLongRow(out long a, out long b, out long c, out long d) { a = NextLong(); b = NextLong(); c = NextLong(); d = NextLong(); } public void GetDoubleRow(out double a, out double b) { a = NextDouble(); b = NextDouble(); } public void GetDoubleRow(out double a, out double b, out double c) { a = NextDouble(); b = NextDouble(); c = NextDouble(); } public void GetDoubleRow(out double a, out double b, out double c, out double d) { a = NextDouble(); b = NextDouble(); c = NextDouble(); d = NextDouble(); } #endregion #endregion #region get 2 ~4 column elements public void GetColumn(int n, out string[] a) { a = new string[n]; for (int i = 0; i < n; i++) { a[i] = Next(); } } public void GetColumn(int n, out string[] a, out string[] b) { a = new string[n]; b = new string[n]; for (int i = 0; i < n; i++) { GetRow(out a[i], out b[i]); } } public void GetColumn(int n, out string[] a, out string[] b, out string[] c) { a = new string[n]; b = new string[n]; c = new string[n]; for (int i = 0; i < n; i++) { GetRow(out a[i], out b[i], out c[i]); } } public void GetColumn(int n, out string[] a, out string[] b, out string[] c, out string[] d) { a = new string[n]; b = new string[n]; c = new string[n]; d = new string[n]; for (int i = 0; i < n; i++) { GetRow(out a[i], out b[i], out c[i], out d[i]); } } public void GetIntColumn(int n, out int[] a) { string[] sa; GetColumn(n, out sa); a = ToIntArray(sa); } public void GetIntColumn(int n, out int[] a, out int[] b) { string[] sa, sb; GetColumn(n, out sa, out sb); a = ToIntArray(sa); b = ToIntArray(sb); } public void GetIntColumn(int n, out int[] a, out int[] b, out int[] c) { string[] sa, sb, sc; GetColumn(n, out sa, out sb, out sc); a = ToIntArray(sa); b = ToIntArray(sb); c = ToIntArray(sc); } public void GetIntColumn(int n, out int[] a, out int[] b, out int[] c, out int[] d) { string[] sa, sb, sc, sd; GetColumn(n, out sa, out sb, out sc, out sd); a = ToIntArray(sa); b = ToIntArray(sb); c = ToIntArray(sc); d = ToIntArray(sd); } public void GetLongColumn(int n, out long[] a) { string[] sa; GetColumn(n, out sa); a = ToLongArray(sa); } public void GetLongColumn(int n, out long[] a, out long[] b) { string[] sa, sb; GetColumn(n, out sa, out sb); a = ToLongArray(sa); b = ToLongArray(sb); } public void GetLongColumn(int n, out long[] a, out long[] b, out long[] c) { string[] sa, sb, sc; GetColumn(n, out sa, out sb, out sc); a = ToLongArray(sa); b = ToLongArray(sb); c = ToLongArray(sc); } public void GetLongColumn(int n, out long[] a, out long[] b, out long[] c, out long[] d) { string[] sa, sb, sc, sd; GetColumn(n, out sa, out sb, out sc, out sd); a = ToLongArray(sa); b = ToLongArray(sb); c = ToLongArray(sc); d = ToLongArray(sd); } public void GetDoubleColumn(int n, out double[] a) { string[] sa; GetColumn(n, out sa); a = ToDoubleArray(sa); } public void GetDoubleColumn(int n, out double[] a, out double[] b) { string[] sa, sb; GetColumn(n, out sa, out sb); a = ToDoubleArray(sa); b = ToDoubleArray(sb); } public void GetDoubleColumn(int n, out double[] a, out double[] b, out double[] c) { string[] sa, sb, sc; GetColumn(n, out sa, out sb, out sc); a = ToDoubleArray(sa); b = ToDoubleArray(sb); c = ToDoubleArray(sc); } public void GetDoubleColumn(int n, out double[] a, out double[] b, out double[] c, out double[] d) { string[] sa, sb, sc, sd; GetColumn(n, out sa, out sb, out sc, out sd); a = ToDoubleArray(sa); b = ToDoubleArray(sb); c = ToDoubleArray(sc); d = ToDoubleArray(sd); } #endregion #region get matrix public string[][] GetMatrix(int h) { string[][] result = new string[h][]; for (int i = 0; i < h; i++) { result[i] = Array(); } return result; } public int[][] GetIntMatrix(int h) { int[][] result = new int [h][]; for (int i = 0; i < h; i++) { result[i] = IntArray(); } return result; } public long[][] GetLongMatrix(int h) { long[][] result = new long [h][]; for (int i = 0; i < h; i++) { result[i] = LongArray(); } return result; } public double[][] GetDoubleMatrix(int h) { double[][] result = new double [h][]; for (int i = 0; i < h; i++) { result[i] = DoubleArray(); } return result; } public char[][] GetCharMatrix(int h) { char[][] result = new char [h][]; for (int i = 0; i < h; i++) { result[i] = Next().ToCharArray(); } return result; } #endregion } class Program { public void Solve() { var sc = new Scanner(); int N = sc.NextInt(); int H = sc.NextInt(); int W = sc.NextInt(); int cnt = 0; for (int i = 0; i < N; i++) { int a = sc.NextInt(); int b = sc.NextInt(); if (a >= H && b >= W) cnt++; } Console.WriteLine(cnt); } static void Main(string[] args) => new Program().Solve(); } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
2,367
20
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Product and GCD var line = ReadLine(); var N = line[0]; var P = line[1]; if (N == 1) { Console.WriteLine(P); } else { var lib = new Library.Factorization(); var factors = lib.SummarizeFactors(P); long ans = 1; foreach (var f in factors) { if (f.Value >= N) { ans *= f.Key; } } Console.WriteLine(ans); } } static List<long> ReadLine() { var line = Console.ReadLine(); var arr = line.Split(' '); return arr.Select(x => long.Parse(x)).ToList(); } } } namespace Library { class Factorization { private List<long> factors; public List<long> GetFactors(long n) { //[summary]ある数を素因数分解する //別の数を素因数分解することもあるので、最初にかならず初期化 factors = new List<long>(); if (n < 2) { // 2より小さい数を受け取った場合 factors.Add(n); } else { Factoring(n); } return factors; } private void Factoring(long n) { //[summary]平方根以下の素数で総当りで割って行く //以下リンクを参考に実装 // https://qiita.com/gushwell/items/561afde2e00bf3380c98 //"GetFactors"以外から呼び出されることもあるので、かならず初期化 factors = new List<long>(); //平方根を求める long sqrt = (long)Math.Sqrt(n); // 2,3,5で割る(割れなくなるまで割り続ける) n = DevideWith(n, 2); n = DevideWith(n, 3); n = DevideWith(n, 5); var primes = new List<int> { 7, 11, 13, 17, 19, 23, 29, 31 }; long i = 0; //平方根以下の素数(候補)で総当りで割る while (n > 1) { foreach (var p in primes) { if (p + i > sqrt) { // 1が素因数に追加されることを防止 if (n > 1) { factors.Add(n); } return; } else { n = DevideWith(n, p + i); } } i += 30; } } private long DevideWith(long n, long d) { while (n % d == 0) { factors.Add(d); n /= d; } return n; } public List<long> GetDivisors(long n) { //[summary]ある数の約数をすべて列挙 //素因数分解した結果(素数,指数...)を受け取る var primes = SummarizeFactors(n); var divisors = new List<long>(); divisors.Add(1); foreach (var p in primes) { var tmp = new List<long>(); for (int i = 0; i <= p.Value; i++) { long pow = (long)Math.Pow(p.Key, i); foreach (var d in divisors) { tmp.Add(d * pow); } } divisors = new List<long>(tmp); } return divisors; } public Dictionary<long, long> SummarizeFactors(long n) { //[summary]素因数分解した結果を、素数,指数...にまとめる Factoring(n); var primes = new Dictionary<long, long>(); foreach (var f in factors) { if (primes.ContainsKey(f)) { primes[f]++; } else { primes.Add(f, 1); } } return primes; } public long CountDivisors(long n) { //[summary]ある数の約数の個数を取得 //素因数分解した結果を受け取る var primes = SummarizeFactors(n); long count = 1; foreach (var v in primes.Values) { count *= (v + 1); } return count; } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Product and GCD var line = ReadLine(); var N = line[0]; var P = line[1]; if (N == 1) { Console.WriteLine(P); } else { var lib = new Library.Factorization(); var factors = lib.SummarizeFactors(P); long ans = 1; foreach (var f in factors) { if (f.Value >= N) { var count = f.Value; while (count >= N) { ans *= f.Key; count -= N; } } } Console.WriteLine(ans); } } static List<long> ReadLine() { var line = Console.ReadLine(); var arr = line.Split(' '); return arr.Select(x => long.Parse(x)).ToList(); } } } namespace Library { class Factorization { private List<long> factors; public List<long> GetFactors(long n) { //[summary]ある数を素因数分解する //別の数を素因数分解することもあるので、最初にかならず初期化 factors = new List<long>(); if (n < 2) { // 2より小さい数を受け取った場合 factors.Add(n); } else { Factoring(n); } return factors; } private void Factoring(long n) { //[summary]平方根以下の素数で総当りで割って行く //以下リンクを参考に実装 // https://qiita.com/gushwell/items/561afde2e00bf3380c98 //"GetFactors"以外から呼び出されることもあるので、かならず初期化 factors = new List<long>(); //平方根を求める long sqrt = (long)Math.Sqrt(n); // 2,3,5で割る(割れなくなるまで割り続ける) n = DevideWith(n, 2); n = DevideWith(n, 3); n = DevideWith(n, 5); var primes = new List<int> { 7, 11, 13, 17, 19, 23, 29, 31 }; long i = 0; //平方根以下の素数(候補)で総当りで割る while (n > 1) { foreach (var p in primes) { if (p + i > sqrt) { // 1が素因数に追加されることを防止 if (n > 1) { factors.Add(n); } return; } else { n = DevideWith(n, p + i); } } i += 30; } } private long DevideWith(long n, long d) { while (n % d == 0) { factors.Add(d); n /= d; } return n; } public List<long> GetDivisors(long n) { //[summary]ある数の約数をすべて列挙 //素因数分解した結果(素数,指数...)を受け取る var primes = SummarizeFactors(n); var divisors = new List<long>(); divisors.Add(1); foreach (var p in primes) { var tmp = new List<long>(); for (int i = 0; i <= p.Value; i++) { long pow = (long)Math.Pow(p.Key, i); foreach (var d in divisors) { tmp.Add(d * pow); } } divisors = new List<long>(tmp); } return divisors; } public Dictionary<long, long> SummarizeFactors(long n) { //[summary]素因数分解した結果を、素数,指数...にまとめる Factoring(n); var primes = new Dictionary<long, long>(); foreach (var f in factors) { if (primes.ContainsKey(f)) { primes[f]++; } else { primes.Add(f, 1); } } return primes; } public long CountDivisors(long n) { //[summary]ある数の約数の個数を取得 //素因数分解した結果を受け取る var primes = SummarizeFactors(n); long count = 1; foreach (var v in primes.Values) { count *= (v + 1); } return count; } } }
[["+", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 57, 64, 196, 0, 52, 0, 24], ["+", 0, 57, 64, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 52, 15, 16, 17, 20], ["+", 0, 57, 64, 196, 0, 52, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 52, 0, 25], ["+", 0, 57, 64, 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, 110], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 46]]
8
692
19
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { long[] NP = LSRead(); long N = NP[0], P = NP[1]; if (P == 1) { Console.WriteLine(1); return; } if (N == 1) { Console.WriteLine(P); return; } var primeFactor = new PrimeFactor(); var factors = primeFactor.Enumerate(P); Dictionary<long, long> dic = new Dictionary<long, long>(); foreach (var l in factors) { if (!dic.ContainsKey(l)) dic[l] = 1; else dic[l]++; } var sorted = dic.OrderByDescending(v => v.Key); long ans = 1; foreach (var v in sorted) { if (v.Value >= N) { ans *= (v.Key * v.Value / N); } } Console.WriteLine(ans); } } public class PrimeFactor { public IEnumerable<long> Enumerate(long n) { while (n > 1) { long factor = GetFactor(n); yield return factor; n = n / factor; } } private long GetFactor(long n, int seed = 1) { if (n % 2 == 0) return 2; if (IsPrime(n)) return n; long x = 2; long y = 2; long d = 1; long count = 0; while (d == 1) { count++; x = f(x, n, seed); y = f(f(y, n, seed), n, seed); d = Gcd(Math.Abs(x - y), n); } if (d == n) // 見つからなかった、乱数発生のシードを変えて再挑戦。 return GetFactor(n, seed + 1); // 素数でない可能性もあるので、再度呼び出す return GetFactor(d); } private int[] seeds = new int[] { 3, 5, 7, 11, 13, 17 }; private long f(long x, long n, int seed) { return (seeds[seed % 6] * x + seed) % n; } private static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); // 引数を入替えて自分を呼び出す if (b == 0) return a; long d = 0; do { d = a % b; a = b; b = d; } while (d != 0); return a; } // 効率は良くないが、これでも十分な速度がでたので、良しとする。 private static bool IsPrime(long number) { long boundary = (long)Math.Floor(Math.Sqrt(number)); if (number == 1) return false; if (number == 2) return true; for (long i = 2; i <= boundary; ++i) { if (number % i == 0) return false; } return true; } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string StrReverce(string s) { return new string(s.Reverse().ToArray()); } public static int intRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } public static long[] LSRead() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { long[] NP = LSRead(); long N = NP[0], P = NP[1]; if (P == 1) { Console.WriteLine(1); return; } if (N == 1) { Console.WriteLine(P); return; } var primeFactor = new PrimeFactor(); var factors = primeFactor.Enumerate(P); Dictionary<long, long> dic = new Dictionary<long, long>(); foreach (var l in factors) { if (!dic.ContainsKey(l)) dic[l] = 1; else dic[l]++; } var sorted = dic.OrderByDescending(v => v.Key); long ans = 1; foreach (var v in sorted) { if (v.Value >= N) { ans *= (long)Math.Pow(v.Key, v.Value / N); } } Console.WriteLine(ans); } } public class PrimeFactor { public IEnumerable<long> Enumerate(long n) { while (n > 1) { long factor = GetFactor(n); yield return factor; n = n / factor; } } private long GetFactor(long n, int seed = 1) { if (n % 2 == 0) return 2; if (IsPrime(n)) return n; long x = 2; long y = 2; long d = 1; long count = 0; while (d == 1) { count++; x = f(x, n, seed); y = f(f(y, n, seed), n, seed); d = Gcd(Math.Abs(x - y), n); } if (d == n) // 見つからなかった、乱数発生のシードを変えて再挑戦。 return GetFactor(n, seed + 1); // 素数でない可能性もあるので、再度呼び出す return GetFactor(d); } private int[] seeds = new int[] { 3, 5, 7, 11, 13, 17 }; private long f(long x, long n, int seed) { return (seeds[seed % 6] * x + seed) % n; } private static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); // 引数を入替えて自分を呼び出す if (b == 0) return a; long d = 0; do { d = a % b; a = b; b = d; } while (d != 0); return a; } // 効率は良くないが、これでも十分な速度がでたので、良しとする。 private static bool IsPrime(long number) { long boundary = (long)Math.Floor(Math.Sqrt(number)); if (number == 1) return false; if (number == 2) return true; for (long i = 2; i <= boundary; ++i) { if (number % i == 0) return false; } return true; } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string StrReverce(string s) { return new string(s.Reverse().ToArray()); } public static int intRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } public static long[] LSRead() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } }
[["+", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 64, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 0, 11, 12, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 74, 51, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 11, 12, 74, 51, 213, 3, 4, 0, 21]]
8
888
8
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var n = input[0]; var p = input[1]; if (n == 1) Console.WriteLine(p); return; long ans = 1; for (var i = 2; i <= (long)Math.Sqrt(p); i++) { if (p % (long)Math.Pow(i, n) == 0) { ans = i; } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; namespace CADDi2018_C { class P { static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var n = input[0]; var p = input[1]; var ans = 1L; if (n == 1) { Console.WriteLine(p); return; } for (var i = 2; i <= (long)Math.Sqrt(p); i++) { if (p % (long)Math.Pow(i, n) == 0) { ans = i; } } Console.WriteLine(ans); } } }
[["-", 36, 36, 0, 208, 0, 235, 0, 251, 0, 259], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 0, 256], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 0, 208, 0, 209, 8, 201, 0, 45], ["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["-", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["+", 54, 55, 0, 220, 39, 224, 225, 226, 0, 70], ["+", 54, 55, 0, 220, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 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, 57, 64, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46]]
8
146
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace C { public class Program { public static void Main(string[] args) { long[] items = RLongAr(); var primes = PrimeFactor(items[1]); Dictionary<long, long> dic = new Dictionary<long, long>(); foreach (long item in primes) { if (!dic.ContainsKey(item)) dic.Add(item, 0); dic[item]++; } long res = 1; foreach (var item in dic) { res *= (item.Value / items[0]) > 0 ? (item.Value / items[0]) * item.Key : 1; } Console.WriteLine(res); } /// <summary> ///最大公約数 /// </summary> public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); // 引数を入替えて自分を呼び出す if (b == 0) return a; //一方が0の場合は、もう片方の数自身がGCD long d = 0; do { d = a % b; a = b; b = d; } while (d != 0); return a; } /// <summary> ///素因数分解(ポラード・ロー素因数分解法) /// </summary> public static IEnumerable<long> PrimeFactor(long n) { while (n > 1) { long factor = GetFactor(n); yield return factor; n = n / factor; } } private static long GetFactor(long n, int seed = 1) { if (n % 2 == 0) return 2; if (IsPrime(n)) return n; long x = 2, y = 2, d = 1; long count = 0; while (d == 1) { count++; x = f(x, n, seed); y = f(f(y, n, seed), n, seed); d = Gcd(Math.Abs(x - y), n); } if (d == n) // 見つからなかった、乱数発生のシードを変えて再挑戦。 return GetFactor(n, seed + 1); // 素数でない可能性もあるので、再度呼び出す return GetFactor(d); } /// <summary> ///素数判定 /// </summary> public static bool IsPrime(long number) { long boundary = (long)Math.Floor(Math.Sqrt(number)); if (number == 1) return false; if (number == 2) return true; for (long i = 2; i <= boundary; ++i) { if (number % i == 0) return false; } return true; } private static int[] seeds = new int[] { 3, 5, 7, 11, 13, 17 }; private static long f(long x, long n, int seed) { return (seeds[seed % 6] * x + seed) % n; } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace C { public class Program { public static void Main(string[] args) { long[] items = RLongAr(); var primes = PrimeFactor(items[1]); Dictionary<long, long> dic = new Dictionary<long, long>(); foreach (long item in primes) { if (!dic.ContainsKey(item)) dic.Add(item, 0); dic[item]++; } long res = 1; foreach (var item in dic) { res *= (item.Value / items[0]) > 0 ? (long)Math.Pow(item.Key, (item.Value / items[0])) : 1; } Console.WriteLine(res); } /// <summary> ///最大公約数 /// </summary> public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); // 引数を入替えて自分を呼び出す if (b == 0) return a; //一方が0の場合は、もう片方の数自身がGCD long d = 0; do { d = a % b; a = b; b = d; } while (d != 0); return a; } /// <summary> ///素因数分解(ポラード・ロー素因数分解法) /// </summary> public static IEnumerable<long> PrimeFactor(long n) { while (n > 1) { long factor = GetFactor(n); yield return factor; n = n / factor; } } private static long GetFactor(long n, int seed = 1) { if (n % 2 == 0) return 2; if (IsPrime(n)) return n; long x = 2, y = 2, d = 1; long count = 0; while (d == 1) { count++; x = f(x, n, seed); y = f(f(y, n, seed), n, seed); d = Gcd(Math.Abs(x - y), n); } if (d == n) // 見つからなかった、乱数発生のシードを変えて再挑戦。 return GetFactor(n, seed + 1); // 素数でない可能性もあるので、再度呼び出す return GetFactor(d); } /// <summary> ///素数判定 /// </summary> public static bool IsPrime(long number) { long boundary = (long)Math.Floor(Math.Sqrt(number)); if (number == 1) return false; if (number == 2) return true; for (long i = 2; i <= boundary; ++i) { if (number % i == 0) return false; } return true; } private static int[] seeds = new int[] { 3, 5, 7, 11, 13, 17 }; private static long f(long x, long n, int seed) { return (seeds[seed % 6] * x + seed) % n; } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
[["+", 0, 1, 0, 11, 12, 41, 64, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 41, 64, 74, 0, 25], ["+", 12, 41, 64, 74, 51, 213, 63, 214, 205, 22], ["+", 12, 41, 64, 74, 51, 213, 63, 214, 0, 131], ["+", 12, 41, 64, 74, 51, 213, 63, 214, 141, 22], ["+", 12, 41, 64, 74, 51, 213, 3, 4, 0, 24], ["+", 51, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 51, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 51, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 12, 41, 64, 74, 51, 213, 3, 4, 0, 21], ["+", 51, 213, 3, 4, 0, 28, 0, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 41, 64, 16, 17, 48], ["-", 0, 11, 12, 41, 64, 16, 12, 214, 205, 22], ["-", 0, 11, 12, 41, 64, 16, 12, 214, 0, 131], ["-", 0, 11, 12, 41, 64, 16, 12, 214, 141, 22], ["+", 12, 41, 64, 74, 51, 213, 3, 4, 0, 25]]
8
843
16
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemA { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var P = NN; var facts = LIB_Math.Factors(P).GroupBy(e => e).ToDictionary( e => e.Key, e => e.Count()); var x = 1L; foreach (var item in facts.Where(e => e.Value >= N)) { x *= item.Key; } Console.WriteLine(x); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_Math { [MethodImpl(MethodImplOptions.AggressiveInlining)] static public IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) { while (x % i == 0) { x /= i; yield return i; } } if (x != 1) yield return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long LCM(long a, long b) => a / GCD(a, b) * b; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; if (x < long.MaxValue / x) x *= x; y >>= 1; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public decimal Sqrt(decimal x) { decimal prev, cur = (decimal)Math.Sqrt((double)x); do { prev = cur; if (prev == 0) return 0; cur = (prev + x / prev) / 2; } while (cur != prev); return cur; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void Build(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Comb(long n, long k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Perm(long n, long k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public IEnumerable<List<int>> MakePermutation(long n, bool zeroIndexed = true) { if (n <= 0) throw new Exception(); var c = new int[n]; var a = new int[n]; if (!zeroIndexed) a[0] = 1; for (var i = 1; i < n; i++) a[i] = a[i - 1] + 1; yield return new List<int>(a); for (var i = 0; i < n;) { if (c[i] < i) { if (i % 2 == 0) { var t = a[0]; a[0] = a[i]; a[i] = t; } else { var t = a[c[i]]; a[c[i]] = a[i]; a[i] = t; } yield return new List<int>(a); ++c[i]; i = 0; } else { c[i] = 0; ++i; } } } } class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemA { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var P = NN; var facts = LIB_Math.Factors(P).GroupBy(e => e).ToDictionary( e => e.Key, e => e.Count()); var x = 1L; foreach (var item in facts.Where(e => e.Value >= N)) { x *= LIB_Math.Pow(item.Key, item.Value / N); } Console.WriteLine(x); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_Math { [MethodImpl(MethodImplOptions.AggressiveInlining)] static public IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) { while (x % i == 0) { x /= i; yield return i; } } if (x != 1) yield return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long LCM(long a, long b) => a / GCD(a, b) * b; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; if (x < long.MaxValue / x) x *= x; y >>= 1; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public decimal Sqrt(decimal x) { decimal prev, cur = (decimal)Math.Sqrt((double)x); do { prev = cur; if (prev == 0) return 0; cur = (prev + x / prev) / 2; } while (cur != prev); return cur; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void Build(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Comb(long n, long k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Perm(long n, long k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public IEnumerable<List<int>> MakePermutation(long n, bool zeroIndexed = true) { if (n <= 0) throw new Exception(); var c = new int[n]; var a = new int[n]; if (!zeroIndexed) a[0] = 1; for (var i = 1; i < n; i++) a[i] = a[i - 1] + 1; yield return new List<int>(a); for (var i = 0; i < n;) { if (c[i] < i) { if (i % 2 == 0) { var t = a[0]; a[0] = a[i]; a[i] = t; } else { var t = a[c[i]]; a[c[i]] = a[i]; a[i] = t; } yield return new List<int>(a); ++c[i]; i = 0; } else { c[i] = 0; ++i; } } } } class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 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, 17, 85], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
2,545
11
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = l[0], P = l[1]; var prime = PrimeFactorsDictionary(P); var ans = 1L; foreach (var p in prime) { for (var i = 0; i < p.Value / N; i++) ans *= p.Key; } Console.WriteLine(ans); } public static Dictionary<long, int> PrimeFactorsDictionary(long n) { var i = 2; var tmp = n; var dict = new Dictionary<long, int>(); for (var p = 2L; p * p <= n; p++) { if (n % p != 0) continue; var num = 0; while (n % p == 0) { num++; n /= p; } dict[p] = num; } if (tmp != 1) dict[tmp] = 1; return dict; } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = l[0], P = l[1]; var prime = PrimeFactorsDictionary(P); var ans = 1L; foreach (var p in prime) { for (var i = 0; i < p.Value / N; i++) ans *= p.Key; } Console.WriteLine(ans); } public static Dictionary<long, int> PrimeFactorsDictionary(long n) { var dict = new Dictionary<long, int>(); for (var p = 2L; p * p <= n; p++) { if (n % p != 0) continue; var num = 0; while (n % p == 0) { num++; n /= p; } dict[p] = num; } if (n != 1) dict[n] = 1; return dict; } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22]]
8
237
14
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadLong(); var P = sc.ReadLong(); var pf = PrimeFactors(P); var group = pf.GroupBy(p => p).Where(g => g.Count() >= N); var ans = group.Select(g => g.Key).Aggregate(1L, (a, v) => a * v); Console.WriteLine(ans); } static List<long> PrimeFactors(long n) { var res = new List<long>(); var tmp = n; for (long x = 2; x * x <= n; x++) { while (tmp % x == 0) { tmp /= x; res.Add(x); } } if (tmp != 1) res.Add(tmp); return res; } static int MOD = (int)1e9 + 7; static int INF = (int)1e7 + 1; static long LINF = (long)1e13 + 1; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadLong(); var P = sc.ReadLong(); var pf = PrimeFactors(P); var group = pf.GroupBy(p => p).Where(g => g.Count() >= N); long ans = 1; foreach (var g in group) { ans *= (long)Math.Pow(g.Key, g.Count() / N); } Console.WriteLine(ans); } static List<long> PrimeFactors(long n) { var res = new List<long>(); var tmp = n; for (long x = 2; x * x <= n; x++) { while (tmp % x == 0) { tmp /= x; res.Add(x); } } if (tmp != 1) res.Add(tmp); return res; } static int MOD = (int)1e9 + 7; static int INF = (int)1e7 + 1; static long LINF = (long)1e13 + 1; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 24], ["+", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["+", 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, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 0, 11, 12, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 74, 51, 213, 63, 214, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["-", 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, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["+", 51, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 51, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46]]
8
746
39
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCorder { public class Program { static void Main(string[] args) { var np = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = np[0]; long p = np[1]; var primes = Primes(p); var values = primes.Where(x => x.Value >= n).ToArray(); long ans = 1; for (int i = 0; i < values.Length; i++) { ans *= values[i].Key; } Console.WriteLine(ans); } static Dictionary<long, long> Primes(long n) { long max = (long)Math.Floor(Math.Sqrt(n)) + 1; var dic = new Dictionary<long, long>(); for (long i = 2; i < max; i++) { while (n % i == 0) { if (dic.ContainsKey(i) == false) { dic[i] = 1; } else { dic[i] += 1; } n /= i; } } if (n != 1) { dic[n] = 1; } return dic; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCorder { public class Program { static void Main(string[] args) { var np = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = np[0]; long p = np[1]; var primes = Primes(p); var values = primes.Where(x => x.Value >= n).ToArray(); long ans = 1; for (long i = 0; i < values.Length; i++) { long num = values[i].Value / n; for (int j = 0; j < num; j++) { ans *= values[i].Key; } } Console.WriteLine(ans); } static Dictionary<long, long> Primes(long n) { long max = (long)Math.Ceiling(Math.Sqrt(n)) + 1; var dic = new Dictionary<long, long>(); for (long i = 2; i < max; i++) { while (n % i == 0) { if (dic.ContainsKey(i) == false) { dic[i] = 1; } else { dic[i] += 1; } n /= i; } } if (n != 1) { dic[n] = 1; } return dic; } } }
[["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 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], ["+", 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, 212, 0, 16, 31, 214, 205, 204, 205, 22], ["+", 0, 16, 31, 214, 205, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 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, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 16, 31, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 74, 51, 213, 63, 214, 141, 22]]
8
275
32
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace Caddi2018C { class Program { public static void Solve(Input input) { var n = input.NextLong(); var p = input.NextLong(); var primes = Prime.PrimeFactors(p); var map = primes.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()); long gcd = 1; foreach (var item in map) { if (item.Value < n) continue; gcd *= item.Key * (item.Value / n); } Console.WriteLine(gcd); } /// <summary> /// 素数判定 /// 素因数分解 /// 素数列挙(エラトステネスの篩) /// 約数列挙 /// </summary> static class Prime { /// <summary> /// 素数か /// </summary> /// <param name="x"></param> /// <returns></returns> public static bool IsPrime(long x) { if (x < 2) { return false; } if (x == 2) { return true; } if ((x % 2) == 0) { return false; } long rx = (long)(Math.Sqrt(x) + 1); for (long n = 3; n < rx; n += 2) { if ((x % n) == 0) { return false; } } return true; } /// <summary> /// 素数判定リスト /// </summary> /// <param name="n"></param> /// <returns></returns> public static bool[] PrimeSieve(int n) { // Sieve of Eratosthenes var sieve = Enumerable.Repeat<bool>(true, n + 1).ToArray(); if (n > 2) { sieve[0] = sieve[1] = false; } var rn = (int)(Math.Sqrt(n) + 1); foreach (var i in Enumerable.Range(2, rn - 2)) { if (sieve[i]) { for (int j = 2 * i; j <= n; j += i) { sieve[j] = false; } } } return sieve; } /// <summary> /// 素数リスト /// </summary> /// <param name="n"></param> /// <returns></returns> public static IEnumerable<int> PrimeList(int n) { var sieve = PrimeSieve(n); return sieve.Select((x, i) => new { X = x, I = i }) .Where(x => x.X) .Select(x => x.I); } /// <summary> /// 素因数分解 /// </summary> /// <param name="n"></param> /// <returns></returns> public static IEnumerable<long> PrimeFactors(long n) { var m = n; var m2 = (long)Math.Sqrt(m) + 1; var p = 2; while (p < m2) { if ((m % p) == 0) { m = m / p; m2 = (long)Math.Sqrt(m) + 1; yield return p; } else { p++; } } if (m > 1) { yield return m; } } /// <summary> /// n以下でnと互いに素な数の個数 /// オイラーのファイ関数 /// </summary> /// <param name="n"></param> /// <returns></returns> public static long PrimeCount(long n) { var primes = PrimeFactors(n).Distinct(); var dsum = new decimal(1); foreach (var p in primes) { var pp = new decimal(p); dsum *= 1 - (1 / pp); } return (long)Math.Round(dsum * n); } /// <summary> /// 約数列挙 順番はバラバラなので注意! /// </summary> /// <param name="n"></param> /// <returns></returns> public static IEnumerable<long> Divisors(long n) { if (n < 1) { yield break; } var rn = (int)(Math.Sqrt(n) + 1); for (long i = 1; i < rn; i++) { if ((n % i) == 0) { yield return i; if (i != (n / i)) { yield return n / i; } } } } /// <summary> /// 約数列挙 昇順にソート /// </summary> /// <param name="n"></param> /// <param name="needsSort"></param> /// <returns></returns> public static IEnumerable<long> Divisors(long n, bool needsSort) { var divs = Divisors(n); if (needsSort) { return divs.OrderBy(x => x); } else { return divs; } } } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; Queue<string> q { get; set; } /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => q.Any() || read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool read() { if (!SetText(sr.ReadLine())) return false; if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!q.Any() && !read()) { return ""; } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); /// <summary> /// n2個の要素をn1個まとめたリストとする /// </summary> List<T>[] NextList<T>(int n1, int n2, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n2 * n1)) return null; var list = Enumerable.Range(0, n1).Select(_ => new List<T>()).ToArray(); for (int i = 0; i < n1; i++) { list[i].Add(add(parse(q.Dequeue()), offset)); } return list; } public List<string>[] Next(int n1, int n2) => NextList(n1, n2, "", x => x, (x, y) => x); public List<int>[] NextInt(int n1, int n2, int offset = 0) => NextList(n1, n2, offset, int.Parse, (x, y) => x + y); public List<long>[] NextLong(int n1, int n2, long offset = 0) => NextList(n1, n2, offset, long.Parse, (x, y) => x + y); public List<double>[] NextDouble(int n1, int n2, double offset = 0.0) => NextList(n1, n2, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace Caddi2018C { class Program { public static void Solve(Input input) { var n = input.NextLong(); var p = input.NextLong(); var primes = Prime.PrimeFactors(p); var map = primes.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count()); long gcd = 1; foreach (var item in map) { if (item.Value < n) continue; gcd *= (long)Math.Pow(item.Key, (item.Value / n)); } Console.WriteLine(gcd); } /// <summary> /// 素数判定 /// 素因数分解 /// 素数列挙(エラトステネスの篩) /// 約数列挙 /// </summary> static class Prime { /// <summary> /// 素数か /// </summary> /// <param name="x"></param> /// <returns></returns> public static bool IsPrime(long x) { if (x < 2) { return false; } if (x == 2) { return true; } if ((x % 2) == 0) { return false; } long rx = (long)(Math.Sqrt(x) + 1); for (long n = 3; n < rx; n += 2) { if ((x % n) == 0) { return false; } } return true; } /// <summary> /// 素数判定リスト /// </summary> /// <param name="n"></param> /// <returns></returns> public static bool[] PrimeSieve(int n) { // Sieve of Eratosthenes var sieve = Enumerable.Repeat<bool>(true, n + 1).ToArray(); if (n > 2) { sieve[0] = sieve[1] = false; } var rn = (int)(Math.Sqrt(n) + 1); foreach (var i in Enumerable.Range(2, rn - 2)) { if (sieve[i]) { for (int j = 2 * i; j <= n; j += i) { sieve[j] = false; } } } return sieve; } /// <summary> /// 素数リスト /// </summary> /// <param name="n"></param> /// <returns></returns> public static IEnumerable<int> PrimeList(int n) { var sieve = PrimeSieve(n); return sieve.Select((x, i) => new { X = x, I = i }) .Where(x => x.X) .Select(x => x.I); } /// <summary> /// 素因数分解 /// </summary> /// <param name="n"></param> /// <returns></returns> public static IEnumerable<long> PrimeFactors(long n) { var m = n; var m2 = (long)Math.Sqrt(m) + 1; var p = 2; while (p < m2) { if ((m % p) == 0) { m = m / p; m2 = (long)Math.Sqrt(m) + 1; yield return p; } else { p++; } } if (m > 1) { yield return m; } } /// <summary> /// n以下でnと互いに素な数の個数 /// オイラーのファイ関数 /// </summary> /// <param name="n"></param> /// <returns></returns> public static long PrimeCount(long n) { var primes = PrimeFactors(n).Distinct(); var dsum = new decimal(1); foreach (var p in primes) { var pp = new decimal(p); dsum *= 1 - (1 / pp); } return (long)Math.Round(dsum * n); } /// <summary> /// 約数列挙 順番はバラバラなので注意! /// </summary> /// <param name="n"></param> /// <returns></returns> public static IEnumerable<long> Divisors(long n) { if (n < 1) { yield break; } var rn = (int)(Math.Sqrt(n) + 1); for (long i = 1; i < rn; i++) { if ((n % i) == 0) { yield return i; if (i != (n / i)) { yield return n / i; } } } } /// <summary> /// 約数列挙 昇順にソート /// </summary> /// <param name="n"></param> /// <param name="needsSort"></param> /// <returns></returns> public static IEnumerable<long> Divisors(long n, bool needsSort) { var divs = Divisors(n); if (needsSort) { return divs.OrderBy(x => x); } else { return divs; } } } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; Queue<string> q { get; set; } /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => q.Any() || read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool read() { if (!SetText(sr.ReadLine())) return false; if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!q.Any() && !read()) { return ""; } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); /// <summary> /// n2個の要素をn1個まとめたリストとする /// </summary> List<T>[] NextList<T>(int n1, int n2, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n2 * n1)) return null; var list = Enumerable.Range(0, n1).Select(_ => new List<T>()).ToArray(); for (int i = 0; i < n1; i++) { list[i].Add(add(parse(q.Dequeue()), offset)); } return list; } public List<string>[] Next(int n1, int n2) => NextList(n1, n2, "", x => x, (x, y) => x); public List<int>[] NextInt(int n1, int n2, int offset = 0) => NextList(n1, n2, offset, int.Parse, (x, y) => x + y); public List<long>[] NextLong(int n1, int n2, long offset = 0) => NextList(n1, n2, offset, long.Parse, (x, y) => x + y); public List<double>[] NextDouble(int n1, int n2, double offset = 0.0) => NextList(n1, n2, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["+", 8, 196, 0, 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, 11, 12, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 74, 51, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 11, 12, 74, 51, 213, 3, 4, 0, 21], ["+", 51, 213, 3, 4, 0, 28, 0, 23, 0, 25]]
8
2,678
10
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { long[] np = Console.ReadLine().Split().Select(long.Parse).ToArray(); Console.WriteLine(factors(np[1]).GroupBy(x => x).Aggregate( 1L, (x, y) => x * Max(1, Enumerable.Repeat(y.Key, y.Count()) .Aggregate(1L, (z, w) => Power(z, w) / np[0])))); } static long Power(long n, long m) { long pow = n; long res = 1; while (m > 0) { if ((m & 1) == 1) res *= pow; pow *= pow; m >>= 1; } return res; } static long[] factors(long n) { long firstn = n; long i = 2; List<long> res = new List<long>(); while (i * i <= firstn + 100) { while (n % i == 0) { res.Add(i); n /= i; } i++; } if (n != 1) res.Add(n); return res.ToArray(); } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { long[] np = Console.ReadLine().Split().Select(long.Parse).ToArray(); Console.WriteLine(factors(np[1]).GroupBy(x => x).Aggregate( 1L, (x, y) => x * Max(1, Power(y.Key, y.Count() / np[0])))); } static long Power(long n, long m) { long pow = n; long res = 1; while (m > 0) { if ((m & 1) == 1) res *= pow; pow *= pow; m >>= 1; } return res; } static long[] factors(long n) { long firstn = n; long i = 2; List<long> res = new List<long>(); while (i * i <= firstn + 100) { while (n % i == 0) { res.Add(i); n /= i; } i++; } if (n > 1) res.Add(n); return res.ToArray(); } }
[["-", 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], ["+", 12, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["-", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 0, 28, 0, 218, 8, 16, 31, 213, 63, 22], ["-", 8, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 218, 8, 16, 31, 213, 3, 4, 0, 21], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
309
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Program { private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static long Solve(int N, long P) { var factors = new Dictionary<long, int>(); for (long i = 2; i * i <= P; ++i) { int n = 0; while (P % i == 0) { P /= i; ++n; } if (n > 0) { factors[i] = n; } } if (P > 1) { factors[P] = 1; } long ans = 1; foreach (var pair in factors) { if (pair.Value >= N) { ans *= pair.Key * (pair.Value / N); } } return ans; } static void Main(string[] args) { var V = ReadLongs(); Console.WriteLine(Solve((int)V[0], V[1])); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Program { private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static long Solve(int N, long P) { var factors = new Dictionary<long, int>(); for (long i = 2; i * i <= P; ++i) { int n = 0; while (P % i == 0) { P /= i; ++n; } if (n > 0) { factors[i] = n; } } if (P > 1) { factors[P] = 1; } long ans = 1; foreach (var pair in factors) { int n = pair.Value / N; for (int i = 0; i < n; ++i) { ans *= pair.Key; } } return ans; } static void Main(string[] args) { var V = ReadLongs(); Console.WriteLine(Solve((int)V[0], V[1])); } } }
[["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 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, 210, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 8, 196, 0, 210, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 210, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 210, 8, 196, 0, 7, 0, 24], ["+", 0, 210, 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, 210, 8, 196, 0, 7, 0, 35], ["+", 0, 210, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 210, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 210, 8, 196, 0, 7, 26, 241, 0, 29], ["+", 0, 210, 8, 196, 0, 7, 26, 241, 0, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 12, 16, 12, 23, 0, 16, 31, 214, 205, 22], ["-", 12, 16, 12, 23, 0, 16, 31, 214, 0, 131], ["-", 12, 16, 12, 23, 0, 16, 31, 214, 141, 22], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 85], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
8
361
29
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); var hs = new Dictionary<long, int>(); long ans = 1; double r = Math.Sqrt(s[1]); for (long i = 2; i <= r; i++) { if (s[1] % i == 0) { s[1] /= i; if (hs.ContainsKey(i)) { hs[i]++; } else { hs.Add(i, 1); } i = 1; } } foreach (KeyValuePair<long, int> e in hs) { long q = e.Value; while (q >= s[0]) { ans *= e.Key; q -= s[0]; } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { long[] s = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); var hs = new Dictionary<long, int>(); long ans = 1, t = s[1]; double r = Math.Sqrt(s[1]) + 1; for (long i = 2; i <= r; i++) { if (s[1] % i == 0) { s[1] /= i; if (hs.ContainsKey(i)) { hs[i]++; } else { hs.Add(i, 1); } i = 1; } } foreach (KeyValuePair<long, int> e in hs) { long q = e.Value; while (q >= s[0]) { ans *= e.Key; q -= s[0]; } } Console.WriteLine(s[0] == 1 ? t : ans); } }
[["+", 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, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 28, 0, 41, 15, 16, 31, 204, 205, 22], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102]]
8
202
18
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static 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 Scanner(); int N = int.Parse(Console.ReadLine()); long sum = 0; for (var i = 0; i < N; i++) sum += long.Parse(Console.ReadLine()); Console.WriteLine(sum % 2 != 0 ? "first" : "second"); // 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; } } } public class Scanner { public int[] ReadSplit() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitL() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplitD() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } 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(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static 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 Scanner(); int N = int.Parse(Console.ReadLine()); for (var i = 0; i < N; i++) { if (long.Parse(Console.ReadLine()) % 2 != 0) { Console.WriteLine("first"); return; } } Console.WriteLine("second"); // 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; } } } public class Scanner { public int[] ReadSplit() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitL() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplitD() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } 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(); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 8, 1, 0, 11, 31, 22], ["-", 0, 7, 8, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 7, 8, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 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, 41, 0, 102], ["+", 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, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 7, 8, 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]]
8
519
34
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = long.Parse(Console.ReadLine()); int c = 0; for (int i = 0; i < n; i++) if (a[i] % 2 == 1) c++; Console.WriteLine(c % 2 == 1 ? "first" : "second"); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = long.Parse(Console.ReadLine()); bool f = false; for (int i = 0; i < n; i++) f = f || a[i] % 2 == 1; Console.WriteLine(f ? "first" : "second"); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["-", 0, 195, 8, 196, 0, 7, 8, 57, 0, 121], ["-", 0, 195, 8, 196, 0, 7, 8, 57, 0, 24], ["+", 8, 196, 0, 7, 8, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 7, 8, 1, 0, 11, 12, 16, 17, 106], ["-", 0, 195, 8, 196, 0, 7, 8, 57, 0, 25], ["-", 0, 7, 8, 57, 64, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 57, 64, 1, 0, 223, 0, 29], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 31, 22], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 109], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203], ["-", 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, 15, 22]]
8
133
21
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string str = Console.ReadLine(); long N = long.Parse(str); int[] A = new int[N]; for (var i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } Array.Sort(A); string ans = "second"; if (A[0] % 2 == 1) { ans = "first"; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string str = Console.ReadLine(); long N = long.Parse(str); int[] A = new int[N]; for (var i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } Array.Sort(A); string ans = "second"; for (var i = 0; i < N; i++) { if (A[i] % 2 == 1) { ans = "first"; break; } } Console.WriteLine(ans); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["+", 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], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
127
20
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); //全てが偶数になった状態で相手にわたれば良い Console.WriteLine(a.All(x => x % 2 == 0) ? "second" : "first"); } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); int[] a = Enumerable.Repeat(0, n) .Select(_ => int.Parse(Console.ReadLine())) .ToArray(); //全てが偶数になった状態で相手にわたれば良い Console.WriteLine(a.All(x => x % 2 == 0) ? "second" : "first"); } }
[["-", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25]]
8
128
20
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; 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 / 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 th = new Thread(Run, 1 << 26); th.Start(); th.Join();*/ Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { int N = Int; var A = _ReadSplitLong; Sort(A); var rec = new Dictionary<long, int>(); for (var i = 0; i < N; i++) { if (rec.ContainsKey(A[i])) rec[A[i]]++; else rec[A[i]] = 1; } int ans = 0; for (var i = N - 1; i >= 0; i--) { for (var j = 32; j >= 0; j--) { long L = (1L << j); if (rec.ContainsKey(L - A[i])) { if (L - A[i] == A[i] && rec[L - A[i]] >= 2) { ans++; rec[A[i]] -= 2; } if (L - A[i] != A[i] && rec[L - A[i]] >= 1 && rec[A[i]] >= 1) { ans++; rec[A[i]]--; rec[L - A[i]]--; } break; } } } OutL(ans); } 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; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); 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; 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 }; 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]; } 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 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) { 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]); } 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 static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; 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 / 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 th = new Thread(Run, 1 << 26); th.Start(); th.Join();*/ Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { int N = Int; var A = _ReadSplitLong; Sort(A); var rec = new Dictionary<long, int>(); for (var i = 0; i < N; i++) { if (rec.ContainsKey(A[i])) rec[A[i]]++; else rec[A[i]] = 1; } int ans = 0; for (var i = N - 1; i >= 0; i--) { for (var j = 32; j >= 0; j--) { long L = (1L << j); if (rec.ContainsKey(L - A[i])) { if (L - A[i] == A[i]) { if (rec[A[i]] >= 2) { ans++; rec[A[i]] -= 2; break; } } else { if (rec[A[i]] >= 1 && rec[L - A[i]] >= 1) { ans++; rec[A[i]]--; rec[L - A[i]]--; break; } } } } } OutL(ans); } 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; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); 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; 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 }; 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]; } 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 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) { 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]); } 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)); } }
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 33], ["-", 31, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["-", 31, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 31, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 79], ["-", 15, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
2,019
31
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() { int N = cin.nextint; var A = cin.scanlong; var H = new HashMap<long, int>(); for (int i = 0; i < N; i++) { if (H.ContainsKey(-A[i])) { H[-A[i]]++; } else { H[-A[i]] = 1; } } var target = (long)1 << 31; int ans = 0; var W = new HashMap<long, int>(); foreach (var v in H) { var y = -v.Key; while (y * 2 < target) { target >>= 1; } var x = target - y; if (x == y) { int w = v.Value; ans += w / 2; } else { if (H.ContainsKey(-x)) { int w = H[-x]; int s = Min(w - W[x], v.Value - W[y]); W[x] += s; W[y] += s; ans += s; } } } WriteLine(ans); // var used = new bool[N]; // Array.Sort(A); // var L = A.ToList(); // int cnt = 0; // var target = (long)1 << 31; // while (L.Count > 0) //{ // var y = L[L.Count - 1]; // while (y * 2 < target) // { // target >>= 1; // } // var x = target - y; // var idx = L.lower_bound(x); // var u = L.upper_bound(x); // //WriteLine(x + " " + y); // if (x == y) // { // if (u - idx > 1) // { // cnt++; // L.RemoveAt(idx); // } // } // else if (u - idx > 0) // { // cnt++; // L.RemoveAt(idx); // } // L.RemoveAt(L.Count - 1); //} // WriteLine(cnt); } } class HashMap<TKey, TValue> : SortedDictionary<TKey, TValue> { public new TValue this[TKey key] { get { TValue value; return TryGetValue(key, out value) ? value : default(TValue); } set { base[key] = value; } } } 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() { int N = cin.nextint; var A = cin.scanlong; var H = new HashMap<long, int>(); for (int i = 0; i < N; i++) { if (H.ContainsKey(-A[i])) { H[-A[i]]++; } else { H[-A[i]] = 1; } } var target = (long)1 << 31; int ans = 0; var W = new HashMap<long, int>(); foreach (var v in H) { var y = -v.Key; while (y * 2 < target) { target >>= 1; } var x = target - y; if (x == y) { int w = v.Value - W[y]; ans += w / 2; W[y] += w / 2; } else { if (H.ContainsKey(-x)) { int w = H[-x]; int s = Min(w - W[x], v.Value - W[y]); W[x] += s; W[y] += s; ans += s; } } } WriteLine(ans); // var used = new bool[N]; // Array.Sort(A); // var L = A.ToList(); // int cnt = 0; // var target = (long)1 << 31; // while (L.Count > 0) //{ // var y = L[L.Count - 1]; // while (y * 2 < target) // { // target >>= 1; // } // var x = target - y; // var idx = L.lower_bound(x); // var u = L.upper_bound(x); // //WriteLine(x + " " + y); // if (x == y) // { // if (u - idx > 1) // { // cnt++; // L.RemoveAt(idx); // } // } // else if (u - idx > 0) // { // cnt++; // L.RemoveAt(idx); // } // L.RemoveAt(L.Count - 1); //} // WriteLine(cnt); } } class HashMap<TKey, TValue> : SortedDictionary<TKey, TValue> { public new TValue this[TKey key] { get { TValue value; return TryGetValue(key, out value) ? value : default(TValue); } set { base[key] = value; } } } 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); }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73]]
8
1,161
14
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; namespace Program { public static class AGC029B { static public void Solve() { var N = NN; var AList = NNList(N); var bt = new BT<long>(); foreach (var item in AList) { bt.Add(item); } var ans = 0L; var twoT = new BT<long>(); var tmp = 1L; for (var i = 0; i < 30; i++) { tmp <<= 1; twoT.Add(tmp); } foreach (var item in AList.OrderByRand().OrderByDescending(e => e)) { if (bt.Have(item)) { var two = twoT.FindUpper(item + 1); var search = two.Item2 - item; if (bt.Have(search)) { bt.Remove(item); if (bt.Have(search)) { bt.Remove(search); ++ans; } else { bt.Add(item); } } } } Console.WriteLine(ans); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { static Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static T Pow<T>(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UF(long s) { d = Repeat(-1L, s).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsSame(long x, long y) => Root(x) == Root(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Count(long x) => -d[Root(d[x])]; } struct Mod : IEquatable<object> { static public long _mod = 1000000007; long _val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val = x % _mod) < 0) _val += _mod; } static public implicit operator Mod(long x) => new Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(Mod x) => x._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, Mod y) => x._val + y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) => x._val - y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator *(Mod x, Mod y) => x._val * y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, Mod y) => x._val == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, Mod y) => x._val != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IEquatable<object>.Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => _val.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => _val.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { T[,] m; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mat(T[,] v) { m = (T[,])v.Clone(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] FromRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] FromLeaf() => FromRoot().Reverse().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; } Comparison<T> c; Node r; bool ch; T lm; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT(Comparison<T> _c) { c = _c; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT() : this((x, y) => x.CompareTo(y)) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool R(Node n) => n != null && !n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool B(Node n) => n != null && n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T x) { r = A(r, x); r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x }; } var r = c(x, n.v); if (r < 0) { n.l = A(n.l, x); return Bl(n); } if (r > 0) { n.r = A(n.r, x); return Bl(n); } ch = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RmM(Node n) { if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindUpper(T x) { var v = FU(r, x); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FU(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0) return FU(n.r, x); return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindLower(T x) { var v = FL(r, x); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FL(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) return FL(n.l, x); if (r > 0) { var v = FL(n.r, x); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => r != null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountSlow() => L(r).Count(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => L(r); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; namespace Program { public static class AGC029B { static public void Solve() { var N = NN; var AList = NNList(N); var bt = new BT<long>(); foreach (var item in AList) { bt.Add(item); } var ans = 0L; var twoT = new BT<long>(); var tmp = 1L; for (var i = 0; i < 30; i++) { tmp <<= 1; twoT.Add(tmp); } foreach (var item in AList.OrderByRand().OrderByDescending(e => e)) { if (bt.Have(item)) { var two = twoT.FindUpper(item + 1); var search = two.Item2 - item; if (bt.Have(search)) { bt.Remove(item); if (bt.Have(search)) { bt.Remove(search); ++ans; } else { bt.Add(item); } } } } Console.WriteLine(ans); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { static Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static T Pow<T>(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UF(long s) { d = Repeat(-1L, s).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsSame(long x, long y) => Root(x) == Root(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Count(long x) => -d[Root(d[x])]; } struct Mod : IEquatable<object> { static public long _mod = 1000000007; long _val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val = x % _mod) < 0) _val += _mod; } static public implicit operator Mod(long x) => new Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(Mod x) => x._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, Mod y) => x._val + y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) => x._val - y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator *(Mod x, Mod y) => x._val * y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, Mod y) => x._val == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, Mod y) => x._val != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IEquatable<object>.Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => _val.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => _val.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { T[,] m; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mat(T[,] v) { m = (T[,])v.Clone(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] FromRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] FromLeaf() => FromRoot().Reverse().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; } Comparison<T> c; Node r; bool ch; T lm; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT(Comparison<T> _c) { c = _c; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT() : this((x, y) => x.CompareTo(y)) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool R(Node n) => n != null && !n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool B(Node n) => n != null && n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T x) { r = A(r, x); r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); return Bl(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RmM(Node n) { if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindUpper(T x) { var v = FU(r, x); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FU(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0) return FU(n.r, x); return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindLower(T x) { var v = FL(r, x); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FL(Node n, T x) { if (n == null) return null; var r = c(x, n.v); if (r < 0) return FL(n.l, x); if (r > 0) { var v = FL(n.r, x); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => r != null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountSlow() => L(r).Count(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => L(r); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 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, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 0, 57, 64, 196, 0, 37, 0, 213, 63, 22], ["-", 64, 196, 0, 37, 0, 213, 3, 4, 0, 24], ["-", 0, 37, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 37, 0, 213, 3, 4, 0, 25], ["-", 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, 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], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 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, 211, 0, 147], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22]]
8
7,101
33
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; using System.IO; namespace AtCoder { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); #if DEBUG ReadLine(); #endif } void Solve(ConsoleInput cin) { int n = cin.ReadInt; long[] a_n = cin.ReadLongArray(n); Array.Sort(a_n); Array.Reverse(a_n); Dictionary<long, long> dict = new Dictionary<long, long>(); foreach (long a in a_n) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } long ans = 0; foreach (long a in a_n) { if (dict[a] == 0) { continue; } dict[a]--; long powered = 1; while (powered <= a) { powered <<= 1; } long b = powered - a; if (dict.ContainsKey(b)) { dict[b]--; ans++; } } Console.WriteLine(ans); } class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; using System.IO; namespace AtCoder { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Program().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); #if DEBUG ReadLine(); #endif } void Solve(ConsoleInput cin) { int n = cin.ReadInt; long[] a_n = cin.ReadLongArray(n); Array.Sort(a_n); Array.Reverse(a_n); Dictionary<long, long> dict = new Dictionary<long, long>(); foreach (long a in a_n) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } long ans = 0; foreach (long a in a_n) { if (dict[a] == 0) { continue; } dict[a]--; long powered = 1; while (powered <= a) { powered <<= 1; } long b = powered - a; if (dict.ContainsKey(b) && dict[b] > 0) { dict[b]--; ans++; } } Console.WriteLine(ans); } class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } } }
[["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
638
7
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(); int[] A = new int[N]; var dic = new Dictionary<int, int>(); int ans = 0; for (var i = 0; i < N; i++) { A[i] = int.Parse(str[i]); if (dic.ContainsKey(A[i])) { dic[A[i]] += 1; } else { dic[A[i]] = 1; } } for (var i = 0; i < N; i++) { for (var j = 31; j >= 1; j--) { int a = (int)Math.Pow(2, j); if (dic.ContainsKey(a - A[i]) && dic[a - A[i]] > 0 && dic.ContainsKey(A[i]) && dic[A[i]] > 0) { if (a == A[i] * 2) { if (dic[A[i]] >= 2) { ans += 1; dic[A[i]] -= 2; } } else { ans += 1; dic[A[i]] -= 1; dic[a - A[i]] -= 1; } break; } } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(); int[] A = new int[N]; var dic = new Dictionary<int, int>(); int ans = 0; for (var i = 0; i < N; i++) { A[i] = int.Parse(str[i]); if (dic.ContainsKey(A[i])) { dic[A[i]] += 1; } else { dic[A[i]] = 1; } } Array.Sort(A); for (var i = N - 1; i >= 0; i--) { for (var j = 31; j >= 1; j--) { int a = (int)Math.Pow(2, j); if (dic.ContainsKey(a - A[i]) && dic[a - A[i]] > 0 && dic.ContainsKey(A[i]) && dic[A[i]] > 0) { if (a == A[i] * 2) { if (dic[A[i]] >= 2) { ans += 1; dic[A[i]] -= 2; } } else { ans += 1; dic[A[i]] -= 1; dic[a - A[i]] -= 1; } break; } } } 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], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
325
17
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); long[] a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long ans = 0, o = 1; Array.Sort(a, ca); var hs = new Dictionary<long, int>(); for (int i = 0; i < n; i++) { if (hs.ContainsKey(a[i]) && hs[a[i]] > 0) { ans++; continue; } for (int j = 1; (o << j) - a[i] <= a[i]; j++) { if ((o << j) > a[i]) { if (hs.ContainsKey((o << j) - a[i])) { hs[(o << j) - a[i]]++; } else { hs.Add((o << j) - a[i], 1); } } } } Console.WriteLine(ans); } static int ca(long a, long b) { if (a < b) { return 1; } else if (a > b) { return -1; } else { return 0; } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); long[] a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long ans = 0, o = 1; Array.Sort(a, ca); var hs = new Dictionary<long, int>(); for (int i = 0; i < n; i++) { if (hs.ContainsKey(a[i]) && hs[a[i]] > 0) { ans++; hs[a[i]]--; continue; } for (int j = 1; (o << j) - a[i] <= a[i]; j++) { if ((o << j) > a[i]) { if (hs.ContainsKey((o << j) - a[i])) { hs[(o << j) - a[i]]++; } else { hs.Add((o << j) - a[i], 1); } } } } Console.WriteLine(ans); } static int ca(long a, long b) { if (a < b) { return 1; } else if (a > b) { return -1; } else { return 0; } } }
[["+", 64, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["+", 0, 1, 0, 223, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 223, 0, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
288
9
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading; namespace ReadWriteTemplate { public static class Solver { private static void SolveCase() { int n = ReadInt(); var a = ReadIntArray().OrderByWithShuffle(x => x).ToArray(); var dict = new Dictionary<int, int>(); foreach (var x in a) { if (dict.ContainsKey(x)) { dict[x]++; } else { dict[x] = 1; } } var p = new int[32]; for (int i = 0; i < 31; i++) { p[i] = 1 << i; } int ans = 0; for (int i = n - 1; i >= 0; i--) { for (int j = 1; j < 31; j++) { int d = p[j] - a[i]; if (d >= a[i] && dict[a[i]] > 0) { if (a[i] != d) { if (dict.ContainsKey(d) && dict[d] > 0) { ans++; dict[a[i]]--; dict[d]--; break; } } else { if (dict[d] > 1) { ans++; dict[d] -= 2; break; } } } } } Writer.WriteLine(ans); } public static void Solve() { SolveCase(); /*var sw = Stopwatch.StartNew();*/ /*int T = ReadInt(); for (int i = 0; i < T; i++) { // Writer.Write("Case #{0}: ", i + 1); SolveCase(); }*/ /*sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds);*/ } public static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; #if DEBUG // Reader = Console.In; Writer = Console.Out; Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt"); #else Reader = Console.In; Writer = Console.Out; #endif // Solve(); Thread thread = new Thread(Solve, 64 * 1024 * 1024); thread.CurrentCulture = CultureInfo.InvariantCulture; thread.Start(); thread.Join(); Reader.Close(); Writer.Close(); } public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { return source.Shuffle().OrderBy(keySelector); } public static T[] Shuffle<T>(this IEnumerable<T> source) { T[] result = source.ToArray(); Random rnd = new Random(); for (int i = result.Length - 1; i >= 1; i--) { int k = rnd.Next(i + 1); T tmp = result[k]; result[k] = result[i]; result[i] = tmp; } return result; } #region Read / Write private static TextReader Reader; private static TextWriter Writer; private static Queue<string> CurrentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (CurrentLineTokens.Count == 0) CurrentLineTokens = new Queue<string>(ReadAndSplitLine()); return CurrentLineTokens.Dequeue(); } public static string ReadLine() { return Reader.ReadLine(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = Reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { Writer.WriteLine(string.Join(" ", array)); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading; namespace ReadWriteTemplate { public static class Solver { private static void SolveCase() { int n = ReadInt(); var a = ReadIntArray().OrderByWithShuffle(x => x).ToArray(); var dict = new Dictionary<int, int>(); foreach (var x in a) { if (dict.ContainsKey(x)) { dict[x]++; } else { dict[x] = 1; } } var p = new int[32]; for (int i = 0; i < 31; i++) { p[i] = 1 << i; } int ans = 0; for (int i = n - 1; i >= 0; i--) { for (int j = 31 - 1; j >= 1; j--) { int d = p[j] - a[i]; if (d > 0 && dict[a[i]] > 0) { if (a[i] != d) { if (dict.ContainsKey(d) && dict[d] > 0) { ans++; dict[a[i]]--; dict[d]--; break; } } else { if (dict[d] > 1) { ans++; dict[d] -= 2; break; } } } } } Writer.WriteLine(ans); } public static void Solve() { SolveCase(); /*var sw = Stopwatch.StartNew();*/ /*int T = ReadInt(); for (int i = 0; i < T; i++) { // Writer.Write("Case #{0}: ", i + 1); SolveCase(); }*/ /*sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds);*/ } public static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; #if DEBUG // Reader = Console.In; Writer = Console.Out; Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt"); #else Reader = Console.In; Writer = Console.Out; #endif // Solve(); Thread thread = new Thread(Solve, 64 * 1024 * 1024); thread.CurrentCulture = CultureInfo.InvariantCulture; thread.Start(); thread.Join(); Reader.Close(); Writer.Close(); } public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { return source.Shuffle().OrderBy(keySelector); } public static T[] Shuffle<T>(this IEnumerable<T> source) { T[] result = source.ToArray(); Random rnd = new Random(); for (int i = result.Length - 1; i >= 1; i--) { int k = rnd.Next(i + 1); T tmp = result[k]; result[k] = result[i]; result[i] = tmp; } return result; } #region Read / Write private static TextReader Reader; private static TextWriter Writer; private static Queue<string> CurrentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (CurrentLineTokens.Count == 0) CurrentLineTokens = new Queue<string>(ReadAndSplitLine()); return CurrentLineTokens.Dequeue(); } public static string ReadLine() { return Reader.ReadLine(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = Reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { Writer.WriteLine(string.Join(" ", array)); } #endregion } }
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 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, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
1,002
15
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const int M2 = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; var a = sc.IntArr; var b = new int[n]; for (int i = 0; i < n; i++) { b[i] = Math.Min(a[i], n + 9); } int ng = 0, ok = n; while (ng + 1 < ok) { int m = (ng + ok) / 2; bool f = true; var cnt = new int[n + 10]; var q = new PriorityQueue<int>() { rev = true }; var nz = new bool[n + 10]; for (int i = 1; i < n; i++) { if (a[i - 1] < a[i]) continue; int k = n + 9 - b[i]; while (q.Count > 0) { if (q.Top < k) { cnt[q.Top] = 0; nz[q.Top] = false; q.Pop(); } else break; } ++cnt[k]; for (int j = k; j < n + 9; j++) { if (cnt[j] >= m) { cnt[j] -= m; if (cnt[j] == 0) nz[j] = false; ++cnt[j + 1]; if (!nz[j + 1]) { nz[j + 1] = true; q.Push(j + 1); } } else break; } if (cnt[n + 9] > 0) { f = false; break; } } if (f) ok = m; else ng = m; } Prt(ok); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P { get { int a, b; Multi(out a, out b); return new P(a, b); } } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } // the greatest element pops class PriorityQueue<T> where T : IComparable<T> { List<T> buf; public bool rev = false; public PriorityQueue() { buf = new List<T>(); } int cmp(int i, int j) => buf[i].CompareTo(buf[j]) * (rev ? -1 : 1); void swap(int i, int j) { var t = buf[i]; buf[i] = buf[j]; buf[j] = t; } public void Push(T elem) { int n = buf.Count; buf.Add(elem); while (n > 0) { int i = (n - 1) >> 1; if (cmp(n, i) > 0) swap(i, n); n = i; } } public T Pop() { T ret = buf[0]; int n = buf.Count - 1; buf[0] = buf[n]; buf.RemoveAt(n); for (int i = 0, j; (j = (i << 1) + 1) < n; i = j) { if (j != n - 1 && cmp(j, j + 1) < 0) ++j; if (cmp(i, j) < 0) swap(i, j); } return ret; } public T Top => buf[0]; public int Count => buf.Count; }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const int M2 = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; var a = sc.IntArr; var b = new int[n]; for (int i = 0; i < n; i++) { b[i] = Math.Min(a[i], n + 9); } int ng = 0, ok = n; while (ng + 1 < ok) { int m = (ng + ok) / 2; bool f = true; var cnt = new int[n + 10]; var q = new PriorityQueue<int>() { rev = true }; var nz = new bool[n + 10]; for (int i = 1; i < n; i++) { if (a[i - 1] < a[i]) continue; int k = n + 9 - b[i]; while (q.Count > 0) { if (q.Top < k) { cnt[q.Top] = 0; nz[q.Top] = false; q.Pop(); } else break; } ++cnt[k]; if (!nz[k]) { nz[k] = true; q.Push(k); } for (int j = k; j < n + 9; j++) { if (cnt[j] >= m) { cnt[j] -= m; if (cnt[j] == 0) nz[j] = false; ++cnt[j + 1]; if (!nz[j + 1]) { nz[j + 1] = true; q.Push(j + 1); } } else break; } if (cnt[n + 9] > 0) { f = false; break; } } if (f) ok = m; else ng = m; } Prt(ok); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P { get { int a, b; Multi(out a, out b); return new P(a, b); } } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } // the greatest element pops class PriorityQueue<T> where T : IComparable<T> { List<T> buf; public bool rev = false; public PriorityQueue() { buf = new List<T>(); } int cmp(int i, int j) => buf[i].CompareTo(buf[j]) * (rev ? -1 : 1); void swap(int i, int j) { var t = buf[i]; buf[i] = buf[j]; buf[j] = t; } public void Push(T elem) { int n = buf.Count; buf.Add(elem); while (n > 0) { int i = (n - 1) >> 1; if (cmp(n, i) > 0) swap(i, n); n = i; } } public T Pop() { T ret = buf[0]; int n = buf.Count - 1; buf[0] = buf[n]; buf.RemoveAt(n); for (int i = 0, j; (j = (i << 1) + 1) < n; i = j) { if (j != n - 1 && cmp(j, j + 1) < 0) ++j; if (cmp(i, j) < 0) swap(i, j); } return ret; } public T Top => buf[0]; public int Count => buf.Count; }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 111], ["+", 8, 196, 0, 57, 15, 241, 0, 204, 205, 22], ["+", 0, 57, 15, 241, 0, 204, 206, 207, 0, 70], ["+", 15, 241, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 241, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
2,554
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { string D; D = Console.ReadLine(); if (D[1] == 5) Console.WriteLine("Christmas"); else if (D[1] == 4) Console.WriteLine("Christmas Eve"); else if (D[1] == 3) Console.WriteLine("Christmas Eve Eve"); else Console.WriteLine("Christmas Eve Eve Eve"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { int D; D = int.Parse(Console.ReadLine()); if (D == 25) Console.WriteLine("Christmas"); else if (D == 24) Console.WriteLine("Christmas Eve"); else if (D == 23) Console.WriteLine("Christmas Eve Eve"); else Console.WriteLine("Christmas Eve Eve Eve"); Console.ReadKey(); } } }
[["-", 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, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 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, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203]]
8
129
22
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { string D; string s; D = Console.ReadLine(); if (D == "25") { s = "Christmas"; Console.Write(s); } else if (D == "24") { s = "Christmas Eve"; Console.Write(s); } else if (D == "23") { s = "Christmas Eve Eve"; Console.Write(s); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115 { class Program { static void Main(string[] args) { string D; string s; D = Console.ReadLine(); if (D == "25") { s = "Christmas"; Console.Write(s); } else if (D == "24") { s = "Christmas Eve"; Console.Write(s); } else if (D == "23") { s = "Christmas Eve Eve"; Console.Write(s); } else if (D == "22") { s = "Christmas Eve Eve Eve"; Console.Write(s); } Console.ReadKey(); } } }
[["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 95], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 75, 57, 75, 57, 15, 16, 12, 5, 0, 62], ["+", 75, 57, 75, 57, 15, 16, 12, 5, 0, 222], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
8
137
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115A { class Program { static void Main(string[] args) { int D; D = int.Parse(Console.ReadLine()); if (D == 25) Console.WriteLine("Christmas"); else if (D == 24) Console.WriteLine("Christmas Eve"); else Console.WriteLine("Christmas Eve Eve"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115A { class Program { static void Main(string[] args) { int D; D = int.Parse(Console.ReadLine()); if (D == 25) Console.WriteLine("Christmas"); else if (D == 24) Console.WriteLine("Christmas Eve"); else if (D == 23) Console.WriteLine("Christmas Eve Eve"); else Console.WriteLine("Christmas Eve Eve Eve"); Console.ReadKey(); } } }
[["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
109
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115B { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = new int[10]; int s = 0; a[0] = int.Parse(Console.ReadLine()); int b = a[0]; s += a[0]; for (int i = 1; i <= n - 1; i++) { a[i] = int.Parse(Console.ReadLine()); s += a[i]; if (a[i - 1] <= a[i]) b = a[i]; } if (b < a[0]) b = a[0]; s = s - b / 2; Console.WriteLine(s = b / 2); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC115B { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = new int[10]; int s = 0; a[0] = int.Parse(Console.ReadLine()); int b = a[0]; s += a[0]; for (int i = 1; i <= n - 1; i++) { a[i] = int.Parse(Console.ReadLine()); s += a[i]; if (b <= a[i]) { b = a[i]; } } if (b < a[0]) b = a[0]; s = s - b / 2; Console.WriteLine(s); Console.ReadKey(); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 3, 4, 0, 28, 0, 11, 0, 202, 0, 32], ["-", 3, 4, 0, 28, 0, 11, 12, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 11, 12, 16, 17, 85], ["-", 3, 4, 0, 28, 0, 11, 12, 16, 12, 203]]
8
210
13
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string input = Console.ReadLine(); int num = int.Parse(input); Console.WriteLine(num); var valueList = new List<int>(); for (int i = 0; i < num; i++) { string value = Console.ReadLine(); ; valueList.Add(int.Parse(value)); } int total = 0; int max = valueList.Max(); foreach (var v in valueList) { total += v; } total = total - max + max / 2; Console.WriteLine(total); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { string input = Console.ReadLine(); int num = int.Parse(input); var valueList = new List<int>(); for (int i = 0; i < num; i++) { string value = Console.ReadLine(); ; valueList.Add(int.Parse(value)); } int total = 0; int max = valueList.Max(); foreach (var v in valueList) { total += v; } total = total - max + max / 2; Console.WriteLine(total); } }
[["-", 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
149
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { int nums = int.Parse(Console.ReadLine()); List<int> dsf = new List<int>(); for (int i = 0; i < nums; i++) { dsf.Add(int.Parse(Console.ReadLine())); } int max = 0; for (int i = 0; i < nums; i++) { max = (max > dsf[i]) ? max : dsf[i]; } int re = 0; foreach (int i in dsf) { if (i != max) { re += i; } else { re += i / 2; } } Console.WriteLine(re); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { int nums = int.Parse(Console.ReadLine()); List<int> dsf = new List<int>(); for (int i = 0; i < nums; i++) { dsf.Add(int.Parse(Console.ReadLine())); } int max = 0; for (int i = 0; i < nums; i++) { max = (max > dsf[i]) ? max : dsf[i]; } int re = 0; bool fl = true; foreach (int i in dsf) { if (i != max || !fl) { re += i; } else { re += i / 2; fl = false; } } Console.WriteLine(re); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 111], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 211, 0, 147]]
8
187
12
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var s = input.ReadLine(); var min = long.MaxValue; for (int i = 0; i < s.Length; i++) { for (int j = i; j < s.Length; j++) { var ss = long.Parse(s.Substring(i, j - i + 1)); min = Math.Min(min, Math.Abs(ss - 753L)); } } return min; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var s = input.ReadLine(); var min = long.MaxValue; for (int i = 0; i < s.Length - 2; i++) { var ss = long.Parse(s.Substring(i, 3)); min = Math.Min(min, Math.Abs(ss - 753L)); } return min; } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 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, 22], ["-", 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], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["-", 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, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
8
218
26
using System; class B { public static void Main() { var a = Console.ReadLine(); var ans = 1000; Console.WriteLine(); for (int i = a.Length - 3; i >= 0; i--) { var dif = Math.Abs( int.Parse(string.Format("{0}{1}{2}", a[i], a[i + 1], a[i + 2])) - 753); if (dif < ans) ans = dif; } } }
using System; class B { public static void Main() { var a = Console.ReadLine(); var ans = 1000; for (int i = a.Length - 3; i >= 0; i--) { var dif = Math.Abs( int.Parse(string.Format("{0}{1}{2}", a[i], a[i + 1], a[i + 2])) - 753); if (dif < ans) ans = dif; } 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], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 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
108
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string s = ReadLine(); int candInd; int mindelta = 1000; for (int i = 0; i <= s.Length - 3; i++) { string tmp = ""; for (int j = i; j < i + 3; j++) tmp += s[j]; int d = 753 - int.Parse(tmp); if (mindelta > d) { mindelta = d; candInd = i; } } WriteLine(mindelta); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string s = ReadLine(); int candInd; int mindelta = 1000; for (int i = 0; i <= s.Length - 3; i++) { string tmp = ""; for (int j = i; j < i + 3; j++) tmp += s[j]; int d = 753 - int.Parse(tmp); d = Math.Abs(d); if (mindelta > d) { mindelta = d; candInd = i; } } WriteLine(mindelta); } } }
[["+", 0, 7, 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, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
149
9
// C# program to build the smallest number // by removing n digits from a given number using System; using System.Collections.Generic; using System.Linq; class GFG { static List<string> list = new List<string>(new string[] { "7", "5", "3" }); public static void Main(String[] args) { ////var t = int.Parse(Console.ReadLine()); ////while (t > 0) //{ // var input = Console.ReadLine().Split(' '); // var n = int.Parse(input[0]); // var k = int.Parse(input[1]); // List<int> coll = new List<int>(); // for (int i = 0; i < n; i++) // { // coll.Add(int.Parse(Console.ReadLine())); // } // // var arr = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); // // MAXXor(n, k, arr); // ChrimasEve(n, k, coll); Solve(long.Parse(Console.ReadLine())); } static long Solve(long n) { return DFS("", n); } public static long DFS(string s, long n) { long res = 0; if (!string.IsNullOrEmpty(s)) { if (Sheck(s, n)) { res++; } else if (long.Parse(s) > n) return 0; } foreach (var next in list) { res += DFS(s + next, n); } return res; } private static bool Sheck(string s, long n) { long sl = long.Parse(s); if (sl > n) { return false; } if (!s.Contains("3") || !s.Contains("5") || !s.Contains("7")) { return false; } return true; } }
// C# program to build the smallest number // by removing n digits from a given number using System; using System.Collections.Generic; using System.Linq; class GFG { static List<string> list = new List<string>(new string[] { "7", "5", "3" }); public static void Main(String[] args) { ////var t = int.Parse(Console.ReadLine()); ////while (t > 0) //{ // var input = Console.ReadLine().Split(' '); // var n = int.Parse(input[0]); // var k = int.Parse(input[1]); // List<int> coll = new List<int>(); // for (int i = 0; i < n; i++) // { // coll.Add(int.Parse(Console.ReadLine())); // } // // var arr = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); // // MAXXor(n, k, arr); // ChrimasEve(n, k, coll); Console.WriteLine(Solve(long.Parse(Console.ReadLine()))); Console.WriteLine(); } static long Solve(long n) { return DFS("", n); } public static long DFS(string s, long n) { long res = 0; if (!string.IsNullOrEmpty(s)) { if (Sheck(s, n)) { res++; } else if (long.Parse(s) > n) return 0; } foreach (var next in list) { res += DFS(s + next, n); } return res; } private static bool Sheck(string s, long n) { long sl = long.Parse(s); if (sl > n) { return false; } if (!s.Contains("3") || !s.Contains("5") || !s.Contains("7")) { return false; } return true; } }
[["+", 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, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
268
11
#if DEBUG using Microsoft.VisualStudio.TestTools.UnitTesting; #endif using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; // cannot be used in GCJ using System.Text; using System.Threading.Tasks; namespace Contest { public class Program { public static IO.StreamScanner scanner = new IO.StreamScanner(Console.OpenStandardInput()); public static void Main() { var n = scanner.Long(); var ans = GetAns(n); IO.Printer.Out.Flush(); } public static int GetAns(long n) { var ret = 0; GetAns(ref ret, n, 0L, false, false, false); return ret; } public static void GetAns(ref int ret, long n, long val, bool seven, bool five, bool three) { if (val > n) return; if (seven && three && five) ret++; GetAns(ref ret, n, val * 10 + 7, seven || true, five, three); GetAns(ref ret, n, val * 10 + 5, seven, five || true, three); GetAns(ref ret, n, val * 10 + 3, seven, five, three || true); } } #if DEBUG [TestClass] public class Test { [TestMethod] public void Test1() { var n = 575; var exp = 4; var ans = Program.GetAns(n); Assert.AreEqual(exp, ans); } [TestMethod] public void Test2() { var n = 3600; var exp = 13; var ans = Program.GetAns(n); Assert.AreEqual(exp, ans); } [TestMethod] public void Test3() { var n = 999999999; var exp = 26484; var ans = Program.GetAns(n); Assert.AreEqual(exp, ans); } public static bool IsEq(IEnumerable<IEnumerable<int>> l1, IEnumerable<IEnumerable<int>> l2) { if (l1.Count() != l2.Count()) return false; for (int i = 0; i < l1.Count(); i++) { if (!IsEq(l1.ElementAt(i), l2.ElementAt(i))) return false; } return true; } public static bool IsEq(IEnumerable<int> l1, IEnumerable<int> l2) { if (l1.Count() != l2.Count()) return false; for (int i = 0; i < l1.Count(); i++) { if (l1.ElementAt(i) != l2.ElementAt(i)) return false; } return true; } public static bool IsEq(IEnumerable<double> l1, IEnumerable<double> l2) { if (l1.Count() != l2.Count()) return false; for (int i = 0; i < l1.Count(); i++) { if (!IsEq(l1.ElementAt(i), l2.ElementAt(i))) return false; } return true; } public static bool IsEq(IEnumerable<bool> l1, IEnumerable<bool> l2) { if (l1.Count() != l2.Count()) return false; for (int i = 0; i < l1.Count(); i++) { if (l1.ElementAt(i) != l2.ElementAt(i)) return false; } return true; } public static bool IsEq(double a, double b) { return Math.Abs(a - b) < 1E-5; } } #endif // Used in LeetCode public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode(int x) { val = x; } } public static class LeetCode { public static TreeNode ParseBinaryTree(string str) { var ar = str.Replace("[", "").Replace("]", "").Split(','); var nodes = new List<TreeNode>(); for (int i = 0; i < ar.Length; i++) { nodes.Add(ar[i] == "null" ? null : new TreeNode(int.Parse(ar[i]))); var parent = (i + 1) / 2 - 1; // if the node class parent property // if(parent >= 0) //{ // nodes.Last().Parent = nodes[parent]; //} } for (int i = 0; i < nodes.Count(); i++) { var l = (i + 1) * 2 - 1; var r = (i + 1) * 2; if (l >= 0 && l < nodes.Count() && nodes[i] != null) nodes[i].left = nodes[l]; if (r >= 0 && r < nodes.Count() && nodes[i] != null) nodes[i].right = nodes[r]; } return nodes.First(); } public static IList<IList<int>> ParseLLI(string str) { var ret = new List<IList<int>>(); var split = str.Split(']'); foreach (var s in split) { var v = s.Replace(",[", "").Replace(", [", "").Replace("[", ""); if (string.IsNullOrWhiteSpace(v)) { ret.Add(new List<int>()); continue; } ret.Add(v.Split(',').Select(i => int.Parse(i)).ToList()); } return (IList<IList<int>>)ret; } public static IList<int> ParseLI(string str) { str = str.Replace("[", "").Replace("]", ""); return str.Split(',').Select(v => int.Parse(v)).ToList(); } } namespace IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } }
#if DEBUG using Microsoft.VisualStudio.TestTools.UnitTesting; #endif using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; // cannot be used in GCJ using System.Text; using System.Threading.Tasks; namespace Contest { public class Program { public static IO.StreamScanner scanner = new IO.StreamScanner(Console.OpenStandardInput()); public static void Main() { var n = scanner.Long(); var ans = GetAns(n); IO.Printer.Out.WriteLine(ans); IO.Printer.Out.Flush(); } public static int GetAns(long n) { var ret = 0; GetAns(ref ret, n, 0L, false, false, false); return ret; } public static void GetAns(ref int ret, long n, long val, bool seven, bool five, bool three) { if (val > n) return; if (seven && three && five) ret++; GetAns(ref ret, n, val * 10 + 7, seven || true, five, three); GetAns(ref ret, n, val * 10 + 5, seven, five || true, three); GetAns(ref ret, n, val * 10 + 3, seven, five, three || true); } } #if DEBUG [TestClass] public class Test { [TestMethod] public void Test1() { var n = 575; var exp = 4; var ans = Program.GetAns(n); Assert.AreEqual(exp, ans); } [TestMethod] public void Test2() { var n = 3600; var exp = 13; var ans = Program.GetAns(n); Assert.AreEqual(exp, ans); } [TestMethod] public void Test3() { var n = 999999999; var exp = 26484; var ans = Program.GetAns(n); Assert.AreEqual(exp, ans); } public static bool IsEq(IEnumerable<IEnumerable<int>> l1, IEnumerable<IEnumerable<int>> l2) { if (l1.Count() != l2.Count()) return false; for (int i = 0; i < l1.Count(); i++) { if (!IsEq(l1.ElementAt(i), l2.ElementAt(i))) return false; } return true; } public static bool IsEq(IEnumerable<int> l1, IEnumerable<int> l2) { if (l1.Count() != l2.Count()) return false; for (int i = 0; i < l1.Count(); i++) { if (l1.ElementAt(i) != l2.ElementAt(i)) return false; } return true; } public static bool IsEq(IEnumerable<double> l1, IEnumerable<double> l2) { if (l1.Count() != l2.Count()) return false; for (int i = 0; i < l1.Count(); i++) { if (!IsEq(l1.ElementAt(i), l2.ElementAt(i))) return false; } return true; } public static bool IsEq(IEnumerable<bool> l1, IEnumerable<bool> l2) { if (l1.Count() != l2.Count()) return false; for (int i = 0; i < l1.Count(); i++) { if (l1.ElementAt(i) != l2.ElementAt(i)) return false; } return true; } public static bool IsEq(double a, double b) { return Math.Abs(a - b) < 1E-5; } } #endif // Used in LeetCode public class TreeNode { public int val; public TreeNode left; public TreeNode right; public TreeNode(int x) { val = x; } } public static class LeetCode { public static TreeNode ParseBinaryTree(string str) { var ar = str.Replace("[", "").Replace("]", "").Split(','); var nodes = new List<TreeNode>(); for (int i = 0; i < ar.Length; i++) { nodes.Add(ar[i] == "null" ? null : new TreeNode(int.Parse(ar[i]))); var parent = (i + 1) / 2 - 1; // if the node class parent property // if(parent >= 0) //{ // nodes.Last().Parent = nodes[parent]; //} } for (int i = 0; i < nodes.Count(); i++) { var l = (i + 1) * 2 - 1; var r = (i + 1) * 2; if (l >= 0 && l < nodes.Count() && nodes[i] != null) nodes[i].left = nodes[l]; if (r >= 0 && r < nodes.Count() && nodes[i] != null) nodes[i].right = nodes[r]; } return nodes.First(); } public static IList<IList<int>> ParseLLI(string str) { var ret = new List<IList<int>>(); var split = str.Split(']'); foreach (var s in split) { var v = s.Replace(",[", "").Replace(", [", "").Replace("[", ""); if (string.IsNullOrWhiteSpace(v)) { ret.Add(new List<int>()); continue; } ret.Add(v.Split(',').Select(i => int.Parse(i)).ToList()); } return (IList<IList<int>>)ret; } public static IList<int> ParseLI(string str) { str = str.Replace("[", "").Replace("]", ""); return str.Split(',').Select(v => int.Parse(v)).ToList(); } } namespace IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } }
[["+", 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, 213, 63, 214, 205, 214, 205, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 214, 205, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 214, 205, 214, 141, 22], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["+", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131]]
8
2,048
11
// Stack Over Flow Recursive using System; using System.Collections; using System.Collections.Generic; namespace Ccs { class Program { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); Program pr = new Program(); Queue<long> queue = new Queue<long>(); queue.Enqueue(0); long x = 0; int count = 0; while (x <= n) { x = queue.Dequeue(); if (pr.Is_sgs(x)) { count++; // Console.WriteLine(x); } for (int i = 3; i <= 7; i += 2) queue.Enqueue(x * 10 + i); // if (queue.Count>0) } Console.WriteLine(count); // var pr = new Program(); // Console.WriteLine(pr.Rec(0,n)); } private const String sgs = "357"; private bool Is_sgs(String s) { bool is_sgs_ = true; for (int i = 0; i < sgs.Length; ++i) is_sgs_ &= s.Contains(sgs[i].ToString()); return is_sgs_; } private bool Is_sgs(long n) { return this.Is_sgs(n.ToString()); } /* private long Rec(int x, int n) { // var x = int.Parse(s); if (n < x) return 0; // if (Is_sgs(x)) // Console.WriteLine(x); long ret = Is_sgs(x) ? 1 : 0; foreach ( char c in sgs) ret += Rec(x * 10 + int.Parse( c.ToString() ), n); return ret; } */ } }
// Stack Over Flow Recursive using System; using System.Collections; using System.Collections.Generic; namespace Ccs { class Program { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); Program pr = new Program(); Queue<long> queue = new Queue<long>(); // queue.Enqueue(0); long x = 0; int count = 0; while (x <= n) { if (pr.Is_sgs(x)) { count++; // Console.WriteLine(x); } for (int i = 3; i <= 7; i += 2) queue.Enqueue(x * 10 + i); x = queue.Dequeue(); // if (queue.Count>0) } Console.WriteLine(count); // var pr = new Program(); // Console.WriteLine(pr.Rec(0,n)); } private const String sgs = "357"; private bool Is_sgs(String s) { bool is_sgs_ = true; for (int i = 0; i < sgs.Length; ++i) is_sgs_ &= s.Contains(sgs[i].ToString()); return is_sgs_; } private bool Is_sgs(long n) { return this.Is_sgs(n.ToString()); } /* private long Rec(int x, int n) { // var x = int.Parse(s); if (n < x) return 0; // if (Is_sgs(x)) // Console.WriteLine(x); long ret = Is_sgs(x) ? 1 : 0; foreach ( char c in sgs) ret += Rec(x * 10 + int.Parse( c.ToString() ), n); return ret; } */ } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 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, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 52, 8, 196, 0, 7, 8, 1, 0, 35], ["+", 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, 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]]
8
235
23
using System; using System.Linq; using System.Collections.Generic; namespace Atcoder { class Program2 { public static void Main(string[] args) { long N = int.Parse(Console.ReadLine()); List<long> list = new List<long>(); bool aSign = false; bool bSign = false; bool cSign = false; bool dSign = false; bool eSign = false; bool fSign = false; for (int a = first(aSign); a < 8; a = Generatei(a)) { for (int b = first(bSign); b < 8; b = Generatei(b)) { for (int c = first(cSign); c < 8; c = Generatei(c)) { for (int d = first(dSign); d < 8; d = Generatei(d)) { for (int e = first(eSign); e < 8; e = Generatei(e)) { for (int f = first(fSign); f < 8; f = Generatei(f)) { for (int g = 3; g < 8; g = Generatei(g)) { for (int h = 3; h < 8; h = Generatei(h)) { for (int i = 3; i < 8; i = Generatei(i)) { long judgedNumber = a * 100000000 + b * 10000000 + c * 1000000 + d * 100000 + e * 10000 + f * 1000 + g * 100 + h * 10 + i; if (Judge(judgedNumber)) { list.Add(judgedNumber); } } } } fSign = true; } eSign = true; } dSign = true; } cSign = true; } bSign = true; } aSign = true; } int count = 0; while (list[count] <= N && count < list.Count) { count++; } Console.WriteLine(count); } public static int first(bool sign) { if (sign == true) { return 3; } else { return 0; } } public static int Generatei(int i) { if (i == 0) { return 3; } else if (i == 3) { return 5; } else if (i == 5) { return 7; } else if (i == 7) { return 8; } return 0; } public static bool Judge(long b) { bool is3appear = false; bool is5appear = false; bool is7appear = false; for (int j = 0; j < b.ToString().Length; j++) { int a = int.Parse(b.ToString().Substring(j, 1)); if (a == 3) { is3appear = true; } else if (a == 5) { is5appear = true; } else if (a == 7) { is7appear = true; } } if (is3appear == true && is5appear == true && is7appear == true) { return true; } else { return false; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Atcoder { class Program2 { public static void Main(string[] args) { long N = int.Parse(Console.ReadLine()); List<long> list = new List<long>(); bool aSign = false; bool bSign = false; bool cSign = false; bool dSign = false; bool eSign = false; bool fSign = false; for (int a = first(aSign); a < 8; a = Generatei(a)) { for (int b = first(bSign); b < 8; b = Generatei(b)) { for (int c = first(cSign); c < 8; c = Generatei(c)) { for (int d = first(dSign); d < 8; d = Generatei(d)) { for (int e = first(eSign); e < 8; e = Generatei(e)) { for (int f = first(fSign); f < 8; f = Generatei(f)) { for (int g = 3; g < 8; g = Generatei(g)) { for (int h = 3; h < 8; h = Generatei(h)) { for (int i = 3; i < 8; i = Generatei(i)) { long judgedNumber = a * 100000000 + b * 10000000 + c * 1000000 + d * 100000 + e * 10000 + f * 1000 + g * 100 + h * 10 + i; if (Judge(judgedNumber)) { list.Add(judgedNumber); } } } } fSign = true; } eSign = true; } dSign = true; } cSign = true; } bSign = true; } aSign = true; } int count = 0; while (count < list.Count && list[count] <= N) { count++; } Console.WriteLine(count); } public static int first(bool sign) { if (sign == true) { return 3; } else { return 0; } } public static int Generatei(int i) { if (i == 0) { return 3; } else if (i == 3) { return 5; } else if (i == 5) { return 7; } else if (i == 7) { return 8; } return 0; } public static bool Judge(long b) { bool is3appear = false; bool is5appear = false; bool is7appear = false; for (int j = 0; j < b.ToString().Length; j++) { int a = int.Parse(b.ToString().Substring(j, 1)); if (a == 3) { is3appear = true; } else if (a == 5) { is5appear = true; } else if (a == 7) { is7appear = true; } } if (is3appear == true && is5appear == true && is7appear == true) { return true; } else { return false; } } } }
[["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 18], ["+", 0, 52, 15, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 52, 15, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 52, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 17, 18], ["-", 0, 52, 15, 16, 12, 16, 12, 214, 205, 22], ["-", 0, 52, 15, 16, 12, 16, 12, 214, 0, 131], ["-", 0, 52, 15, 16, 12, 16, 12, 214, 141, 22]]
8
618
12
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var PF = new int[101]; for (int i = 2; i <= N; i++) { foreach (var item in PrimeFactors(i)) { PF[item]++; } } // 75 = 5 * 5 * 3 // = 25 * 3 // = 15 * 5 PF = PF.Where(x => x >= 2).OrderBy(x => x).ToArray(); var ans = 0; for (int i = 0; i < PF.Length; i++) { // 3個 for (int j = 0; j < PF.Length; j++) { // 5個 if (j == i) continue; if (PF[j] < 4) continue; for (int k = j + 1; k < PF.Length; k++) { // 5個 if (k == i || k == j) continue; if (PF[k] < 4) continue; ans++; } } } var ans2 = (PF.Count() - 1) * PF.Count(x => x >= 24); PF = PF.Where(x => x >= 4).ToArray(); var ans3 = 0; ans3 = (PF.Count() - 1) * PF.Count(x => x >= 14); Console.WriteLine(ans + ans2 + ans3); } static List<long> PrimeFactors(long n) { var res = new List<long>(); var tmp = n; for (long x = 2; x * x <= n; x++) { while (tmp % x == 0) { tmp /= x; res.Add(x); } } if (tmp != 1) res.Add(tmp); return res; } static int MOD = (int)1e9 + 7; static int INF = (int)1e7 + 1; static long LINF = (long)1e13 + 1; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class Debug { public static void Dump<T>(T[,] array) { #if !DEBUG return; #endif Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { #if !DEBUG return; #endif Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var PF = new int[101]; for (int i = 2; i <= N; i++) { foreach (var item in PrimeFactors(i)) { PF[item]++; } } // 75 = 5 * 5 * 3 // = 25 * 3 // = 15 * 5 // = 75 PF = PF.Where(x => x >= 2).OrderBy(x => x).ToArray(); var ans = 0; for (int i = 0; i < PF.Length; i++) { // 3個 for (int j = 0; j < PF.Length; j++) { // 5個 if (j == i) continue; if (PF[j] < 4) continue; for (int k = j + 1; k < PF.Length; k++) { // 5個 if (k == i || k == j) continue; if (PF[k] < 4) continue; ans++; } } } // 25, 3 ans += (PF.Count() - 1) * PF.Count(x => x >= 24); PF = PF.Where(x => x >= 4).ToArray(); // 15, 5 ans += (PF.Count() - 1) * PF.Count(x => x >= 14); // 75 ans += PF.Count(x => x >= 74); Console.WriteLine(ans); } static List<long> PrimeFactors(long n) { var res = new List<long>(); var tmp = n; for (long x = 2; x * x <= n; x++) { while (tmp % x == 0) { tmp /= x; res.Add(x); } } if (tmp != 1) res.Add(tmp); return res; } static int MOD = (int)1e9 + 7; static int INF = (int)1e7 + 1; static long LINF = (long)1e13 + 1; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class Debug { public static void Dump<T>(T[,] array) { #if !DEBUG return; #endif Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { #if !DEBUG return; #endif Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } }
[["-", 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, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 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, 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, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 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], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
1,097
31
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace kyoupuro1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var ps = GetPNLs(N); var sisuu = new int[ps.Count()]; for (int m = 1; m <= N; m++) { for (int i = 0; i < ps.Count; i++) { sisuu[i] += E(ps[i], m); } } int dob = sisuu.Count(x => x >= 2); int f = sisuu.Count(x => x >= 4); int ft = sisuu.Count(x => x >= 14); int tf = sisuu.Count(x => x >= 24); int sf = sisuu.Count(x => x >= 74); int res = C(f, 2) * A(dob - 2) + tf * A(dob - 1) + sf + ft * A(f - 1); Console.WriteLine(res); } static int A(int x) { if (x < 0) return 0; else return x; } static List<int> GetPNLs(int max) { List<int> prime = new List<int>(); if (max <= 1) return null; for (int i = 2; i <= max; i++) { bool isPrime = true; foreach (var p in prime) { if (i % p == 0 && i != p) { isPrime = false; break; } } if (isPrime) prime.Add(i); } return prime; } static int E(int prime, int n) { int k = n; int c = 0; while (k % prime == 0) { k = k / prime; c++; } return c; } static int C(int a, int b) { if (a < b) return 0; return F(a) / (F(b) * F(a - b)); } static int F(int n) { if (n > 1) return F(n - 1) * n; else return 1; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace kyoupuro1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var ps = GetPNLs(N); var sisuu = new int[ps.Count()]; for (int m = 1; m <= N; m++) { for (int i = 0; i < ps.Count; i++) { sisuu[i] += E(ps[i], m); } } int dob = sisuu.Count(x => x >= 2); int f = sisuu.Count(x => x >= 4); int ft = sisuu.Count(x => x >= 14); int tf = sisuu.Count(x => x >= 24); int sf = sisuu.Count(x => x >= 74); int res = C(f, 2) * A(dob - 2) + tf * A(dob - 1) + sf + ft * A(f - 1); Console.WriteLine(res); } static int A(int x) { if (x < 0) return 0; else return x; } static List<int> GetPNLs(int max) { List<int> prime = new List<int>(); if (max <= 1) return new List<int> { 2 }; for (int i = 2; i <= max; i++) { bool isPrime = true; foreach (var p in prime) { if (i % p == 0 && i != p) { isPrime = false; break; } } if (isPrime) prime.Add(i); } return prime; } static int E(int prime, int n) { int k = n; int c = 0; while (k % prime == 0) { k = k / prime; c++; } return c; } static int C(int a, int b) { if (a < b) return 0; return F(a) / (F(b) * F(a - b)); } static int F(int n) { if (n > 1) return F(n - 1) * n; else return 1; } } }
[["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 215], ["+", 8, 196, 0, 57, 64, 37, 0, 230, 0, 228], ["+", 0, 57, 64, 37, 0, 230, 39, 236, 141, 22], ["+", 64, 37, 0, 230, 39, 236, 237, 238, 0, 18], ["+", 64, 37, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 64, 37, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 57, 64, 37, 0, 230, 10, 229, 0, 45], ["+", 0, 57, 64, 37, 0, 230, 10, 229, 0, 203], ["+", 0, 57, 64, 37, 0, 230, 10, 229, 0, 46]]
8
479
9
using System; public class AtCoder { public static void Main() { int[] p = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; int n; n = int.Parse(Console.ReadLine().Trim()); int[] q = new int[25]; int d; int[] x = new int[5]; int[] div = { 2, 4, 14, 24, 74 }; for (int i = 1; i <= n; i++) { d = i; for (int j = 0; j < 25; j++) { while (d % p[j] == 0) { d /= p[j]; q[j]++; } } } for (int i = 0; i < 25; i++) { for (int j = 0; j < 5; j++) { if (q[i] >= div[j]) x[j]++; } } int ans = 0; ans += x[0] * x[1] * (x[1] - 1) / 2; ans += x[0] * x[3]; ans += x[1] * x[2]; ans += x[4]; Console.WriteLine(ans); } }
using System; public class AtCoder { public static void Main() { int[] p = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; int n; n = int.Parse(Console.ReadLine().Trim()); int[] q = new int[25]; int d; int[] x = new int[5]; int[] div = { 2, 4, 14, 24, 74 }; for (int i = 1; i <= n; i++) { d = i; for (int j = 0; j < 25; j++) { while (d % p[j] == 0) { d /= p[j]; q[j]++; } } } for (int i = 0; i < 25; i++) { for (int j = 0; j < 5; j++) { if (q[i] >= div[j]) x[j]++; } } int ans = 0; ans += (x[0] - 2) * x[1] * (x[1] - 1) / 2; ans += (x[0] - 1) * x[3]; ans += (x[1] - 1) * x[2]; ans += x[4]; Console.WriteLine(ans); } }
[["+", 12, 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], ["+", 12, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
8
313
12
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var p = GeneratePrime(n / 2); var a = new int[p.Count()]; for (int i = 2; i <= n; i++) getA(a, p, i); var ans = getAns(a); Console.WriteLine(ans); } static int getAns(int[] a) { var k = new int[] { 2, 4, 14, 24, 74 }; var d = new Dictionary<int, int>(); foreach (var x in k) d[x] = 0; foreach (var x in a) foreach (var y in k) if (x >= y) d[y]++; var a1 = d[74]; var a2 = d[24] * (d[2] - 1); var a3 = d[14] * (d[4] - 1); var a4 = d[4] * (d[4] - 1) / 2 * (d[2] - 2); return a1 + a2 + a3 + a4; } static void getA(int[] a, List<int> p, int t) { var tp = t; var pc = p.Count(); for (int i = 0; i < pc; i++) { if (p[i] > t) break; while (true) if (tp % p[i] == 0) { tp /= p[i]; a[i]++; } else break; } } public static List<int> GeneratePrime(int m) { var a = new List<int>(); int p; var sqrtMax = Math.Sqrt(m); var s = Enumerable.Range(2, m - 1).ToList(); do { p = s.First(); a.Add(p); s.RemoveAll(n => n % p == 0); } while (p < sqrtMax); a.AddRange(s); return a; } }
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); if (n <= 4) { Console.WriteLine(0); goto exit; } var p = GeneratePrime(n / 2); var a = new int[p.Count()]; for (int i = 2; i <= n; i++) getA(a, p, i); var ans = getAns(a); Console.WriteLine(ans); exit:; } static int getAns(int[] a) { var k = new int[] { 2, 4, 14, 24, 74 }; var d = new Dictionary<int, int>(); foreach (var x in k) d[x] = 0; foreach (var x in a) foreach (var y in k) if (x >= y) d[y]++; var a1 = d[74]; var a2 = d[24] * (d[2] - 1); var a3 = d[14] * (d[4] - 1); var a4 = d[4] * (d[4] - 1) / 2 * (d[2] - 2); return a1 + a2 + a3 + a4; } static void getA(int[] a, List<int> p, int t) { var tp = t; var pc = p.Count(); for (int i = 0; i < pc; i++) { if (p[i] > t) break; while (true) if (tp % p[i] == 0) { tp /= p[i]; a[i]++; } else break; } } public static List<int> GeneratePrime(int m) { var a = new List<int>(); int p; var sqrtMax = Math.Sqrt(m); var s = Enumerable.Range(2, m - 1).ToList(); do { p = s.First(); a.Add(p); s.RemoveAll(n => n % p == 0); } while (p < sqrtMax); a.AddRange(s); return a; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 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, 126, 0, 127], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 126, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 97, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 97, 0, 102]]
8
466
21
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; using static System.Console; using static System.Math; class Z { static void Main() => new K(); } class K { int F => int.Parse(Str); long FL => long.Parse(Str); int[] G => Strs.Select(int.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } int P; List<int> ps; void Solve() { var N = F; ps = GetPrimes(N); P = ps.Count; var fact = new Dictionary<int, int>(); for (var n = 2; n <= N; n++) fact = Multiply(fact, Factorize(n, ps)); var s = 0; foreach (var x in Calc1(74)) if (IsMultiple(fact, x)) s++; foreach (var x in Calc2(24, 2)) if (IsMultiple(fact, x)) s++; foreach (var x in Calc2(14, 4)) if (IsMultiple(fact, x)) s++; foreach (var x in Calc3(4, 2)) if (IsMultiple(fact, x)) s++; WriteLine(s); } IEnumerable<Dictionary<int, int>> Calc1(int e) { foreach (var p in ps) yield return new Dictionary<int, int> { [p] = e }; } IEnumerable<Dictionary<int, int>> Calc2(int e, int f) { foreach (var p in ps) foreach (var q in ps) if (p != q) yield return new Dictionary<int, int> { [p] = e, [q] = f }; } IEnumerable<Dictionary<int, int>> Calc3(int e, int f) { foreach (var p in ps) foreach (var q in ps) if (p < q) foreach (var r in ps) if (r != p && r != q) yield return new Dictionary<int, int> { [p] = e, [q] = e, [r] = f }; } public static List<int> GetPrimes(int n) { var m = (n - 1) >> 1; var ps = new List<int>((int)(n / Log(n))) { 2 }; var ng = new bool[m]; ng[0] = false; for (var p = 0; p < m; p++) if (!ng[p]) { var x = 2 * p + 3; ps.Add(x); for (var k = 3 * p + 3; k < m; k += x) ng[k] = true; } return ps; } public static Dictionary<int, int> Factorize(int n, List<int> primes) { var d = new Dictionary<int, int>(); for (var j = 0; j < primes.Count; j++) { var i = primes[j]; if (i * i > n) break; if (n % i == 0) { d.Add(i, 0); while (n % i == 0) { n /= i; d[i]++; } } } if (n > 1) d.Add(n, 1); return d; } public static Dictionary<int, int> Multiply(Dictionary<int, int> x, Dictionary<int, int> y) { var z = new Dictionary<int, int>(); foreach (var t in x) z[t.Key] = t.Value + (y.ContainsKey(t.Key) ? y[t.Key] : 0); foreach (var t in y) if (!x.ContainsKey(t.Key)) z[t.Key] = t.Value; return z; } public static bool IsMultiple(Dictionary<int, int> x, Dictionary<int, int> y) { foreach (var t in y) if (!x.ContainsKey(t.Key) || x[t.Key] < t.Value) return false; return true; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; using static System.Console; using static System.Math; class Z { static void Main() => new K(); } class K { int F => int.Parse(Str); long FL => long.Parse(Str); int[] G => Strs.Select(int.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } int P; List<int> ps; void Solve() { var N = F; if (N < 10) { WriteLine(0); return; } ps = GetPrimes(N); P = ps.Count; var fact = new Dictionary<int, int>(); for (var n = 2; n <= N; n++) fact = Multiply(fact, Factorize(n, ps)); var s = 0; foreach (var x in Calc1(74)) if (IsMultiple(fact, x)) s++; foreach (var x in Calc2(24, 2)) if (IsMultiple(fact, x)) s++; foreach (var x in Calc2(14, 4)) if (IsMultiple(fact, x)) s++; foreach (var x in Calc3(4, 2)) if (IsMultiple(fact, x)) s++; WriteLine(s); } IEnumerable<Dictionary<int, int>> Calc1(int e) { foreach (var p in ps) yield return new Dictionary<int, int> { [p] = e }; } IEnumerable<Dictionary<int, int>> Calc2(int e, int f) { foreach (var p in ps) foreach (var q in ps) if (p != q) yield return new Dictionary<int, int> { [p] = e, [q] = f }; } IEnumerable<Dictionary<int, int>> Calc3(int e, int f) { foreach (var p in ps) foreach (var q in ps) if (p < q) foreach (var r in ps) if (r != p && r != q) yield return new Dictionary<int, int> { [p] = e, [q] = e, [r] = f }; } public static List<int> GetPrimes(int n) { var m = (n - 1) >> 1; var ps = new List<int>((int)(n / Log(n))) { 2 }; var ng = new bool[m]; ng[0] = false; for (var p = 0; p < m; p++) if (!ng[p]) { var x = 2 * p + 3; ps.Add(x); for (var k = 3 * p + 3; k < m; k += x) ng[k] = true; } return ps; } public static Dictionary<int, int> Factorize(int n, List<int> primes) { var d = new Dictionary<int, int>(); for (var j = 0; j < primes.Count; j++) { var i = primes[j]; if (i * i > n) break; if (n % i == 0) { d.Add(i, 0); while (n % i == 0) { n /= i; d[i]++; } } } if (n > 1) d.Add(n, 1); return d; } public static Dictionary<int, int> Multiply(Dictionary<int, int> x, Dictionary<int, int> y) { var z = new Dictionary<int, int>(); foreach (var t in x) z[t.Key] = t.Value + (y.ContainsKey(t.Key) ? y[t.Key] : 0); foreach (var t in y) if (!x.ContainsKey(t.Key)) z[t.Key] = t.Value; return z; } public static bool IsMultiple(Dictionary<int, int> x, Dictionary<int, int> y) { foreach (var t in y) if (!x.ContainsKey(t.Key) || x[t.Key] < t.Value) return false; return true; } }
[["+", 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], ["+", 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
999
15
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) { int[] box = new int[100]; int N = int.Parse(Console.ReadLine()); ; for (int c = 2; c <= N; c++) { if (isPrime(c)) { box[c]++; continue; } else { int bigone = c; while (isPrime(bigone) == false) { int div = candivideby(bigone); box[div]++; bigone = bigone / div; } box[bigone]++; } }; int output = 0; // 75候補 List<int> upto74 = new List<int>(); List<int> upto24 = new List<int>(); List<int> upto14 = new List<int>(); List<int> upto4 = new List<int>(); List<int> upto2 = new List<int>(); for (int i = 0; i < 51; i++) { if (box[i] >= 74) upto74.Add(i); if (box[i] >= 24) upto24.Add(i); if (box[i] >= 14) upto14.Add(i); if (box[i] >= 4) upto4.Add(i); if (box[i] >= 2) upto2.Add(i); }; output = upto74.Count; for (int i = 0; i < upto24.Count; i++) { int choice = upto24[i]; for (int j = 0; j < upto2.Count; j++) { if (choice != upto2[j]) output++; } } for (int i = 0; i < upto14.Count; i++) { int choice = upto14[i]; for (int j = 0; j < upto4.Count; j++) { if (choice != upto4[j]) output++; } } for (int i = 0; i < upto2.Count; i++) { int choice = upto2[i]; int combination = upto4.Count; if (upto4.Contains(choice)) { combination--; } output += (combination) * (combination - 1) / 2; } ; } static int candivideby(int n) { int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; for (int i = 0; i < primes.Length; i++) { if (n % primes[i] == 0) return primes[i]; } return 1; } static bool isPrime(int n) { int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; if (primes.Contains(n)) return true; else return false; } } }
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) { int[] box = new int[100]; int N = int.Parse(Console.ReadLine()); ; for (int c = 2; c <= N; c++) { if (isPrime(c)) { box[c]++; continue; } else { int bigone = c; while (isPrime(bigone) == false) { int div = candivideby(bigone); box[div]++; bigone = bigone / div; } box[bigone]++; } }; int output = 0; // 75候補 List<int> upto74 = new List<int>(); List<int> upto24 = new List<int>(); List<int> upto14 = new List<int>(); List<int> upto4 = new List<int>(); List<int> upto2 = new List<int>(); for (int i = 0; i < 51; i++) { if (box[i] >= 74) upto74.Add(i); if (box[i] >= 24) upto24.Add(i); if (box[i] >= 14) upto14.Add(i); if (box[i] >= 4) upto4.Add(i); if (box[i] >= 2) upto2.Add(i); }; output = upto74.Count; for (int i = 0; i < upto24.Count; i++) { int choice = upto24[i]; for (int j = 0; j < upto2.Count; j++) { if (choice != upto2[j]) output++; } } for (int i = 0; i < upto14.Count; i++) { int choice = upto14[i]; for (int j = 0; j < upto4.Count; j++) { if (choice != upto4[j]) output++; } } for (int i = 0; i < upto2.Count; i++) { int choice = upto2[i]; int combination = upto4.Count; if (upto4.Contains(choice)) { combination--; } output += (combination) * (combination - 1) / 2; } ; Console.WriteLine(output); } static int candivideby(int n) { int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; for (int i = 0; i < primes.Length; i++) { if (n % primes[i] == 0) return primes[i]; } return 1; } static bool isPrime(int n) { int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; if (primes.Contains(n)) return true; else return false; } } }
[["+", 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
698
7
using System; public class AtCoder { public static void Main() { int n; n = int.Parse(Console.ReadLine().Trim()); string[] s; s = Console.ReadLine().Trim().Split(' '); int[] a = new int[n]; double avg = 0; for (int i = 0; i < n; i++) { a[i] = int.Parse(s[i]); avg = avg + a[i]; } avg = avg / n; double m, ans; m = 10000000; for (int i = 0; i < n; i++) { m = Math.Min(m, (double)Math.Abs(avg - a[i])); } ans = -1; int j = 0; while (ans == -1) { if (avg - a[j] == m) ans = j; j++; } Console.WriteLine(ans); } }
using System; public class AtCoder { public static void Main() { int n; n = int.Parse(Console.ReadLine().Trim()); string[] s; s = Console.ReadLine().Trim().Split(' '); int[] a = new int[n]; double avg = 0; for (int i = 0; i < n; i++) { a[i] = int.Parse(s[i]); avg = avg + a[i]; } avg = avg / n; double m, ans; m = 10000000; for (int i = 0; i < n; i++) { m = Math.Min(m, (double)Math.Abs(avg - a[i])); } ans = -1; int j = 0; while (ans == -1) { if ((double)Math.Abs(avg - a[j]) == m) ans = j; j++; } Console.WriteLine(ans); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 31, 74, 0, 25], ["+", 15, 16, 31, 74, 51, 213, 63, 214, 205, 22], ["+", 15, 16, 31, 74, 51, 213, 63, 214, 0, 131], ["+", 15, 16, 31, 74, 51, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 74, 51, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 74, 51, 213, 3, 4, 0, 25]]
8
215
8
using System; public class AtCoder { public static void Main() { int n; n = int.Parse(Console.ReadLine().Trim()); string[] s; s = Console.ReadLine().Trim().Split(' '); int[] a = new int[n]; int avg = 0; for (int i = 0; i < n; i++) { a[i] = n * int.Parse(s[i]); avg = avg + a[i]; } avg = avg / n; int m, k; int ans; m = 10000000; for (int i = 0; i < n; i++) { k = avg - a[i]; if (k < 0) k = -k; m = (int)Math.Min(m, k); } ans = -1; int j = 0; while (ans == -1) { if (avg - a[j] == m) ans = j; j++; } Console.WriteLine(ans); } }
using System; public class AtCoder { public static void Main() { int n; n = int.Parse(Console.ReadLine().Trim()); string[] s; s = Console.ReadLine().Trim().Split(' '); int[] a = new int[n]; int avg = 0; for (int i = 0; i < n; i++) { a[i] = n * int.Parse(s[i]); avg = avg + a[i]; } avg = avg / n; int m, k; int ans; m = 10000000; for (int i = 0; i < n; i++) { k = avg - a[i]; if (k < 0) k = -k; m = (int)Math.Min(m, k); } ans = -1; int j = 0; while (ans == -1) { k = avg - a[j]; if (k < 0) k = -k; if (k == m) ans = j; j++; } Console.WriteLine(ans); } }
[["-", 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, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 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, 18], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 52, 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, 241, 0, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 22], ["+", 0, 52, 8, 196, 0, 57, 64, 1, 0, 35]]
8
230
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); var flames = new List<int>(); foreach (var item in input) { flames.Add(int.Parse(item)); } var ave = flames.Average(); double? min = null; var flamePoint = 0; var i = 0; foreach (var flame in flames) { if (min == null) { min = Math.Abs(flame - ave); } else { if (Math.Abs(flame - ave) < min) { min = flame; flamePoint = i; } } i++; } Console.WriteLine(flamePoint); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); var flames = new List<double>(); foreach (var item in input) { flames.Add(double.Parse(item)); } var ave = flames.Average(); double? min = null; var flamePoint = 0; var i = 0; foreach (var flame in flames) { if (min == null) { min = Math.Abs(flame - ave); } else { if (Math.Abs(flame - ave) < min) { min = Math.Abs(flame - ave); flamePoint = i; } } i++; } Console.WriteLine(flamePoint); } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 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], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
197
11
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var num = ToInt32(ReadLine()); var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse); var ave = ar.Sum() / num; var min = int.MaxValue; var mini = -1; for (var i = 0; i < num; i++) { if (min > Abs(ave - ar[i])) { min = Abs(ave - ar[i]); mini = i; } } WriteLine(mini); } private const string ALFA = "abcdefghijklmnopqrstuvwxyz"; private const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var num = ToInt32(ReadLine()); var ar = Array.ConvertAll(ReadLine().Split(' '), double.Parse); var ave = (double)ar.Sum() / num; var min = 10000d; var mini = -1; for (var i = 0; i < num; i++) { if (min > Abs(ave - ar[i])) { min = Abs(ave - ar[i]); mini = i; } } WriteLine(mini); } private const string ALFA = "abcdefghijklmnopqrstuvwxyz"; private const int MOD = 1000000007; }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["-", 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, 197, 0, 198, 0, 200, 0, 212, 0, 250]]
8
174
9
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; public class Solver { public void Solve() { int n = ReadInt(); var a = ReadIntArray(); int s = a.Sum(); int x = 0; for (int i = 1; i < n; i++) { int d = Math.Abs(a[i] * n - s); if (d < Math.Abs(a[x] * n - s)) x = i; } Write(x); } #region Main protected static TextReader reader; protected static TextWriter writer; static void Main() { #if DEBUG reader = new StreamReader("..\\..\\input.txt"); // reader = new StreamReader(Console.OpenStandardInput()); writer = Console.Out; // writer = new StreamWriter("..\\..\\output.txt"); #else // reader = new StreamReader(Console.OpenStandardInput()); // writer = new StreamWriter(Console.OpenStandardOutput()); reader = new StreamReader("input.txt"); writer = new StreamWriter("output.txt"); #endif try { new Solver().Solve(); // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128); // thread.Start(); // thread.Join(); } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #else throw; #endif } reader.Close(); writer.Close(); } #endregion #region Read / Write private static Queue<string> currentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return reader.ReadLine().Split( new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static int[][] ReadAndTransposeIntMatrix(int numberOfRows) { int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][]; for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; } return ret; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); } public static void Write(params object[] array) { WriteArray(array); } public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); } private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue> { public new TValue this[TKey key] { get { return ContainsKey(key) ? base[key] : default(TValue); } set { base[key] = value; } } } private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; } #endregion }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; public class Solver { public void Solve() { int n = ReadInt(); var a = ReadIntArray(); int s = a.Sum(); int x = 0; for (int i = 1; i < n; i++) { int d = Math.Abs(a[i] * n - s); if (d < Math.Abs(a[x] * n - s)) x = i; } Write(x); } #region Main protected static TextReader reader; protected static TextWriter writer; static void Main() { #if DEBUG reader = new StreamReader("..\\..\\input.txt"); // reader = new StreamReader(Console.OpenStandardInput()); writer = Console.Out; // writer = new StreamWriter("..\\..\\output.txt"); #else reader = new StreamReader(Console.OpenStandardInput()); writer = new StreamWriter(Console.OpenStandardOutput()); // reader = new StreamReader("input.txt"); // writer = new StreamWriter("output.txt"); #endif try { new Solver().Solve(); // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128); // thread.Start(); // thread.Join(); } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #else throw; #endif } reader.Close(); writer.Close(); } #endregion #region Read / Write private static Queue<string> currentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return reader.ReadLine().Split( new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static int[][] ReadAndTransposeIntMatrix(int numberOfRows) { int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][]; for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; } return ret; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); } public static void Write(params object[] array) { WriteArray(array); } public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); } private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue> { public new TValue this[TKey key] { get { return ContainsKey(key) ? base[key] : default(TValue); } set { base[key] = value; } } } private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; } #endregion }
[["-", 12, 230, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 12, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24]]
8
909
16
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static Asakatsu20200325E.Input; namespace Asakatsu20200325E { static class Input { private static Func<string, T[]> Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray(); private static Func<string, T> Convert<T>() { Type t = typeof(T); if (t == typeof(string)) return _ => (T)(object)_; if (t == typeof(int)) return _ => (T)(object) int.Parse(_); if (t == typeof(long)) return _ => (T)(object) long.Parse(_); if (t == typeof(double)) return _ => (T)(object) double.Parse(_); if (t == typeof(string[])) return _ => (T)(object)_.Split(' '); if (t == typeof(int[])) return _ => (T)(object)Cast<int>()(_); if (t == typeof(long[])) return _ => (T)(object)Cast<long>()(_); if (t == typeof(double[])) return _ => (T)(object)Cast<double>()(_); throw new NotSupportedException(t + "is not supported."); } private static T Convert<T>(string s) => Convert<T>()(s); private static string String() => Console.ReadLine(); private static string[] String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToArray(); public static void Cin<T>(out T a) => a = Convert<T>(String()); public static void Cin<T1, T2>(out T1 a1, out T2 a2) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); } public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); } public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3, out T4 a4) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); } public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); set(v[4], out a5); } public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5, out T6 a6) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); set(v[4], out a5); set(v[5], out a6); } private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s); public static void Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray(); public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) { l1 = new T1[n]; l2 = new T2[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i]); } public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2, out T3[] l3) { l1 = new T1[n]; l2 = new T2[n]; l3 = new T3[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i]); } public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2, out T3[] l3, out T4[] l4) { l1 = new T1[n]; l2 = new T2[n]; l3 = new T3[n]; l4 = new T4[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i], out l4[i]); } public static void Cin<T>(out T[] a) => a = Convert<T[]>(String()); public static void Cin<T>(long h, out T[][] map) => map = String(h).Select(Convert<T[]>()).ToArray(); } class Program { public static void Main(string[] args) { StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); new Solver().Solve(); Console.Out.Flush(); } public static void Debug() { new Solver().Solve(); } } class Solver { private long N, K; private long[] A; public void Solve() { Cin(out N, out K); Cin(out A); long[] sum = new long[N + 1]; for (int i = 0; i < N; i++) { sum[i + 1] = sum[i] + A[i]; } List<long> l = new List<long>(); for (int i = 0; i <= N - 1; i++) { for (int j = i + 1; j <= N; j++) { l.Add(sum[j] - sum[i]); } } l.Sort(); l.Reverse(); long max = sum[N]; List<long> t = new List<long>(); long tt = 1; while (tt < max) { t.Add(tt); tt *= 2; } t.Reverse(); foreach (long t1 in t) { List<long> ok = new List<long>(); for (int i = 0; i < l.Count; i++) { if ((l[i] & t1) == t1) { ok.Add(l[i]); } } if (ok.Count >= K) l = ok; } long ans = max; for (int i = 0; i < K; i++) { ans = ans & l[i]; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static Asakatsu20200325E.Input; namespace Asakatsu20200325E { static class Input { private static Func<string, T[]> Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToArray(); private static Func<string, T> Convert<T>() { Type t = typeof(T); if (t == typeof(string)) return _ => (T)(object)_; if (t == typeof(int)) return _ => (T)(object) int.Parse(_); if (t == typeof(long)) return _ => (T)(object) long.Parse(_); if (t == typeof(double)) return _ => (T)(object) double.Parse(_); if (t == typeof(string[])) return _ => (T)(object)_.Split(' '); if (t == typeof(int[])) return _ => (T)(object)Cast<int>()(_); if (t == typeof(long[])) return _ => (T)(object)Cast<long>()(_); if (t == typeof(double[])) return _ => (T)(object)Cast<double>()(_); throw new NotSupportedException(t + "is not supported."); } private static T Convert<T>(string s) => Convert<T>()(s); private static string String() => Console.ReadLine(); private static string[] String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToArray(); public static void Cin<T>(out T a) => a = Convert<T>(String()); public static void Cin<T1, T2>(out T1 a1, out T2 a2) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); } public static void Cin<T1, T2, T3>(out T1 a1, out T2 a2, out T3 a3) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); } public static void Cin<T1, T2, T3, T4>(out T1 a1, out T2 a2, out T3 a3, out T4 a4) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); } public static void Cin<T1, T2, T3, T4, T5>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); set(v[4], out a5); } public static void Cin<T1, T2, T3, T4, T5, T6>(out T1 a1, out T2 a2, out T3 a3, out T4 a4, out T5 a5, out T6 a6) { var v = String().Split(' '); set(v[0], out a1); set(v[1], out a2); set(v[2], out a3); set(v[3], out a4); set(v[4], out a5); set(v[5], out a6); } private static void set<T1>(string s, out T1 o1) => o1 = Convert<T1>(s); public static void Cin<T>(long n, out T[] l) => l = String(n).Select(Convert<T>()).ToArray(); public static void Cin<T1, T2>(long n, out T1[] l1, out T2[] l2) { l1 = new T1[n]; l2 = new T2[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i]); } public static void Cin<T1, T2, T3>(long n, out T1[] l1, out T2[] l2, out T3[] l3) { l1 = new T1[n]; l2 = new T2[n]; l3 = new T3[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i]); } public static void Cin<T1, T2, T3, T4>(long n, out T1[] l1, out T2[] l2, out T3[] l3, out T4[] l4) { l1 = new T1[n]; l2 = new T2[n]; l3 = new T3[n]; l4 = new T4[n]; for (int i = 0; i < n; i++) Cin(out l1[i], out l2[i], out l3[i], out l4[i]); } public static void Cin<T>(out T[] a) => a = Convert<T[]>(String()); public static void Cin<T>(long h, out T[][] map) => map = String(h).Select(Convert<T[]>()).ToArray(); } class Program { public static void Main(string[] args) { StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); new Solver().Solve(); Console.Out.Flush(); } public static void Debug() { new Solver().Solve(); } } class Solver { private long N, K; private long[] A; public void Solve() { Cin(out N, out K); Cin(out A); long[] sum = new long[N + 1]; for (int i = 0; i < N; i++) { sum[i + 1] = sum[i] + A[i]; } List<long> l = new List<long>(); for (int i = 0; i <= N - 1; i++) { for (int j = i + 1; j <= N; j++) { l.Add(sum[j] - sum[i]); } } l.Sort(); l.Reverse(); long max = sum[N]; List<long> t = new List<long>(); long tt = 1; while (tt < max) { t.Add(tt); tt *= 2; } t.Reverse(); long ans = 0; foreach (long t1 in t) { List<long> ok = new List<long>(); for (int i = 0; i < l.Count; i++) { if ((l[i] & t1) == t1) { ok.Add(l[i]); } } if (ok.Count >= K) { ans += t1; l = ok; } } Console.WriteLine(ans); } } }
[["+", 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, 210, 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, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 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], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 67], ["-", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["-", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
1,688
39
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Hello { private const long INF = 1000000007; private struct Pair { public long x, y; public Pair(long xx, long yy) { x = xx; y = yy; } } public static void Main() { int N = NextInt(); int K = NextInt(); long[] a = LineLong(); long[] b = new long[N + 1]; for (int i = 1; i <= N; i++) b[i] = b[i - 1] + a[i - 1]; //とりまN^2で全列挙 List<long> next = new List<long>(); for (int i = 0; i <= N; i++) for (int j = i + 1; j <= N; j++) next.Add(b[j] - b[i]); //各bitについて、立っているものが何個あるか数える // log_2(10^12) = 40 for (int bit = 40; bit >= 0; bit--) { List<long> A = new List<long>(); List<long> B = new List<long>(); foreach (var C in next) { if ((1 & C >> bit) == 1) A.Add(C); else B.Add(C); } if (A.Count() >= K) next = A; else if (B.Count() >= K) next = B; } long ans = next[0]; next.ForEach(v => ans &= v); Console.WriteLine(ans); } } public class Input { private static Queue<string> queue = new Queue<string>(); private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); } public static string NextString() { Confirm(); return queue.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Hello { private const long INF = 1000000007; private struct Pair { public long x, y; public Pair(long xx, long yy) { x = xx; y = yy; } } public static void Main() { int N = NextInt(); int K = NextInt(); long[] a = LineLong(); long[] b = new long[N + 1]; for (int i = 1; i <= N; i++) b[i] = b[i - 1] + a[i - 1]; //とりまN^2で全列挙 List<long> next = new List<long>(); for (int i = 0; i <= N; i++) for (int j = i + 1; j <= N; j++) next.Add(b[j] - b[i]); //各bitについて、立っているものが何個あるか数える // log_2(10^12) = 40 for (int bit = 40; bit >= 0; bit--) { List<long> A = new List<long>(); List<long> B = new List<long>(); foreach (var C in next) { if ((1 & C >> bit) == 1) A.Add(C); else B.Add(C); } if (A.Count() >= K) next = A; } long ans = next[0]; next.ForEach(v => ans &= v); Console.WriteLine(ans); } } public class Input { private static Queue<string> queue = new Queue<string>(); private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); } public static string NextString() { Confirm(); return queue.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
[["-", 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], ["-", 75, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 75, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 75, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 75, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 75, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["-", 0, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["-", 75, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 57, 64, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35]]
8
621
15
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderCs { class Program { static void Main() { var Arg = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); // 木の本数 int[] Trees = new int[Arg[0]]; for (int i = 0; i < Arg[0]; i++) { Trees[i] = int.Parse(Console.ReadLine()); } Array.Sort(Trees); // 高位差 int[] Voltage = new int[Arg[0] - Arg[1]]; for (int i = 0; i < Arg[0] - Arg[1]; i++) { Voltage[i] = Trees[i + Arg[1]] - Trees[i]; } Console.WriteLine(Voltage.Min()); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderCs { class Program { static void Main() { var Arg = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); // 木の本数 int[] Trees = new int[Arg[0]]; for (int i = 0; i < Arg[0]; i++) { Trees[i] = int.Parse(Console.ReadLine()); } Array.Sort(Trees); // 高位差 int Checker = Arg[0] - Arg[1] + 1; int[] Voltage = new int[Checker]; for (int i = 0; i < Checker; i++) { Voltage[i] = Trees[i + Arg[1] - 1] - Trees[i]; } Console.WriteLine(Voltage.Min()); } } }
[["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["-", 0, 7, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 0, 7, 15, 16, 12, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
194
31
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var l = Input().ToInt(); int n = l[0]; int k = l[1]; var h = new int[n]; for (int i = 0; i < n; i++) h[i] = Console.ReadLine().ToInt(); Array.Sort(h); Console.WriteLine(h[k - 1] - h[0]); } 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]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { int[] r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var l = Input().ToInt(); int n = l[0]; int k = l[1]; var h = new long[n]; for (int i = 0; i < n; i++) h[i] = Console.ReadLine().ToInt(); Array.Sort(h); long r = 9999999999; for (int i = 0; i <= n - k; i++) { r = Math.Min(h[k - 1 + i] - h[i], r); } Console.WriteLine(r); } 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]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { int[] r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 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, 19], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 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], ["+", 0, 7, 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], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
360
44
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var K = cin.ReadInt; var h = new List<int>(); for (var i = 0; i < N; i++) { h.Add(cin.ReadInt); } h.Sort(); var ans = 10 ^ 9; for (var i = 0; i <= N - K; i++) { ans = Math.Min(ans, h[i + K - 1] - h[i]); } WriteLine(ans); } static long GcdArray(long[] array) { var ans = array[0]; for (var i = 1; i < array.Length; i++) { ans = Gcd(ans, array[i]); } return ans; } 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; } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var K = cin.ReadInt; var h = new List<long>(); for (var i = 0; i < N; i++) { h.Add(cin.ReadLong); } h.Sort(); var ans = Math.Pow(10, 9); for (var i = 0; i <= N - K; i++) { ans = Math.Min(ans, h[i + K - 1] - h[i]); } WriteLine(ans); } static long GcdArray(long[] array) { var ans = array[0]; for (var i = 1; i < array.Length; i++) { ans = Gcd(ans, array[i]); } return ans; } 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; } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 140], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
672
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Console; namespace AtCoder_1 { class Program { static void Main(string[] args) { var NK = CinTAr(); long[] h = new long[NK[0]]; for (int i = 0; i < NK[0]; i++) { h[i] = CinL(); } Array.Sort(h, (x, y) => { return (int)y - (int)x; }); long min = MOD10E9; for (int i = 0; i <= NK[0] - NK[1]; i++) { min = Math.Min(min, h[i] - h[i + NK[1] - 1]); } Cout(min); Cin(); } static int GCD(int a, int b) { if (a < b) { swap(ref a, ref b); } if (a % b == 0) { return b; } else { return GCD(b, a % b); } } static void swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static readonly int MOD10E9 = 10000007; static bool isInt(double d) { return (int)d == d; } static string Cin() { return ReadLine(); } static string[] CinAr() { return ReadLine().Split(' '); } static int CinT() { return S2i(Cin()); } static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); } static long CinL() { return S2L(Cin()); } static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); } static double CinD() { return S2D(Cin()); } static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); } static int S2i(string s) { return int.Parse(s); } static long S2L(string s) { return long.Parse(s); } static double S2D(string s) { return double.Parse(s); } static void Cout(object s) { WriteLine(s); } static int[] yakusuu(int n) { if (n == 1) { return new int[] { 1 }; } HashSet<int> res = new HashSet<int>(); for (int i = 1; i < Math.Ceiling(n / 2.0); i++) { if (n % i == 0) { res.Add(i); res.Add(n / i); } } return res.ToArray(); } static void CoutAr<Type>(IEnumerable<Type> types) { string text = string.Join(" ", types); WriteLine(text); } public static long nCr(int n, int r) { // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r)); return nPr(n, r) / Factorial(r); } public static long nPr(int n, int r) { // naive: return Factorial(n) / Factorial(n - r); return FactorialDivision(n, n - r); } private static long FactorialDivision(int topFactorial, int divisorFactorial) { long result = 1; for (int i = topFactorial; i > divisorFactorial; i--) result *= i; return result; } private static long Factorial(int i) { if (i <= 1) return 1; return i * Factorial(i - 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Console; namespace AtCoder_1 { class Program { static void Main(string[] args) { var NK = CinTAr(); long[] h = new long[NK[0]]; for (int i = 0; i < NK[0]; i++) { h[i] = CinL(); } Array.Sort(h); h = h.Reverse().ToArray(); long min = long.MaxValue; for (int i = 0; i <= NK[0] - NK[1]; i++) { min = Math.Min(min, h[i] - h[i + NK[1] - 1]); } Cout(min); Cin(); } static int GCD(int a, int b) { if (a < b) { swap(ref a, ref b); } if (a % b == 0) { return b; } else { return GCD(b, a % b); } } static void swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static readonly int MOD10E9 = 10000007; static bool isInt(double d) { return (int)d == d; } static string Cin() { return ReadLine(); } static string[] CinAr() { return ReadLine().Split(' '); } static int CinT() { return S2i(Cin()); } static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); } static long CinL() { return S2L(Cin()); } static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); } static double CinD() { return S2D(Cin()); } static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); } static int S2i(string s) { return int.Parse(s); } static long S2L(string s) { return long.Parse(s); } static double S2D(string s) { return double.Parse(s); } static void Cout(object s) { WriteLine(s); } static int[] yakusuu(int n) { if (n == 1) { return new int[] { 1 }; } HashSet<int> res = new HashSet<int>(); for (int i = 1; i < Math.Ceiling(n / 2.0); i++) { if (n % i == 0) { res.Add(i); res.Add(n / i); } } return res.ToArray(); } static void CoutAr<Type>(IEnumerable<Type> types) { string text = string.Join(" ", types); WriteLine(text); } public static long nCr(int n, int r) { // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r)); return nPr(n, r) / Factorial(r); } public static long nPr(int n, int r) { // naive: return Factorial(n) / Factorial(n - r); return FactorialDivision(n, n - r); } private static long FactorialDivision(int topFactorial, int divisorFactorial) { long result = 1; for (int i = topFactorial; i > divisorFactorial; i--) result *= i; return result; } private static long Factorial(int i) { if (i <= 1) return 1; return i * Factorial(i - 1); } } }
[["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["-", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 196, 0, 45], ["-", 0, 28, 0, 218, 8, 196, 0, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 37, 0, 16, 31, 74, 39, 199], ["-", 8, 196, 0, 37, 0, 16, 31, 74, 51, 22], ["-", 0, 218, 8, 196, 0, 37, 0, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 37, 0, 16, 12, 74, 39, 199], ["-", 8, 196, 0, 37, 0, 16, 12, 74, 51, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 196, 0, 46], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 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]]
8
810
28
using System; using System.Linq; namespace ABC115_C { class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var h = new int[N]; for (int i = 0; i < N; i++) { h[i] = int.Parse(Console.ReadLine()); } Array.Sort(h); var min = (int)Math.Pow(10, 5) + 1; for (int i = 0; i + K <= N; i++) { min = Math.Min(min, h[i + K - 1] - h[i]); } Console.WriteLine(min); } } }
using System; using System.Linq; namespace ABC115_C { class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var h = new int[N]; for (int i = 0; i < N; i++) { h[i] = int.Parse(Console.ReadLine()); } Array.Sort(h); var min = int.MaxValue; for (int i = 0; i + K <= N; i++) { min = Math.Min(min, h[i + K - 1] - h[i]); } Console.WriteLine(min); } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["-", 0, 16, 31, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 16, 31, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 24], ["-", 31, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 21], ["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
180
12
using System; using System.Collections.Generic; namespace ABC115_C_Christmas_Eve { internal class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); List<int> hList = new List<int>(n); for (int i = 0; i < n; i++) hList.Add(int.Parse(Console.ReadLine())); hList.Sort(); int hMin = hList[0]; int hMax = hList[k - 1]; for (int i = 0; i < n - k + 1; i++) { if (hList[i] == hList[i + k - 1]) { hMin = hList[i]; hMax = hList[i]; break; } if (hList[i + k - 1] - hList[i] < hMax - hMin) { hMin = hList[i]; hMax = hList[i + k - 1]; Console.WriteLine(hMax - hMin); } } Console.WriteLine(hMax - hMin); } } }
using System; using System.Collections.Generic; namespace ABC115_C_Christmas_Eve { internal class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int k = int.Parse(input[1]); List<int> hList = new List<int>(n); for (int i = 0; i < n; i++) hList.Add(int.Parse(Console.ReadLine())); hList.Sort(); int hMin = hList[0]; int hMax = hList[k - 1]; for (int i = 0; i < n - k + 1; i++) { if (hList[i] == hList[i + k - 1]) { hMin = hList[i]; hMax = hList[i]; break; } if (hList[i + k - 1] - hList[i] < hMax - hMin) { hMin = hList[i]; hMax = hList[i + k - 1]; } } Console.WriteLine(hMax - hMin); } } }
[["-", 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, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
256
9
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProgrammingContest { class Writer : IDisposable { private System.IO.TextWriter Out { get; } private StringBuilder Sb { get; } private bool IsReactive { get; } public Writer(string path) : this(new System.IO.StreamWriter(path)) {} public Writer(bool isReactive) : this(null, isReactive) {} public Writer(System.IO.TextWriter writer = null, bool isReactive = false) { this.Out = (writer ?? Console.Out); this.IsReactive = isReactive; if (!this.IsReactive) { this.Sb = new StringBuilder(); } } public void Dispose() { if (!this.IsReactive) { this.Out.Write(Sb.ToString()); } if (!this.Out.Equals(Console.Out)) { this.Out.Dispose(); } } public void Write(object val) { if (this.IsReactive) { this.Out.Write(val.ToString()); this.Out.Flush(); } else { this.Sb.Append(val.ToString()); } } public void WriteFormat(string format, params object[] vals) { if (this.IsReactive) { this.Out.Write(format, vals); this.Out.Flush(); } else { this.Sb.AppendFormat(format, vals); } } public void WriteLine(object val = null) => this.WriteFormat((val?.ToString() ?? string.Empty) + Environment.NewLine); public void WriteLine(int val) => this.WriteLine(val.ToString()); public void WriteLine(long val) => this.WriteLine(val.ToString()); public void WriteLine(string val) => this.WriteLine((object)val); public void WriteLine(string format, params object[] vals) => this.WriteFormat(format + Environment.NewLine, vals); } class Scanner : IDisposable { private Queue<string> Buffer { get; } private char[] Sep { get; } private System.IO.TextReader Reader { get; } public Scanner(string path, char[] sep = null) : this(new System.IO.StreamReader(path), sep) {} public Scanner(System.IO.TextReader reader = null, char[] sep = null) { this.Buffer = new Queue<string>(); this.Sep = (sep ?? new char[] { ' ' }); this.Reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.Buffer.Count == 0 && this.Reader.Peek() != -1) { string str = string.Empty; for (; string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str); str = this.Reader.ReadLine()) ; var strs = str.Split(this.Sep).Where( el => !(string.IsNullOrEmpty(el) || string.IsNullOrWhiteSpace(el))); foreach (var el in strs) { this.Buffer.Enqueue(el); } } } public void Dispose() { if (!this.Reader.Equals(Console.In)) { this.Reader.Dispose(); } } public string Next() { this.CheckBuffer(); return this.Buffer.Dequeue(); } public string[] GetStringArray(int N) => Enumerable.Range(0, N).Select(e => this.Next()).ToArray(); public int NextInt() => int.Parse(this.Next()); public int[] GetIntArray(int N) => Enumerable.Range(0, N).Select(e => this.NextInt()).ToArray(); public double NextDouble() => double.Parse(this.Next()); public double[] GetdoubleArray(int N) => Enumerable.Range(0, N).Select(e => this.NextDouble()).ToArray(); public long NextLong() => long.Parse(this.Next()); public long[] GetLongArray(int N) => Enumerable.Range(0, N).Select(e => this.NextLong()).ToArray(); public bool IsEnd { get { this.CheckBuffer(); return this.Buffer.Count == 0; } } } class MainClass : IDisposable { private Scanner Sc { get; } private Writer Wr { get; } private string InFilePath => "in.txt"; private string OutFilePath => "out.txt"; public MainClass() { this.Wr = new Writer(this.IsReactive); // this.Wr = new Writer(this.OutFilePath); #if DEBUG if (!this.IsReactive) { this.Sc = new Scanner(this.InFilePath); } else { this.Sc = new Scanner(); } #else this.Sc = new Scanner(); #endif this.Solve(); } static void Main(string[] args) { using (new MainClass()) {} } public void Dispose() { this.Sc?.Dispose(); this.Wr?.Dispose(); #if DEBUG Console.WriteLine("press any key to continue..."); Console.ReadKey(); #endif } void Solve() { int N = Sc.NextInt(); int K = Sc.NextInt(); var h = Sc.GetLongArray(N); Array.Sort(h); long ans = (long)1e18; for (int i = 0; i < N - K; i++) { ans = Math.Min(ans, h[i + K - 1] - h[i]); } Wr.WriteLine(ans); } private bool IsReactive => false; // TODO: reactive check !! } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProgrammingContest { class Writer : IDisposable { private System.IO.TextWriter Out { get; } private StringBuilder Sb { get; } private bool IsReactive { get; } public Writer(string path) : this(new System.IO.StreamWriter(path)) {} public Writer(bool isReactive) : this(null, isReactive) {} public Writer(System.IO.TextWriter writer = null, bool isReactive = false) { this.Out = (writer ?? Console.Out); this.IsReactive = isReactive; if (!this.IsReactive) { this.Sb = new StringBuilder(); } } public void Dispose() { if (!this.IsReactive) { this.Out.Write(Sb.ToString()); } if (!this.Out.Equals(Console.Out)) { this.Out.Dispose(); } } public void Write(object val) { if (this.IsReactive) { this.Out.Write(val.ToString()); this.Out.Flush(); } else { this.Sb.Append(val.ToString()); } } public void WriteFormat(string format, params object[] vals) { if (this.IsReactive) { this.Out.Write(format, vals); this.Out.Flush(); } else { this.Sb.AppendFormat(format, vals); } } public void WriteLine(object val = null) => this.WriteFormat((val?.ToString() ?? string.Empty) + Environment.NewLine); public void WriteLine(int val) => this.WriteLine(val.ToString()); public void WriteLine(long val) => this.WriteLine(val.ToString()); public void WriteLine(string val) => this.WriteLine((object)val); public void WriteLine(string format, params object[] vals) => this.WriteFormat(format + Environment.NewLine, vals); } class Scanner : IDisposable { private Queue<string> Buffer { get; } private char[] Sep { get; } private System.IO.TextReader Reader { get; } public Scanner(string path, char[] sep = null) : this(new System.IO.StreamReader(path), sep) {} public Scanner(System.IO.TextReader reader = null, char[] sep = null) { this.Buffer = new Queue<string>(); this.Sep = (sep ?? new char[] { ' ' }); this.Reader = (reader ?? Console.In); } private void CheckBuffer() { if (this.Buffer.Count == 0 && this.Reader.Peek() != -1) { string str = string.Empty; for (; string.IsNullOrEmpty(str) || string.IsNullOrWhiteSpace(str); str = this.Reader.ReadLine()) ; var strs = str.Split(this.Sep).Where( el => !(string.IsNullOrEmpty(el) || string.IsNullOrWhiteSpace(el))); foreach (var el in strs) { this.Buffer.Enqueue(el); } } } public void Dispose() { if (!this.Reader.Equals(Console.In)) { this.Reader.Dispose(); } } public string Next() { this.CheckBuffer(); return this.Buffer.Dequeue(); } public string[] GetStringArray(int N) => Enumerable.Range(0, N).Select(e => this.Next()).ToArray(); public int NextInt() => int.Parse(this.Next()); public int[] GetIntArray(int N) => Enumerable.Range(0, N).Select(e => this.NextInt()).ToArray(); public double NextDouble() => double.Parse(this.Next()); public double[] GetdoubleArray(int N) => Enumerable.Range(0, N).Select(e => this.NextDouble()).ToArray(); public long NextLong() => long.Parse(this.Next()); public long[] GetLongArray(int N) => Enumerable.Range(0, N).Select(e => this.NextLong()).ToArray(); public bool IsEnd { get { this.CheckBuffer(); return this.Buffer.Count == 0; } } } class MainClass : IDisposable { private Scanner Sc { get; } private Writer Wr { get; } private string InFilePath => "in.txt"; private string OutFilePath => "out.txt"; public MainClass() { this.Wr = new Writer(this.IsReactive); // this.Wr = new Writer(this.OutFilePath); #if DEBUG if (!this.IsReactive) { this.Sc = new Scanner(this.InFilePath); } else { this.Sc = new Scanner(); } #else this.Sc = new Scanner(); #endif this.Solve(); } static void Main(string[] args) { using (new MainClass()) {} } public void Dispose() { this.Sc?.Dispose(); this.Wr?.Dispose(); #if DEBUG Console.WriteLine("press any key to continue..."); Console.ReadKey(); #endif } void Solve() { int N = Sc.NextInt(); int K = Sc.NextInt(); var h = Sc.GetLongArray(N); Array.Sort(h); long ans = (long)1e18; for (int i = 0; i < N; i++) { if (i + K - 1 < N) ans = Math.Min(ans, h[i + K - 1] - h[i]); } Wr.WriteLine(ans); } private bool IsReactive => false; // TODO: reactive check !! } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 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, 72], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
8
1,217
12
using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int k = int.Parse(str[1]); long[] tree = new long[n]; for (int i = 0; i < n; i++) { tree[i] = long.Parse(Console.ReadLine()); } Array.Sort(tree); long result = long.MaxValue; for (int i = 0; i < n - 2; i++) { if (result > tree[i + 2] - tree[i]) { result = tree[i + 2] - tree[i]; } if (result == 0) { break; } } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; namespace _0030 { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int k = int.Parse(str[1]); long[] tree = new long[n]; for (long i = 0; i < n; i++) { tree[i] = long.Parse(Console.ReadLine()); } Array.Sort(tree); long result = long.MaxValue; for (int i = 0; i < n - k + 1; i++) { if (result > tree[i + k - 1] - tree[i]) { result = tree[i + k - 1] - tree[i]; } } Console.WriteLine(result); } } }
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
197
31
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.D { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var (N, X) = Read2Longs(); var p = new long[N + 1]; var count = new long[N + 1]; count[0] = 1; p[0] = 1; for (var i = 1; i <= N; i++) { count[i] = 2 * count[i - 1] + 3; p[i] = 2 * p[i - 1] + 1; } var pcount = 0L; var j = N; while (X > 0 && j > 0) { var kukaku = GetKukaku(count[j], X); if (kukaku == 1) { X -= X; } else if (kukaku == 2) { X -= 1; } else if (kukaku == 3) { pcount += p[j - 1] + 1; X -= X; } else if (kukaku == 4) { pcount += p[j - 1] + 1; X -= count[j - 1] + 2; } else if (kukaku == 5) { pcount += p[j]; X -= X; } j--; } return pcount; } private static int GetKukaku(long n, long x) { var line = (n - 3) / 2; if (x == 1) { return 1; } else if (x <= line + 1) { return 2; } else if (x == line + 2) { return 3; } else if (x <= 2 * line + 2) { return 4; } else { return 5; } } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime; namespace AtCoder.D { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var (N, X) = Read2Longs(); var p = new long[N + 1]; var count = new long[N + 1]; count[0] = 1; p[0] = 1; for (var i = 1; i <= N; i++) { count[i] = 2 * count[i - 1] + 3; p[i] = 2 * p[i - 1] + 1; } var pcount = 0L; var j = N; while (X > 0 && j > 0) { var kukaku = GetKukaku(count[j], X); if (kukaku == 1) { X -= X; } else if (kukaku == 2) { X -= 1; } else if (kukaku == 3) { pcount += p[j - 1] + 1; X -= X; } else if (kukaku == 4) { pcount += p[j - 1] + 1; X -= count[j - 1] + 2; } else if (kukaku == 5) { pcount += p[j]; X -= X; } j--; } if (X > 0) { pcount++; } return pcount; } private static int GetKukaku(long n, long x) { var line = (n - 3) / 2; if (x == 1) { return 1; } else if (x <= line + 1) { return 2; } else if (x == line + 2) { return 3; } else if (x <= 2 * line + 2) { return 4; } else { return 5; } } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 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, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29]]
8
669
16
using System; using System.Collections.Generic; using System.Linq; using System.Net.NetworkInformation; class MainClass { static void Main() { var NX = Console.ReadLine().Split().Select(long.Parse).ToArray(); int N = (int)NX[0]; long X = NX[1]; var leng = new long[N + 1]; leng[0] = 1; var patty = new long[N + 1]; patty[0] = 1; for (int i = 0; i < N; i++) { leng[i + 1] = leng[i] * 2 + 3; patty[i + 1] = patty[i] * 2 + 1; } int n = N; long ans = 0; while (n > 0) { if (X < leng[n] / 2) { X--; n--; } else if (X == leng[n] / 2) { ans += patty[n] / 2; break; } else { ans += patty[n] / 2 + 1; X -= leng[n] / 2 + 1; n--; } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Net.NetworkInformation; class MainClass { static void Main() { var NX = Console.ReadLine().Split().Select(long.Parse).ToArray(); int N = (int)NX[0]; long X = NX[1]; var leng = new long[N + 1]; leng[0] = 1; var patty = new long[N + 1]; patty[0] = 1; for (int i = 0; i < N; i++) { leng[i + 1] = leng[i] * 2 + 3; patty[i + 1] = patty[i] * 2 + 1; } int n = N; long ans = 0; while (n >= 0) { if (X < leng[n] / 2) { X = X == 0 ? 0 : --X; n--; } else if (X == leng[n] / 2) { ans += patty[n] / 2; break; } else { ans += patty[n] / 2 + 1; X -= leng[n] / 2 + 1; n--; } } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 64, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 0, 1, 0, 11, 12, 41, 75, 241, 0, 22]]
8
257
10
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var o = Longs; var N = (int)o[0]; var X = o[1]; a = new long[N + 1]; p = new long[N + 1]; a[0] = 1; p[0] = 1; for (int i = 1; i <= N; ++i) { a[i] = 2L * a[i - 1] + 3; p[i] = 2L * p[i - 1] + 1; } Write(rec(N, X)); } long[] a, p; long rec(int n, long x) { if (n == 0) return 0; if (x == 1) return 0; if (1 < x && x < a[n - 1] + 2) return rec(n - 1, x - 1); if (x == a[n - 1] + 2) return p[n - 1] + 1; return p[n - 1] + 1 + rec(n - 1, x - 2 - a[n - 1]); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var o = Longs; var N = (int)o[0]; var X = o[1]; a = new long[N + 1]; p = new long[N + 1]; a[0] = 1; p[0] = 1; for (int i = 1; i <= N; ++i) { a[i] = 2L * a[i - 1] + 3; p[i] = 2L * p[i - 1] + 1; } Write(rec(N, X)); } long[] a, p; long rec(int n, long x) { if (n == 0 && x <= 0) return 0; if (n == 0) return 1; if (x == 1) return 0; if (1 < x && x < a[n - 1] + 2) return rec(n - 1, x - 1); if (x == a[n - 1] + 2) return p[n - 1] + 1; return p[n - 1] + 1 + rec(n - 1, x - 2 - a[n - 1]); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203]]
8
1,123
13
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Math; namespace CSharpSpiral { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var X = cin.ReadLong; Console.WriteLine(BurgerSearch(N, X - 1)); } public long BurgerSearch(int Level, long X) { if (Level == 0) return 1; var middlePatty = (4L << (Level - 1)) - 2; var finalSize = 2 * middlePatty + 1; if (X == 0) return 0; if (X > finalSize) throw new IndexOutOfRangeException(); if (X == finalSize) return 2 * (2L << Level) - 1; switch (X.CompareTo(middlePatty)) { case 1: return (2L << (Level - 1)) + BurgerSearch(Level - 1, X - middlePatty - 1); case -1: return BurgerSearch(Level - 1, X - 1); default: if (Level == 0) return 1; else return (2L << (Level - 1)); } } } static class ExtendClass { public static void Swap<T>(this T[] A, int x, int y) { var tmp = A[x]; A[x] = A[y]; A[y] = tmp; } public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length); public static IEnumerable<int> Indices<T>(this T[,] X, int dim) => Enumerable.Range(0, X.GetLength(dim)); public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n") => X.Indices(0) .Select(i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)) .Join(separatorD1); } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } class ResidueField { public readonly long modulo; public ResidueField(int mModulo) { modulo = mModulo; } private long[] factorialTable = { 1 }; private int factorialTableLastIndex { get { return factorialTable.Length - 1; } } public long mod(long x) => x < 0 ? x % modulo + modulo : x % modulo; public long Add(long a, long b) => mod(a + b); public long Sub(long a, long b) => mod(a - b); public long Mul(long a, long b) => mod(a * b); public long Pow(long a, long n) { if (n == 0) return 1; var R = 1L; n = n < 0 ? n % (modulo - 1) + (modulo - 1) : n % (modulo - 1); for (; n > 0; a = Mul(a, a), n >>= 1) { if ((n & 1) != 0) R = Mul(R, a); } return R; } private static long extgcd(long a, long b, ref long x, ref long y) { if (b == 0) { x = 1; y = 0; return a; } var q = a / b; var g = extgcd(b, a - q * b, ref x, ref y); var z = x - q * y; x = y; y = z; return g; } public long Inv(long a) { if (a == 0) throw new DivideByZeroException(); long x = 0, y = 0; extgcd(a, modulo, ref x, ref y); return mod(x); } public long Div(long a, long b) => Mul(a, Inv(b)); public void ExpandFactorialTable(int N) { var k = factorialTableLastIndex; Array.Resize(ref factorialTable, N + 1); for (int i = k + 1; i <= N; i++) { if (i == 0) { factorialTable[i] = 1; continue; } factorialTable[i] = Mul(factorialTable[i - 1], i); } } public long Factorial(int n) { if (n > factorialTableLastIndex) ExpandFactorialTable(n); return factorialTable[n]; } public long Permutation(int n, int k) { if (k < 0 || k > n) return 0; if (n > 200000) { var Res = 1L; for (int i = 0; i < k; i++) Res = Mul(Res, n - i); return Res; } else return Div(Factorial(n), Factorial(n - k)); } public long Combination(int n, int k) { if (k < 0 || k > n) return 0; k = Math.Min(k, n - k); return Div(Permutation(n, k), Factorial(k)); } public long Calculate(params object[] RPN) { var S = new Stack<long>(); foreach (var token in RPN) { var type = token.GetType(); if (type == typeof(int)) { S.Push((int)token); } else if (type == typeof(long)) { S.Push((long)token); } else if (type == typeof(char)) { long v1 = 0L, v2 = 0L; v2 = S.Pop(); HashSet<char> unaries = new HashSet<char>() { 'n', 'N', '!' }; if (!unaries.Contains((char)token)) v1 = S.Pop(); long res; switch ((char)token) { case '+': res = Add(v1, v2); break; case '-': res = Sub(v1, v2); break; case '*': res = Mul(v1, v2); break; case '/': res = Div(v1, v2); break; case '^': res = Pow(v1, v2); break; case 'n': case 'N': res = modulo - v2; break; case '!': res = Factorial((int)v2); break; case 'C': res = Combination((int)v1, (int)v2); break; case 'P': res = Permutation((int)v1, (int)v2); break; default: throw new InvalidOperationException(); } S.Push(res); } else throw new InvalidOperationException(); } return S.Peek(); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Math; namespace CSharpSpiral { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var X = cin.ReadLong; Console.WriteLine(BurgerSearch(N, X - 1)); } public long BurgerSearch(int Level, long X) { if (Level == 0) return 1; var middlePatty = (4L << (Level - 1)) - 2; var finalSize = 2 * middlePatty + 1; if (X == 0) return 0; if (X >= finalSize) throw new IndexOutOfRangeException(); if (X == finalSize - 1) X--; switch (X.CompareTo(middlePatty)) { case 1: return (2L << (Level - 1)) + BurgerSearch(Level - 1, X - middlePatty - 1); case -1: return BurgerSearch(Level - 1, X - 1); default: return (2L << (Level - 1)); } } } static class ExtendClass { public static void Swap<T>(this T[] A, int x, int y) { var tmp = A[x]; A[x] = A[y]; A[y] = tmp; } public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length); public static IEnumerable<int> Indices<T>(this T[,] X, int dim) => Enumerable.Range(0, X.GetLength(dim)); public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n") => X.Indices(0) .Select(i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)) .Join(separatorD1); } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } class ResidueField { public readonly long modulo; public ResidueField(int mModulo) { modulo = mModulo; } private long[] factorialTable = { 1 }; private int factorialTableLastIndex { get { return factorialTable.Length - 1; } } public long mod(long x) => x < 0 ? x % modulo + modulo : x % modulo; public long Add(long a, long b) => mod(a + b); public long Sub(long a, long b) => mod(a - b); public long Mul(long a, long b) => mod(a * b); public long Pow(long a, long n) { if (n == 0) return 1; var R = 1L; n = n < 0 ? n % (modulo - 1) + (modulo - 1) : n % (modulo - 1); for (; n > 0; a = Mul(a, a), n >>= 1) { if ((n & 1) != 0) R = Mul(R, a); } return R; } private static long extgcd(long a, long b, ref long x, ref long y) { if (b == 0) { x = 1; y = 0; return a; } var q = a / b; var g = extgcd(b, a - q * b, ref x, ref y); var z = x - q * y; x = y; y = z; return g; } public long Inv(long a) { if (a == 0) throw new DivideByZeroException(); long x = 0, y = 0; extgcd(a, modulo, ref x, ref y); return mod(x); } public long Div(long a, long b) => Mul(a, Inv(b)); public void ExpandFactorialTable(int N) { var k = factorialTableLastIndex; Array.Resize(ref factorialTable, N + 1); for (int i = k + 1; i <= N; i++) { if (i == 0) { factorialTable[i] = 1; continue; } factorialTable[i] = Mul(factorialTable[i - 1], i); } } public long Factorial(int n) { if (n > factorialTableLastIndex) ExpandFactorialTable(n); return factorialTable[n]; } public long Permutation(int n, int k) { if (k < 0 || k > n) return 0; if (n > 200000) { var Res = 1L; for (int i = 0; i < k; i++) Res = Mul(Res, n - i); return Res; } else return Div(Factorial(n), Factorial(n - k)); } public long Combination(int n, int k) { if (k < 0 || k > n) return 0; k = Math.Min(k, n - k); return Div(Permutation(n, k), Factorial(k)); } public long Calculate(params object[] RPN) { var S = new Stack<long>(); foreach (var token in RPN) { var type = token.GetType(); if (type == typeof(int)) { S.Push((int)token); } else if (type == typeof(long)) { S.Push((long)token); } else if (type == typeof(char)) { long v1 = 0L, v2 = 0L; v2 = S.Pop(); HashSet<char> unaries = new HashSet<char>() { 'n', 'N', '!' }; if (!unaries.Contains((char)token)) v1 = S.Pop(); long res; switch ((char)token) { case '+': res = Add(v1, v2); break; case '-': res = Sub(v1, v2); break; case '*': res = Mul(v1, v2); break; case '/': res = Div(v1, v2); break; case '^': res = Pow(v1, v2); break; case 'n': case 'N': res = modulo - v2; break; case '!': res = Factorial((int)v2); break; case 'C': res = Combination((int)v1, (int)v2); break; case 'P': res = Permutation((int)v1, (int)v2); break; default: throw new InvalidOperationException(); } S.Push(res); } else throw new InvalidOperationException(); } return S.Peek(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["-", 0, 57, 64, 37, 0, 16, 31, 16, 31, 203], ["-", 0, 57, 64, 37, 0, 16, 31, 16, 17, 48], ["-", 64, 37, 0, 16, 31, 16, 12, 23, 0, 24], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 31, 203], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 17, 151], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["-", 64, 37, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 68], ["-", 0, 99, 8, 254, 0, 239, 0, 57, 0, 121], ["-", 0, 99, 8, 254, 0, 239, 0, 57, 0, 24], ["-", 8, 254, 0, 239, 0, 57, 15, 16, 31, 22], ["-", 8, 254, 0, 239, 0, 57, 15, 16, 17, 60], ["-", 8, 254, 0, 239, 0, 57, 15, 16, 12, 203], ["-", 0, 99, 8, 254, 0, 239, 0, 57, 0, 25], ["-", 8, 254, 0, 239, 0, 57, 64, 37, 0, 38], ["-", 8, 254, 0, 239, 0, 57, 64, 37, 0, 203], ["-", 8, 254, 0, 239, 0, 57, 64, 37, 0, 35], ["-", 0, 99, 8, 254, 0, 239, 0, 57, 0, 95]]
8
1,920
24
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N; long X; Multi(out N, out X); long[][] pb = Enumerable.Repeat(0, N + 1) .Select(s => (Enumerable.Repeat(0L, 3).ToArray())) .ToArray(); pb[0][0] = 1; pb[0][1] = 0; pb[0][2] = 1; for (int i = 1; i <= N; i++) { pb[i][0] = pb[i - 1][0] * 2 + 1; pb[i][1] = pb[i - 1][1] * 2 + 2; pb[i][2] = pb[i][0] + pb[i][1]; } long ans = 0; int n = N; while (true) { if (X == 1) { if (n == 0) { ans++; } break; } if (X < (pb[n][2] + 1) / 2) { n--; X--; } else if (X == (pb[n][2] + 1) / 2) { ans += pb[n][0] / 2 + 1; break; } else { X -= pb[n][2] / 2 + 1; ans += pb[n][0] / 2 + 1; n--; } } Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N; long X; Multi(out N, out X); long[][] pb = Enumerable.Repeat(0, N + 1) .Select(s => (Enumerable.Repeat(0L, 3).ToArray())) .ToArray(); pb[0][0] = 1; pb[0][1] = 0; pb[0][2] = 1; for (int i = 1; i <= N; i++) { pb[i][0] = pb[i - 1][0] * 2 + 1; pb[i][1] = pb[i - 1][1] * 2 + 2; pb[i][2] = pb[i][0] + pb[i][1]; } long ans = 0; int n = N; while (true) { if (X == 1) { if (n == 0) { ans++; } break; } if (X < (pb[n][2] + 1) / 2) { n--; X--; } else if (X == (pb[n][2] + 1) / 2) { ans += pb[n][0] / 2 + 1; break; } else if (X == pb[n][2]) { ans += pb[n][0]; break; } else { X -= pb[n][2] / 2 + 1; ans += pb[n][0] / 2 + 1; n--; } } Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } }
[["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 75, 57, 15, 16, 12, 204, 205, 204, 205, 22], ["+", 15, 16, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 204, 205, 204, 205, 22], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 75, 57, 64, 196, 0, 93, 0, 94], ["+", 75, 57, 75, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 95], ["+", 0, 57, 75, 57, 75, 57, 75, 196, 0, 45]]
8
1,407
27
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using static kyoupuro.Input; using static kyoupuro.MyMath; namespace kyoupuro { class MainClass { static long[] array; static long[] len; public static void Main() { var N = NextInt(); var X = NextLong(); array = new long[N + 1]; len = new long[N + 1]; array[0] = 1; len[0] = 1; for (int i = 1; i <= N; i++) { array[i] = 2 * array[i - 1] + 1; len[i] = 2 * len[i - 1] + 3; } Console.WriteLine(Count(X, N)); } public static long Count(long length, int n) { if (length <= 1) { return 0; } else if (length <= len[n - 1] + 1) { return Count(length - 1, n - 1); } else if (length == len[n - 1] + 2) { return array[n - 1] + 1; } else if (length <= 2 * len[n - 1] + 2) { return array[n - 1] + Count(length - len[n - 1] - 2, n - 1) + 1; } else { return array[n]; } } } class MyMath { public static long mod = 1000000007; public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static List<long> Factor(long n) { var list = new List<long>(); n = DivideToLimit(n, 2, list); n = DivideToLimit(n, 3, list); long sqrt = Sqrt(n); for (int i = 5; i <= n && i <= sqrt; i += 4) { n = DivideToLimit(n, i, list); i += 2; n = DivideToLimit(n, i, list); } if (n > 1) list.Add(n); return list; } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } static long DivideToLimit(long divisor, long dividend, List<long> list) { while (divisor % dividend == 0) { list.Add(dividend); divisor /= dividend; } return divisor; } } class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line() { return Console.ReadLine(); } public static int NextInt() { while (!enumerator.MoveNext()) { enumerator = StrArr().AsEnumerable().GetEnumerator(); } return int.Parse(enumerator.Current); } public static long NextLong() { while (!enumerator.MoveNext()) { enumerator = StrArr().AsEnumerable().GetEnumerator(); } return long.Parse(enumerator.Current); } public static string[] StrArr() { return Line().Split(' '); } public static List<int> IntList() { return StrArr().Select(int.Parse).ToList(); } public static List<long> LongList() { return StrArr().Select(long.Parse).ToList(); } public static void Skip(int line = 1) { enumerator.Reset(); for (int i = 0; i < line; i++) Console.ReadLine(); } public static void Reset() { enumerator.Reset(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using static kyoupuro.Input; using static kyoupuro.MyMath; namespace kyoupuro { class MainClass { static long[] array; static long[] len; public static void Main() { var N = NextInt(); var X = NextLong(); array = new long[N + 1]; len = new long[N + 1]; array[0] = 1; len[0] = 1; for (int i = 1; i <= N; i++) { array[i] = 2 * array[i - 1] + 1; len[i] = 2 * len[i - 1] + 3; } Console.WriteLine(Count(X, N)); } public static long Count(long length, int n) { if (len[n] == length) return array[n]; if (length <= 1) { return 0; } else if (length <= len[n - 1] + 1) { return Count(length - 1, n - 1); } else if (length == len[n - 1] + 2) { return array[n - 1] + 1; } else if (length <= 2 * len[n - 1] + 2) { return array[n - 1] + Count(length - len[n - 1] - 2, n - 1) + 1; } else { return array[n]; } } } class MyMath { public static long mod = 1000000007; public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static List<long> Factor(long n) { var list = new List<long>(); n = DivideToLimit(n, 2, list); n = DivideToLimit(n, 3, list); long sqrt = Sqrt(n); for (int i = 5; i <= n && i <= sqrt; i += 4) { n = DivideToLimit(n, i, list); i += 2; n = DivideToLimit(n, i, list); } if (n > 1) list.Add(n); return list; } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } static long DivideToLimit(long divisor, long dividend, List<long> list) { while (divisor % dividend == 0) { list.Add(dividend); divisor /= dividend; } return divisor; } } class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line() { return Console.ReadLine(); } public static int NextInt() { while (!enumerator.MoveNext()) { enumerator = StrArr().AsEnumerable().GetEnumerator(); } return int.Parse(enumerator.Current); } public static long NextLong() { while (!enumerator.MoveNext()) { enumerator = StrArr().AsEnumerable().GetEnumerator(); } return long.Parse(enumerator.Current); } public static string[] StrArr() { return Line().Split(' '); } public static List<int> IntList() { return StrArr().Select(int.Parse).ToList(); } public static List<long> LongList() { return StrArr().Select(long.Parse).ToList(); } public static void Skip(int line = 1) { enumerator.Reset(); for (int i = 0; i < line; i++) Console.ReadLine(); } public static void Reset() { enumerator.Reset(); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 37, 0, 204, 205, 22], ["+", 0, 57, 64, 37, 0, 204, 206, 207, 0, 70], ["+", 64, 37, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 64, 37, 0, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
8
867
15
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Program { static List<long> LevelN; static List<long> SumN; static void Main(string[] args) { var NX = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray(); var N = NX[0]; var X = NX[1]; LevelN = new List<long>(); for (int i = 0; i <= 50; i++) { var NPatti = (long)Math.Pow(2, i + 1) - 1; LevelN.Add(NPatti); } SumN = new List<long>(); SumN.Add(1); for (int i = 1; i <= 50; i++) { SumN.Add(2 * SumN[i - 1] + 3); } Console.WriteLine(CountPatti(N, X)); } // Nはレベル、Xはルンルンが食べる量 static long CountPatti(long N, long X) { if (X <= 0) { return 0; } else if (N == 0) { return 1; } else { //半分以上のパティを食べるか if (SumN[(int)N] / 2 < X) { return CountPatti(N - 1, X - SumN[(int)N - 1] - 1) + 1 + LevelN[(int)N - 1]; } else { return CountPatti(N - 1, X - 1); } } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Program { static List<long> LevelN; static List<long> SumN; static void Main(string[] args) { var NX = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray(); var N = NX[0]; var X = NX[1]; LevelN = new List<long>(); for (int i = 0; i <= 50; i++) { var NPatti = (long)Math.Pow(2, i + 1) - 1; LevelN.Add(NPatti); } SumN = new List<long>(); SumN.Add(1); for (int i = 1; i <= 50; i++) { SumN.Add(2 * SumN[i - 1] + 3); } Console.WriteLine(CountPatti(N, X)); } // Nはレベル、Xはルンルンが食べる量 static long CountPatti(long N, long X) { if (X <= 0) { return 0; } else if (N == 0) { return 1; } else if (X >= SumN[(int)N]) { return LevelN[(int)N]; } else { //半分以上のパティを食べるか if (SumN[(int)N] / 2 < X) { return CountPatti(N - 1, X - SumN[(int)N - 1] - 2) + 1 + LevelN[(int)N - 1]; } else { return CountPatti(N - 1, X - 1); } } } }
[["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 20], ["+", 75, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 0, 24], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 39, 199], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 0, 25], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 51, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 75, 57, 64, 196, 0, 37, 0, 38], ["+", 75, 57, 64, 196, 0, 37, 0, 204, 205, 22], ["+", 64, 196, 0, 37, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 74, 0, 24], ["+", 0, 204, 206, 207, 0, 28, 0, 74, 39, 199], ["+", 0, 204, 206, 207, 0, 28, 0, 74, 0, 25], ["+", 0, 204, 206, 207, 0, 28, 0, 74, 51, 22], ["+", 64, 196, 0, 37, 0, 204, 206, 207, 0, 73], ["+", 75, 57, 75, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 95], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
312
26
using System; using System.Linq; namespace ABC115 { class Program { static long[] P; static long[] A; static void Main(string[] args) { long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = input[0]; long X = input[1]; P = new long[N + 1]; A = new long[N + 1]; P[0] = 1; A[0] = 1; for (int i = 1; i <= N; i++) { P[i] = 2 * P[i - 1] + 1; A[i] = 2 * A[i - 1] + 3; } // Console.WriteLine("A : " + string.Join(" ", A)); // Console.WriteLine("P : " + string.Join(" ", P)); if (f(N, X) <= 0) Console.WriteLine(0); else Console.WriteLine(f(N, X) - 1); } static long f(long N, long X) { if (N == 0) { if (0 <= X) return 0; else return 1; } else if (X <= 1 + A[N - 1]) return f(N - 1, X - 1); else return P[N - 1] + 1 + f(N - 1, X - 2 - A[N - 1]); } } }
using System; using System.Linq; namespace ABC115 { class Program { static long[] P; static long[] A; static void Main(string[] args) { long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = input[0]; long X = input[1]; P = new long[N + 1]; A = new long[N + 1]; P[0] = 1; A[0] = 1; for (int i = 1; i < N; i++) { P[i] = 2 * P[i - 1] + 1; A[i] = 2 * A[i - 1] + 3; } Console.WriteLine(f(N, X)); } static long f(long N, long X) { if (N == 0) { if (X <= 0) return 0; else return 1; } else if (X <= 1 + A[N - 1]) return f(N - 1, X - 1); else return P[N - 1] + 1 + f(N - 1, X - 2 - A[N - 1]); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 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, 213, 63, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 21], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 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], ["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 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, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203]]
8
286
27
using System; using System.Linq; namespace A { class Program { static void Main(string[] args) { var xy = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(xy.Sum() - xy[1] >> 1); } } }
using System; using System.Linq; namespace A { class Program { static void Main(string[] args) { var xy = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(xy[0] + (xy[1] >> 1)); } } }
[["-", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
69
9
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; public class Solver { public void Solve() { int a = ReadInt(); int b = ReadInt(); Write(a + b / 2); } #region Main protected static TextReader reader; protected static TextWriter writer; static void Main() { #if DEBUG reader = new StreamReader("..\\..\\input.txt"); // reader = new StreamReader(Console.OpenStandardInput()); writer = Console.Out; // writer = new StreamWriter("..\\..\\output.txt"); #else // reader = new StreamReader(Console.OpenStandardInput()); // writer = new StreamWriter(Console.OpenStandardOutput()); reader = new StreamReader("input.txt"); writer = new StreamWriter("output.txt"); #endif try { new Solver().Solve(); // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128); // thread.Start(); // thread.Join(); } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #else throw; #endif } reader.Close(); writer.Close(); } #endregion #region Read / Write private static Queue<string> currentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return reader.ReadLine().Split( new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static int[][] ReadAndTransposeIntMatrix(int numberOfRows) { int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][]; for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; } return ret; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); } public static void Write(params object[] array) { WriteArray(array); } public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); } private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue> { public new TValue this[TKey key] { get { return ContainsKey(key) ? base[key] : default(TValue); } set { base[key] = value; } } } private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; } #endregion }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; public class Solver { public void Solve() { int a = ReadInt(); int b = ReadInt(); Write(a + b / 2); } #region Main protected static TextReader reader; protected static TextWriter writer; static void Main() { #if DEBUG reader = new StreamReader("..\\..\\input.txt"); // reader = new StreamReader(Console.OpenStandardInput()); writer = Console.Out; // writer = new StreamWriter("..\\..\\output.txt"); #else reader = new StreamReader(Console.OpenStandardInput()); writer = new StreamWriter(Console.OpenStandardOutput()); // reader = new StreamReader("input.txt"); // writer = new StreamWriter("output.txt"); #endif try { new Solver().Solve(); // var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128); // thread.Start(); // thread.Join(); } catch (Exception ex) { #if DEBUG Console.WriteLine(ex); #else throw; #endif } reader.Close(); writer.Close(); } #endregion #region Read / Write private static Queue<string> currentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return reader.ReadLine().Split( new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static int[][] ReadAndTransposeIntMatrix(int numberOfRows) { int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][]; for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; } return ret; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); } public static void Write(params object[] array) { WriteArray(array); } public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); } private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue> { public new TValue this[TKey key] { get { return ContainsKey(key) ? base[key] : default(TValue); } set { base[key] = value; } } } private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; } #endregion }
[["-", 12, 230, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 12, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24]]
8
844
16
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); double[] TA = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray(); double[] H = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray(); int result = 0; for (int j = 0; j < N; j++) { if (Math.Abs(TA[1] - H[j] * 0.006) <= Math.Abs(TA[1] - H[result] * 0.006)) { result = j; } } Console.WriteLine(result + 1); } } } // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // long n = long.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray();
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); double[] TA = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray(); double[] H = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray(); int result = 0; for (int j = 0; j < N; j++) { // A -H[]*0.006の差が小さいのが答え if (Math.Abs(TA[1] - (TA[0] - H[j] * 0.006)) <= Math.Abs(TA[1] - (TA[0] - H[result] * 0.006))) { result = j; } } Console.WriteLine(result + 1); } } } // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // long n = long.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray();
[["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
216
14
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] TA = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int T = TA[0]; int A = TA[1]; int[] H = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); // List<int> intlist = new List<int>(); int ind = 0; int val = int.MaxValue; for (int i = 0; i < N; i++) { if (Math.Abs((int)(A - (T - H[i] * 0.006))) < val) { val = Math.Abs((int)(A - (T - H[i] * 0.006))); ind = i + 1; } // intlist.Add(Math.Abs((int)(A - (T - H[i] * 0.006)))); } // Console.WriteLine(intlist.IndexOf(intlist.Min()) + 1); Console.WriteLine(ind); } } } // int n = int.Parse(Console.ReadLine()); // int[] N = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] TA = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int T = TA[0]; int A = TA[1]; int[] H = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); // List<int> intlist = new List<int>(); int ind = 0; double val = int.MaxValue; for (int i = 0; i < N; i++) { if (Math.Abs((A - (T - H[i] * 0.006))) < val) { val = Math.Abs((A - (T - H[i] * 0.006))); ind = i + 1; } // intlist.Add(Math.Abs((int)(A - (T - H[i] * 0.006)))); } // Console.WriteLine(intlist.IndexOf(intlist.Min()) + 1); Console.WriteLine(ind); } } } // int n = int.Parse(Console.ReadLine()); // int[] N = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 31, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 31, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 12, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 12, 213, 3, 4, 0, 28, 0, 74, 0, 25]]
8
232
8
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using static kyoupuro.Input; using static kyoupuro.MyMath; using static kyoupuro.Modular; namespace kyoupuro { class MainClass { public static void Main() { int N = NextInt, A = NextInt, T = NextInt; var h = IntList; var list = h.Select(x => Math.Abs(T - x * 0.006 - A)).ToList(); int minid = 0; for (int i = 1; i < N; i++) { if (list[i] < list[minid]) { minid = i; } } Console.WriteLine(minid + 1); } } class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : 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, mod - 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) % mod)); } 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; } } public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } 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 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 static kyoupuro.Input; using static kyoupuro.MyMath; using static kyoupuro.Modular; namespace kyoupuro { class MainClass { public static void Main() { int N = NextInt, T = NextInt, A = NextInt; var h = IntList; var list = h.Select(x => Math.Abs(T - x * 0.006 - A)).ToList(); int minid = 0; for (int i = 1; i < N; i++) { if (list[i] < list[minid]) { minid = i; } } Console.WriteLine(minid + 1); } } class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : 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, mod - 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) % mod)); } 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; } } public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } 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 string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22]]
8
1,458
4
using System; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); int T = int.Parse(input[0]); int A = int.Parse(input[1]); var list = new int[N]; double ans = 10000; int goal = 0; input = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { list[i] = int.Parse(input[i]); if (ans > Math.Abs(A - (T - list[i] * 0.006))) goal = i; } Console.WriteLine(goal + 1); } }
using System; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); int T = int.Parse(input[0]); int A = int.Parse(input[1]); var list = new int[N]; double ans = 100000; int goal = 0; input = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { list[i] = int.Parse(input[i]); if (ans > Math.Abs(A - (T - list[i] * 0.006))) { ans = Math.Abs(A - (T - list[i] * 0.006)); goal = i; } } Console.WriteLine(goal + 1); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 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], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 17, 48], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 12, 250], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
170
24
using System; using System.Collections.Generic; namespace CompetitiveProgramming { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] t_a = Console.ReadLine().Split(' '); string[] h_list = Console.ReadLine().Split(' '); int t = int.Parse(t_a[0]); int a = int.Parse(t_a[1]); double diff_min = 0; int ans_index = 0; for (var i = 0; i < n; i++) { double i_temp = t - int.Parse(h_list[i]) * 000.6; double diff = Math.Abs(a - i_temp); if (i == 0) { diff_min = diff; } if (diff < diff_min) { diff_min = diff; ans_index = i; } } Console.WriteLine(ans_index + 1); } } }
using System; using System.Collections.Generic; namespace CompetitiveProgramming { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] t_a = Console.ReadLine().Split(' '); string[] h_list = Console.ReadLine().Split(' '); int t = int.Parse(t_a[0]); int a = int.Parse(t_a[1]); double diff_min = 0; int ans_index = 0; for (var i = 0; i < n; i++) { double i_temp = t - int.Parse(h_list[i]) * 0.006; double diff = Math.Abs(a - i_temp); if (i == 0 || diff < diff_min) { diff_min = diff; ans_index = i; } } Console.WriteLine(ans_index + 1); } } }
[["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 250], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 250], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 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, 17, 106]]
8
197
12
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str1 = Console.ReadLine().Split(' '); string[] str2 = Console.ReadLine().Split(' '); int[] intArray = str1.Select(int.Parse).ToArray(); double[] HeightArray = str2.Select(double.Parse).ToArray(); int Answer = 0; double Comparison = 0; double[] AbsArray = new double[HeightArray.Length]; for (int i = 0; i < HeightArray.Length; i++) { AbsArray[i] = System.Math.Abs(intArray[0] - (HeightArray[i] * 0.006) - intArray[1]); if (i == 0) { Answer = i; Comparison = AbsArray[i]; } else if (AbsArray[i] < Comparison) { Answer = i; } } Console.WriteLine(Answer + 1); } } }
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str1 = Console.ReadLine().Split(' '); string[] str2 = Console.ReadLine().Split(' '); int[] intArray = str1.Select(int.Parse).ToArray(); double[] HeightArray = str2.Select(double.Parse).ToArray(); int Answer = 0; double Comparison = 0; double[] AbsArray = new double[HeightArray.Length]; for (int i = 0; i < HeightArray.Length; i++) { AbsArray[i] = System.Math.Abs(intArray[0] - (HeightArray[i] * 0.006) - intArray[1]); if (i == 0) { Answer = i; Comparison = AbsArray[i]; } else if (AbsArray[i] < Comparison) { Answer = i; Comparison = AbsArray[i]; } } Console.WriteLine(Answer + 1); } } }
[["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35]]
8
229
7
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const int M2 = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; int t, a; sc.Multi(out t, out a); t *= 1000; a *= 1000; int mi = M, ans = -1; var h = sc.IntArr.Select(x => x * 1000).ToArray(); for (int i = 0; i < n; i++) { if (mi > Math.Abs(t - h[i] * 6 - a)) { mi = Math.Abs(t - h[i] * 6 - a); ans = i + 1; } } Prt(ans); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P { get { int a, b; Multi(out a, out b); return new P(a, b); } } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const int M2 = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; int t, a; sc.Multi(out t, out a); t *= 1000; a *= 1000; int mi = M, ans = -1; var h = sc.IntArr; for (int i = 0; i < n; i++) { if (mi > Math.Abs(t - h[i] * 6 - a)) { mi = Math.Abs(t - h[i] * 6 - a); ans = i + 1; } } Prt(ans); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P { get { int a, b; Multi(out a, out b); return new P(a, b); } } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 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
2,019
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace kyoupuro1 { class Program { static void Main(string[] args) { int a, t, n; var h = new List<int>(); n = int.Parse(Console.ReadLine()); var ip1 = Console.ReadLine().Split(' '); var ip2 = Console.ReadLine().Split(' '); t = int.Parse(ip1[0]); a = int.Parse(ip2[1]); foreach (var tmp in ip2) h.Add(int.Parse(tmp)); float minAbs = Math.Abs(a - (t - h[0] * 0.006f)); int minind = 0; for (int i = 1; i < n; i++) { var d = Math.Abs(a - (t - h[i] * 0.006f)); if (minAbs > d) { minAbs = d; minind = i; } } Console.WriteLine(minind + 1); } static List<int> GetPNLs(int max) { List<int> prime = new List<int>(); if (max <= 1) return new List<int> { 2 }; for (int i = 2; i <= max; i++) { bool isPrime = true; foreach (var p in prime) { if (i % p == 0 && i != p) { isPrime = false; break; } } if (isPrime) prime.Add(i); } return prime; } static int E(int prime, int n) { int k = n; int c = 0; while (k % prime == 0) { k = k / prime; c++; } return c; } static int C(int a, int b) { if (a < b) return 0; return F(a) / (F(b) * F(a - b)); } static int F(int n) { if (n > 1) return F(n - 1) * n; else return 1; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace kyoupuro1 { class Program { static void Main(string[] args) { int a, t, n; var h = new List<int>(); n = int.Parse(Console.ReadLine()); var ip1 = Console.ReadLine().Split(' '); var ip2 = Console.ReadLine().Split(' '); t = int.Parse(ip1[0]); a = int.Parse(ip1[1]); for (int i = 0; i < n; i++) h.Add(int.Parse(ip2[i])); float minAbs = Math.Abs(a - (t - h[0] * 0.006f)); int minind = 0; for (int i = 1; i < n; i++) { var d = Math.Abs(a - (t - h[i] * 0.006f)); if (minAbs > d) { minAbs = d; minind = i; } } Console.WriteLine(minind + 1); } static List<int> GetPNLs(int max) { List<int> prime = new List<int>(); if (max <= 1) return new List<int> { 2 }; for (int i = 2; i <= max; i++) { bool isPrime = true; foreach (var p in prime) { if (i % p == 0 && i != p) { isPrime = false; break; } } if (isPrime) prime.Add(i); } return prime; } static int E(int prime, int n) { int k = n; int c = 0; while (k % prime == 0) { k = k / prime; c++; } return c; } static int C(int a, int b) { if (a < b) return 0; return F(a) / (F(b) * F(a - b)); } static int F(int n) { if (n > 1) return F(n - 1) * n; else return 1; } } }
[["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 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], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 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
460
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // 入力 string[] sS = System.Console.ReadLine().Trim().Split(' '); int iN = int.Parse(sS[0]); sS = System.Console.ReadLine().Trim().Split(' '); double dT = double.Parse(sS[0]); double dA = double.Parse(sS[1]); sS = System.Console.ReadLine().Trim().Split(' '); List<ClsPos> lstH = new List<ClsPos>(); for (int i = 0; i < sS.Length; i++) { ClsPos oneUsr = new ClsPos(); oneUsr.iX = i + 1; // 地点No oneUsr.iH = int.Parse(sS[i]); // 標高 oneUsr.dT = dT - (double)oneUsr.iH * 0.006D; // 度 oneUsr.dD = Math.Abs(dA - oneUsr.dT); // 度差 lstH.Add(oneUsr); } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // 解析 lstH.Sort(delegate(ClsPos mca1, ClsPos mca2) { return (int)(mca1.dD - mca2.dD); }); // 度差で昇順 // 出力 System.Console.WriteLine("{0}", lstH[0].iX.ToString().Trim()); sw.Stop(); #if DEBUG Console.WriteLine(); Console.WriteLine("{0}", sw.Elapsed.ToString()); Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } // 情報 private class ClsPos { public int iX { get; set; } = 0; // 地点No public int iH { get; set; } = 0; // 標高 public double dT { get; set; } = 0; // 度 public double dD { get; set; } = 0; // 度差 } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // 入力 string[] sS = System.Console.ReadLine().Trim().Split(' '); int iN = int.Parse(sS[0]); sS = System.Console.ReadLine().Trim().Split(' '); int iT = int.Parse(sS[0]) * 1000; int iA = int.Parse(sS[1]) * 1000; sS = System.Console.ReadLine().Trim().Split(' '); List<ClsPos> lstH = new List<ClsPos>(); for (int i = 0; i < sS.Length; i++) { ClsPos oneUsr = new ClsPos(); oneUsr.iX = i + 1; // 地点No oneUsr.iH = int.Parse(sS[i]); // 標高 oneUsr.iT = iT - oneUsr.iH * 6; // 度 oneUsr.iD = Math.Abs(iA - oneUsr.iT); // 度差 lstH.Add(oneUsr); } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // 解析 lstH.Sort(delegate(ClsPos mca1, ClsPos mca2) { return (int)(mca1.iD - mca2.iD); }); // 度差で昇順 // 出力 System.Console.WriteLine("{0}", lstH[0].iX.ToString().Trim()); sw.Stop(); #if DEBUG Console.WriteLine(); Console.WriteLine("{0}", sw.Elapsed.ToString()); Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } // 情報 private class ClsPos { public int iX { get; set; } = 0; // 地点No public int iH { get; set; } = 0; // 標高 public int iT { get; set; } = 0; // 度 public int iD { get; set; } = 0; // 度差 } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 31, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 11, 12, 16, 12, 16, 31, 74, 0, 24], ["-", 0, 11, 12, 16, 12, 16, 31, 74, 39, 199], ["-", 0, 11, 12, 16, 12, 16, 31, 74, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 12, 250], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 203], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 214, 141, 22], ["-", 0, 74, 51, 23, 0, 16, 31, 214, 141, 22], ["+", 0, 74, 51, 23, 0, 16, 31, 214, 141, 22], ["-", 0, 74, 51, 23, 0, 16, 12, 214, 141, 22], ["+", 0, 74, 51, 23, 0, 16, 12, 214, 141, 22], ["-", 8, 201, 0, 235, 8, 201, 0, 277, 39, 199], ["-", 8, 201, 0, 235, 8, 201, 0, 277, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 277, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 277, 141, 22]]
8
432
43
using System; class Program { static void Main(string[] args) { //入力 int N = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); string[] t = s.Split(' '); //数字の割り当て float T = float.Parse(t[0]); float A = float.Parse(t[1]); string h = Console.ReadLine(); string[] h_split = h.Split(' '); //数字の割り当て float[] H = new float[N]; for (int i = 0; i < N; i++) { H[i] = float.Parse(h_split[i]); } //その高さの温度 float[] temp = new float[N]; //差となる温度(絶対値) float[] diff = new float[N]; //最小値を保存する用の変数 float min_temp = 1145141919f; int a = 0; //各地点において温度を求める for (int i = 0; i < N; i++) { temp[i] = T - H[i] * 0.006f; diff[i] = Math.Abs(A - temp[i]); if (i == 0) { min_temp = diff[0]; } else { min_temp = Math.Min(diff[i], diff[i - 1]); if (diff[i] < diff[i - 1]) { a = i; } } } //出力 Console.WriteLine(a + 1); } }
using System; class Program { static void Main(string[] args) { //入力 int N = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); string[] t = s.Split(' '); //数字の割り当て float T = float.Parse(t[0]); float A = float.Parse(t[1]); string h = Console.ReadLine(); string[] h_split = h.Split(' '); //数字の割り当て float[] H = new float[N]; for (int i = 0; i < N; i++) { H[i] = float.Parse(h_split[i]); } //その高さの温度 float[] temp = new float[N]; //差となる温度(絶対値) float[] diff = new float[N]; //最小値を保存する用の変数 float min_temp = 999.0f; int a = 0; //各地点において温度を求める for (int i = 0; i < N; i++) { temp[i] = T - H[i] * 0.006f; diff[i] = Math.Abs(A - temp[i]); if (i == 0) { min_temp = diff[0]; a = 0; } else { // min_temp = Math.Min(diff[i], diff[i - 1]); // if (diff[i] < diff[i - 1]) { // a = i; //} else { // break; //} if (diff[i] == 0) { a = i; break; } else if (diff[i] < min_temp) { min_temp = diff[i]; a = i; } } } //出力 Console.WriteLine(a + 1); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 75, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 75, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 75, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["-", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35]]
8
299
39
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int N = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int[] H = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray(); int T = a[0]; int A = a[1]; int ans = 1; int difMin = 1000000; for (int i = 0; i < N; i++) { //標高H[i]における平均気温tを求める int t = T - (int)(H[i] * 0.006); // tとAの差difを求める int dif = Math.Abs(t - A); if (dif < difMin) //もしdifが最小値より小さいならば { //最小値を更新 difMin = dif; //その時の場所の番号を記録 ans = i + 1; } } Console.WriteLine(ans); } }
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int N = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int[] H = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray(); int T = a[0]; int A = a[1]; int ans = 1; double difMin = 1000000; for (int i = 0; i < N; i++) { //標高H[i]における平均気温tを求める double t = (double)T - (double)(H[i] * 0.006); // tとAの差difを求める double dif = (double)Math.Abs(t - A); if (dif < difMin) //もしdifが最小値より小さいならば { //最小値を更新 difMin = dif; //その時の場所の番号を記録 ans = i + 1; } } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["-", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25]]
8
205
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace regio { class Class1 { static void Main() { string str; string[] arr; int N, T, A, SaM; int Temp; int bangou = 0; str = Console.ReadLine(); N = int.Parse(str); int H; double Tem, Sa; str = Console.ReadLine(); arr = str.Split(' '); T = int.Parse(arr[0]); A = int.Parse(arr[1]); SaM = 1145141919; str = Console.ReadLine(); arr = str.Split(' '); for (int i = 0; i < N; i++) { H = int.Parse(arr[i]); Temp = (int)0.006 * H; Tem = T - Temp; Sa = Math.Abs(Tem) - A; if (Sa < SaM) { bangou = i; } } Console.WriteLine("{0}", bangou); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace regio { class Class1 { static void Main() { string str; string[] arr; int N, T, A; double Temp, SaM; int bangou = 0; str = Console.ReadLine(); N = int.Parse(str); int H; double Tem, Sa, Te; str = Console.ReadLine(); arr = str.Split(' '); T = int.Parse(arr[0]); A = int.Parse(arr[1]); SaM = 1145141919; str = Console.ReadLine(); arr = str.Split(' '); for (int i = 0; i < N; i++) { H = int.Parse(arr[i]); Temp = 0.006 * H; Tem = T - Temp; Te = Tem - A; Sa = Math.Abs(Te); if (Sa < SaM) { SaM = Sa; bangou = i + 1; } } Console.WriteLine("{0}", bangou); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 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, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
235
27
using System; using System.Collections.Generic; using System.Linq; namespace ABC113_B { internal class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); int t = int.Parse(input[0]); int a = int.Parse(input[1]); string[] h = Console.ReadLine().Split(' '); List<int> hArrs = new List<int>(); List<double> hotMinArrs = new List<double>(); for (int i = 0; i < n; i++) { hArrs.Add(int.Parse(h[i])); hotMinArrs.Add(Math.Abs(a - Math.Abs(t - hArrs[i] * 0.006))); } int hMinKey = 0; for (int i = 0; i < n; i++) { if (hotMinArrs[i] == hotMinArrs.Min()) { hMinKey = i; } } Console.WriteLine(hMinKey + 1); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC113_B { internal class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); int t = int.Parse(input[0]); int a = int.Parse(input[1]); string[] h = Console.ReadLine().Split(' '); List<int> hArrs = new List<int>(); List<double> hotMinArrs = new List<double>(); for (int i = 0; i < n; i++) { hArrs.Add(int.Parse(h[i])); hotMinArrs.Add(Math.Abs(a - (t - hArrs[i] * 0.006))); } Console.WriteLine(hotMinArrs.IndexOf(hotMinArrs.Min()) + 1); } } }
[["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 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, 7, 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, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 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], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
246
46
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { int kazu = int.Parse(ReadLine()); string[] input = ReadLine().Split(' '); int kion = int.Parse(input[0]); int mokuhyo = int.Parse(input[1]); string[] hyokol = ReadLine().Split(' '); int minsa = 99999999; int titen = 0; for (int i = 0; i < kazu; i++) { int hyoko = int.Parse(hyokol[i]); int kionh = kion - ((hyoko * 6) / 1000); int sa = Abs(kionh - mokuhyo); if (minsa > sa) { minsa = sa; titen = i + 1; } } WriteLine(titen); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { int kazu = int.Parse(ReadLine()); string[] kionmo = ReadLine().Split(' '); int kion = int.Parse(kionmo[0]); int moku = int.Parse(kionmo[1]); string[] hyokol = ReadLine().Split(' '); double minsa = 99999999; int titen = 0; for (int i = 0; i < kazu; i++) { int hyoko = int.Parse(hyokol[i]); double hiku = (double)(hyoko * 6) / 1000; double kionh = (double)kion - hiku; double sa = Abs(kionh - (double)moku); // WriteLine(kionh); // WriteLine(sa); if (minsa > sa) { minsa = sa; titen = i + 1; } } WriteLine(titen); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 51, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 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], ["+", 3, 4, 0, 28, 0, 16, 12, 74, 51, 22]]
8
197
34
using System; using System.Collections.Generic; using System.Text; namespace AtTest.ABC_113 { class B { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int n = ReadInt(); int[] ta = ReadInts(); int tP = ta[0] * 1000; int aP = ta[1] * 1000; int[] hs = ReadInts(); int resIndex = 0; int deltaMin = int.MaxValue; for (int i = 0; i < n; i++) { int tTemp = tP - hs[i]; int deltaTemp = aP - tTemp; if (deltaMin > deltaTemp) { deltaMin = deltaTemp; resIndex = i; } } Console.WriteLine(resIndex + 1); } private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Text; namespace AtTest.ABC_113 { class B { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int n = ReadInt(); int[] ta = ReadInts(); int tP = ta[0] * 1000; int aP = ta[1] * 1000; int[] hs = ReadInts(); int resIndex = 0; int deltaMin = int.MaxValue; for (int i = 0; i < n; i++) { int tTemp = tP - 6 * hs[i]; int deltaTemp = Math.Abs(aP - tTemp); if (deltaMin > deltaTemp) { deltaMin = deltaTemp; resIndex = i; } } Console.WriteLine(resIndex + 1); } private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["+", 0, 200, 0, 212, 0, 16, 12, 16, 31, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 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
326
7
using System; class hogehoge { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); int t = int.Parse(s[0]); int a = int.Parse(s[1]); string[] u = Console.ReadLine().Split(' '); int[] h = new int[n]; for (int i = 0; i < n; i++) { h[i] = int.Parse(u[i]); } int r = 0; for (int i = 1; i < n; i++) { if (Math.Abs(a - ((t * 1000) - (h[i] * 6))) < Math.Abs(a - ((t * 1000) - (h[r] * 6)))) r = i; } Console.WriteLine(r + 1); } }
using System; class hogehoge { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); int t = int.Parse(s[0]); int a = int.Parse(s[1]); string[] u = Console.ReadLine().Split(' '); int[] h = new int[n]; for (int i = 0; i < n; i++) { h[i] = int.Parse(u[i]); } int r = 0; for (int i = 1; i < n; i++) { if (Math.Abs((a * 1000) - ((t * 1000) - (h[i] * 6))) < Math.Abs((a * 1000) - ((t * 1000) - (h[r] * 6)))) r = i; } Console.WriteLine(r + 1); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24]]
8
220
8