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.Linq; namespace ProblemA { class Program { static void Main(string[] args) { string S = CIN.String(); char initial = S[0]; for (int i = 1; i < 4; i++) { if (initial == S[i]) { Console.WriteLine("Bad"); return; } } Console.WriteLine("Good"); } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
using System; using System.Linq; namespace ProblemA { class Program { static void Main(string[] args) { string S = CIN.String(); char initial = S[0]; for (int i = 1; i < 4; i++) { if (initial == S[i]) { Console.WriteLine("Bad"); return; } initial = S[i]; } Console.WriteLine("Good"); } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
257
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC131 { class Program { static void Main(string[] args) { char[] input = Console.ReadLine().ToCharArray(); char mem; string output = ""; for (int i = 0; i < 4; i++) { mem = input[i]; if (mem == input[i]) { output = "Bad"; break; } output = "Good"; } Console.WriteLine(output); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC131 { class Program { static void Main(string[] args) { char[] input = Console.ReadLine().ToCharArray(); char mem = input[0]; string output = ""; for (int i = 1; i < 4; i++) { if (mem == input[i]) { output = "Bad"; break; } mem = input[i]; output = "Good"; } Console.WriteLine(output); } } }
[["+", 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, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
125
21
using System; using System.Text.RegularExpressions; namespace ABC131A { class Program { static void Main(string[] args) { Console.WriteLine(Regex.IsMatch(Console.ReadLine(), @"([0-9])\1")); } } }
using System; using System.Text.RegularExpressions; namespace ABC131A { class Program { static void Main(string[] args) { Console.WriteLine(Regex.IsMatch(Console.ReadLine(), @"([0-9])\1") ? "Bad" : "Good"); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
47
8
using System; class Solution { public string Proc(string val) { char before = ' '; foreach (var it in val) { if (before == it) return "Bad"; before = it; } return "Good"; } } class Program { static string[] GetVals(string splitChar) { var src = Console.ReadLine(); return src.Split(new string[] { splitChar }, StringSplitOptions.None); } static string[] GetVals(char splitChar) { var src = Console.ReadLine(); return src.Split(splitChar); } static string GetVal() { return Console.ReadLine(); } static void Write(object o) { Console.WriteLine(String.Format("{0}", o)); } static int ParseI(string val) { return int.Parse(val); } static double ParseD(string val) { return double.Parse(val); } static void Main(string[] args) { // var s = GetVal(); // Write(new Solution().Proc(s)); Write(new Solution().Proc("3776")); // B Write(new Solution().Proc("8080")); // G Write(new Solution().Proc("1333")); // B GetVal(); } }
using System; class Solution { public string Proc(string val) { char before = ' '; foreach (var it in val) { if (before == it) return "Bad"; before = it; } return "Good"; } } class Program { static string[] GetVals(string splitChar) { var src = Console.ReadLine(); return src.Split(new string[] { splitChar }, StringSplitOptions.None); } static string[] GetVals(char splitChar) { var src = Console.ReadLine(); return src.Split(splitChar); } static string GetVal() { return Console.ReadLine(); } static void Write(object o) { Console.WriteLine(String.Format("{0}", o)); } static int ParseI(string val) { return int.Parse(val); } static double ParseD(string val) { return double.Parse(val); } static void Main(string[] args) { var s = GetVal(); Write(new Solution().Proc(s)); // Write(new Solution().Proc("3776"));//B // Write(new Solution().Proc("8080"));//G // Write(new Solution().Proc("1333"));//B // GetVal(); } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 63, 214, 205, 230, 0, 228], ["-", 0, 28, 0, 213, 63, 214, 205, 230, 39, 22], ["-", 0, 213, 63, 214, 205, 230, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 230, 3, 4, 0, 25], ["-", 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, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22]]
8
260
39
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // int[] n = inta(); int min = 99999999; int total = 0; for (int i = 0; i < n[0]; i++) { int a = n[1] + i; min = Min(min, Abs(a)); total += a; } WriteLine(total - min); } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // int[] n = inta(); int min = 99999999; int total = 0; for (int i = 0; i < n[0]; i++) { int a = n[1] + i; min = Min(min, Abs(a)); total += a; } if (total < 0) { WriteLine(total + min); } else { WriteLine(total - min); } } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
[["+", 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, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,518
18
using System; namespace ABC131 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int L = int.Parse(input[1]); int[] aji = new int[N]; for (int i = 0; i < N; i++) { aji[i] = L + i; } if (0 <= L) { aji[0] = 0; } if (L < 0) { if (Math.Abs(L) >= Math.Abs(N)) { aji[N - 1] = 0; } else { aji[L + N - 1] = 0; } } int res = 0; foreach (var k in aji) { res += k; } Console.WriteLine(res); } } }
using System; namespace ABC131 { class B { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int L = int.Parse(input[1]); int[] aji = new int[N]; for (int i = 0; i < N; i++) { aji[i] = L + i; } if (0 <= L) { aji[0] = 0; } if (L < 0) { if (Math.Abs(L) >= Math.Abs(N)) { aji[N - 1] = 0; } } int res = 0; foreach (var k in aji) { res += k; } Console.WriteLine(res); } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["-", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["-", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 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], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["-", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
191
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var NL = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var N = NL[0]; var L = NL[1]; int[] Ringo = new int[N]; int aji_abs = 0; for (int i = 0; i < N; i++) { Ringo[i] = L + i - 1; aji_abs = Math.Abs(Ringo[i]); } if (L >= 0) { Console.WriteLine(Ringo.Sum() - aji_abs); } else { Console.WriteLine(Ringo.Sum() + aji_abs); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var NL = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var N = NL[0]; var L = NL[1]; int[] Ringo = new int[N]; int[] aji_abs = new int[N]; for (int i = 0; i < N; i++) { Ringo[i] = L + i; aji_abs[i] = Math.Abs(Ringo[i]); } if (L >= 0) { Console.WriteLine(Ringo.Sum() - aji_abs.Min()); } else { Console.WriteLine(Ringo.Sum() + aji_abs.Min()); } } } }
[["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 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], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
8
176
21
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace Test { public class Program { public static void Main(string[] args) { new Program().abc131_b(); } public void abc131_b() { var CinTemp = ReadLine().Split(' '); int a = int.Parse(CinTemp[0]); int b = int.Parse(CinTemp[1]); int ans = 100000; int total = 0; for (int i = 0; i < a; i++) { total += b + i; ans = Min(ans, b + i); } WriteLine(total - ans); } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace Test { public class Program { public static void Main(string[] args) { new Program().abc131_b(); } public void abc131_b() { var CinTemp = ReadLine().Split(' '); int a = int.Parse(CinTemp[0]); int b = int.Parse(CinTemp[1]); int ans = 100000; int total = 0; for (int i = 0; i < a; i++) { total += b + i; ans = Abs(ans) > Abs(b + i) ? b + i : ans; } WriteLine(total - ans); } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 11, 12, 41, 15, 16, 31, 213, 63, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 41, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 47], ["+", 0, 11, 12, 41, 15, 16, 12, 213, 63, 22], ["+", 12, 41, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 0, 1, 0, 11, 12, 41, 64, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 41, 64, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 41, 64, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 75, 22]]
8
164
13
using System; using System.Linq; namespace B { class Program { static void Main(string[] args) { var nl = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var n = nl[0]; var l = nl[1]; var taste = new int [n].ToList(); for (var i = 0; i < n; i++) { taste[i] = l + i; } if (taste.Contains(0)) { Console.WriteLine(taste.Sum()); return; } var min = int.MaxValue; var minj = 0; for (var i = 0; i < n; i++) { if (min > Math.Abs(taste[i])) { minj = i; } } if (taste[minj] > 0) { Console.WriteLine(taste.Sum() - Math.Abs(taste[minj])); } else { Console.WriteLine(taste.Sum() + Math.Abs(taste[minj])); } } } }
using System; using System.Linq; namespace B { class Program { static void Main(string[] args) { var nl = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var n = nl[0]; var l = nl[1]; var taste = new int [n].ToList(); for (var i = 0; i < n; i++) { taste[i] = l + i; } if (taste.Contains(0)) { Console.WriteLine(taste.Sum()); return; } var min = int.MaxValue; var minj = 0; for (var i = 0; i < n; i++) { if (min > Math.Abs(taste[i])) { min = Math.Abs(taste[i]); minj = i; } } if (taste[minj] > 0) { Console.WriteLine(taste.Sum() - Math.Abs(taste[minj])); } else { Console.WriteLine(taste.Sum() + Math.Abs(taste[minj])); } } } }
[["+", 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, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
234
12
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { public class Program { public static void Main(string[] args) { int[] NL = Read(Console.ReadLine()); int N = NL[0]; int L = NL[1]; int sum2 = (2 * L + N - 1) * N; if (L < 0) Console.WriteLine(sum2 / 2); else { Console.WriteLine(sum2 / 2 - L); } } private static bool S(int[] data, int K, int l, int x) { int sum = 0; int max = Math.Min(x + 1, data.Length); for (int i = l; i < max; i++) { sum += data[i]; } // Console.WriteLine(sum); return sum >= K; } private static int Stair(int N) { if (N < 0) return 0; int twoM = N / 2; int ans = 0; for (int two = 0; two < twoM + 1; two++) { int one = N - 2 * two; ans += Combination(one + two, two); } return ans; } private static int Combination(int N, int M) { int ans = Product(N) / (Product(M) * Product(N - M)); return ans; } private static int Product(int N) { if (N == 0 || N == 1) return 1; int ans = N; for (int i = 1; i < N; i++) { ans *= i; } return ans; } private static string ReplaceOneChar(string S, int index, string newS) { string s1 = S.Substring(0, index - 1); string s2 = S.Substring(index); return s1 + newS + s2; } private static bool PartialSum(int target, int[] Ns) { // if (target == 0) return true; bool[][] ps = new bool [Ns.Length + 1][]; // i=0では、どんなWに対してもfalse ps[0] = new bool[target + 1]; for (int i = 0; i < ps[0].Length; i++) ps[0][i] = false; ps[0][0] = true; //考慮に入れるitemを、前から順に追加していく for (int i = 0; i < Ns.Length; i++) { //初期化 ps[i + 1] = new bool[target + 1]; for (int t = 0; t <= target; t++) { if (t >= Ns[i]) ps[i + 1][t] = ps[i][t - Ns[i]] || ps[i][t]; else ps[i + 1][t] = ps[i][t]; } } return ps[Ns.Length][target]; } /// <summary> /// 引数は、W(重さ制限)、items[重さ][価値] /// </summary> /// <param name="W"></param> /// <param name="items"></param> /// <returns></returns> private static int DP(int W, int[][] items) { //データ int[][] dp = new int [items.Length + 1][]; // i=0では、どんなWに対しても0 dp[0] = new int[W + 1]; //考慮に入れるitemを、前から順に追加していく for (int i = 0; i < items.Length; i++) { //初期化 dp[i + 1] = new int[W + 1]; for (int w = 0; w <= W; w++) { if (w >= items[i][0]) dp[i + 1][w] = Math.Max(dp[i][w - items[i][0]] + items[i][1], dp[i][w]); else dp[i + 1][w] = dp[i][w]; } } return dp[items.Length][W]; } private static int[] Read(string input) { string[] inputs = input.Split(' '); int num = inputs.Length; int[] ints = new int[num]; for (int i = 0; i < num; i++) { ints[i] = int.Parse(inputs[i]); } return ints; } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { public class Program { public static void Main(string[] args) { int[] NL = Read(Console.ReadLine()); int N = NL[0]; int L = NL[1]; int sum2 = (2 * L + N - 1) * N; int min = L; int max = L + N - 1; if (max < 0) Console.WriteLine(sum2 / 2 - max); else if (min > 0) Console.WriteLine(sum2 / 2 - min); else { Console.WriteLine(sum2 / 2); } } private static bool S(int[] data, int K, int l, int x) { int sum = 0; int max = Math.Min(x + 1, data.Length); for (int i = l; i < max; i++) { sum += data[i]; } // Console.WriteLine(sum); return sum >= K; } private static int Stair(int N) { if (N < 0) return 0; int twoM = N / 2; int ans = 0; for (int two = 0; two < twoM + 1; two++) { int one = N - 2 * two; ans += Combination(one + two, two); } return ans; } private static int Combination(int N, int M) { int ans = Product(N) / (Product(M) * Product(N - M)); return ans; } private static int Product(int N) { if (N == 0 || N == 1) return 1; int ans = N; for (int i = 1; i < N; i++) { ans *= i; } return ans; } private static string ReplaceOneChar(string S, int index, string newS) { string s1 = S.Substring(0, index - 1); string s2 = S.Substring(index); return s1 + newS + s2; } private static bool PartialSum(int target, int[] Ns) { // if (target == 0) return true; bool[][] ps = new bool [Ns.Length + 1][]; // i=0では、どんなWに対してもfalse ps[0] = new bool[target + 1]; for (int i = 0; i < ps[0].Length; i++) ps[0][i] = false; ps[0][0] = true; //考慮に入れるitemを、前から順に追加していく for (int i = 0; i < Ns.Length; i++) { //初期化 ps[i + 1] = new bool[target + 1]; for (int t = 0; t <= target; t++) { if (t >= Ns[i]) ps[i + 1][t] = ps[i][t - Ns[i]] || ps[i][t]; else ps[i + 1][t] = ps[i][t]; } } return ps[Ns.Length][target]; } /// <summary> /// 引数は、W(重さ制限)、items[重さ][価値] /// </summary> /// <param name="W"></param> /// <param name="items"></param> /// <returns></returns> private static int DP(int W, int[][] items) { //データ int[][] dp = new int [items.Length + 1][]; // i=0では、どんなWに対しても0 dp[0] = new int[W + 1]; //考慮に入れるitemを、前から順に追加していく for (int i = 0; i < items.Length; i++) { //初期化 dp[i + 1] = new int[W + 1]; for (int w = 0; w <= W; w++) { if (w >= items[i][0]) dp[i + 1][w] = Math.Max(dp[i][w - items[i][0]] + items[i][1], dp[i][w]); else dp[i + 1][w] = dp[i][w]; } } return dp[items.Length][W]; } private static int[] Read(string input) { string[] inputs = input.Split(' '); int num = inputs.Length; int[] ints = new int[num]; for (int i = 0; i < num; i++) { ints[i] = int.Parse(inputs[i]); } return ints; } } }
[["+", 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], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
873
38
using System; class B_Bite_Eating { static void Main(string[] args) { string[] NL = Console.ReadLine().Split(' '); int N = int.Parse(NL[0]); int L = int.Parse(NL[1]); int Eaten; if (L <= 0 && L + N - 1 >= 1) Eaten = 0; else Eaten = Math.Min(Math.Abs(L), Math.Abs(L + N - 1)); Console.WriteLine(N * (2 * L + N - 1) / 2 - Eaten); } }
using System; class B_Bite_Eating { static void Main(string[] args) { string[] NL = Console.ReadLine().Split(' '); int N = int.Parse(NL[0]); int L = int.Parse(NL[1]); int Eaten; if (L <= 0 && L + N - 1 >= 1) Eaten = 0; else { if (Math.Abs(L) < Math.Abs(L + N - 1)) Eaten = L; else Eaten = L + N - 1; } Console.WriteLine(N * (2 * L + N - 1) / 2 - Eaten); } }
[["-", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 75, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 75, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 75, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 18], ["+", 75, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 75, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 75, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 75, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
130
22
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here int N = Cin, L = Cin; int maxSum = int.MinValue; int minAbs = int.MaxValue; for (int i = 0; i < N; i++) { int sum = 0; for (int r = 0; r < N; r++) { if (i != r) sum += L + r; } if (minAbs > Abs(i)) maxSum = sum; } Coutln(maxSum); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here int N = Cin, L = Cin; int maxSum = int.MinValue; int minAbs = int.MaxValue; for (int i = 0; i < N; i++) { int sum = 0; for (int r = 0; r < N; r++) { if (i != r) sum += L + r; } if (minAbs > Abs(L + i)) { maxSum = sum; minAbs = Abs(L + i); } } Coutln(maxSum); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 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], ["+", 64, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,735
13
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(' '); int b = int.Parse(a[0]); int c = int.Parse(a[1]); int d = 0; int[] atr = new int[b]; int min = 999999999; for (int i = 1; i <= b; i++) { d = c + i - 1; atr[i - 1] = d; min = System.Math.Min(min, System.Math.Abs(d)); } int ans = 0; for (int i = 0; i < atr.Length; i++) { if (atr[i] != min) { ans = ans + atr[i]; } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(' '); int b = int.Parse(a[0]); int c = int.Parse(a[1]); int d = 0; int[] atr = new int[b]; int min = 999999999; for (int i = 1; i <= b; i++) { d = c + i - 1; atr[i - 1] = d; min = System.Math.Min(min, System.Math.Abs(d)); } if (d < 0) { min = min * -1; } int ans = 0; for (int i = 0; i < atr.Length; i++) { if (atr[i] != min) { ans = ans + atr[i]; } } Console.WriteLine(ans); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 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, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 241, 0, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
205
15
using System; class Program { static void Main(string[] args) {   int N, L; string[] str = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得 N = int.Parse(str[0]); //数値で受け取りたい場合は変換する L = int.Parse(str[1]); int pickup_idx = -1; int pickup_val = 200; int sum = 0; for (int i = 0; i < N; i++) { int v = L + i; if (v > 100) { v = 100; } if (v < -100) { v = -100; } sum += v; if (Math.Abs(v) < Math.Abs(pickup_val)) { pickup_idx = i; pickup_val = v; } } sum -= pickup_val; Console.WriteLine(sum); } }
using System; class Program { static void Main(string[] args) {   int N, L; string[] str = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得 N = int.Parse(str[0]); //数値で受け取りたい場合は変換する L = int.Parse(str[1]); int pickup_idx = -1; int pickup_val = 1000; int sum = 0; for (int i = 0; i < N; i++) { int v = L + i; sum += v; if (Math.Abs(v) < Math.Abs(pickup_val)) { pickup_idx = i; pickup_val = v; } } sum -= pickup_val; Console.WriteLine(sum); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 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], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 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, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203]]
8
174
28
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; using static System.Math; using static Func; 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(); uint[] GU => Strs.Select(uint.Parse).ToArray(); decimal[] GD => Strs.Select(decimal.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); static ulong One(int k) => 1ul << k; static ulong All(int k) => One(k) - 1; static bool Has(ulong s, int k) => (s & One(k)) != 0; const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var I = G; int N = I[0], L = I[1]; var min = Abs(L); var sum = L; for (var i = 1; i < N; i++) { min = Min(min, Abs(L + i)); sum += L + i; } WriteLine(sum - min); } } static class Func { static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; } static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; } static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; } static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; } public static long GCD(long a, long b) { var n = (ulong)Math.Abs(a); var m = (ulong)Math.Abs(b); if (n == 0) return (long)m; if (m == 0) return (long)n; int zm = 0, zn = 0; while ((n & 1) == 0) { n >>= 1; zn++; } while ((m & 1) == 0) { m >>= 1; zm++; } while (m != n) { if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; } else { n -= m; while ((n & 1) == 0) n >>= 1; } } return (long)n << Math.Min(zm, zn); } public static long Inverse(long a, long mod) { if (a < 0) { a %= mod; if (a < 0) a += mod; } var t = SolveLinear(a, mod); return t.Item1 > 0 ? t.Item1 : t.Item1 + mod; } public static long Pow(long a, long b, long mod) { var p = 1L; var x = a; while (b > 0) { if ((b & 1) == 1) p = (p * x) % mod; b >>= 1; x = (x * x) % mod; } return p; } public static Tuple<long, long> SolveLinear(long n, long m) { if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); } if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); } if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); } long a = 1, b = 0, c = 0, d = 1; while (m > 0) { var r = n % m; var q = n / m; n = m; m = r; var tmp = a; a = -a * q + b; b = tmp; tmp = c; c = -c * q + d; d = tmp; } return n != 1 ? null : new Tuple<long, long>(d, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Console; using static System.Math; using static Func; 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(); uint[] GU => Strs.Select(uint.Parse).ToArray(); decimal[] GD => Strs.Select(decimal.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); static ulong One(int k) => 1ul << k; static ulong All(int k) => One(k) - 1; static bool Has(ulong s, int k) => (s & One(k)) != 0; const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var I = G; int N = I[0], L = I[1]; var min = Abs(L); var am = 0; var sum = L; for (var i = 1; i < N; i++) { if (min > Abs(L + i)) { min = Abs(L + i); am = i; } sum += L + i; } WriteLine(sum - (L + am)); } } static class Func { static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; } static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; } static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; } static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; } public static long GCD(long a, long b) { var n = (ulong)Math.Abs(a); var m = (ulong)Math.Abs(b); if (n == 0) return (long)m; if (m == 0) return (long)n; int zm = 0, zn = 0; while ((n & 1) == 0) { n >>= 1; zn++; } while ((m & 1) == 0) { m >>= 1; zm++; } while (m != n) { if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; } else { n -= m; while ((n & 1) == 0) n >>= 1; } } return (long)n << Math.Min(zm, zn); } public static long Inverse(long a, long mod) { if (a < 0) { a %= mod; if (a < 0) a += mod; } var t = SolveLinear(a, mod); return t.Item1 > 0 ? t.Item1 : t.Item1 + mod; } public static long Pow(long a, long b, long mod) { var p = 1L; var x = a; while (b > 0) { if ((b & 1) == 1) p = (p * x) % mod; b >>= 1; x = (x * x) % mod; } return p; } public static Tuple<long, long> SolveLinear(long n, long m) { if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); } if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); } if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); } long a = 1, b = 0, c = 0, d = 1; while (m > 0) { var r = n % m; var q = n / m; n = m; m = r; var tmp = a; a = -a * q + b; b = tmp; tmp = c; c = -c * q + d; d = tmp; } return n != 1 ? null : new Tuple<long, long>(d, b); } }
[["+", 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, 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, 213, 63, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 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], ["+", 64, 196, 0, 1, 0, 11, 12, 213, 63, 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, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 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, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 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, 72], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
1,210
31
using System; using System.Linq; class Program { static void Main(string[] args) { int[] line = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 0; for (int i = 1; i < line.Length - 1; i++) { var target = line[i]; var intArray = new int[] { line[i], line[i - 1], line[i + 1] }; Array.Sort(intArray); if (target == intArray[1]) { ans++; } } Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { var a = Console.ReadLine(); int[] line = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 0; for (int i = 1; i < line.Length - 1; i++) { var intArray = new int[] { line[i], line[i - 1], line[i + 1] }; Array.Sort(intArray); if (line[i] == intArray[1]) ans++; } Console.WriteLine(ans); } }
[["+", 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, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 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, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
138
24
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; namespace AtCoder { class Program { static void Main() { var N = int.Parse(ReadLine()); var raw = ReadLine().Split().Select(int.Parse).ToArray(); if (N < 5) { WriteLine(0); return; } var ans = 0; for (int i = 0; i < N - 1; i++) { if (raw[i + 1] == raw.Skip(i).Take(3).OrderBy(s => s).ToList()[1]) ans++; } WriteLine(ans); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; namespace AtCoder { class Program { static void Main() { var N = int.Parse(ReadLine()); var raw = ReadLine().Split().Select(int.Parse).ToArray(); var ans = 0; for (int i = 0; i < N - 2; i++) { if (raw[i + 1] == raw.Skip(i).Take(3).OrderBy(s => s).ToList()[1]) ans++; } WriteLine(ans); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 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, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
161
17
using System; using System.IO; using System.Linq; class sol { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); static void Main(string[] args) { int n = sc.Int; var d = sc.IntArr; Array.Sort(d); foreach (int j in d) { Console.WriteLine(j); } int ans = 0; int i = d.Count<int>(); Console.WriteLine(i); if (d[i / 2 - 1] - d[i / 2] == 0) { ans = 0; } else { ans = d[i / 2] - d[i / 2 - 1]; Console.WriteLine(d[i / 2] + "," + d[i / 2 - 1]); } Prt(ans); sw.Flush(); } static void Prt(string a) => sw.WriteLine(a); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public string Str => sr.ReadLine().Trim(); public int Int => int.Parse(Str); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => ct<T, int>(int.Parse(s)); 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]); } }
using System; using System.IO; using System.Linq; class sol { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); static void Main(string[] args) { int n = sc.Int; var d = sc.IntArr; Array.Sort(d); foreach (int j in d) { // Console.WriteLine(j); } int ans = 0; int i = d.Count<int>(); // Console.WriteLine(i); if (d[i / 2 - 1] - d[i / 2] == 0) { ans = 0; } else { ans = d[i / 2] - d[i / 2 - 1]; // Console.WriteLine(d[i / 2] + "," + d[i / 2 -1]); } Prt(ans); sw.Flush(); } static void Prt(string a) => sw.WriteLine(a); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public string Str => sr.ReadLine().Trim(); public int Int => int.Parse(Str); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => ct<T, int>(int.Parse(s)); 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]); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 16, 31, 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, 85], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 17, 85], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
454
39
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int cnt = 0; var mondaisuu = int.Parse(Console.ReadLine()); var mondai = Console.ReadLine() .Split() .Select(x => int.Parse(x)) .OrderBy(x => x) .ToList(); for (int K = mondai[mondaisuu / 2 - 1]; K < mondai[mondaisuu / 2]; K++) { var arcMondai = mondai.Where(x => x >= K); var abcMondai = mondai.Where(x => x < K); if (IsCountMatch(arcMondai, abcMondai)) { cnt = arcMondai.Min() - abcMondai.Max(); break; } } Console.WriteLine(cnt); } private static bool IsCountMatch(IEnumerable<int> mondaiA, IEnumerable<int> mondaiB) { return mondaiA.Count() == mondaiB.Count(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int cnt = 0; var mondaisuu = int.Parse(Console.ReadLine()); var mondai = Console.ReadLine() .Split() .Select(x => int.Parse(x)) .OrderBy(x => x) .ToList(); int K = mondai[mondaisuu / 2]; var arcMondai = mondai.Where(x => x >= K); var abcMondai = mondai.Where(x => x < K); if (IsCountMatch(arcMondai, abcMondai)) { cnt = arcMondai.Min() - abcMondai.Max(); } Console.WriteLine(cnt); } private static bool IsCountMatch(IEnumerable<int> mondaiA, IEnumerable<int> mondaiB) { return mondaiA.Count() == mondaiB.Count(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 10, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 17, 85], ["-", 206, 207, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 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, 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, 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
211
20
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace _20190629_ABC { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var di = Console.ReadLine().Split(' '); int X, Y; // X:配列の中央の大きいほう、 Y:配列の真ん中の小さいほう int[] int_di = new int[N]; for (int i = 0; i < N; i++) { int_di[i] = int.Parse(di[i]); Console.WriteLine(int_di[i]); } // diを降順に整列し、平均値を求める Array.Sort(int_di); double int_diAverage = int_di.Average(); X = int_di[(int_di.Length / 2)]; Y = int_di[((int_di.Length / 2) - 1)]; Console.WriteLine(X - Y); } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace _20190629_ABC { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var di = Console.ReadLine().Split(' '); int X, Y; // X:配列の中央の大きいほう、 Y:配列の真ん中の小さいほう int[] int_di = new int[N]; for (int i = 0; i < N; i++) { int_di[i] = int.Parse(di[i]); } // diを降順に整列し、平均値を求める Array.Sort(int_di); X = int_di[(int_di.Length / 2)]; Y = int_di[((int_di.Length / 2) - 1)]; Console.WriteLine(X - Y); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 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]]
8
183
19
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var NK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var (N, K) = (NK[0], NK[1]); var mCombination = new ModCombination(2000); for (int i = 0; i < K; i++) { var r = N - K; var rFree = r - i; var rInsert = i + 1; var rCombination = mCombination.Combination(rFree + rInsert, rInsert); var b = K; var bFree = (i == 0) ? 0 : b - (i + 1); var bInsert = i; var bCombination = mCombination.Combination(bFree + bInsert, bInsert); var ans = rCombination * bCombination; WriteLine(ans); } } } class ModCombination { private ModInt[] fact, ifact; public int MaxN { get; } public ModCombination(int maxN) { if (maxN < 0 || ModInt.Mod <= maxN) throw new ArgumentException(); MaxN = maxN; fact = new ModInt[maxN + 1]; ifact = new ModInt[maxN + 1]; fact[0] = new ModInt(1); for (int i = 1; i <= maxN; ++i) fact[i] = fact[i - 1] * new ModInt(i); ifact[maxN] = ModInt.Inv(fact[maxN]); for (int i = maxN; i >= 1; --i) ifact[i - 1] = ifact[i] * new ModInt(i); } public ModInt Combination(int n, int k) { if ((n < 0 || MaxN < n) || (k < 0 || n < k)) throw new ArgumentException(); return fact[n] * ifact[k] * ifact[n - k]; } } struct ModInt { public const int Mod = 1000000007; public long X { get; } public ModInt(long x = 0) => X = (x % Mod + Mod) % Mod; public static ModInt operator +(ModInt mint) => mint; public static ModInt operator -(ModInt mint) => new ModInt(-mint.X); public static ModInt operator +(ModInt mint1, ModInt mint2) => new ModInt(mint1.X + mint2.X); public static ModInt operator -(ModInt mint1, ModInt mint2) => new ModInt(mint1.X - mint2.X); public static ModInt operator *(ModInt mint1, ModInt mint2) => new ModInt(mint1.X * mint2.X); public static ModInt operator /(ModInt mint1, ModInt mint2) => mint1 * Inv(mint2); public static ModInt Pow(ModInt mint, long t) { if (t == 0) return new ModInt(1); var a = Pow(mint, t >> 1); a *= a; if (t % 2 == 1) a *= mint; return a; } public static ModInt Inv(ModInt mint) => Pow(mint, Mod - 2); public override string ToString() => X.ToString(); }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var NK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var (N, K) = (NK[0], NK[1]); var mCombination = new ModCombination(2001); for (int i = 0; i < K; i++) { var r = N - K; var rFree = r - i; if (rFree < 0) { WriteLine(0); continue; } var rInsert = i + 1; var rCombination = mCombination.Combination(rFree + rInsert, rInsert); var b = K; var bFree = (i == 0) ? 0 : b - (i + 1); var bInsert = i; var bCombination = mCombination.Combination(bFree + bInsert, bInsert); var ans = rCombination * bCombination; WriteLine(ans); } } } class ModCombination { private ModInt[] fact, ifact; public int MaxN { get; } public ModCombination(int maxN) { if (maxN < 0 || ModInt.Mod <= maxN) throw new ArgumentException(); MaxN = maxN; fact = new ModInt[maxN + 1]; ifact = new ModInt[maxN + 1]; fact[0] = new ModInt(1); for (int i = 1; i <= maxN; ++i) fact[i] = fact[i - 1] * new ModInt(i); ifact[maxN] = ModInt.Inv(fact[maxN]); for (int i = maxN; i >= 1; --i) ifact[i - 1] = ifact[i] * new ModInt(i); } public ModInt Combination(int n, int k) { if ((n < 0 || MaxN < n) || (k < 0 || n < k)) throw new ArgumentException(); return fact[n] * ifact[k] * ifact[n - k]; } } struct ModInt { public const int Mod = 1000000007; public long X { get; } public ModInt(long x = 0) => X = (x % Mod + Mod) % Mod; public static ModInt operator +(ModInt mint) => mint; public static ModInt operator -(ModInt mint) => new ModInt(-mint.X); public static ModInt operator +(ModInt mint1, ModInt mint2) => new ModInt(mint1.X + mint2.X); public static ModInt operator -(ModInt mint1, ModInt mint2) => new ModInt(mint1.X - mint2.X); public static ModInt operator *(ModInt mint1, ModInt mint2) => new ModInt(mint1.X * mint2.X); public static ModInt operator /(ModInt mint1, ModInt mint2) => mint1 * Inv(mint2); public static ModInt Pow(ModInt mint, long t) { if (t == 0) return new ModInt(1); var a = Pow(mint, t >> 1); a *= a; if (t % 2 == 1) a *= mint; return a; } public static ModInt Inv(ModInt mint) => Pow(mint, Mod - 2); public override string ToString() => X.ToString(); }
[["-", 0, 212, 0, 230, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 230, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 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, 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, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
670
17
using System; using System.Collections.Generic; using System.Linq; namespace ABC142D_2 { class Program { static void Main(string[] args) { var NK = ReadInt(); int N = NK[0]; int K = NK[1]; int mod = 1000000007; long[] anss = new long[K]; for (int i = 1; i <= K; i++) { anss[i - 1] = (nCk(N - K + 1, i, mod) * nCk(K - 1, i - 1, mod)) % mod; } foreach (var a in anss) { Console.WriteLine(a); } Console.ReadKey(); } static int[] ReadInt() { int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray(); return ret; } static long[] ReadLong() { long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray(); return ret; } /// <summary> /// a^n (mod p) /// nが非常に大きい時に有効 /// </summary> /// <param name="a"></param> /// <param name="n"></param> /// <param name="mod"></param> /// <returns></returns> public static long ModPow(long a, long n, long p) { if (n == 0) return 1; if (n == 1) return a % p; if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p; long t = ModPow(a, n / 2, p); return (t * t) % p; } /// <summary> /// 組み合わせ個数 /// </summary> /// <param name="n"></param> /// <param name="k"></param> /// <param name="p"></param> /// <returns></returns> public static long nCk(long n, long k, long p) { long ans = 1; k = Math.Min(k, n - k); for (long i = n; i > n - k; i--) { ans = (ans * i) % p; } for (long i = 1; i <= k; i++) { ans = (ans * ModPow(i, p - 2, p)) % p; } return ans; } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC142D_2 { class Program { static void Main(string[] args) { var NK = ReadInt(); int N = NK[0]; int K = NK[1]; int mod = 1000000007; long[] anss = new long[K]; for (int i = 1; i <= K; i++) { if (i > N - K + 1) { break; } anss[i - 1] = (nCk(N - K + 1, i, mod) * nCk(K - 1, i - 1, mod)) % mod; } foreach (var a in anss) { Console.WriteLine(a); } Console.ReadKey(); } static int[] ReadInt() { int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray(); return ret; } static long[] ReadLong() { long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray(); return ret; } /// <summary> /// a^n (mod p) /// nが非常に大きい時に有効 /// </summary> /// <param name="a"></param> /// <param name="n"></param> /// <param name="mod"></param> /// <returns></returns> public static long ModPow(long a, long n, long p) { if (n == 0) return 1; if (n == 1) return a % p; if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p; long t = ModPow(a, n / 2, p); return (t * t) % p; } /// <summary> /// 組み合わせ個数 /// </summary> /// <param name="n"></param> /// <param name="k"></param> /// <param name="p"></param> /// <returns></returns> public static long nCk(long n, long k, long p) { long ans = 1; k = Math.Min(k, n - k); for (long i = n; i > n - k; i--) { ans = (ans * i) % p; } for (long i = 1; i <= k; i++) { ans = (ans * ModPow(i, p - 2, p)) % p; } return ans; } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
424
14
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = inta(); var b = n[1]; var r = n[0] - b; for (int i = 1; i <= n[1]; i++) { long a1 = ncr(b - 1, i - 1); long a2 = ncr(r + 1, r - i + 1); WriteLine((a1 * a2) % mod); // WriteLine($"{a1} {a2}"); } } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = inta(); var b = n[1]; var r = n[0] - b; var m = Min(r + 1, b); for (int i = 1; i <= n[1]; i++) { if (i <= m) { long a1 = ncr(b - 1, i - 1); long a2 = ncr(r + 1, r - i + 1); WriteLine((a1 * a2) % mod); } else { WriteLine(0); } } } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } 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, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,173
28
using AtCoderBeginnerContest132.Questions; using AtCoderBeginnerContest132.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest132.Questions { public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nk = inputStream.ReadIntArray(); var totalBalls = nk[0]; var blueBalls = nk[1]; var redBalls = totalBalls - blueBalls; for (int blueGroup = 1; blueGroup <= blueBalls; blueGroup++) { if (blueGroup <= redBalls + 1) { var combination = Modular.CombinationWithRepetition( blueGroup, blueBalls - blueGroup); combination *= Modular.CombinationWithRepetition( blueGroup + 1, redBalls - (blueGroup - 1)); yield return combination.Value; } else { yield return 0; } } } [System.Runtime.InteropServices.StructLayout( System.Runtime.InteropServices.LayoutKind.Auto)] public struct Modular : IEquatable<Modular>, IComparable<Modular> { private const int _defaultMod = 1000000007; private readonly long _value; // 0 <= value < Mod の値をとる public int Mod { get; } public int Value => (int)_value; public Modular(long value, int mod = _defaultMod) { if (mod < 2) { throw new ArgumentOutOfRangeException( nameof(mod), $"{nameof(mod)}は2以上の素数でなければなりません。"); } Mod = mod; if (value >= 0 && value < mod) { _value = value; } else { _value = value % mod; if (Value < 0) { _value += mod; } } } private static void CheckModEquals(Modular a, Modular b) { if (a.Mod != b.Mod) { throw new ArgumentException( $"{nameof(a)}, {nameof(b)}", $"両者の法({nameof(Mod)})は等しくなければなりません。"); } } public static Modular operator +(Modular a, Modular b) { CheckModEquals(a, b); var result = a._value + b._value; if (result > a.Mod) { result -= a.Mod; // 剰余演算を避ける } return new Modular(result, a.Mod); } public static Modular operator -(Modular a, Modular b) { CheckModEquals(a, b); var result = a._value - b._value; if (result < 0) { result += a.Mod; // 剰余演算を避ける } return new Modular(result, a.Mod); } public static Modular operator *(Modular a, Modular b) { CheckModEquals(a, b); return new Modular(a._value * b._value, a.Mod); } public static Modular operator /(Modular a, Modular b) // こいつは値渡しの方が速いっぽい { CheckModEquals(a, b); return a * Pow(b, a.Mod - 2); } // 需要は不明だけど一応 public static bool operator ==(Modular left, Modular right) => left.Equals(right); public static bool operator !=(Modular left, Modular right) => !(left == right); public static bool operator<(Modular left, Modular right) => left.CompareTo(right) < 0; public static bool operator <=(Modular left, Modular right) => left.CompareTo(right) <= 0; public static bool operator>(Modular left, Modular right) => left.CompareTo(right) > 0; public static bool operator >=(Modular left, Modular right) => left.CompareTo(right) >= 0; public static explicit operator int(Modular a) => a.Value; public static explicit operator long(Modular a) => a._value; public static Modular Pow(Modular a, int n) { switch (n) { case 0: return new Modular(1, a.Mod); case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } private static Dictionary<int, List<int>> FactorialCache { get; } = new Dictionary<int, List<int>>(); private static Dictionary<int, List<int>> PermutationCache { get; } = new Dictionary<int, List<int>>(); public static Modular Factorial(int n, int mod = _defaultMod) { if (n < 0) { throw new ArgumentOutOfRangeException( nameof(n), $"{nameof(n)}は0以上の整数でなければなりません。"); } if (mod < 2) { throw new ArgumentOutOfRangeException( nameof(mod), $"{nameof(mod)}は2以上の素数でなければなりません。"); } if (!FactorialCache.ContainsKey(mod)) { FactorialCache.Add(mod, new List<int>() { 1 }); } var cache = FactorialCache[mod]; for (int i = cache.Count; i <= n; i++) // Countが1(0!までキャッシュ済み)のとき1!~n!まで計算 { cache.Add((int)((long)cache[i - 1] * i % mod)); } return new Modular(cache[n], mod); } public static Modular Permutation(int n, int r, int mod = _defaultMod) { CheckNR(n, r); if (!PermutationCache.ContainsKey(mod ^ n)) { PermutationCache.Add(mod ^ n, new List<int>() { 1 }); } var cache = PermutationCache[mod ^ n]; for (int i = cache.Count; i <= r; i++) // Countが1(nP0までキャッシュ済み)のときnP1~nPrまで計算 { cache.Add((int)((long)cache[i - 1] * (n - (i - 1)) % mod)); } return new Modular(cache[r], mod); } public static Modular Combination(int n, int r, int mod = _defaultMod) { CheckNR(n, r); r = Math.Min(r, n - r); return n == r ? new Modular(1, mod) : Permutation(n, r, mod) / Factorial(r, mod); // nCr = n! / (n-r)!r! = nPr / n! } public static Modular CombinationWithRepetition(int n, int r, int mod = _defaultMod) => Combination(n + r - 1, r, mod); private static void CheckNR(int n, int r) { if (n <= 0) { throw new ArgumentOutOfRangeException( nameof(n), $"{nameof(n)}は正の整数でなければなりません。"); } if (r < 0) { throw new ArgumentOutOfRangeException( nameof(r), $"{nameof(r)}は0以上の整数でなければなりません。"); } if (n < r) { throw new ArgumentOutOfRangeException( $"{nameof(n)},{nameof(r)}", $"{nameof(r)}は{nameof(n)}以下でなければなりません。"); } } public override string ToString() => $"{_value} (mod {Mod})"; public bool Equals(Modular other) => _value == other._value && Mod == other.Mod; public int CompareTo(Modular other) => Mod == other.Mod ? _value.CompareTo(other._value) : 0; public override int GetHashCode() => Value ^ Mod; } } } namespace AtCoderBeginnerContest132 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest132.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest132.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using AtCoderBeginnerContest132.Questions; using AtCoderBeginnerContest132.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest132.Questions { public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nk = inputStream.ReadIntArray(); var totalBalls = nk[0]; var blueBalls = nk[1]; var redBalls = totalBalls - blueBalls; for (int blueGroup = 1; blueGroup <= blueBalls; blueGroup++) { if (blueGroup <= redBalls + 1) { var combination = blueBalls != 1 ? Modular.CombinationWithRepetition( blueGroup, blueBalls - blueGroup) : new Modular(1); combination *= Modular.CombinationWithRepetition( blueGroup + 1, redBalls - (blueGroup - 1)); yield return combination.Value; } else { yield return 0; } } } [System.Runtime.InteropServices.StructLayout( System.Runtime.InteropServices.LayoutKind.Auto)] public struct Modular : IEquatable<Modular>, IComparable<Modular> { private const int _defaultMod = 1000000007; private readonly long _value; // 0 <= value < Mod の値をとる public int Mod { get; } public int Value => (int)_value; public Modular(long value, int mod = _defaultMod) { if (mod < 2) { throw new ArgumentOutOfRangeException( nameof(mod), $"{nameof(mod)}は2以上の素数でなければなりません。"); } Mod = mod; if (value >= 0 && value < mod) { _value = value; } else { _value = value % mod; if (Value < 0) { _value += mod; } } } private static void CheckModEquals(Modular a, Modular b) { if (a.Mod != b.Mod) { throw new ArgumentException( $"{nameof(a)}, {nameof(b)}", $"両者の法({nameof(Mod)})は等しくなければなりません。"); } } public static Modular operator +(Modular a, Modular b) { CheckModEquals(a, b); var result = a._value + b._value; if (result > a.Mod) { result -= a.Mod; // 剰余演算を避ける } return new Modular(result, a.Mod); } public static Modular operator -(Modular a, Modular b) { CheckModEquals(a, b); var result = a._value - b._value; if (result < 0) { result += a.Mod; // 剰余演算を避ける } return new Modular(result, a.Mod); } public static Modular operator *(Modular a, Modular b) { CheckModEquals(a, b); return new Modular(a._value * b._value, a.Mod); } public static Modular operator /(Modular a, Modular b) // こいつは値渡しの方が速いっぽい { CheckModEquals(a, b); return a * Pow(b, a.Mod - 2); } // 需要は不明だけど一応 public static bool operator ==(Modular left, Modular right) => left.Equals(right); public static bool operator !=(Modular left, Modular right) => !(left == right); public static bool operator<(Modular left, Modular right) => left.CompareTo(right) < 0; public static bool operator <=(Modular left, Modular right) => left.CompareTo(right) <= 0; public static bool operator>(Modular left, Modular right) => left.CompareTo(right) > 0; public static bool operator >=(Modular left, Modular right) => left.CompareTo(right) >= 0; public static explicit operator int(Modular a) => a.Value; public static explicit operator long(Modular a) => a._value; public static Modular Pow(Modular a, int n) { switch (n) { case 0: return new Modular(1, a.Mod); case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } private static Dictionary<int, List<int>> FactorialCache { get; } = new Dictionary<int, List<int>>(); private static Dictionary<int, List<int>> PermutationCache { get; } = new Dictionary<int, List<int>>(); public static Modular Factorial(int n, int mod = _defaultMod) { if (n < 0) { throw new ArgumentOutOfRangeException( nameof(n), $"{nameof(n)}は0以上の整数でなければなりません。"); } if (mod < 2) { throw new ArgumentOutOfRangeException( nameof(mod), $"{nameof(mod)}は2以上の素数でなければなりません。"); } if (!FactorialCache.ContainsKey(mod)) { FactorialCache.Add(mod, new List<int>() { 1 }); } var cache = FactorialCache[mod]; for (int i = cache.Count; i <= n; i++) // Countが1(0!までキャッシュ済み)のとき1!~n!まで計算 { cache.Add((int)((long)cache[i - 1] * i % mod)); } return new Modular(cache[n], mod); } public static Modular Permutation(int n, int r, int mod = _defaultMod) { CheckNR(n, r); if (!PermutationCache.ContainsKey(mod ^ n)) { PermutationCache.Add(mod ^ n, new List<int>() { 1 }); } var cache = PermutationCache[mod ^ n]; for (int i = cache.Count; i <= r; i++) // Countが1(nP0までキャッシュ済み)のときnP1~nPrまで計算 { cache.Add((int)((long)cache[i - 1] * (n - (i - 1)) % mod)); } return new Modular(cache[r], mod); } public static Modular Combination(int n, int r, int mod = _defaultMod) { CheckNR(n, r); r = Math.Min(r, n - r); return n == r ? new Modular(1, mod) : Permutation(n, r, mod) / Factorial(r, mod); // nCr = n! / (n-r)!r! = nPr / n! } public static Modular CombinationWithRepetition(int n, int r, int mod = _defaultMod) => Combination(n + r - 1, r, mod); private static void CheckNR(int n, int r) { if (n <= 0) { throw new ArgumentOutOfRangeException( nameof(n), $"{nameof(n)}は正の整数でなければなりません。"); } if (r < 0) { throw new ArgumentOutOfRangeException( nameof(r), $"{nameof(r)}は0以上の整数でなければなりません。"); } if (n < r) { throw new ArgumentOutOfRangeException( $"{nameof(n)},{nameof(r)}", $"{nameof(r)}は{nameof(n)}以下でなければなりません。"); } } public override string ToString() => $"{_value} (mod {Mod})"; public bool Equals(Modular other) => _value == other._value && Mod == other.Mod; public int CompareTo(Modular other) => Mod == other.Mod ? _value.CompareTo(other._value) : 0; public override int GetHashCode() => Value ^ Mod; } } } namespace AtCoderBeginnerContest132 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest132.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest132.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 79], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 212, 0, 41, 64, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 200, 0, 212, 0, 41, 75, 230, 0, 228], ["+", 0, 200, 0, 212, 0, 41, 75, 230, 39, 22], ["+", 0, 212, 0, 41, 75, 230, 3, 4, 0, 24], ["+", 0, 41, 75, 230, 3, 4, 0, 28, 0, 203]]
8
1,820
10
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace D { 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 nk = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var p = (long)Math.Pow(10, 9) + 7; for (var i = 1; i <= nk[1]; i++) { var continuousBlue = CombinationCount(nk[0] - nk[1] + 1, i, p); var modBlue = CombinationCount(nk[1] - 1, i - 1, p); Console.WriteLine((continuousBlue * modBlue) % p); } } static long PermutationCount(long n, long k, long mod) { if (n < k) throw new ArgumentException(); var result = 1L; for (var i = 0; i < k; i++) result = (result * (n - i) % mod) % mod; return result; } static long CombinationCount(long n, long k, long mod) { if (n < k) throw new ArgumentException(); k = Math.Min(k, n - k); var top = PermutationCount(n, k, mod); var bottom = PermutationCount(k, k, mod); return (top * Power(bottom, mod - 2, mod)) % mod; } static long Power(long x, long y, long mod) { var result = 1L; while (y > 0) { if ((y & 1) == 1) result = ((result % mod) * (x % mod)) % mod; x = ((x % mod) * (x % mod)) % mod; y >>= 1; } return result; } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace D { 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 nk = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var p = (long)Math.Pow(10, 9) + 7; for (var i = 1; i <= nk[1]; i++) { var continuousBlue = CombinationCount(nk[0] - nk[1] + 1, i, p); var modBlue = CombinationCount(nk[1] - 1, i - 1, p); Console.WriteLine((continuousBlue * modBlue) % p); } } static long PermutationCount(long n, long k, long mod) { if (n < k) return 0; var result = 1L; for (var i = 0; i < k; i++) result = (result * (n - i) % mod) % mod; return result; } static long CombinationCount(long n, long k, long mod) { if (n < k) return 0; k = Math.Min(k, n - k); var top = PermutationCount(n, k, mod); var bottom = PermutationCount(k, k, mod); return (top * Power(bottom, mod - 2, mod)) % mod; } static long Power(long x, long y, long mod) { var result = 1L; while (y > 0) { if ((y & 1) == 1) result = ((result % mod) * (x % mod)) % mod; x = ((x % mod) * (x % mod)) % mod; y >>= 1; } return result; } } }
[["-", 0, 195, 8, 196, 0, 57, 64, 293, 0, 294], ["-", 8, 196, 0, 57, 64, 293, 0, 230, 0, 228], ["-", 8, 196, 0, 57, 64, 293, 0, 230, 39, 22], ["-", 0, 57, 64, 293, 0, 230, 3, 4, 0, 24], ["-", 0, 57, 64, 293, 0, 230, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
8
439
14
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { static long mod = (int)Pow(10, 9) + 7; static void Main() { int[] NK = ReadInts; int N = NK[0]; int K = NK[1]; long[] ans = new long[K]; for (int k = 1; k <= K; k++) { long a = Combination(N - K + 1, k, mod); long b = Combination(K - 1, k - 1, mod); ans[k - 1] = (a * b) % mod; } WriteLine(string.Join("\n", ans)); ReadLine(); } public static long GetInv(long a, long mod) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod) { if (b < 0 || b > a) return 0; if (b > a / 2) Swap(ref a, ref b); long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod) { if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } struct Vector2Int { public Vector2Int(int x, int y) { X = x; Y = y; } public int X; public int Y; public double Magnitude => Math.Sqrt(X * X + Y * Y); public static Vector2Int zero => new Vector2Int(0, 0); public static Vector2Int u => new Vector2Int(0, 1); public static Vector2Int r => new Vector2Int(1, 0); public static Vector2Int d => new Vector2Int(0, -1); public static Vector2Int l => new Vector2Int(-1, 0); public static Vector2Int[] AllDirections => new Vector2Int[4] { u, r, d, l }; public static Vector2Int[] AllDirections8 => new Vector2Int[8] { u, r, d, l, u + r, r + d, d + l, l + u }; public static Vector2Int operator +(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X + b.X, a.Y + b.Y); } public static Vector2Int operator -(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X - b.X, a.Y - b.Y); } public static bool operator ==(Vector2Int a, Vector2Int b) { return a.X == b.X && a.Y == b.Y; } public static bool operator !=(Vector2Int a, Vector2Int b) { return a.X != b.X || a.Y != b.Y; } public static Vector2Int operator *(Vector2Int v, int n) { return new Vector2Int(v.X * n, v.Y * n); } public static Vector2Int operator *(int n, Vector2Int v) { return new Vector2Int(v.X * n, v.Y * n); } } struct Vector3Int { public Vector3Int(int x, int y, int z) { X = x; Y = y; Z = z; } public int X; public int Y; public int Z; public double Magnitude => Math.Sqrt(X * X + Y * Y + Z * Z); public static Vector3Int zero => new Vector3Int(0, 0, 0); public static Vector3Int u => new Vector3Int(0, 1, 0); public static Vector3Int r => new Vector3Int(1, 0, 0); public static Vector3Int d => new Vector3Int(0, -1, 0); public static Vector3Int l => new Vector3Int(-1, 0, 0); public static Vector3Int operator +(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z); } public static Vector3Int operator -(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z); } public static bool operator ==(Vector3Int a, Vector3Int b) { return a.X == b.X && a.Y == b.Y && a.Z == b.Z; } public static bool operator !=(Vector3Int a, Vector3Int b) { return a.X != b.X || a.Y != b.Y || a.Z != b.Z; } public static Vector3Int operator *(Vector3Int v, int n) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } public static Vector3Int operator *(int n, Vector3Int v) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } } #region Reader static Vector2Int ReadVec2Int { get { string[] s = Console.ReadLine().Split(' '); return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); } } static Vector2Int[] ReadVec2Ints(int n) { List<Vector2Int> list = new List<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Vector2Int(ab[0], ab[1])); } return list.ToArray(); } static HashSet<Vector2Int> ReadVec2IntHash(int n) { HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; hash.Add(new Vector2Int(ab[0], ab[1])); } return hash; } static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } }
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { static long mod = (int)Pow(10, 9) + 7; static void Main() { int[] NK = ReadInts; int N = NK[0]; int K = NK[1]; long[] ans = new long[K]; for (int k = 1; k <= K; k++) { long a = Combination(N - K + 1, k, mod); long b = Combination(K - 1, k - 1, mod); ans[k - 1] = (a * b) % mod; } WriteLine(string.Join("\n", ans)); ReadLine(); } public static long GetInv(long a, long mod) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod) { if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } struct Vector2Int { public Vector2Int(int x, int y) { X = x; Y = y; } public int X; public int Y; public double Magnitude => Math.Sqrt(X * X + Y * Y); public static Vector2Int zero => new Vector2Int(0, 0); public static Vector2Int u => new Vector2Int(0, 1); public static Vector2Int r => new Vector2Int(1, 0); public static Vector2Int d => new Vector2Int(0, -1); public static Vector2Int l => new Vector2Int(-1, 0); public static Vector2Int[] AllDirections => new Vector2Int[4] { u, r, d, l }; public static Vector2Int[] AllDirections8 => new Vector2Int[8] { u, r, d, l, u + r, r + d, d + l, l + u }; public static Vector2Int operator +(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X + b.X, a.Y + b.Y); } public static Vector2Int operator -(Vector2Int a, Vector2Int b) { return new Vector2Int(a.X - b.X, a.Y - b.Y); } public static bool operator ==(Vector2Int a, Vector2Int b) { return a.X == b.X && a.Y == b.Y; } public static bool operator !=(Vector2Int a, Vector2Int b) { return a.X != b.X || a.Y != b.Y; } public static Vector2Int operator *(Vector2Int v, int n) { return new Vector2Int(v.X * n, v.Y * n); } public static Vector2Int operator *(int n, Vector2Int v) { return new Vector2Int(v.X * n, v.Y * n); } } struct Vector3Int { public Vector3Int(int x, int y, int z) { X = x; Y = y; Z = z; } public int X; public int Y; public int Z; public double Magnitude => Math.Sqrt(X * X + Y * Y + Z * Z); public static Vector3Int zero => new Vector3Int(0, 0, 0); public static Vector3Int u => new Vector3Int(0, 1, 0); public static Vector3Int r => new Vector3Int(1, 0, 0); public static Vector3Int d => new Vector3Int(0, -1, 0); public static Vector3Int l => new Vector3Int(-1, 0, 0); public static Vector3Int operator +(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X + b.X, a.Y + b.Y, a.Z + b.Z); } public static Vector3Int operator -(Vector3Int a, Vector3Int b) { return new Vector3Int(a.X - b.X, a.Y - b.Y, a.Z - b.Z); } public static bool operator ==(Vector3Int a, Vector3Int b) { return a.X == b.X && a.Y == b.Y && a.Z == b.Z; } public static bool operator !=(Vector3Int a, Vector3Int b) { return a.X != b.X || a.Y != b.Y || a.Z != b.Z; } public static Vector3Int operator *(Vector3Int v, int n) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } public static Vector3Int operator *(int n, Vector3Int v) { return new Vector3Int(v.X * n, v.Y * n, v.Z * n); } } #region Reader static Vector2Int ReadVec2Int { get { string[] s = Console.ReadLine().Split(' '); return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); } } static Vector2Int[] ReadVec2Ints(int n) { List<Vector2Int> list = new List<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Vector2Int(ab[0], ab[1])); } return list.ToArray(); } static HashSet<Vector2Int> ReadVec2IntHash(int n) { HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; hash.Add(new Vector2Int(ab[0], ab[1])); } return hash; } static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } }
[["-", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["-", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 275], ["+", 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, 213, 3, 4, 0, 21], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25]]
8
2,126
9
using System; using System.Linq; public class HelloWorld { static long[,] C = new long[2001, 2001]; static long div = 1000000007; static public void Main() { var NK = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray(); var N = NK[0]; var K = NK[1]; for (long i = 1; i <= (N - K + 1) && i <= K; i++) { var loc = Combination(N - K + 1, i); var num = Combination(K - 1, i - 1); var res = (loc * num) % div; Console.WriteLine(res); } } static long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { C[n, r] = 1; } else if (C[n, r] == 0) { C[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return C[n, r]; } }
using System; using System.Linq; public class HelloWorld { static long[,] C = new long[2001, 2001]; static long div = 1000000007; static public void Main() { var NK = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray(); var N = NK[0]; var K = NK[1]; for (long i = 1; i <= K; i++) { var loc = Combination(N - K + 1, i); var num = Combination(K - 1, i - 1); var res = (loc * num) % div; Console.WriteLine(res); } } static long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { C[n, r] = 1; } else if (C[n, r] == 0) { C[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return C[n, r]; } }
[["-", 0, 7, 15, 16, 31, 16, 12, 23, 0, 24], ["-", 31, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 31, 16, 12, 23, 0, 16, 31, 16, 17, 33], ["-", 31, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["-", 15, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["-", 15, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 7, 15, 16, 31, 16, 12, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 98], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 19]]
8
256
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Program { static void Main(string[] args) { int[] nums = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray(); int N = nums[0]; int K = nums[1]; Combination combination = new Combination(5000); for (int i = 1; i <= K; i++) { Console.WriteLine( (combination[N - K + 1, i] * combination[K - 1, i - 1]) % (Math.Pow(10, 9) + 7)); } } } class Combination { private int Devisor = (int)(Math.Pow(10, 9) + 7); public int this[int index1, int index2] => data[index1, index2]; private int[,] data; public Combination(int N) { data = new int[N + 1, N + 1]; data[0, 0] = 1; // 0C0=1 for (int i = 1; i <= N; i++) { for (int j = 0; j <= i; j++) { if (j == 0) { data[i, j] = data[i - 1, j] % Devisor; } else if (j == i) { data[i, j] = data[i - 1, j - i] % Devisor; } else { data[i, j] = (data[i - 1, j - 1] + data[i - 1, j]) % Devisor; } } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Program { static void Main(string[] args) { int[] nums = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray(); int N = nums[0]; int K = nums[1]; Combination combination = new Combination(2000); for (int i = 1; i <= K; i++) { long product = ((long)combination[N - K + 1, i] * (long)combination[K - 1, i - 1]); Console.WriteLine(product % (long)(Math.Pow(10, 9) + 7)); } } } class Combination { private int Devisor = (int)(Math.Pow(10, 9) + 7); public int this[int index1, int index2] => data[index1, index2]; private int[,] data; public Combination(int N) { data = new int[N + 1, N + 1]; data[0, 0] = 1; // 0C0=1 for (int i = 1; i <= N; i++) { for (int j = 0; j <= i; j++) { if (j == 0) { data[i, j] = data[i - 1, j] % Devisor; } else if (j == i) { data[i, j] = data[i - 1, j - i] % Devisor; } else { data[i, j] = (data[i - 1, j - 1] + data[i - 1, j]) % Devisor; } } } } } }
[["-", 0, 212, 0, 230, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 230, 3, 4, 0, 28, 0, 203], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 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, 23, 0, 16, 31, 74, 39, 199], ["+", 0, 212, 0, 23, 0, 16, 31, 74, 0, 25], ["+", 0, 212, 0, 23, 0, 16, 12, 74, 0, 24], ["+", 0, 212, 0, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 212, 0, 23, 0, 16, 12, 74, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 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]]
8
365
22
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC132D { class Program { static void Solve(Input input) { var n = input.NextInt(); var k = input.NextInt(); var blue = k; var red = n - blue; var mod = new Modulo(); for (int i = 1; i <= k; i++) { if (i - 1 == red) { Console.WriteLine(1); continue; } if (i > red) { Console.WriteLine(0); continue; } // 青い玉をi個の箱に入れる(空き箱無し) long m = mod.Ncr(blue - 1, i - 1); // 赤い玉をi+1個の箱に入れる(両端だけ空き箱あり) // -> 赤い玉-(i-1)個の玉をi+1個の箱に入れる(空き箱あり) m = mod.Mul(m, mod.Ncr(red - (i - 1) + i + 1 - 1, i + 1 - 1)); Console.WriteLine(m); } } /// <summary> /// Mを法とする数値 /// </summary> class Modulo { public long M { get; private set; } private bool mIsPrime; long[] factorials; public Modulo(long m = (long)1e9 + 7) { this.M = m; this.mIsPrime = isPrime(m); factorials = new long[1]; factorials[0] = 1; } public long Add(long a, long b) { return (a + b) % this.M; } public long Sub(long a, long b) { return (a + this.M - b) % this.M; } public long Mul(long a, long b) { return ((a % this.M) * (b % this.M)) % this.M; } /// <summary> /// x^y /// 繰り返し二乗法 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public long Power(long x, long y) { switch (y) { case 0: return 1; case 1: return x % this.M; default: long z1 = Power(x, y / 2); long z2 = Mul(z1, z1); if ((y % 2) == 0) { return z2; } else { return Mul(z2, x); } } } /// <summary> /// x^y /// 繰り返し二乗法(バイナリ) /// 通常版よりは早いだろうけれど、直感的でないし不採用で /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> long PowerBin(long x, long y) { var r = 1L; while (y > 0) { if ((y & 1) != 0) { r = Mul(r, x); } x = Mul(x, x); y >>= 1; } return r; } /// <summary> /// aの逆元(a^-1) /// </summary> /// <param name="a"></param> /// <returns></returns> public long Inverse(long a) { long b = this.M; long u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; swap<long>(ref a, ref b); u -= t * v; swap<long>(ref u, ref v); } u %= M; if (u < 0) u += this.M; return u; } /// <summary> /// 素数限定の逆元 /// </summary> /// <param name="a"></param> /// <returns></returns> public long inv2(long a) => this.mIsPrime ? Power(a, this.M - 2) : 0; /// <summary> /// a/b /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public long Div(long a, long b) { if (!this.mIsPrime) { throw new ArgumentException(); } return Mul(a, Inverse(b)); } /// <summary> /// nの階乗を返す /// ただし、n<=M /// </summary> /// <param name="n"></param> /// <returns></returns> long factorial(int n) { if (factorials == null || n >= factorials.Length) { int begin = 1; // 以前計算していた部分は使い回す if (factorials != null) { begin = factorials.Length; } Array.Resize(ref factorials, n + 1); for (int i = begin; i <= n; i++) { factorials[i] = Mul(factorials[i - 1], i); } } return factorials[n]; } /// <summary> /// nCr /// </summary> /// <param name="n"></param> /// <param name="r"></param> /// <returns></returns> public long Ncr(int n, int r) { if (n == r) return 1; long ans = factorial(n); ans = Div(ans, factorial(r)); ans = Div(ans, factorial(n - r)); return ans; } /// <summary> /// 素数か /// </summary> /// <param name="x"></param> /// <returns></returns> 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; } static void swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } } #region Competitive Template static readonly int MOD = (int)1e9 + 7; 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(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> 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> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> 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> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> 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); } 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> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> 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> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> 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 ABC132D { class Program { static void Solve(Input input) { var n = input.NextInt(); var k = input.NextInt(); var blue = k; var red = n - blue; var mod = new Modulo(); for (int i = 1; i <= k; i++) { if (i > blue) { Console.WriteLine("0"); continue; } if (i - 1 > red) { Console.WriteLine("0"); continue; } // 青い玉をi個の箱に入れる(空き箱無し) long m = mod.Ncr(blue - 1, i - 1); // 赤い玉をi+1個の箱に入れる(両端だけ空き箱あり) // -> 赤い玉-(i-1)個の玉をi+1個の箱に入れる(空き箱あり) m = mod.Mul(m, mod.Ncr(red - (i - 1) + i + 1 - 1, i + 1 - 1)); Console.WriteLine(m); } } /// <summary> /// Mを法とする数値 /// </summary> class Modulo { public long M { get; private set; } private bool mIsPrime; long[] factorials; public Modulo(long m = (long)1e9 + 7) { this.M = m; this.mIsPrime = isPrime(m); factorials = new long[1]; factorials[0] = 1; } public long Add(long a, long b) { return (a + b) % this.M; } public long Sub(long a, long b) { return (a + this.M - b) % this.M; } public long Mul(long a, long b) { return ((a % this.M) * (b % this.M)) % this.M; } /// <summary> /// x^y /// 繰り返し二乗法 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public long Power(long x, long y) { switch (y) { case 0: return 1; case 1: return x % this.M; default: long z1 = Power(x, y / 2); long z2 = Mul(z1, z1); if ((y % 2) == 0) { return z2; } else { return Mul(z2, x); } } } /// <summary> /// x^y /// 繰り返し二乗法(バイナリ) /// 通常版よりは早いだろうけれど、直感的でないし不採用で /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> long PowerBin(long x, long y) { var r = 1L; while (y > 0) { if ((y & 1) != 0) { r = Mul(r, x); } x = Mul(x, x); y >>= 1; } return r; } /// <summary> /// aの逆元(a^-1) /// </summary> /// <param name="a"></param> /// <returns></returns> public long Inverse(long a) { long b = this.M; long u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; swap<long>(ref a, ref b); u -= t * v; swap<long>(ref u, ref v); } u %= M; if (u < 0) u += this.M; return u; } /// <summary> /// 素数限定の逆元 /// </summary> /// <param name="a"></param> /// <returns></returns> public long inv2(long a) => this.mIsPrime ? Power(a, this.M - 2) : 0; /// <summary> /// a/b /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public long Div(long a, long b) { if (!this.mIsPrime) { throw new ArgumentException(); } return Mul(a, Inverse(b)); } /// <summary> /// nの階乗を返す /// ただし、n<=M /// </summary> /// <param name="n"></param> /// <returns></returns> long factorial(int n) { if (factorials == null || n >= factorials.Length) { int begin = 1; // 以前計算していた部分は使い回す if (factorials != null) { begin = factorials.Length; } Array.Resize(ref factorials, n + 1); for (int i = begin; i <= n; i++) { factorials[i] = Mul(factorials[i - 1], i); } } return factorials[n]; } /// <summary> /// nCr /// </summary> /// <param name="n"></param> /// <param name="r"></param> /// <returns></returns> public long Ncr(int n, int r) { if (n == r) return 1; long ans = factorial(n); ans = Div(ans, factorial(r)); ans = Div(ans, factorial(n - r)); return ans; } /// <summary> /// 素数か /// </summary> /// <param name="x"></param> /// <returns></returns> 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; } static void swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } } #region Competitive Template static readonly int MOD = (int)1e9 + 7; 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("5 4"); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> 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> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> 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> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> 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); } 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> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> 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> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> 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, 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, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
2,050
14
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 c = new long [4000][]; var mod = 1000000007; for (int i = 0; i < 4000; i++) { c[i] = new long[i + 1]; for (int j = 0; j < i + 1; j++) { c[i][j] = (j == 0 || j == i) ? 1 : (c[i - 1][j - 1] + c[i - 1][j]) % mod; } } for (int i = 1; i <= K; i++) { var ans = (c[N - K + 1][i] * c[K - 1][i - 1]) % mod; Console.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; } } }
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 c = new long [4000][]; var mod = 1000000007; for (int i = 0; i < 4000; i++) { c[i] = new long[i + 1]; for (int j = 0; j < i + 1; j++) { c[i][j] = (j == 0 || j == i) ? 1 : (c[i - 1][j - 1] + c[i - 1][j]) % mod; } } for (int i = 1; i <= K; i++) { var ans = (N - K + 1 < i) ? 0 : (c[N - K + 1][i] * c[K - 1][i - 1]) % mod; Console.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; } } }
[["+", 15, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 17, 33], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 72], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 17, 18], ["+", 0, 212, 0, 41, 15, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 64, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 212, 0, 41, 75, 16, 31, 23, 0, 24]]
8
601
12
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC132D { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); return; } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; var K = cin.ReadLong; var com = new Combination(N * 2); for (int i = 1; i <= K; i++) { Console.WriteLine(com.Calc(N - K + 1, i) * com.Calc(K - 1, i - 1)); } } public class Combination { private long[] fac; private long[] finv; private long[] inv; private readonly long MOD = 1000000007; public Combination(long max) { this.fac = new long[max]; this.finv = new long[max]; this.inv = new long[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i % this.MOD; inv[i] = this.MOD - inv[this.MOD % i] * (this.MOD / i) % this.MOD; finv[i] = finv[i - 1] * inv[i] % this.MOD; } } public long Calc(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % this.MOD) % this.MOD; } } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC132D { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); return; } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; var K = cin.ReadLong; const long MOD = 1000000007; var com = new Combination(N * 2); for (int i = 1; i <= K; i++) { Console.WriteLine(com.Calc(N - K + 1, i) * com.Calc(K - 1, i - 1) % MOD); } } public class Combination { private long[] fac; private long[] finv; private long[] inv; private readonly long MOD = 1000000007; public Combination(long max) { this.fac = new long[max]; this.finv = new long[max]; this.inv = new long[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i % this.MOD; inv[i] = this.MOD - inv[this.MOD % i] * (this.MOD / i) % this.MOD; finv[i] = finv[i - 1] * inv[i] % this.MOD; } } public long Calc(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % this.MOD) % this.MOD; } } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 251, 0, 154], ["+", 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, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
786
8
using System; using System.Linq; class D { static void Main() { var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var M = 1000000007; for (int i = 1; i <= a[1]; i++) Console.WriteLine((long)ModNcr(a[0] - a[1] + 1, i, M) * ModNcr(a[1] - 1, i - 1, M) % M); } static int ModPow(int b, int i, int mod) { for (var r = 1;; b = (int)((long)b * b % mod)) { if (i % 2 > 0) r = (int)((long)r * b % mod); if ((i /= 2) < 1) return r; } } static int ModInv(int x, int p) => ModPow(x, p - 2, p); static int ModFactorial(int n, int mod) => n == 0 ? 1 : (int)Enumerable.Range(1, n) .Select(x => (long)x) .Aggregate((x, y) => x * y % mod); static int ModNpr(int n, int r, int mod) => r == 0 ? 1 : (int)Enumerable.Range(n - r + 1, r) .Select(x => (long)x) .Aggregate((x, y) => x * y % mod); static int ModNcr(int n, int r, int p) => n - r < r ? ModNcr(n, n - r, p) : (int)((long)ModNpr(n, r, p) * ModInv(ModFactorial(r, p), p) % p); }
using System; using System.Linq; class D { static void Main() { var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var M = 1000000007; for (int i = 1; i <= a[1]; i++) Console.WriteLine(i > a[0] - a[1] + 1 ? 0 : (long)ModNcr(a[0] - a[1] + 1, i, M) * ModNcr(a[1] - 1, i - 1, M) % M); } static int ModPow(int b, int i, int mod) { for (var r = 1;; b = (int)((long)b * b % mod)) { if (i % 2 > 0) r = (int)((long)r * b % mod); if ((i /= 2) < 1) return r; } } static int ModInv(int x, int p) => ModPow(x, p - 2, p); static int ModFactorial(int n, int mod) => n == 0 ? 1 : (int)Enumerable.Range(1, n) .Select(x => (long)x) .Aggregate((x, y) => x * y % mod); static int ModNpr(int n, int r, int mod) => r == 0 ? 1 : (int)Enumerable.Range(n - r + 1, r) .Select(x => (long)x) .Aggregate((x, y) => x * y % mod); static int ModNcr(int n, int r, int p) => n - r < r ? ModNcr(n, n - r, p) : (int)((long)ModNpr(n, r, p) * ModInv(ModFactorial(r, p), p) % p); }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 41, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 15, 16, 12, 16, 31, 16, 12, 204, 205, 22], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 72], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102]]
8
387
16
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; using System.Threading.Tasks; class Sobaya { const long MOD = 1000000007; const int MAX_C = 2002; long[,] Com = new long[MAX_C, MAX_C]; void calc_com() { Com[0, 0] = 1; for (int i = 1; i < MAX_C; ++i) { Com[i, 0] = 1; for (int j = 1; j < MAX_C; ++j) { Com[i, j] = (Com[i - 1, j - 1] + Com[i - 1, j]) % MOD; } Com[i, i] = 1; } } static void Main() { new Sobaya().calc(); return; } Scanner cin; void calc() { cin = new Scanner(); long[] std = cin.ArrayLong(2); long n = std[0]; long k = std[1]; long i1, ii, v1; long[] prep = new long[n]; int mod = 1000000007; v1 = 1; for (i1 = 0; i1 < n; i1++) { ii = i1 + 1; v1 = (v1 * ii) % mod; prep[i1] = v1; } calc_com(); long ans = 0; for (i1 = 1; i1 <= k; i1++) { ans = 0; // both side red // red divided to i1+1 space // red total n-k balls // free red ball n-k-(i1+1) balls remained // sikiri: i1 // n-k-1 C i1 // blue total k balls to i1 space // blue free k-i1 and i1-1 sikiri if (n - k < i1 + 1) ans += 0; else ans += (Com[n - k - 1, i1] * Com[k - 1, i1 - 1]) % mod; // red divided to i1 space // red total n-k balls // n-k-i1 balls into sikiri i1-1 if (n - k < i1) ans += 0; else ans += 2 * (Com[n - k - 1, i1 - 1] * Com[k - 1, i1 - 1]) % mod; // both side blue if (n - k < i1 - 1 || i1 == 1) ans += 0; else ans += (Com[n - k - 1, i1 - 2] * Com[k - 1, i1 - 1]) % mod; Console.WriteLine(ans % mod); } // Console.WriteLine(string.Join(" ",prep)); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; using System.Threading.Tasks; class Sobaya { const long MOD = 1000000007; const int MAX_C = 2002; long[,] Com = new long[MAX_C, MAX_C]; void calc_com() { Com[0, 0] = 1; for (int i = 1; i < MAX_C; ++i) { Com[i, 0] = 1; for (int j = 1; j < MAX_C; ++j) { Com[i, j] = (Com[i - 1, j - 1] + Com[i - 1, j]) % MOD; } Com[i, i] = 1; } } static void Main() { new Sobaya().calc(); return; } Scanner cin; void calc() { cin = new Scanner(); long[] std = cin.ArrayLong(2); long n = std[0]; long k = std[1]; long i1, ii, v1; long[] prep = new long[n]; int mod = 1000000007; v1 = 1; for (i1 = 0; i1 < n; i1++) { ii = i1 + 1; v1 = (v1 * ii) % mod; prep[i1] = v1; } calc_com(); long ans = 0; for (i1 = 1; i1 <= k; i1++) { ans = 0; // both side red // red divided to i1+1 space // red total n-k balls // free red ball n-k-(i1+1) balls remained // sikiri: i1 // n-k-1 C i1 // blue total k balls to i1 space // blue free k-i1 and i1-1 sikiri if (n - k < i1 + 1) ans += 0; else ans += (Com[n - k - 1, i1] * Com[k - 1, i1 - 1]) % mod; // red divided to i1 space // red total n-k balls // n-k-i1 balls into sikiri i1-1 if (n - k < i1) ans += 0; else ans += 2 * (Com[n - k - 1, i1 - 1] * Com[k - 1, i1 - 1]) % mod; // both side blue if (i1 == 1 && n == k) ans += 1; else if (n - k < i1 - 1 || i1 == 1) ans += 0; else ans += (Com[n - k - 1, i1 - 2] * Com[k - 1, i1 - 1]) % mod; Console.WriteLine(ans % mod); } // Console.WriteLine(string.Join(" ",prep)); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 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, 16, 31, 16, 31, 22]]
8
837
15
using System; using System.Linq; class Program4 { static void Main() { var input = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var md = new Modulo(2000); for (int i = 1; i <= input[1]; i++) { if (i - 1 > input[0] - input[1]) { Console.WriteLine("0"); continue; } // i個青いボール列 それぞれに何個割り当てるか i-1個のセパレーション // i+1個の枠に赤を入れる var blue = md.DuplicateCombination(i, input[1] - i); var red = md.DuplicateCombination(i + 1, input[0] - input[1] - (i - 1)); Console.WriteLine(blue * red); } } } class Modulo { private readonly int M = 1000000007; private readonly int[] m_facs; public Modulo(int n, int m = -1) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Multiply(m_facs[i - 1], i); } if (m != -1) M = m; } public int Multiply(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public int Factorial(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiply(p1, p1); return ((m % 2) == 0) ? p2 : Multiply(p2, a); } } public int Divide(int a, int b) { return Multiply(a, Pow(b, M - 2)); } public int DuplicateCombination(int n, int r) { n = n + r - 1; if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Divide(res, Factorial(r)); res = Divide(res, Factorial(n - r)); return res; } }
using System; using System.Linq; class Program4 { static void Main() { var input = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var md = new Modulo(2000); for (int i = 1; i <= input[1]; i++) { if (i - 1 > input[0] - input[1]) { Console.WriteLine("0"); continue; } // i個青いボール列 それぞれに何個割り当てるか i-1個のセパレーション // i+1個の枠に赤を入れる var blue = md.DuplicateCombination(i, input[1] - i); var red = md.DuplicateCombination(i + 1, input[0] - input[1] - (i - 1)); var ans = md.Multiply(blue, red); Console.WriteLine(ans); } } } class Modulo { private readonly int M = 1000000007; private readonly int[] m_facs; public Modulo(int n, int m = -1) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Multiply(m_facs[i - 1], i); } if (m != -1) M = m; } public int Multiply(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public int Factorial(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiply(p1, p1); return ((m % 2) == 0) ? p2 : Multiply(p2, a); } } public int Divide(int a, int b) { return Multiply(a, Pow(b, M - 2)); } public int DuplicateCombination(int n, int r) { n = n + r - 1; if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Divide(res, Factorial(r)); res = Divide(res, Factorial(n - r)); return res; } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 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, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
481
16
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int N = input[0]; int K = input[1]; var mo1 = new Modulo(N - 1); var mo2 = new Modulo(N - K + 1); for (var i = 1; i <= K; i++) { long ans = ((mo1.Ncr(N - 1, i - 1)) * (mo2.Ncr(N - K + 1, i))) % 1000000007; Console.WriteLine(ans); } } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int N = input[0]; int K = input[1]; var mo = new Modulo(0); var mo1 = new Modulo(K - 1); var mo2 = new Modulo(N - K + 1); for (var i = 1; i <= K; i++) { long ans = mo.Mul(mo1.Ncr(K - 1, i - 1), mo2.Ncr(N - K + 1, i)); Console.WriteLine(ans); } } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 212, 0, 230, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 230, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 16, 31, 23, 0, 213, 3, 4, 0, 25], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 48], ["-", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
468
24
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Solver { Scanner sc = new Scanner(); public void Solve() { var N = sc.nextInt(); var K = sc.nextInt(); for (int i = 1; i <= K; i++) { var ans = Combination.Calc(N - K + 1, i) * Combination.Calc(K - 1, i - 1) % 1000000007; WriteLine(ans); } } } class Combination { static int mod = 1000000007; public static long Calc(int a, int b) { if (b > a - b) return Calc(a, a - b); long ansMul = 1; long ansDiv = 1; for (int i = 0; i < b; i++) { ansMul *= (a - i); ansDiv *= (i + 1); ansMul %= mod; ansDiv %= mod; } return ansMul * ModPow(ansDiv, mod - 2) % mod; } private static long ModPow(long a, int p) { if (p == 0) return 1; if (p % 2 == 0) { long half = ModPow(a, p / 2); return half * half % mod; } else { return a * ModPow(a, p - 1) % mod; } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] args) { Solver s = new Solver(); s.Solve(); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Solver { Scanner sc = new Scanner(); public void Solve() { var N = sc.nextInt(); var K = sc.nextInt(); for (int i = 1; i <= K; i++) { if (N - K + 1 < i) { WriteLine(0); continue; } WriteLine(Combination.Calc(N - K + 1, i) * Combination.Calc(K - 1, i - 1) % 1000000007); } } } class Combination { static int mod = 1000000007; public static long Calc(int a, int b) { if (b > a - b) return Calc(a, a - b); long ansMul = 1; long ansDiv = 1; for (int i = 0; i < b; i++) { ansMul *= (a - i); ansDiv *= (i + 1); ansMul %= mod; ansDiv %= mod; } return ansMul * ModPow(ansDiv, mod - 2) % mod; } private static long ModPow(long a, int p) { if (p == 0) return 1; if (p % 2 == 0) { long half = ModPow(a, p / 2); return half * half % mod; } else { return a * ModPow(a, p - 1) % mod; } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] args) { Solver s = new Solver(); s.Solve(); } }
[["-", 8, 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, 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, 33], ["+", 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, 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], ["+", 0, 7, 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, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
662
28
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Solve { public Solve() {} public static int Main() { new Solve().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int K = cin.nextInt(); var mod = new Modulo(N); for (int i = 0; i < K; i++) { var comb = mod.Ncr(N - K + 1, i + 1); var coef = mod.Ncr(K - 1, i); Console.WriteLine((comb * coef).ToString()); } } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Solve { public Solve() {} public static int Main() { new Solve().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int K = cin.nextInt(); var mod = new Modulo(3000); for (int i = 1; i <= K; i++) { var a = mod.Ncr(N - K + 1, i); var b = mod.Ncr(K - 1, i - 1); Console.WriteLine(mod.Mul(a, b).ToString()); } } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 0, 212, 0, 230, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 230, 3, 4, 0, 28, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 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, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 23, 0, 16, 31, 22], ["-", 0, 213, 63, 214, 205, 23, 0, 16, 17, 48], ["-", 0, 213, 63, 214, 205, 23, 0, 16, 12, 22], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 21]]
8
818
23
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class D { public static readonly long MOD = 1000000007; public static void Main() { long N = GetLong(); long K = GetLong(); var mct = new ModCombTable((int)N, MOD); var sb = new StringBuilder(); for (long i = 1; i <= K; i++) { long combBlue = mct.ModComb(K - 1, i - 1); long combRed = mct.ModComb(N - K + 1, i); long comb = (combBlue * combRed) % MOD; sb.AppendFormat($"{comb}\n"); } Console.Write(sb); } } public class ModCombTable { private long[] f = null; private long[] fInv = null; private long mod; public ModCombTable(int N, long m) { mod = m; // calc factorial f = new long[N + 1]; f[0] = 1; for (int i = 1; i <= N; i++) f[i] = (f[i - 1] * i) % mod; // calc factorial inverse fInv = new long[N + 1]; fInv[N] = ModInv(f[N]); for (int i = N; i > 0; i--) fInv[i - 1] = (fInv[i] * i) % mod; } public long ModComb(long n, long k) { return (((f[n] * fInv[k]) % mod) * fInv[n - k]) % mod; } public long ModInv(long x) { return ModPow(x, mod - 2); } public long ModPow(long x, long n) { long res = 1; while (n > 0) { if ((n & 1) == 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class D { public static readonly long MOD = 1000000007; public static void Main() { long N = GetLong(); long K = GetLong(); long R = N - K; var mct = new ModCombTable((int)N, MOD); var sb = new StringBuilder(); for (long i = 1; i <= K; i++) { long combBlue = mct.ModComb(K - 1, i - 1); long combRed = mct.ModComb(R + 1, i); long comb = (combBlue * combRed) % MOD; sb.AppendFormat($"{comb}\n"); } Console.Write(sb); } } public class ModCombTable { private long[] f = null; private long[] fInv = null; private long mod; public ModCombTable(int N, long m) { mod = m; // calc factorial f = new long[N + 1]; f[0] = 1; for (int i = 1; i <= N; i++) f[i] = (f[i - 1] * i) % mod; // calc factorial inverse fInv = new long[N + 1]; fInv[N] = ModInv(f[N]); for (int i = N; i > 0; i--) fInv[i - 1] = (fInv[i] * i) % mod; } public long ModComb(long n, long k) { if (n < 0 || k < 0 || n < k) return 0; return (((f[n] * fInv[k]) % mod) * fInv[n - k]) % mod; } public long ModInv(long x) { return ModPow(x, mod - 2); } public long ModPow(long x, long n) { long res = 1; while (n > 0) { if ((n & 1) == 1) res = (res * x) % mod; x = (x * x) % mod; n >>= 1; } return res; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 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, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 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, 18], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35]]
8
577
28
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemD { class Program { public static int div = 1000000007; public static Dictionary<List<int>, int> dict = new Dictionary<List<int>, int>(); static void Main(string[] args) { var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = read[0]; var K = read[1]; int redNum = N - K; var rets = new int[K]; for (int i = 0; i < K; i++) { var C1 = nCm(redNum + 1, i + 1) % div; var C2 = nCm(K - 1, i) % div; rets[i] = (int)((C1 * C2) % div); Console.WriteLine(rets[i]); } } public static long nCm(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * (nCm(n - 1, m - 1) % div) * modinv(m, div); } public static long modinv(long a, long m) { long b = m, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } public static void swap(ref long a, ref long b) { var temp = a; a = b; b = temp; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemD { class Program { public static int div = 1000000007; public static Dictionary<List<int>, int> dict = new Dictionary<List<int>, int>(); static void Main(string[] args) { var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = read[0]; var K = read[1]; int redNum = N - K; var rets = new long[K]; for (int i = 0; i < K; i++) { var C1 = nCm(redNum + 1, i + 1) % div; var C2 = nCm(K - 1, i) % div; rets[i] = ((C1 * C2) % div); Console.WriteLine(rets[i]); } } public static long nCm(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return (n * (nCm(n - 1, m - 1) % div)) % div * modinv(m, div); } public static long modinv(long a, long m) { long b = m, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } public static void swap(ref long a, ref long b) { var temp = a; a = b; b = temp; } } }
[["-", 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, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 12, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 37, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 37, 0, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 37, 0, 16, 31, 16, 12, 22]]
8
389
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq); public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq); } static class MyMath { static private long gcdInner(long a, long b) => (a % b == 0) ? b : gcdInner(b, a % b); static public long GCD(long a, long b) => (a > b) ? gcdInner(a, b) : gcdInner(b, a); static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static long mmmmmm = 1000000000 + 7; static void Main() { // long x = 500000004; // Console.WriteLine(4 * x % mmmmmm); // return; // Nのかいじょうまでを計算できるようにしておく。 //また、Nのかいじょうまでの逆元を計算できるようにしておく int[] nk = Console.ReadLine().ToIntArray(); int N = nk[0]; int K = nk[1]; long[] Kaijou = new long[N + 1]; long[] Gyaku = new long[N + 1]; Kaijou[0] = 1; for (int i = 1; i <= N; i++) { Kaijou[i] = Kaijou[i - 1] * i; Kaijou[i] = mod(Kaijou[i], mmmmmm); } for (int i = 0; i <= N; i++) { Gyaku[i] = getGyakuGen(Kaijou[i], mmmmmm); } for (int i = 1; i <= K; i++) { long ans = Kaijou[N - K + 1]; ans = mod(ans, mmmmmm); ans *= Kaijou[K - 1]; ans = mod(ans, mmmmmm); ans *= Gyaku[i]; ans = mod(ans, mmmmmm); ans *= Gyaku[N - K + 1 - i]; ans = mod(ans, mmmmmm); ans *= Gyaku[K - i]; ans = mod(ans, mmmmmm); ans *= Gyaku[i - 1]; ans = mod(ans, mmmmmm); Console.WriteLine(ans); } } static long getGyakuGen(long a, long m) { long x = 0; long y = 0; xxx(a, m, ref x, ref y); return mod(x, m); } static long xxx(long a, long b, ref long x, ref long y) { if (b == 0) { x = 1; y = 0; return a; } long d = xxx(b, a % b, ref y, ref x); y -= a / b * x; return d; } static long mod(long a, long m) { return (a % m + m) % m; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq); public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq); } static class MyMath { static private long gcdInner(long a, long b) => (a % b == 0) ? b : gcdInner(b, a % b); static public long GCD(long a, long b) => (a > b) ? gcdInner(a, b) : gcdInner(b, a); static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static long mmmmmm = 1000000000 + 7; static void Main() { // Nのかいじょうまでを計算できるようにしておく。 //また、Nのかいじょうまでの逆元を計算できるようにしておく int[] nk = Console.ReadLine().ToIntArray(); int N = nk[0]; int K = nk[1]; long[] Kaijou = new long[N + 1]; long[] Gyaku = new long[N + 1]; Kaijou[0] = 1; for (int i = 1; i <= N; i++) { Kaijou[i] = Kaijou[i - 1] * i; Kaijou[i] = mod(Kaijou[i], mmmmmm); } for (int i = 0; i <= N; i++) { Gyaku[i] = getGyakuGen(Kaijou[i], mmmmmm); } for (int i = 1; i <= K; i++) { if (i > N - K + 1) { Console.WriteLine(0); continue; } long ans = Kaijou[N - K + 1]; ans = mod(ans, mmmmmm); ans *= Kaijou[K - 1]; ans = mod(ans, mmmmmm); ans *= Gyaku[i]; ans = mod(ans, mmmmmm); ans *= Gyaku[N - K + 1 - i]; ans = mod(ans, mmmmmm); ans *= Gyaku[K - i]; ans = mod(ans, mmmmmm); ans *= Gyaku[i - 1]; ans = mod(ans, mmmmmm); Console.WriteLine(ans); } } static long getGyakuGen(long a, long m) { long x = 0; long y = 0; xxx(a, m, ref x, ref y); return mod(x, m); } static long xxx(long a, long b, ref long x, ref long y) { if (b == 0) { x = 1; y = 0; return a; } long d = xxx(b, a % b, ref y, ref x); y -= a / b * x; return d; } static long mod(long a, long m) { return (a % m + m) % m; } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 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, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
917
21
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; namespace ABC132_D { class Program { const int MOD = 1000000007; static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var red = N - K; long sum = 0; for (int i = 1; i <= K; i++) { if (i == K) Console.WriteLine(nCr(red + 1, K)); else { var temp = nCr(red + 1, i) * nCr(K - 1, i - 1); sum = (sum + temp) % MOD; Console.WriteLine(temp); } } } static mlong nCr(int n, int r) { return Factorial(n) / (Factorial(n - r) * Factorial(r)); } static List<mlong> factorialMemo = new List<mlong>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } } struct mlong { public static implicit operator long(mlong modInt) => modInt.V; const long mod = (long)1e9 + 7; long V; public mlong(long _v = 0) { V = _v; } public static mlong operator +(mlong a, mlong b) { var v0 = a.V + b.V; if (v0 >= mod) v0 -= mod; return new mlong(v0); } public static mlong operator -(mlong a, mlong b) { var v0 = mod + a.V - b.V; if (v0 >= mod) v0 -= mod; return new mlong(v0); } public static mlong operator *(mlong a, mlong b) { var v0 = a.V * b.V; if (v0 >= mod) v0 %= mod; return new mlong(v0); } public static mlong operator /(mlong a, mlong b) { var v0 = a.V * inv(b.V).V; if (v0 >= mod) v0 %= mod; return new mlong(v0); } public static mlong inv(long x) { long a = 0, b = 0, c = 0; ExtGCD(x, mod, ref a, ref b, ref c); return (mlong)((a + mod) % mod); } public static void ExtGCD(long x, long y, ref long a, ref long b, ref long c) { long r0 = x; long r1 = y; long a0 = 1; long a1 = 0; long b0 = 0; long b1 = 1; long q1, r2, a2, b2; while (r1 > 0) { q1 = r0 / r1; r2 = r0 % r1; a2 = a0 - q1 * a1; b2 = b0 - q1 * b1; r0 = r1; r1 = r2; a0 = a1; a1 = a2; b0 = b1; b1 = b2; } c = r0; a = a0; b = b0; } public static mlong ModPow(mlong a, long k) { if (k == 0) return (mlong)1; if (a == 0) return (mlong)0; mlong x = a; mlong ret = 1; while (k > 0) { if (k % 2 == 1) ret *= x; x *= x; k >>= 1; } return ret; } public static bool operator ==(mlong a, mlong b) { return a.Equals(b); } public static bool operator !=(mlong a, mlong b) { return !(a == b); } public override bool Equals(System.Object obj) { if (obj == null) return false; mlong p = (mlong)obj; if ((System.Object)p == null) return false; return p.V == V; } public override int GetHashCode() { return V.GetHashCode(); } public static implicit operator mlong(long n) { long v = n % mod; if (v < 0) v += mod; return new mlong(v); } public static implicit operator mlong(int n) { long v = n % mod; if (v < 0) v += mod; return new mlong(v); } public override String ToString() { return V.ToString(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; namespace ABC132_D { class Program { const int MOD = 1000000007; static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var red = N - K; long sum = 0; for (int i = 1; i <= K; i++) { if (i > red + 1) Console.WriteLine(0); else { if (i == K) Console.WriteLine(nCr(red + 1, K)); else { var temp = nCr(red + 1, i) * nCr(K - 1, i - 1); sum = (sum + temp) % MOD; Console.WriteLine(temp); } } } } static mlong nCr(int n, int r) { return Factorial(n) / (Factorial(n - r) * Factorial(r)); } static List<mlong> factorialMemo = new List<mlong>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } } struct mlong { public static implicit operator long(mlong modInt) => modInt.V; const long mod = (long)1e9 + 7; long V; public mlong(long _v = 0) { V = _v; } public static mlong operator +(mlong a, mlong b) { var v0 = a.V + b.V; if (v0 >= mod) v0 -= mod; return new mlong(v0); } public static mlong operator -(mlong a, mlong b) { var v0 = mod + a.V - b.V; if (v0 >= mod) v0 -= mod; return new mlong(v0); } public static mlong operator *(mlong a, mlong b) { var v0 = a.V * b.V; if (v0 >= mod) v0 %= mod; return new mlong(v0); } public static mlong operator /(mlong a, mlong b) { var v0 = a.V * inv(b.V).V; if (v0 >= mod) v0 %= mod; return new mlong(v0); } public static mlong inv(long x) { long a = 0, b = 0, c = 0; ExtGCD(x, mod, ref a, ref b, ref c); return (mlong)((a + mod) % mod); } public static void ExtGCD(long x, long y, ref long a, ref long b, ref long c) { long r0 = x; long r1 = y; long a0 = 1; long a1 = 0; long b0 = 0; long b1 = 1; long q1, r2, a2, b2; while (r1 > 0) { q1 = r0 / r1; r2 = r0 % r1; a2 = a0 - q1 * a1; b2 = b0 - q1 * b1; r0 = r1; r1 = r2; a0 = a1; a1 = a2; b0 = b1; b1 = b2; } c = r0; a = a0; b = b0; } public static mlong ModPow(mlong a, long k) { if (k == 0) return (mlong)1; if (a == 0) return (mlong)0; mlong x = a; mlong ret = 1; while (k > 0) { if (k % 2 == 1) ret *= x; x *= x; k >>= 1; } return ret; } public static bool operator ==(mlong a, mlong b) { return a.Equals(b); } public static bool operator !=(mlong a, mlong b) { return !(a == b); } public override bool Equals(System.Object obj) { if (obj == null) return false; mlong p = (mlong)obj; if ((System.Object)p == null) return false; return p.V == V; } public override int GetHashCode() { return V.GetHashCode(); } public static implicit operator mlong(long n) { long v = n % mod; if (v < 0) v += mod; return new mlong(v); } public static implicit operator mlong(int n) { long v = n % mod; if (v < 0) v += mod; return new mlong(v); } public override String ToString() { return V.ToString(); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
8
962
18
using System; using System.IO; using System.Collections.Generic; namespace I_am_the_green_coder { class Inonoa { // なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて static void Main() { long[] nk = ILongs(); long n = nk[0]; long k = nk[1]; long combi = n - k + 1; for (long i = 0; i < k; i++) { if (i == 0) { Console.WriteLine(combi); continue; } if (n - k - i + 1 < 1) { Console.WriteLine(0); continue; } else if (n - k - i + 1 == 1) { Console.WriteLine(1); continue; } combi *= (k - i) * (n - k + 1 - i); combi %= MOD; long b = Modinv((i + 1) * i, MOD); combi *= b; combi %= MOD; Console.WriteLine(combi); } } static readonly long MOD = 1000000007; static long Modinv(long a, long m) { long b = m; long u = 1; long v = 0; long tmp; while (b > 0) { long t = a / b; a -= t * b; tmp = a; a = b; b = tmp; u -= t * v; tmp = v; v = u; u = tmp; } u %= m; if (u < 0) u += m; return u; } ///< summary>a_1, a_2, a_3, ...みたいなの</summary> static long[] ILongs() { string[] s = Console.ReadLine().Split(); long[] re = new long[s.Length]; for (long i = 0; i < s.Length; i++) { re[i] = long.Parse(s[i]); } return re; } ///< summary>xooxoxoxxoxo...みたいなの</summary> static char[] IChars() { return Console.ReadLine().ToCharArray(); } ///< summary>n m とかをちょっとはやくかくだけ</summary> static string[] IStrings() { return Console.ReadLine().Split(); } ///< summary>n行の入力を取ったり</summary> static long[][] ILongLongs(long n) { long[][] re = new long [n][]; for (long i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(); re[i] = new long[s.Length]; for (long j = 0; j < s.Length; j++) { re[i][j] = long.Parse(s[j]); } } return re; } static char[][] ICharsChars(long n) { char[][] re = new char [n][]; for (long i = 0; i < n; i++) { re[i] = Console.ReadLine().ToCharArray(); } return re; } } }
using System; using System.IO; using System.Collections.Generic; namespace I_am_the_green_coder { class Inonoa { // なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて static void Main() { long[] nk = ILongs(); long n = nk[0]; long k = nk[1]; long combi = n - k + 1; for (long i = 0; i < k; i++) { if (i == 0) { Console.WriteLine(combi); continue; } if (n - k - i + 1 < 1) { Console.WriteLine(0); continue; } combi *= (k - i) * (n - k + 1 - i); combi %= MOD; long b = Modinv((i + 1) * i, MOD); combi *= b; combi %= MOD; Console.WriteLine(combi); } } static readonly long MOD = 1000000007; static long Modinv(long a, long m) { long b = m; long u = 1; long v = 0; long tmp; while (b > 0) { long t = a / b; a -= t * b; tmp = a; a = b; b = tmp; u -= t * v; tmp = v; v = u; u = tmp; } u %= m; if (u < 0) u += m; return u; } ///< summary>a_1, a_2, a_3, ...みたいなの</summary> static long[] ILongs() { string[] s = Console.ReadLine().Split(); long[] re = new long[s.Length]; for (long i = 0; i < s.Length; i++) { re[i] = long.Parse(s[i]); } return re; } ///< summary>xooxoxoxxoxo...みたいなの</summary> static char[] IChars() { return Console.ReadLine().ToCharArray(); } ///< summary>n m とかをちょっとはやくかくだけ</summary> static string[] IStrings() { return Console.ReadLine().Split(); } ///< summary>n行の入力を取ったり</summary> static long[][] ILongLongs(long n) { long[][] re = new long [n][]; for (long i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(); re[i] = new long[s.Length]; for (long j = 0; j < s.Length; j++) { re[i][j] = long.Parse(s[j]); } } return re; } static char[][] ICharsChars(long n) { char[][] re = new char [n][]; for (long i = 0; i < n; i++) { re[i] = Console.ReadLine().ToCharArray(); } return re; } } }
[["-", 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], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 33], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 75, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["-", 75, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 72], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 75, 57, 64, 196, 0, 116, 0, 117], ["-", 0, 57, 75, 57, 64, 196, 0, 116, 0, 35], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46]]
8
593
24
using System; using System.Collections.Generic; using System.Linq; using System.Diagnostics; class Program { static void Main(string[] args) { const long MOD = 1000000007; var sc = new Scanner(); var n = sc.nextInt(); var k = sc.nextInt(); for (int i = 1; i <= k; i++) { //仕切りの入れ方 long ans = Combination(n - k + 1, i); //青の分け方(i分割) ans = ans * Combination(k - 1, i - 1) % MOD; Console.WriteLine(ans); }; } static long Combination(int n, int r) { const long MOD = 1000000007; long ans = 1; for (int i = r + 1; i <= n; i++) { ans = ans * i % MOD; } for (int i = 1; i <= n - r; i++) { ans = ans * Pow(i, MOD - 2, MOD) % MOD; } return ans; } static long Pow(long a, long b, long c) { long n = 1; long p = a; while (b > 0) { if (b % 2 == 0) { p = p * p % c; b = b / 2; } else { n = n * p % c; b = b - 1; } } return n; } } // chokudai's Scanner class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections.Generic; using System.Linq; using System.Diagnostics; class Program { static void Main(string[] args) { const long MOD = 1000000007; var sc = new Scanner(); var n = sc.nextInt(); var k = sc.nextInt(); for (int i = 1; i <= k; i++) { //仕切りの入れ方 long ans = Combination(n - k + 1, i); //青の分け方(i分割) ans = ans * Combination(k - 1, i - 1) % MOD; Console.WriteLine(ans); }; } static long Combination(int n, int r) { if (n == r) return 1; else if (n < r) return 0; const long MOD = 1000000007; long ans = 1; for (int i = r + 1; i <= n; i++) { ans = ans * i % MOD; } for (int i = 1; i <= n - r; i++) { ans = ans * Pow(i, MOD - 2, MOD) % MOD; } return ans; } static long Pow(long a, long b, long c) { long n = 1; long p = a; while (b > 0) { if (b % 2 == 0) { p = p * p % c; b = b / 2; } else { n = n * p % c; b = b - 1; } } return n; } } // chokudai's Scanner class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["+", 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, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 37, 0, 38], ["+", 8, 196, 0, 57, 75, 57, 64, 37, 0, 203], ["+", 8, 196, 0, 57, 75, 57, 64, 37, 0, 35]]
8
639
19
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { static long mod = 1000000007; static int[] ans; static void Main(string[] args) { char[] cs = new char[] { ' ' }; // char[] cs = new char[] { ' ', ',' }; // int n = int.Parse(Console.ReadLine()); // int val = int.Parse(Console.ReadLine()); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); long res = 0; int[] vals = parseAry(Console.ReadLine().Split(cs)); int n = vals[0]; int ao = vals[1]; int aka = n - ao; long[] powd = new long[2001]; powd[0] = 1; for (long i = 1; i <= 2000; i++) { powd[i] = (powd[i - 1] * i) % mod; } for (int i = 1; i <= ao; i++) { long akaside = 0; long nowaka = aka; // i=3 nowaka -= i - 1; long tt = powd[nowaka] * (powd[i]) % mod; // long tttt = t * mod_pow(tt, mod - 2)%mod; akaside = (powd[nowaka + (i)] * (mod_pow(tt, mod - 2) % mod)) % mod; long aoside = 0; // i=3 long nowao = ao; nowao -= i; tt = powd[nowao] * (powd[i - 1]) % mod; aoside = (powd[nowao + (i - 1)] * (mod_pow(tt, mod - 2) % mod)) % mod; long restemp = akaside * aoside % mod; Console.WriteLine(restemp); } // Console.WriteLine(res); return; } static public long mod_pow(long x, long n) { long mod = 1000000007; long res = 1; while (n > 0) { if ((n & 1) == 1) { res = res * x % mod; } x = x * x % mod; n >>= 1; } return res; } // 文字列strをindex番目からdで上書き static string strOverWrite(string str, int i, string s) { return str.Remove(i, s.Length).Insert(i, s); } // String[] -----> int[] static int[] parseAry(string[] str) { int[] nums = new int[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } // String[] -----> long[] static long[] parseAryL(string[] str) { long[] nums = new long[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); } return nums; } //文字列を1文字ずつString[]に入れる static string[] strAry(String str) { string[] re = new string[str.Length]; for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); } return re; } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { static long mod = 1000000007; static int[] ans; static void Main(string[] args) { char[] cs = new char[] { ' ' }; // char[] cs = new char[] { ' ', ',' }; // int n = int.Parse(Console.ReadLine()); // int val = int.Parse(Console.ReadLine()); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); long res = 0; int[] vals = parseAry(Console.ReadLine().Split(cs)); int n = vals[0]; int ao = vals[1]; int aka = n - ao; long[] powd = new long[2001]; powd[0] = 1; for (long i = 1; i <= 2000; i++) { powd[i] = (powd[i - 1] * i) % mod; } for (int i = 1; i <= ao; i++) { long akaside = 0; long nowaka = aka; // i=3 nowaka -= i - 1; if (nowaka < 0) { Console.WriteLine("0"); continue; } long tt = powd[nowaka] * (powd[i]) % mod; // long tttt = t * mod_pow(tt, mod - 2)%mod; akaside = (powd[nowaka + (i)] * (mod_pow(tt, mod - 2) % mod)) % mod; long aoside = 0; // i=3 long nowao = ao; nowao -= i; tt = powd[nowao] * (powd[i - 1]) % mod; aoside = (powd[nowao + (i - 1)] * (mod_pow(tt, mod - 2) % mod)) % mod; long restemp = akaside * aoside % mod; Console.WriteLine(restemp); } // Console.WriteLine(res); return; } static public long mod_pow(long x, long n) { long mod = 1000000007; long res = 1; while (n > 0) { if ((n & 1) == 1) { res = res * x % mod; } x = x * x % mod; n >>= 1; } return res; } // 文字列strをindex番目からdで上書き static string strOverWrite(string str, int i, string s) { return str.Remove(i, s.Length).Insert(i, s); } // String[] -----> int[] static int[] parseAry(string[] str) { int[] nums = new int[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } // String[] -----> long[] static long[] parseAryL(string[] str) { long[] nums = new long[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); } return nums; } //文字列を1文字ずつString[]に入れる static string[] strAry(String str) { string[] re = new string[str.Length]; for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); } return re; } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 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, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
620
19
using System; using System.IO; using System.Linq; namespace DBlueAndRedBalls { class Program { static void Main(string[] args) { // 入力の取得 var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = inputs[0]; var k = inputs[1]; var blueBalls = k; var redBalls = n - k; var answers = new ModNum[k]; for (var i = 1; i <= k; i++) { var bluePatterns = MultiChoose(i, blueBalls - i); var redPatterns = MultiChoose(i + 1, redBalls - i + 1); answers[i - 1] = bluePatterns * redPatterns; } // 解答の出力 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); foreach (var answer in answers) { Console.WriteLine(answer.X); } Console.Out.Flush(); } static ModNum MultiChoose(int i, int balls) { var n = i + balls - 1; ModNum numer = 1, denom = 1; for (var j = 1; j <= balls; j++) { denom *= j; numer *= n - j + 1; } return numer / denom; } } public struct ModNum : IEquatable<ModNum> { const int Mod = 1000000007; public long X { get; } public ModNum(long x) { X = x % Mod; } public static implicit operator ModNum(long x) => new ModNum(x); public bool Equals(ModNum other) => X == other.X; public override bool Equals(object obj) => obj is ModNum && Equals((ModNum)obj); public override int GetHashCode() => X.GetHashCode(); public static bool operator ==(ModNum a, ModNum b) => a.X == b.X; public static bool operator !=(ModNum a, ModNum b) => a.X != b.X; public static ModNum operator +(ModNum a, ModNum b) => a.X + b.X; public static ModNum operator -(ModNum a, ModNum b) => Mod + a.X - b.X; public static ModNum operator *(ModNum a, ModNum b) => a.X * b.X; public static ModNum operator /(ModNum a, ModNum b) => a.X * Pow(b, Mod - 2); public static ModNum Pow(ModNum baseNum, int exponent) { switch (exponent) { case 0: return 1; case 1: return baseNum; default: var pow = Pow(baseNum, exponent / 2); return (exponent % 2) == 0 ? pow * pow : pow * pow * baseNum; } } } }
using System; using System.IO; using System.Linq; namespace DBlueAndRedBalls { class Program { static void Main(string[] args) { // 入力の取得 var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = inputs[0]; var k = inputs[1]; var blueBalls = k; var redBalls = n - k; var answers = new ModNum[k]; for (var i = 1; i <= k; i++) { if (i - 1 <= redBalls) { var bluePatterns = MultiChoose(i, blueBalls - i); var redPatterns = MultiChoose(i + 1, redBalls - i + 1); answers[i - 1] = bluePatterns * redPatterns; } else { answers[i - 1] = 0; } } // 解答の出力 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); foreach (var answer in answers) { Console.WriteLine(answer.X); } Console.Out.Flush(); } static ModNum MultiChoose(int i, int balls) { var n = i + balls - 1; ModNum numer = 1, denom = 1; for (var j = 1; j <= balls; j++) { denom *= j; numer *= n - j + 1; } return numer / denom; } } public struct ModNum : IEquatable<ModNum> { const int Mod = 1000000007; public long X { get; } public ModNum(long x) { X = x % Mod; } public static implicit operator ModNum(long x) => new ModNum(x); public bool Equals(ModNum other) => X == other.X; public override bool Equals(object obj) => obj is ModNum && Equals((ModNum)obj); public override int GetHashCode() => X.GetHashCode(); public static bool operator ==(ModNum a, ModNum b) => a.X == b.X; public static bool operator !=(ModNum a, ModNum b) => a.X != b.X; public static ModNum operator +(ModNum a, ModNum b) => a.X + b.X; public static ModNum operator -(ModNum a, ModNum b) => Mod + a.X - b.X; public static ModNum operator *(ModNum a, ModNum b) => a.X * b.X; public static ModNum operator /(ModNum a, ModNum b) => a.X * Pow(b, Mod - 2); public static ModNum Pow(ModNum baseNum, int exponent) { switch (exponent) { case 0: return 1; case 1: return baseNum; default: var pow = Pow(baseNum, exponent / 2); return (exponent % 2) == 0 ? pow * pow : pow * pow * baseNum; } } } }
[["+", 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, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 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, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
562
22
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC132 { class D { static int _Mod = 1000000007; static void Main(string[] args) { int[] p = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray(); int N = p[0], K = p[1]; int R = N - K; List<long[]> C = PascalTriangle(N); for (int i = 1; i <= K; i++) { long r = C[R + 1][R - i + 1] * C[K - 1][i - 1]; r = r %= _Mod; Console.WriteLine(r); } } //パスカルの三角形(O(n^2) public static List<long[]> PascalTriangle(int n) { List<long[]> list = new List<long[]>(); for (int i = 0; i <= n; i++) { long[] arr = new long[i + 1]; arr[0] = 1; arr[i] = 1; if (i >= 2) { long[] arrBfr = list[i - 1]; for (int j = 1; j < arr.Length - 1; j++) { arr[j] = arrBfr[j - 1] + arrBfr[j]; arr[j] %= _Mod; } } list.Add(arr); } return list; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC132 { class D { static int _Mod = 1000000007; static void Main(string[] args) { int[] p = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray(); int N = p[0], K = p[1]; int R = N - K; List<long[]> C = PascalTriangle(N); for (int i = 1; i <= K; i++) { long r; if (R - i + 1 < 0) { r = 0; } else { r = C[R + 1][R - i + 1] * C[K - 1][i - 1]; r = r %= _Mod; } Console.WriteLine(r); } } //パスカルの三角形(O(n^2) public static List<long[]> PascalTriangle(int n) { List<long[]> list = new List<long[]>(); for (int i = 0; i <= n; i++) { long[] arr = new long[i + 1]; arr[0] = 1; arr[i] = 1; if (i >= 2) { long[] arrBfr = list[i - 1]; for (int j = 1; j < arr.Length - 1; j++) { arr[j] = arrBfr[j - 1] + arrBfr[j]; arr[j] %= _Mod; } } list.Add(arr); } return list; } } }
[["+", 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], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 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, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 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, 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, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
330
21
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; public struct Pair<T> { public T x, y; public Pair(T x, T y) { this.x = x; this.y = y; } } public static void Solve() { long N = NextLong(); long K = NextLong(); long red = N - K; //どこの隙間を埋めるか int sukima = 0; for (int i = 1; i <= K; i++) { if (K < sukima) { Console.WriteLine(0); continue; } //隙間が1の時、そこに1-K個と弾と、残った弾を自由に分配する //つまり隙間個を確定させて、他で自由に分配すればいいい //隙間も組み合わせで決められる long _sukima = PCH.nCr(K - 1, sukima) % INF; long H = PCH.nHr(sukima + 2, red - sukima) % INF; // sukima個、隙間を埋めるのに使うので他をsukima個+2で使える Console.WriteLine(Math.Max(_sukima, 1) * Math.Max(H, 1) % INF); sukima++; } } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public static class PCH { public static long nPr(long n, long r, long m = 1000000007) { for (long i = 0; i < r; r++) { n *= (n - i); n %= m; } return n; } public static long nCr(long n, long r, long m = 1000000007) { if (r == 0) return 0; long a = 1; for (long i = 0; i < r; i++) { a *= (n - i); a %= m; } long b = 1; for (long x = 2; x <= r; x++) { b *= x; b %= m; } b = RepPow(b, m - 2) % m; return (a * b) % m; } public static long nHr(long n, long r, long m = 1000000007) { return nCr(n + r - 1, r, m); } public static long RepPow(long x, long p, long m = 1000000007) { if (p == 0) return 1; if (p == 1) return x % m; long b = RepPow(x, p / 2, m) % m; if (p % 2 == 0) { return (b * b) % m; } else { return (x * ((b * b) % m)) % m; } } } public class Input { 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; public struct Pair<T> { public T x, y; public Pair(T x, T y) { this.x = x; this.y = y; } } public static void Solve() { long N = NextLong(); long K = NextLong(); long red = N - K; //どこの隙間を埋めるか int sukima = 0; for (int i = 1; i <= K; i++) { // if (K < sukima) { Console.WriteLine(0); continue; } //隙間が1の時、そこに1-K個と弾と、残った弾を自由に分配する //つまり隙間個を確定させて、他で自由に分配すればいいい //隙間も組み合わせで決められる long _sukima = PCH.nCr(K - 1, sukima) % INF; if (red - sukima < 0) { Console.WriteLine(0); continue; } long H = PCH.nHr(sukima + 2, red - sukima) % INF; // sukima個、隙間を埋めるのに使うので他をsukima個+2で使える Console.WriteLine((Math.Max(_sukima, 1) * Math.Max(H, 1)) % INF); sukima++; } } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public static class PCH { public static long nPr(long n, long r, long m = 1000000007) { for (long i = 0; i < r; r++) { n *= (n - i); n %= m; } return n; } public static long nCr(long n, long r, long m = 1000000007) { if (r == 0) return 0; long a = 1; for (long i = 0; i < r; i++) { a *= (n - i); a %= m; } long b = 1; for (long x = 2; x <= r; x++) { b *= x; b %= m; } b = RepPow(b, m - 2) % m; return (a * b) % m; } public static long nHr(long n, long r, long m = 1000000007) { return nCr(n + r - 1, r, m); } public static long RepPow(long x, long p, long m = 1000000007) { if (p == 0) return 1; if (p == 1) return x % m; long b = RepPow(x, p / 2, m) % m; if (p % 2 == 0) { return (b * b) % m; } else { return (x * ((b * b) % m)) % m; } } } public class Input { 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, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 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, 116, 0, 117], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 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, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 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], ["+", 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, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
852
38
using System; using System.Collections.Generic; public class ABC132D { public static int BIGMUM = 1000000007; public static void Main() { int N, K, ans = 0; string[] str = Console.ReadLine().Split(' '); N = int.Parse(str[0]); K = int.Parse(str[1]); int[,] nCk = new int[2000, 2000]; Fill(nCk); for (int i = 1; i <= K; i++) { ans = nCk[N - K + 1, i] * nCk[K - 1, i - 1] % BIGMUM; Console.WriteLine(ans); } } public static void Fill(int[,] nCk) { for (int i = 0; i < 2000; i++) { nCk[i, 0] = 1; nCk[i, i] = 1; } for (int i = 0; i < 2000; i++) { for (int j = 1; j < i; j++) { nCk[i, j] = (nCk[i - 1, j] + nCk[i - 1, j - 1]) % BIGMUM; } } } }
using System; using System.Collections.Generic; public class ABC132D { public static long BIGMUM = 1000000007; public static void Main() { long N, K, ans = 0; string[] str = Console.ReadLine().Split(' '); N = long.Parse(str[0]); K = long.Parse(str[1]); long[,] nCk = new long[4000, 4000]; Fill(nCk); for (int i = 1; i <= K; i++) { ans = (nCk[N - K + 1, i] * nCk[K - 1, i - 1]) % BIGMUM; Console.WriteLine(ans); } } public static void Fill(long[,] nCk) { for (int i = 0; i < 4000; i++) { nCk[i, 0] = 1; nCk[i, i] = 1; } for (int i = 0; i < 4000; i++) { for (int j = 1; j < i; j++) { nCk[i, j] = (nCk[i - 1, j] + nCk[i - 1, j - 1]) % BIGMUM; } } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
259
24
using System; using System.Collections.Generic; using System.Linq; using static Constans; public static class Constans { public const long Mod = (long)1e9 + 7; } public class Combination { private readonly long[] Fact; private readonly long[] InvFact; // モジュラ逆数 public Combination(long n) { Fact = new long[n + 1]; InvFact = new long[n + 1]; long f = 1; Fact[0] = f; for (long i = 1; i <= n; i++) { f *= i; f %= Mod; Fact[i] = f; } long inv = ModInt.GetInv(f).Num; InvFact[n] = inv; for (long i = n - 1; i >= 0; i--) { InvFact[i] = (InvFact[i + 1] * (i + 1)) % Mod; } } // nCr public ModInt GetCombination(long n, long r) { var comb = Fact[n] * InvFact[r] % Mod; comb = comb * InvFact[n - r] % Mod; return new ModInt(comb); } } public struct ModInt { public long Num; public ModInt(long num) { Num = num; } // x^n public static long Power(long x, long n) { long pow = 1; while (n > 0) { if (n % 2 == 0) { x *= x; x %= Mod; n /= 2; } else { pow *= x; pow %= Mod; n--; } } return pow; } public static ModInt GetInv(long f) { // フェルマーの小定理 a^(-1) = a^(mod-2) return new ModInt(Power(f, Mod - 2)); } public ModInt GetInv() { return GetInv(Num); } public override string ToString() { return Num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.Num += r.Num; if (l.Num >= Mod) { l.Num -= Mod; } return l; } public static ModInt operator -(ModInt l, ModInt r) { l.Num -= r.Num; if (l.Num < 0) { l.Num += Mod; } return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.Num * r.Num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) { n += Mod; } return new ModInt(n); } } public class Solution { public static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = vals[0]; var K = vals[1]; var comb = new Combination(N); var patterns = new List<ModInt>(); for (int i = 1; i <= K; i++) { var pattern = comb.GetCombination(K - 1, i - 1) * comb.GetCombination(N - K + 1, i); patterns.Add(pattern); } Console.WriteLine(string.Join(Environment.NewLine, patterns)); } }
using System; using System.Collections.Generic; using System.Linq; using static Constans; public static class Constans { public const long Mod = (long)1e9 + 7; } public class Combination { private readonly long[] Fact; private readonly long[] InvFact; // モジュラ逆数 public Combination(long n) { Fact = new long[n + 1]; InvFact = new long[n + 1]; long f = 1; Fact[0] = f; for (long i = 1; i <= n; i++) { f *= i; f %= Mod; Fact[i] = f; } long inv = ModInt.GetInv(f).Num; InvFact[n] = inv; for (long i = n - 1; i >= 0; i--) { InvFact[i] = (InvFact[i + 1] * (i + 1)) % Mod; } } // nCr public ModInt GetCombination(long n, long r) { if (n < r) { return 0; } var comb = Fact[n] * InvFact[r] % Mod; comb = comb * InvFact[n - r] % Mod; return new ModInt(comb); } } public struct ModInt { public long Num; public ModInt(long num) { Num = num; } // x^n public static long Power(long x, long n) { long pow = 1; while (n > 0) { if (n % 2 == 0) { x *= x; x %= Mod; n /= 2; } else { pow *= x; pow %= Mod; n--; } } return pow; } public static ModInt GetInv(long f) { // フェルマーの小定理 a^(-1) = a^(mod-2) return new ModInt(Power(f, Mod - 2)); } public ModInt GetInv() { return GetInv(Num); } public override string ToString() { return Num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.Num += r.Num; if (l.Num >= Mod) { l.Num -= Mod; } return l; } public static ModInt operator -(ModInt l, ModInt r) { l.Num -= r.Num; if (l.Num < 0) { l.Num += Mod; } return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.Num * r.Num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) { n += Mod; } return new ModInt(n); } } public class Solution { public static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = vals[0]; var K = vals[1]; var comb = new Combination(N); var patterns = new List<ModInt>(); for (int i = 1; i <= K; i++) { var pattern = comb.GetCombination(K - 1, i - 1) * comb.GetCombination(N - K + 1, i); patterns.Add(pattern); } Console.WriteLine(string.Join(Environment.NewLine, patterns)); } }
[["+", 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], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
664
11
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nk[0]; var k = nk[1]; var blue = (k); var red = (n - k); //青をiグループ、赤をi-1,i,i+1グループ StringBuilder builder = new StringBuilder(); for (int i = 1; i <= k; i++) { //仕切りを入れる // var bluePartation = Calc(blue, i); var m1 = (i == 1 ? 0 : Calc(red, i - 1)); var z = Calc(red, i) * 2; var p1 = Calc(red, i + 1); var redPartation = (i == 1 ? 0 : Calc(red, i - 1)) + (Calc(red, i) * 2) + Calc(red, i + 1); builder.AppendLine((bluePartation * redPartation).ToString()); } Console.WriteLine(builder.ToString()); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static ModInt Calc(int count, int partation) { if (count < partation) return 0; if (partation == 1) return 1; return Factorial(count - 1) * FactorialInv(partation - 1) * FactorialInv(count - partation); } static List<ModInt> factorialMemo = new List<ModInt>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static ModInt Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static List<ModInt> factorialInvMemo = new List<ModInt>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static ModInt FactorialInv(int x) { for (int i = factorialInvMemo.Count; i <= x; i++) factorialInvMemo.Add(factorialInvMemo.Last() / i); return factorialInvMemo[x]; } } struct ModInt { const int MOD = 1000000007; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetInverse(long a) { long div; long p = MOD; long x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } }
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nk[0]; var k = nk[1]; var blue = (k); var red = (n - k); //青をiグループ、赤をi-1,i,i+1グループ StringBuilder builder = new StringBuilder(); for (int i = 1; i <= k; i++) { //仕切りを入れる var bluePartation = Calc(blue, i); var m1 = (i == 1 ? 0 : Calc(red, i - 1)); var z = Calc(red, i) * 2; var p1 = Calc(red, i + 1); var redPartation = (i == 1 ? (red == 0 ? 1 : 0) : Calc(red, i - 1)) + (Calc(red, i) * 2) + Calc(red, i + 1); builder.AppendLine((bluePartation * redPartation).ToString()); } Console.Write(builder.ToString()); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static ModInt Calc(int count, int partation) { if (count < partation) return 0; if (partation == 1) return 1; return Factorial(count - 1) * FactorialInv(partation - 1) * FactorialInv(count - partation); } static List<ModInt> factorialMemo = new List<ModInt>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static ModInt Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static List<ModInt> factorialInvMemo = new List<ModInt>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static ModInt FactorialInv(int x) { for (int i = factorialInvMemo.Count; i <= x; i++) factorialInvMemo.Add(factorialInvMemo.Last() / i); return factorialInvMemo[x]; } } struct ModInt { const int MOD = 1000000007; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetInverse(long a) { long div; long p = MOD; long x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } }
[["+", 31, 16, 31, 23, 0, 41, 64, 23, 0, 24], ["+", 0, 41, 64, 23, 0, 41, 15, 16, 31, 22], ["+", 0, 41, 64, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 41, 64, 23, 0, 41, 15, 16, 12, 203], ["+", 31, 23, 0, 41, 64, 23, 0, 41, 0, 101], ["+", 31, 23, 0, 41, 64, 23, 0, 41, 64, 203], ["+", 31, 23, 0, 41, 64, 23, 0, 41, 0, 102], ["+", 31, 16, 31, 23, 0, 41, 64, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
8
939
10
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static string[] inputa = Console.ReadLine().Split(' '); static long n = long.Parse(inputa[0]); static long k = long.Parse(inputa[1]); static long p = 1000000007; static long[] factorials = new long[n + 1]; // i!(mod p)を先にメモ static long[] factorialRs = new long[n + 1]; // i!^-1(mod p), pは素数 static void Main() { factorials[0] = 1; factorialRs[n] = DivideModFactorial(n, p); for (long i = 1; i <= n; i++) { factorials[i] = (factorials[i - 1] * i) % p; // i!(mod p) factorialRs[n - i] = (factorialRs[n + 1 - i] * (n + 1 - i)) % p; //逆元も先にメモ } for (int i = 1; i <= k; i++) { Console.WriteLine((Comb(n - k + 1, i, p) * Comb(k - 1, i - 1, p)) % p); // nCk(mod p),pは素数 } } static long MathPow(long x, long a) //戻り値はx^a { long num = 2; long answer = 1; long check = a; long memo = x; while (check > 0) { if (check % num == num / 2) { check -= num / 2; answer *= memo; } memo *= memo; num *= 2; } return answer; } static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p) { long num = 2; long answer = 1; long check = a; long memo = x % p; while (check > 0) { if (check % num == num / 2) { check -= num / 2; answer *= memo; answer %= p; } memo *= memo; memo %= p; num *= 2; } return answer; } static long DivideModReverse(long x, long p) //戻り値はx^-1(mod p), pは素数 { long answer = DivideMod(x, p - 2, p); return answer; } static long DivideModFactorial(long x, long p) //戻り値はx!^-1(mod p), pは素数 { long answer = 1; for (long i = x; i >= 2; i--) { answer *= DivideModReverse(i, p); answer %= p; } return answer; } static long Comb(long a, long b, long p) //戻り値は組み合わせC(a,b)のmod p { long answer = 1; answer *= factorials[a]; answer %= p; answer *= factorialRs[a - b]; //引数a-bは負にならないようにする answer %= p; answer *= factorialRs[b]; answer %= p; return answer; } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static string[] inputa = Console.ReadLine().Split(' '); static long n = long.Parse(inputa[0]); static long k = long.Parse(inputa[1]); static long p = 1000000007; static long[] factorials = new long[n + 1]; // i!(mod p)を先にメモ static long[] factorialRs = new long[n + 1]; // i!^-1(mod p), pは素数 static void Main() { factorials[0] = 1; factorialRs[n] = DivideModFactorial(n, p); for (long i = 1; i <= n; i++) { factorials[i] = (factorials[i - 1] * i) % p; // i!(mod p) factorialRs[n - i] = (factorialRs[n + 1 - i] * (n + 1 - i)) % p; //逆元も先にメモ } for (int i = 1; i <= k; i++) { Console.WriteLine((Comb(n - k + 1, i, p) * Comb(k - 1, i - 1, p)) % p); // nCk(mod p),pは素数 } } static long MathPow(long x, long a) //戻り値はx^a { long num = 2; long answer = 1; long check = a; long memo = x; while (check > 0) { if (check % num == num / 2) { check -= num / 2; answer *= memo; } memo *= memo; num *= 2; } return answer; } static long DivideMod(long x, long a, long p) //戻り値はx^a(mod p) { long num = 2; long answer = 1; long check = a; long memo = x % p; while (check > 0) { if (check % num == num / 2) { check -= num / 2; answer *= memo; answer %= p; } memo *= memo; memo %= p; num *= 2; } return answer; } static long DivideModReverse(long x, long p) //戻り値はx^-1(mod p), pは素数 { long answer = DivideMod(x, p - 2, p); return answer; } static long DivideModFactorial(long x, long p) //戻り値はx!^-1(mod p), pは素数 { long answer = 1; for (long i = x; i >= 2; i--) { answer *= DivideModReverse(i, p); answer %= p; } return answer; } static long Comb(long a, long b, long p) //戻り値は組み合わせC(a,b)のmod p { if (a - b < 0) return 0; long answer = 1; answer *= factorials[a]; answer %= p; answer *= factorialRs[a - b]; //引数a-bは負にならないようにする answer %= p; answer *= factorialRs[b]; answer %= p; return answer; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 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, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35]]
8
546
11
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 N = Int1; var a = Ints; var ans = new int[N]; for (int i = N - 1; i >= 0; --i) { int j = 1; int sum = 0; while (true) { if (j > N) break; sum += ans[j - 1]; j += (i + 1); } if ((sum % 2) != (a[i] % 2)) ans[i] = 1; } int k = ans.Where(l => l == 1).Sum(); var wr = new List<int>(); for (int i = 0; i < N; ++i) { if (ans[i] == 1) wr.Add(i + 1); } Write(k); if (k > 0) Write(wr.ToArray()); } } 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 i, long N, long MOD = 1000000007) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long Power2(long i, long N) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i; i = i * i; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) 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 N = Int1; var a = Ints; var ans = new int[N]; for (int i = N; i > 0; --i) { int j = 0; int sum = 0; while (true) { j += i; if (j > N) break; sum += ans[j - 1]; } if ((sum % 2) != (a[i - 1] % 2)) ans[i - 1] = 1; } int k = ans.Where(l => l == 1).Sum(); var wr = new List<int>(); for (int i = 0; i < N; ++i) { if (ans[i] == 1) wr.Add(i + 1); } Write(k); if (k > 0) Write(wr.ToArray()); } } 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 i, long N, long MOD = 1000000007) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long Power2(long i, long N) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i; i = i * i; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) 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"); } }
[["-", 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, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 17, 72], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
1,098
22
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp15 { class Class285 { static void Main() { int N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => x == "1").ToArray(); var ans = new bool[N]; for (int i = N - 1; i >= 0; i--) { var num = a[i]; int index = i + 1; while (index * 2 - 1 < N) { index *= 2; if (ans[index - 1]) num = !num; } if (num) ans[i] = true; } Console.WriteLine(ans.Count(y => y == true)); for (int i = 0; i < N; i++) if (ans[i]) Console.WriteLine(i + 1); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp15 { class Class285 { static void Main() { int N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => x == "1").ToArray(); var ans = new bool[N]; for (int i = N - 1; i >= 0; i--) { var num = a[i]; int index = i + 1; for (int j = 2; index * j - 1 < N; j++) { if (ans[index * j - 1]) num = !num; } if (num) ans[i] = true; } Console.WriteLine(ans.Count(y => y == true)); for (int i = 0; i < N; i++) if (ans[i]) Console.WriteLine(i + 1); } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 52, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 7, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 22]]
8
201
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class7 { static void Main() { int N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); List<int> ans = new List<int>(); var b = new int[N]; for (int i = 0; i < N; i++) b[i] = 0; for (int i = N - 1; i >= 0; i--) { int j = i + 1; int k = a[i]; j *= 2; while (j <= N) { k += b[j - 1]; j *= 2; } k %= 2; if (k == 1) { b[i] = 1; ans.Add(i + 1); } } ans = ans.OrderBy(x => x).ToList(); Console.WriteLine(ans.Count()); if (ans.Count > 0) Console.WriteLine(string.Join(" ", ans)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class7 { static void Main() { int N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); List<int> ans = new List<int>(); var b = new int[N]; for (int i = 0; i < N; i++) b[i] = 0; for (int i = N - 1; i >= 0; i--) { int j = i + 1; int k = a[i]; for (int l = 2; j * l <= N; l++) { k += b[j * l - 1]; } k %= 2; if (k == 1) { b[i] = 1; ans.Add(i + 1); } } ans = ans.OrderBy(x => x).ToList(); Console.WriteLine(ans.Count()); if (ans.Count > 0) Console.WriteLine(string.Join(" ", ans)); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 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], ["-", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["-", 8, 196, 0, 7, 8, 196, 0, 52, 0, 24], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203]]
8
260
20
using System; using System.Linq; using System.Collections.Generic; namespace ABC134 { class D { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var iList = new List<int>(); var res = new int[N + 1]; for (int i = N; i > 0; i--) { var j = 1; var sum = 0; while (i * j <= N) { if (res[i * j] != 0) sum++; j++; } if ((sum % 2 == 0 && a[i - 1] == 1) || (sum % 2 == 1 && a[i - 1] == 0)) { res[i - 1]++; iList.Add(i); } } Console.WriteLine(iList.Count); if (iList.Count != 0) Console.WriteLine(string.Join(" ", iList)); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC134 { class D { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var iList = new List<int>(); var res = new int[N + 1]; for (int i = N; i > 0; i--) { var j = 1; var sum = 0; while (i * j <= N) { sum += res[i * j]; j++; } if (sum % 2 != a[i - 1]) { res[i] = 1; iList.Add(i); } } Console.WriteLine(iList.Count); if (iList.Count != 0) Console.WriteLine(string.Join(" ", iList)); } } }
[["-", 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, 107], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 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, 223, 0, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 15, 16, 31, 23, 0, 16, 31, 16, 17, 60], ["-", 15, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 17, 98], ["-", 31, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["-", 0, 16, 12, 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, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 15, 16, 31, 23, 0, 16, 12, 16, 17, 60], ["-", 15, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 12, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 12, 23, 0, 16, 31, 16, 31, 16, 17, 109], ["-", 12, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
235
39
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static Asakatsu20200319D.Input; namespace Asakatsu20200319D { static class Input { /// <summary> /// 1行の入力をTに応じてリストに変換する関数を返す /// </summary> static Func<string, List<T>> Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToList(); /// <summary> /// 1行の入力をTに応じて変換する関数を返す /// </summary> 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(List<string>)) return _ => (T)(object)Cast<string>()(_); if (t == typeof(List<int>)) return _ => (T)(object)Cast<int>()(_); if (t == typeof(List<long>)) return _ => (T)(object)Cast<long>()(_); if (t == typeof(List<double>)) return _ => (T)(object)Cast<double>()(_); throw new NotSupportedException(t + "is not supported."); } static string String() => Console.ReadLine(); static List<string> String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToList(); /// <summary> /// 1行の値の入力 /// </summary> public static void @in<T>(out T a) => a = Convert<List<T>>()(String())[0]; public static void @in<T>(out T a1, out T a2) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; } public static void @in<T>(out T a1, out T a2, out T a3) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; a3 = v[2]; } public static void @in<T>(out T a1, out T a2, out T a3, out T a4) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; a3 = v[2]; a4 = v[3]; } public static void @in<T>(out T a1, out T a2, out T a3, out T a4, out T a5) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; a3 = v[2]; a4 = v[3]; a5 = v[4]; } public static void @in<T>(out T a1, out T a2, out T a3, out T a4, out T a5, out T a6) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; a3 = v[2]; a4 = v[3]; a5 = v[4]; a6 = v[5]; } /// <summary> /// 複数行の値の入力 /// </summary> public static void @in<T>(long rowNumber, out List<T> l) => l = String(rowNumber).Select(Convert<T>()).ToList(); public static void @in<T1, T2>(long rowNumber, out List<T1> l1, out List<T2> l2) { l1 = new List<T1>(); l2 = new List<T2>(); foreach (List<string> l in String(rowNumber).Select( Convert<List<string>>())) { l1.Add(Convert<T1>()(l[0])); l2.Add(Convert<T2>()(l[1])); } } public static void @in<T1, T2, T3>(long rowNumber, out List<T1> l1, out List<T2> l2, out List<T3> l3) { l1 = new List<T1>(); l2 = new List<T2>(); l3 = new List<T3>(); foreach (List<string> l in String(rowNumber).Select( Convert<List<string>>())) { l1.Add(Convert<T1>()(l[0])); l2.Add(Convert<T2>()(l[1])); l3.Add(Convert<T3>()(l[2])); } } public static void @in<T1, T2, T3, T4>(long rowNumber, out List<T1> l1, out List<T2> l2, out List<T3> l3, out List<T4> l4) { l1 = new List<T1>(); l2 = new List<T2>(); l3 = new List<T3>(); l4 = new List<T4>(); foreach (List<string> l in String(rowNumber).Select( Convert<List<string>>())) { l1.Add(Convert<T1>()(l[0])); l2.Add(Convert<T2>()(l[1])); l3.Add(Convert<T3>()(l[2])); l4.Add(Convert<T4>()(l[3])); } } /// <summary> /// 1行に書かれた複数の値の入力 /// </summary> public static void @in<T>(out List<T> lArr) => lArr = Convert<List<T>>()(String()); /// <summary> /// h行の行列の入力 /// </summary> public static void @in<T>(long h, out List<List<T>> map) => map = String(h).Select(Convert<List<T>>()).ToList(); } 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; private List<int> a; public void Solve() { @in(out N); @in(out a); var d = new int[N + 1]; int ans = 0; for (long i = N; i > 0; i--) { var l = 1; List<long> divisor = new List<long>(); while (i >= l * l) { if (i % l == 0) { divisor.Add(l); if (i / l != l) divisor.Add(i / l); } l++; } if ((d[i] - a[(int)i - 1]) % 2 != 0) { ans++; foreach (var k in divisor) { d[k] = d[k] + 1; } } } Console.WriteLine(ans); if (ans == 0) { return; } for (int i = 0; i < ans; i++) { Console.Write("1 "); } Console.WriteLine(); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static Asakatsu20200319D.Input; namespace Asakatsu20200319D { static class Input { /// <summary> /// 1行の入力をTに応じてリストに変換する関数を返す /// </summary> static Func<string, List<T>> Cast<T>() => _ => _.Split(' ').Select(Convert<T>()).ToList(); /// <summary> /// 1行の入力をTに応じて変換する関数を返す /// </summary> 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(List<string>)) return _ => (T)(object)Cast<string>()(_); if (t == typeof(List<int>)) return _ => (T)(object)Cast<int>()(_); if (t == typeof(List<long>)) return _ => (T)(object)Cast<long>()(_); if (t == typeof(List<double>)) return _ => (T)(object)Cast<double>()(_); throw new NotSupportedException(t + "is not supported."); } static string String() => Console.ReadLine(); static List<string> String(long rowNumber) => new bool [rowNumber].Select(_ => String()).ToList(); /// <summary> /// 1行の値の入力 /// </summary> public static void @in<T>(out T a) => a = Convert<List<T>>()(String())[0]; public static void @in<T>(out T a1, out T a2) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; } public static void @in<T>(out T a1, out T a2, out T a3) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; a3 = v[2]; } public static void @in<T>(out T a1, out T a2, out T a3, out T a4) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; a3 = v[2]; a4 = v[3]; } public static void @in<T>(out T a1, out T a2, out T a3, out T a4, out T a5) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; a3 = v[2]; a4 = v[3]; a5 = v[4]; } public static void @in<T>(out T a1, out T a2, out T a3, out T a4, out T a5, out T a6) { var v = Convert<List<T>>()(String()); a1 = v[0]; a2 = v[1]; a3 = v[2]; a4 = v[3]; a5 = v[4]; a6 = v[5]; } /// <summary> /// 複数行の値の入力 /// </summary> public static void @in<T>(long rowNumber, out List<T> l) => l = String(rowNumber).Select(Convert<T>()).ToList(); public static void @in<T1, T2>(long rowNumber, out List<T1> l1, out List<T2> l2) { l1 = new List<T1>(); l2 = new List<T2>(); foreach (List<string> l in String(rowNumber).Select( Convert<List<string>>())) { l1.Add(Convert<T1>()(l[0])); l2.Add(Convert<T2>()(l[1])); } } public static void @in<T1, T2, T3>(long rowNumber, out List<T1> l1, out List<T2> l2, out List<T3> l3) { l1 = new List<T1>(); l2 = new List<T2>(); l3 = new List<T3>(); foreach (List<string> l in String(rowNumber).Select( Convert<List<string>>())) { l1.Add(Convert<T1>()(l[0])); l2.Add(Convert<T2>()(l[1])); l3.Add(Convert<T3>()(l[2])); } } public static void @in<T1, T2, T3, T4>(long rowNumber, out List<T1> l1, out List<T2> l2, out List<T3> l3, out List<T4> l4) { l1 = new List<T1>(); l2 = new List<T2>(); l3 = new List<T3>(); l4 = new List<T4>(); foreach (List<string> l in String(rowNumber).Select( Convert<List<string>>())) { l1.Add(Convert<T1>()(l[0])); l2.Add(Convert<T2>()(l[1])); l3.Add(Convert<T3>()(l[2])); l4.Add(Convert<T4>()(l[3])); } } /// <summary> /// 1行に書かれた複数の値の入力 /// </summary> public static void @in<T>(out List<T> lArr) => lArr = Convert<List<T>>()(String()); /// <summary> /// h行の行列の入力 /// </summary> public static void @in<T>(long h, out List<List<T>> map) => map = String(h).Select(Convert<List<T>>()).ToList(); } 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; private List<int> a; public void Solve() { @in(out N); @in(out a); var d = new int[N + 1]; List<long> ans = new List<long>(); for (long i = N; i > 0; i--) { var l = 1; List<long> divisor = new List<long>(); while (i >= l * l) { if (i % l == 0) { divisor.Add(l); if (i / l != l) divisor.Add(i / l); } l++; } if ((d[i] - a[(int)i - 1]) % 2 != 0) { ans.Add(i); foreach (var k in divisor) { d[k] = d[k] + 1; } } } Console.WriteLine(ans.Count); if (ans.Count == 0) return; foreach (long an in ans) { Console.Write("" + an + " "); } Console.WriteLine(); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 18], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 47], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 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, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 28, 0, 16, 31, 16, 31, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 12, 5, 0, 222]]
8
1,656
47
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { public class Program { static long mod = (long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); string[] aString = Console.ReadLine().Split(' '); List<int> balls = new List<int>(); int[] relatedBall = new int[N]; for (int i = (int)N - 1; i > -1; i--) { if ((relatedBall[i] + int.Parse(aString[i])) % 2 == 1) { balls.Add(i + 1); #region Divisor int Number = i + 1; int max = (int)Math.Sqrt(Number); for (int j = 0; j < max - 1; j++) { if (Number % j == 0) { relatedBall[j - 1]++; relatedBall[Number / j - 1]++; } } if (Number % max == 0) { if (Number / max == max) relatedBall[max - 1]++; else { relatedBall[max - 1]++; relatedBall[Number / max - 1]++; } } #endregion } } Console.WriteLine(balls.Count); Console.WriteLine(string.Join(" ", balls)); Console.ReadLine(); } private static long[] Read(string input) { string[] strings = input.Split(' '); long num = strings.Length; long[] ints = new long[num]; for (int i = 0; i < num; i++) { ints[i] = long.Parse(strings[i]); } return ints; } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { public class Program { static long mod = (long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] aString = Console.ReadLine().Split(' '); List<int> balls = new List<int>(); int[] relatedBall = new int[N]; for (int i = N - 1; i > -1; i--) { if ((relatedBall[i] + int.Parse(aString[i])) % 2 == 1) { balls.Add(i + 1); #region Divisor int Number = i + 1; int max = (int)Math.Sqrt(Number); for (int j = 1; j < max; j++) { if (Number % j == 0) { relatedBall[j - 1]++; relatedBall[Number / j - 1]++; } } if (Number % max == 0) { if (Number / max == max) relatedBall[max - 1]++; else { relatedBall[max - 1]++; relatedBall[Number / max - 1]++; } } #endregion } } Console.WriteLine(balls.Count); Console.WriteLine(string.Join(" ", balls)); Console.ReadLine(); } private static long[] Read(string input) { string[] strings = input.Split(' '); long num = strings.Length; long[] ints = new long[num]; for (int i = 0; i < num; i++) { ints[i] = long.Parse(strings[i]); } return ints; } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 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, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 64, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 64, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
394
11
namespace AtCoder { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Util; class AtCoder { /*------------------------------------------------------------------*/ private int N; private int[] A; void Solve() { io.i(out N); io.ini(out A, N); var ans = new List<int>(); var isOdds = new bool[N]; // var for (var i = N; i > 0; i--) { if (ODD(A[i - 1])) { var isOdd = false; for (var j = i; j < N; j += i) { if (isOdds[j]) { isOdd = !isOdd; } } // 必要であれば1に if (!isOdd) { ans.Add(i); isOdds[i - 1] = true; } } else { var isOdd = false; for (var j = i; j < N; j += i) { if (isOdds[j]) { isOdd = !isOdd; } } if (isOdd) { ans.Add(i); isOdds[i - 1] = true; } } } ans.Count().Prt(); ans.Join().Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] _) => new AtCoder().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Util { public static T Id<T>(T x) => x; public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static IEnumerable<TResult> ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, Func<T1, T2, TResult> f = null) { using (var e1 = xs.GetEnumerator()) using ( var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext()) yield return f(e1.Current, e2.Current); } public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs, IEnumerable<T2> ys) => ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y)); public static IEnumerable<TResult> ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) { using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using ( var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) yield return f(e1.Current, e2.Current, e3.Current); } public static IEnumerable<Tuple<T1, T2, T3>> ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z)); public static bool ODD(int x) => x % 2 != 0; public static bool ODD(long x) => x % 2L != 0L; public static bool EVE(int x) => !ODD(x); public static bool EVE(long x) => !ODD(x); public static T MAX<T>(params T[] xs) => xs.Max(); public static T MIN<T>(params T[] xs) => xs.Min(); public static int SUM(params int[] xs) => xs.Sum(); public static long SUM(params long[] xs) => xs.Sum(); public static IEnumerable<int> RANGE(int start, int step = 1) { var v = start; while (true) { yield return v; v += step; } } public struct IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public class Counts<T> : Dictionary<T, int> { public Counts() {} public Counts(params T[] xs) : this() { Add(xs); } public Counts(IEnumerable<T> xs) : this() { foreach (var x in xs) Add(x); } public new int this[T key] { get { int v; return this.TryGetValue(key, out v) ? v : 0; } } public void Add(T key) { if (!base.ContainsKey(key)) base.Add(key, 0); base[key]++; } public void Add(params T[] xs) => xs.Iter(Add); public IEnumerable<KeyValuePair<T, int>> SortByCount(bool isAsc) => (isAsc ? (this.OrderBy(kp => kp.Value)) : (this.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key); } public class PriorityQueue<T> where T : IComparable<T> { private List<T> heap; private readonly bool isAsc; private int size; public T Peek => heap[0]; public int Count => size; public bool Any => size > 0; public bool Empty => !Any; public IEnumerable<T> Values => heap; public PriorityQueue(bool isAsc = true) { this.isAsc = isAsc; size = 0; heap = new List<T>(); } public void Enqueue(T item) { heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) / 2; if (Compare(heap[p], item) <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = item; } public T Dequeue() { var ret = heap[0]; var x = heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } private int Compare(T x, T y) => isAsc ? x.CompareTo(y) : y.CompareTo(x); } } static class Ex { public static Tuple<IEnumerable<T>, IEnumerable<T>> Split<T>(this IEnumerable<T> xs, Func<T, bool> f) { var ys = xs.Where(f); var zs = xs.Where(x => !f(x)); return Tuple.Create(ys, zs); } public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static void Log<T>(this T x) { #if DEBUG WriteLine($"LOG [{nameof(x)}] : {x}"); #endif } public static IEnumerable<IndexedItem<T>> Indexed<T>(this IEnumerable<T> xs) => xs.Select((x, idx) => new IndexedItem<T>(idx, x)); public static IEnumerable<T> UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val); public static IEnumerable<Tuple<T, T>> Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1)); public static IEnumerable<int> ToZeroIndexed(this IEnumerable<int> xs) => xs.Select(x => x - 1); public static string Join<T>(this IEnumerable<T> xs, string str = " ") => String.Join(str, xs); public static string Sort(this string s) { var arr = s.ToCharArray(); Array.Sort(arr); return new string(arr); } public static string Yn(this bool f, string y = "Yes", string n = "No") => f ? y : n; public static bool Is<T>(this T x, Func<T, bool> f) => f(x); public static TU Fun<T, TU>(this T x, Func<T, TU> f) => f(x); } }
namespace AtCoder { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Util; class AtCoder { /*------------------------------------------------------------------*/ private int N; private int[] A; void Solve() { io.i(out N); io.ini(out A, N); var ans = new List<int>(); var isOdds = new bool[N]; // var for (var i = N; i > 0; i--) { if (ODD(A[i - 1])) { var isOdd = isOdds[i - 1]; for (var j = i + i - 1; j < N; j += i) { if (isOdds[j]) { isOdd = !isOdd; } } // 必要であれば1に if (!isOdd) { ans.Add(i); isOdds[i - 1] = true; } } else { var isOdd = isOdds[i - 1]; for (var j = i + i - 1; j < N; j += i) { if (isOdds[j]) { isOdd = !isOdd; } } if (isOdd) { ans.Add(i); isOdds[i - 1] = true; } } } ans.Count().Prt(); ans.Join().Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] _) => new AtCoder().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Util { public static T Id<T>(T x) => x; public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static IEnumerable<TResult> ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, Func<T1, T2, TResult> f = null) { using (var e1 = xs.GetEnumerator()) using ( var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext()) yield return f(e1.Current, e2.Current); } public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs, IEnumerable<T2> ys) => ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y)); public static IEnumerable<TResult> ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) { using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using ( var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) yield return f(e1.Current, e2.Current, e3.Current); } public static IEnumerable<Tuple<T1, T2, T3>> ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z)); public static bool ODD(int x) => x % 2 != 0; public static bool ODD(long x) => x % 2L != 0L; public static bool EVE(int x) => !ODD(x); public static bool EVE(long x) => !ODD(x); public static T MAX<T>(params T[] xs) => xs.Max(); public static T MIN<T>(params T[] xs) => xs.Min(); public static int SUM(params int[] xs) => xs.Sum(); public static long SUM(params long[] xs) => xs.Sum(); public static IEnumerable<int> RANGE(int start, int step = 1) { var v = start; while (true) { yield return v; v += step; } } public struct IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public class Counts<T> : Dictionary<T, int> { public Counts() {} public Counts(params T[] xs) : this() { Add(xs); } public Counts(IEnumerable<T> xs) : this() { foreach (var x in xs) Add(x); } public new int this[T key] { get { int v; return this.TryGetValue(key, out v) ? v : 0; } } public void Add(T key) { if (!base.ContainsKey(key)) base.Add(key, 0); base[key]++; } public void Add(params T[] xs) => xs.Iter(Add); public IEnumerable<KeyValuePair<T, int>> SortByCount(bool isAsc) => (isAsc ? (this.OrderBy(kp => kp.Value)) : (this.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key); } public class PriorityQueue<T> where T : IComparable<T> { private List<T> heap; private readonly bool isAsc; private int size; public T Peek => heap[0]; public int Count => size; public bool Any => size > 0; public bool Empty => !Any; public IEnumerable<T> Values => heap; public PriorityQueue(bool isAsc = true) { this.isAsc = isAsc; size = 0; heap = new List<T>(); } public void Enqueue(T item) { heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) / 2; if (Compare(heap[p], item) <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = item; } public T Dequeue() { var ret = heap[0]; var x = heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } private int Compare(T x, T y) => isAsc ? x.CompareTo(y) : y.CompareTo(x); } } static class Ex { public static Tuple<IEnumerable<T>, IEnumerable<T>> Split<T>(this IEnumerable<T> xs, Func<T, bool> f) { var ys = xs.Where(f); var zs = xs.Where(x => !f(x)); return Tuple.Create(ys, zs); } public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static void Log<T>(this T x) { #if DEBUG WriteLine($"LOG [{nameof(x)}] : {x}"); #endif } public static IEnumerable<IndexedItem<T>> Indexed<T>(this IEnumerable<T> xs) => xs.Select((x, idx) => new IndexedItem<T>(idx, x)); public static IEnumerable<T> UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val); public static IEnumerable<Tuple<T, T>> Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1)); public static IEnumerable<int> ToZeroIndexed(this IEnumerable<int> xs) => xs.Select(x => x - 1); public static string Join<T>(this IEnumerable<T> xs, string str = " ") => String.Join(str, xs); public static string Sort(this string s) { var arr = s.ToCharArray(); Array.Sort(arr); return new string(arr); } public static string Yn(this bool f, string y = "Yes", string n = "No") => f ? y : n; public static bool Is<T>(this T x, Func<T, bool> f) => f(x); public static TU Fun<T, TU>(this T x, Func<T, TU> f) => f(x); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 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], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22]]
8
3,231
22
using System.Collections.Generic; using System.Linq; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = ("0 " + Console.ReadLine().Trim()).Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(a, n); } static void getAns(int[] a, int n) { var b = new int[n + 1]; var ans = new List<int>(); for (int i = n; i >= 1; i--) { var mod2 = getSum(b, n, i) % 2; if (a[i] != mod2) { b[i] = 1; ans.Add(i); } } var ac = ans.Count(); if (ac == 0) Console.WriteLine(0); else { Console.WriteLine(ac); var ans2 = ans.ToArray(); Console.WriteLine(string.Join(" ", ans2)); } } static int getSum(int[] b, int n, int t) { var p = 1; var sum = 0; while (true) { t *= p++; if (t > n) break; sum += b[t]; } return sum; } }
using System.Collections.Generic; using System.Linq; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = ("0 " + Console.ReadLine().Trim()).Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(a, n); } static void getAns(int[] a, int n) { var b = new int[n + 1]; var ans = new List<int>(); for (int i = n; i >= 1; i--) { var mod2 = getSum(b, n, i) % 2; if (a[i] != mod2) { b[i] = 1; ans.Add(i); } } var ac = ans.Count(); if (ac == 0) Console.WriteLine(0); else { Console.WriteLine(ac); var ans2 = ans.ToArray(); Array.Reverse(ans2); Console.WriteLine(string.Join(" ", ans2)); } } static int getSum(int[] b, int n, int t) { var p = 1; var sum = 0; var t2 = t; while (true) { t2 = t * p++; if (t2 > n) break; sum += b[t2]; } return sum; } }
[["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 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, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22]]
8
299
20
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC134D { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); return; } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var a = new int[N + 1]; for (int i = 1; i <= N; i++) { a[i] = cin.ReadInt; } var c = new int[N + 1]; for (int i = N; i > 0; i--) { int tmpCount = 0; for (int j = i; j <= N; j += i) { tmpCount += c[j]; } if (tmpCount % 2 != a[i]) { c[i] = 1; } } var M = c.Sum(); Console.WriteLine(M); if (M != 0) { var b = c.Where(v => v == 1); Console.WriteLine(string.Join(" ", b.ToList())); } return; } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC134D { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); return; } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var a = new int[N + 1]; for (int i = 1; i <= N; i++) { a[i] = cin.ReadInt; } var c = new int[N + 1]; for (int i = N; i > 0; i--) { int tmpCount = 0; for (int j = i; j <= N; j += i) { tmpCount += c[j]; } if (tmpCount % 2 != a[i]) { c[i] = 1; } } var M = c.Sum(); Console.WriteLine(M); if (M != 0) { var b = c.Select((value, index) => new { Index = index, Value = value }) .Where(value => value.Value == 1) .Select(value => value.Index); Console.WriteLine(string.Join(" ", b.ToList())); } return; } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 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], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 228], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 45], ["+", 0, 28, 0, 218, 8, 312, 0, 313, 0, 22], ["+", 0, 28, 0, 218, 8, 312, 0, 313, 0, 32], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 46], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 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, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22]]
8
647
35
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Solve(int N, int[] a) { // b[i] := i番目の箱に入っているボールの数(1 or 0)(i:1~N) int[] b = new int[N + 1]; //ボールが1つ入っている箱の数 int M = 0; //各i番目の箱に対してb[i]を決める for (int i = N; i >= 1; i--) { // iの倍数のインデックスにおいて1をカウント int one_cnt = 0; for (int j = i + i; j <= N; j += i) { if (b[j] == 1) one_cnt++; } // one_cntに基づいてb[i]を決める if (a[i] != one_cnt % 2) { b[i] = 1; M++; } // i番目の箱にボールが入っているならMをインクリメント // i番目の箱に書かれている整数を保存 if (b[i] == 1) M++; } //出力 Console.WriteLine(M); if (M == 0) return; List<int> ans = new List<int>(); for (int i = 1; i <= N; i++) { if (b[i] == 1) ans.Add(i); } Console.WriteLine(string.Join(" ", ans)); } static void Main(string[] args) { //入力1(N) int N = int.Parse(Console.ReadLine()); //入力2(a) string[] input = Console.ReadLine().Split(' '); int[] a = new int[N + 1]; for (int i = 1; i <= N; i++) { a[i] = int.Parse(input[i - 1]); } Solve(N, a); } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Solve(int N, int[] a) { // b[i] := i番目の箱に入っているボールの数(1 or 0)(i:1~N) int[] b = new int[N + 1]; //ボールが1つ入っている箱の数 int M = 0; //各i番目の箱に対してb[i]を決める for (int i = N; i >= 1; i--) { // iの倍数のインデックスにおいて1をカウント int one_cnt = 0; for (int j = i; j <= N; j += i) { if (b[j] == 1) one_cnt++; } // one_cntに基づいてb[i]を決める if (a[i] != (one_cnt % 2)) { b[i] = 1; M++; } } //出力 Console.WriteLine(M); if (M == 0) return; List<int> ans = new List<int>(); for (int i = 1; i <= N; i++) { if (b[i] == 1) ans.Add(i); } Console.WriteLine(string.Join(" ", ans)); } static void Main(string[] args) { //入力1(N) int N = int.Parse(Console.ReadLine()); //入力2(a) string[] input = Console.ReadLine().Split(' '); int[] a = new int[N + 1]; for (int i = 1; i <= N; i++) { a[i] = int.Parse(input[i - 1]); } Solve(N, a); } } }
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["-", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35]]
8
325
16
#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.Integer(); var a = scanner.ScanLine().Split().Select(v => int.Parse(v)).ToList(); var ans = GetAns(n, a); if (ans.Any()) { IO.Printer.Out.WriteLine(ans.Count()); foreach (var aa in ans) { IO.Printer.Out.Write(aa + " "); } IO.Printer.Out.WriteLine(); } else { IO.Printer.Out.WriteLine(-1); } IO.Printer.Out.WriteLine(ans); IO.Printer.Out.Flush(); } public static List<int> GetAns(int n, List<int> a) { var ret = Enumerable.Range(0, n).Select(v => 0).ToList(); for (int i = n - 1; i >= 0; i--) { var cnt = 0; var k = i + 1; var mux = 1 + 1; while (k * mux - 1 < a.Count()) { cnt += ret[k * mux - 1]; mux++; } if (a[i] == 0) { ret[i] = cnt % 2 == 0 ? 0 : 1; } else { ret[i] = cnt % 2 == 0 ? 1 : 0; } } var ans = new List<int>(); for (int i = 0; i < ret.Count(); i++) { if (ret[i] == 1) ans.Add(i + 1); } return ans; } } #if DEBUG [TestClass] public class Test { [TestMethod] public void Test1() { // var ans = Program.GetAns(3, new List<int> { 1, 0, 0 }); // var ans2 = Program.GetAns(5, new List<int> { 0, 0, 0, 0, 0 }); var ans3 = Program.GetAns(10, new List<int> { 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 }); } 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.Integer(); var a = scanner.ScanLine().Split().Select(v => int.Parse(v)).ToList(); var ans = GetAns(n, a); IO.Printer.Out.WriteLine(ans.Count()); foreach (var aa in ans) { IO.Printer.Out.Write(aa + " "); } IO.Printer.Out.WriteLine(); IO.Printer.Out.Flush(); } public static List<int> GetAns(int n, List<int> a) { var ret = Enumerable.Range(0, n).Select(v => 0).ToList(); for (int i = n - 1; i >= 0; i--) { var cnt = 0; var k = i + 1; var mux = 1 + 1; while (k * mux - 1 < a.Count()) { cnt += ret[k * mux - 1]; mux++; } if (a[i] == 0) { ret[i] = cnt % 2 == 0 ? 0 : 1; } else { ret[i] = cnt % 2 == 0 ? 1 : 0; } } var ans = new List<int>(); for (int i = 0; i < ret.Count(); i++) { if (ret[i] == 1) ans.Add(i + 1); } return ans; } } #if DEBUG [TestClass] public class Test { [TestMethod] public void Test1() { // var ans = Program.GetAns(3, new List<int> { 1, 0, 0 }); // var ans2 = Program.GetAns(5, new List<int> { 0, 0, 0, 0, 0 }); var ans3 = Program.GetAns(10, new List<int> { 1, 0, 1, 0, 0, 1, 0, 1, 0, 1 }); } 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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 210, 8, 196, 0, 46], ["-", 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], ["-", 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], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 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
2,156
36
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 n = CinT(); var a = CinTAr(); int[] r = new int[n]; string st = ""; int c = 0; int bp = 0; for (int i = n; i > 0; i--) { int fasd = 0; for (int g = i + i; g <= n; g += i) { fasd += r[g - 1]; } if (fasd % 2 != a[i - 1]) { for (int g = i; g <= n; g += i) { r[g - 1]++; } } } List<int> af = new List<int>(); for (int i = 0; i < n; i++) { if (r[i] % 2 > 0) { af.Add(i + 1); } } if (af.Count == 0) { Cout(0); } else { Cout(af.Count); for (int i = 0; i < af.Count; i++) { Write(af[i] + " "); } } Cin(); } static int[] yakusuu(int n) { if (n == 1) { return new int[] { 1 }; } List<int> res = new List<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 readonly int MOD1E9 = (int)1e9 + 7; 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 OYes() { Cout("Yes"); } static void ONo() { Cout("No"); } static void Cout(object s) { WriteLine(s); } /// <summary> /// Debug時のみの使用を推奨 /// </summary> /// <typeparam name="Type"></typeparam> /// <param name="types"></param> static void CoutAr<Type>(IEnumerable<Type> types) { string text = ""; foreach (var i in types) { text += " " + i; } WriteLine(text.Substring(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 n = CinT(); var a = CinTAr(); int[] r = new int[n]; string st = ""; int c = 0; int bp = 0; for (int i = n; i > 0; i--) { int fasd = 0; for (int g = i + i; g <= n; g += i) { fasd += r[g - 1]; } if (fasd % 2 != a[i - 1]) { // for (int g = i; g <= n; g += i) //{ // r[g - 1]+=1; //} r[i - 1] = 1; } // CoutAr(r); } // for (int i = 0; i < n; i++) //{ // if (r[i] % 2 != a[i]) // { // Cout(-1); // return; // } //} List<int> af = new List<int>(); for (int i = 0; i < n; i++) { if (r[i] % 2 >= 1) { af.Add(i + 1); } } if (af.Count == 0) { Cout(0); } else { Cout(af.Count); for (int i = 0; i < af.Count; i++) { Write(af[i] + " "); } } Cin(); } static int[] yakusuu(int n) { if (n == 1) { return new int[] { 1 }; } List<int> res = new List<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 readonly int MOD1E9 = (int)1e9 + 7; 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 OYes() { Cout("Yes"); } static void ONo() { Cout("No"); } static void Cout(object s) { WriteLine(s); } /// <summary> /// Debug時のみの使用を推奨 /// </summary> /// <typeparam name="Type"></typeparam> /// <param name="types"></param> static void CoutAr<Type>(IEnumerable<Type> types) { string text = ""; foreach (var i in types) { text += " " + i; } WriteLine(text.Substring(1)); } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 7, 0, 88], ["-", 8, 196, 0, 57, 64, 196, 0, 7, 0, 24], ["-", 0, 57, 64, 196, 0, 7, 10, 198, 39, 199], ["-", 64, 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, 57, 64, 196, 0, 7, 0, 35], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 7, 26, 11, 31, 22], ["-", 64, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 196, 0, 7, 26, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 7, 0, 25], ["-", 0, 57, 64, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
8
742
26
using System; using System.Linq; using System.Collections.Generic; class ProgramD { static void Main(string[] args) { // string input = Console.ReadLine(); int n = int.Parse(input); string[] inputA = Console.ReadLine().Split(' '); int[] A = new int[n]; int[] ans = new int[n]; for (int i = 0; i < n; i++) A[i] = int.Parse(inputA[i]); int r = n; for (int i = n / 2; i < n; i++) { ans[i] = A[i]; } for (int i = n / 2 - 1; i >= 0; i--) { int sum = 0; for (int j = i; j < n; j = j + (i + 1)) { sum += A[j]; } ans[i] = sum % 2; } int count = 0; for (int i = 0; i < n; i++) { if (ans[i] == 1) count++; } Console.WriteLine(count); for (int i = 0; i < n; i++) { if (ans[i] == 1) Console.Write(i + 1); Console.Write(" "); } } }
using System; using System.Linq; using System.Collections.Generic; class ProgramD { static void Main(string[] args) { // string input = Console.ReadLine(); int n = int.Parse(input); string[] inputA = Console.ReadLine().Split(' '); int[] A = new int[n]; int[] ans = new int[n]; for (int i = 0; i < n; i++) A[i] = int.Parse(inputA[i]); for (int i = n / 2; i < n; i++) { ans[i] = A[i]; } for (int i = n / 2 - 1; i >= 0; i--) { int sum = 0; for (int j = i; j < n; j = j + (i + 1)) { if (j == i) sum += A[j]; else sum += ans[j]; } ans[i] = sum % 2; } int count = 0; for (int i = 0; i < n; i++) { if (ans[i] == 1) count++; } Console.WriteLine(count); for (int i = 0; i < n; i++) { if (ans[i] == 1) Console.Write(i + 1); Console.Write(" "); } } }
[["-", 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, 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, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 75, 1, 0, 11, 12, 204, 205, 22]]
8
299
19
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; class Solver { Scanner sc = new Scanner(); public void Solve() { var N = sc.nextInt(); var a = sc.ArrayInt(N); var ans = new int[N]; var total = 0; for (int i = N; i > 0; i--) { if (N / i == 1) { ans[i - 1] = a[i - 1]; if (a[i - 1] == 1) { total++; } } else { // 倍数がある var sum = 0; for (int j = i * 2; j <= N; j += i) { if (i == 1) { if (total % 2 != a[i - 1]) { ans[i - 1] = 1; } break; } sum += ans[j - 1]; } if (a[i - 1] != sum) { ans[i - 1] = 1; total++; } } } var cnt = ans.Where(val => val == 1).Count(); WriteLine(cnt); var tmp = new List<string>(); // Array.Reverse(ans); for (int i = 0; i < N; i++) { if (ans[i] == 1) { tmp.Add((i + 1).ToString()); } } if (cnt > 0) { WriteLine(string.Join(" ", tmp)); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] args) { Solver s = new Solver(); s.Solve(); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; class Solver { Scanner sc = new Scanner(); public void Solve() { var N = sc.nextInt(); var a = sc.ArrayInt(N); var ans = new int[N]; var total = 0; for (int i = N; i > 0; i--) { if (N / i == 1) { ans[i - 1] = a[i - 1]; if (a[i - 1] == 1) { total++; } } else { // 倍数がある var sum = 0; var b = false; for (int j = i * 2; j <= N; j += i) { if (i == 1) { if (total % 2 != a[i - 1]) { ans[i - 1] = 1; } b = true; break; } sum += ans[j - 1]; } if (b) break; if (a[i - 1] != sum % 2) { ans[i - 1] = 1; total++; } } } var cnt = ans.Where(val => val == 1).Count(); WriteLine(cnt); var tmp = new List<string>(); for (int i = 0; i < N; i++) { if (ans[i] == 1) { tmp.Add((i + 1).ToString()); } } if (cnt > 0) { WriteLine(string.Join(" ", tmp)); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] args) { Solver s = new Solver(); s.Solve(); } }
[["+", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 15, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 57, 75, 196, 0, 57, 64, 93, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 109], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
709
17
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { solve(); } static int N; static int[] A; static void input() { N = int.Parse(ReadLine()); A = new int[N + 1]; int[] tmp = ReadLineParseIntArray(); for (int i = 0; i < N; i++) { A[i + 1] = tmp[i]; } } static void solve() { input(); int[] ans = new int[N + 1]; int ballCount = 0; for (int i = N; i >= 1; i--) { int c = 0; for (int j = Min(2 * i, N); j <= N; j += i) { c += ans[j]; } ans[i] = (c + A[i]) % 2; if (ans[i] == 1) ballCount++; } WriteLine(ballCount); int k = 1; for (; k < N; k++) { if (ans[k] == 1) Write(k); } for (; k < N; k++) { if (ans[k] == 1) Write(" " + k); } WriteLine(); } static int ReadLineParseInt() => int.Parse(ReadLine()); static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { solve(); } static int N; static int[] A; static void input() { N = int.Parse(ReadLine()); A = new int[N + 1]; int[] tmp = ReadLineParseIntArray(); for (int i = 0; i < N; i++) { A[i + 1] = tmp[i]; } } static void solve() { input(); int[] ans = new int[N + 1]; int ballCount = 0; for (int i = N; i >= 1; i--) { int c = 0; if (2 * i <= N) { for (int j = 2 * i; j <= N; j += i) { c += ans[j]; } } ans[i] = (c + A[i]) % 2; if (ans[i] == 1) ballCount++; } WriteLine(ballCount); int k = 1; for (; k < N; k++) { if (ans[k] == 1) { Write(k); k++; break; } } for (; k <= N; k++) { if (ans[k] == 1) Write(" " + k); } WriteLine(); } static int ReadLineParseInt() => int.Parse(ReadLine()); static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); }
[["+", 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, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 10, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
350
24
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC134D { class Program { public static void Solve(Input input) { var n = input.NextInt(); var a = input.NextInt(n); var b = new int[n]; for (int i = n - 1; i >= 0; i--) { // 自分の倍数の箱にすでに入っている数の和を求める var sum = 0; for (int j = i; j < n; j += i + 1) { sum += b[j]; } if (sum % 2 != a[i]) { b[i] = 1; } } var bb = b.Where(x => x != 0).ToArray(); Console.WriteLine(bb.Length); if (bb.Length != 0) { Console.WriteLine(string.Join(" ", bb)); } } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC134D { class Program { public static void Solve(Input input) { var n = input.NextInt(); var a = input.NextInt(n); var b = new int[n]; for (int i = n - 1; i >= 0; i--) { // 自分の倍数の箱にすでに入っている数の和を求める var sum = 0; for (int j = i; j < n; j += i + 1) { sum += b[j]; } if (sum % 2 != a[i]) { b[i] = 1; } } var bb = b.Select((V, I) => new { V, I }).Where(x => x.V != 0).ToArray(); Console.WriteLine(bb.Length); if (bb.Length != 0) { Console.WriteLine(string.Join(" ", bb.Select(x => x.I + 1))); } } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 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], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 228], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 45], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 8, 312, 0, 46], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
1,786
29
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; public class Solver { public void Solve() { int n = ri; bool[] a = new bool[n]; bool[] b = new bool[n]; for (int i = 0; i < n; i++) { a[i] = ri == 1; } for (int i = n - 1; i >= 0; i--) { b[i] = a[i]; for (int k = 2 * i + 1; k < n; k += i + 1) { b[i] = b[i] ^ b[k]; } if (b[i] != a[i]) { Write(-1); return; } } int m = 0; List<int> p = new List<int>(); for (int i = 0; i < n; i++) { if (b[i]) { m++; p.Add(i + 1); } } Write(m); Write(string.Join(" ", p)); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const long mod = 1000000007; long Reverse(long n) { return Pow(n, mod - 2); } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } long Mul(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p * n[i]) % mod; } return p; } long Pow(long n, long p) { long t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p /= 2; } return q; } long PowUpper(long n, long b) { long p = 1; while (p <= n) { p *= b; } return p; } long Abs(long n) { return (n > 0) ? n : -n; } long Gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } long Gcd(long a, long b) { return (a == 0) ? b : Gcd(b % a, a); } long Lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } long Lcm(long a, long b) { return a * b / Gcd(a, b); } long Max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } long Min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; public class Solver { public void Solve() { int n = ri; bool[] a = new bool[n]; bool[] b = new bool[n]; for (int i = 0; i < n; i++) { a[i] = ri == 1; } for (int i = n - 1; i >= 0; i--) { b[i] = a[i]; for (int k = 2 * i + 1; k < n; k += i + 1) { b[i] = b[i] ^ b[k]; } } int m = 0; List<int> p = new List<int>(); for (int i = 0; i < n; i++) { if (b[i]) { m++; p.Add(i + 1); } } Write(m); Write(string.Join(" ", p)); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const long mod = 1000000007; long Reverse(long n) { return Pow(n, mod - 2); } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } long Mul(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p * n[i]) % mod; } return p; } long Pow(long n, long p) { long t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p /= 2; } return q; } long PowUpper(long n, long b) { long p = 1; while (p <= n) { p *= b; } return p; } long Abs(long n) { return (n > 0) ? n : -n; } long Gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } long Gcd(long a, long b) { return (a == 0) ? b : Gcd(b % a, a); } long Lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } long Lcm(long a, long b) { return a * b / Gcd(a, b); } long Max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } long Min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 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, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 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, 7, 8, 196, 0, 46]]
8
1,600
22
using System; using System.Collections.Generic; using System.Linq; namespace ABC134E_2 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } A = A.Reverse().ToArray(); int[] dp = new int [N].Select(x => x = int.MaxValue).ToArray(); int sameCount = 0; for (int i = 0; i < N; i++) { int a = LowerBound(dp, A[i]); if (dp[a] == A[i]) sameCount++; dp[a] = A[i]; } Console.WriteLine(LowerBound(dp, int.MaxValue) + sameCount); Console.ReadKey(); } /// <summary> /// 二分探索 vを超える最低 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="v"></param> /// <returns></returns> public static int LowerBound<T>(T[] a, T v) { return LowerBound(a, v, Comparer<T>.Default); } public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) { var l = 0; var r = a.Length - 1; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res == -1) l = mid + 1; else r = mid - 1; } return l; } static int[] ReadInt() { int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray(); return ret; } static long[] ReadLong() { long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray(); return ret; } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC134E_2 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } A = A.Reverse().ToArray(); int[] dp = new int [N].Select(x => x = int.MaxValue).ToArray(); for (int i = 0; i < N; i++) { int a = UpperBound(dp, A[i]); if (dp[a] == A[i]) dp[a + 1] = A[i]; else dp[a] = A[i]; } Console.WriteLine(UpperBound(dp, int.MaxValue - 1)); Console.ReadKey(); } /// <summary> /// 二分探索 vを超えない最高 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="v"></param> /// <returns></returns> public static int UpperBound<T>(T[] a, T v) { return UpperBound(a, v, Comparer<T>.Default); } public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp) { var l = 0; var r = a.Length - 1; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res <= 0) l = mid + 1; else r = mid - 1; } return l; } static int[] ReadInt() { int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray(); return ret; } static long[] ReadLong() { long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray(); return ret; } } }
[["-", 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, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 3, 4, 0, 28, 0, 16, 31, 213, 63, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["-", 0, 195, 8, 196, 0, 37, 0, 213, 63, 22], ["+", 0, 195, 8, 196, 0, 37, 0, 213, 63, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203]]
8
423
38
using System; using System.Text; using System.Collections.Generic; using System.Collections; using System.Linq; using E = System.Linq.Enumerable; class Program { static long mod = 1000000007; static long end = 100000; static long st = 100000; static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var A = new long[1000000]; // var A = new List<long>(); A[st] = long.Parse(Console.ReadLine()); for (int i = 1; i < N; i++) { var num = long.Parse(Console.ReadLine()); var ins = UpperBound(A, num); // Console.WriteLine(ins);  if (A[st] >= num) { st--; A[st] = num; } else { // Console.WriteLine("ins:"+ins+"num:"+num); if (A[ins - 1] < num) { A[ins - 1] = num; Console.WriteLine(A[ins - 1]); } else { ins = UpperBound(A, num - 1); A[ins - 1] = num; // Console.WriteLine(i); } } // A.Insert(ins,num); } Console.WriteLine(end - st + 1); } public static long UpperBound<T>(T[] a, T v) { return UpperBound(a, v, Comparer<T>.Default); } public static long UpperBound<T>(T[] a, T v, Comparer<T> cmp) { var l = st; var r = end; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res <= 0) l = mid + 1; else r = mid - 1; } return l; } public static long RepPow(long x, long p, long m = 1000000007) { if (p == 0) return 1; if (p == 1) return x % m; long b = RepPow(x, p / 2, m) % m; if (p % 2 == 0) { return (b * b) % m; } else { return (x * ((b * b) % m)) % m; } } } class UnionFind { // 親要素のインデックスを保持する // 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ public long[] Parents { get; set; } public UnionFind(long n) { this.Parents = new long[n]; for (int i = 0; i < n; i++) { // 初期状態ではそれぞれが別のグループ(ルートは自分自身) // ルートなのでマイナスで要素数(1個)を保持する this.Parents[i] = -1; } } // 要素xのルート要素はどれか public long Find(long x) { // 親がマイナスの場合は自分自身がルート if (this.Parents[x] < 0) return x; // ルートが見つかるまで再帰的に探す // 見つかったルートにつなぎかえる this.Parents[x] = Find(this.Parents[x]); return this.Parents[x]; } // 要素xの属するグループの要素数を取得する public long Size(long x) { // ルート要素を取得して、サイズを取得して返す return -this.Parents[this.Find(x)]; } // 要素x, yが同じグループかどうか判定する public bool Same(long x, long y) { return this.Find(x) == this.Find(y); } // 要素x, yが属するグループを同じグループにまとめる public bool Union(long x, long y) { // x, y のルート x = this.Find(x); y = this.Find(y); // すでに同じグループの場合処理しない if (x == y) return false; // 要素数が少ないグループを多いほうに書き換えたい if (this.Size(x) < this.Size(y)) { var tmp = x; x = y; y = tmp; } // まとめる先のグループの要素数を更新 this.Parents[x] += this.Parents[y]; // まとめられるグループのルートの親を書き換え this.Parents[y] = x; return true; } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }
using System; using System.Text; using System.Collections.Generic; using System.Collections; using System.Linq; using E = System.Linq.Enumerable; class Program { static long mod = 1000000007; static long end = 100000; static long st = 100000; static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var A = new long[1000000]; // var A = new List<long>(); A[st] = long.Parse(Console.ReadLine()); for (int i = 1; i < N; i++) { var num = long.Parse(Console.ReadLine()); var ins = UpperBound(A, num); // Console.WriteLine(ins);  if (A[st] >= num) { st--; A[st] = num; } else { if (A[ins - 1] < num) { A[ins - 1] = num; } else { ins = UpperBound(A, num - 1); A[ins - 1] = num; } } // A.Insert(ins,num); } Console.WriteLine(end - st + 1); } public static long UpperBound<T>(T[] a, T v) { return UpperBound(a, v, Comparer<T>.Default); } public static long UpperBound<T>(T[] a, T v, Comparer<T> cmp) { var l = st; var r = end; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res <= 0) l = mid + 1; else r = mid - 1; } return l; } public static long RepPow(long x, long p, long m = 1000000007) { if (p == 0) return 1; if (p == 1) return x % m; long b = RepPow(x, p / 2, m) % m; if (p % 2 == 0) { return (b * b) % m; } else { return (x * ((b * b) % m)) % m; } } } class UnionFind { // 親要素のインデックスを保持する // 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ public long[] Parents { get; set; } public UnionFind(long n) { this.Parents = new long[n]; for (int i = 0; i < n; i++) { // 初期状態ではそれぞれが別のグループ(ルートは自分自身) // ルートなのでマイナスで要素数(1個)を保持する this.Parents[i] = -1; } } // 要素xのルート要素はどれか public long Find(long x) { // 親がマイナスの場合は自分自身がルート if (this.Parents[x] < 0) return x; // ルートが見つかるまで再帰的に探す // 見つかったルートにつなぎかえる this.Parents[x] = Find(this.Parents[x]); return this.Parents[x]; } // 要素xの属するグループの要素数を取得する public long Size(long x) { // ルート要素を取得して、サイズを取得して返す return -this.Parents[this.Find(x)]; } // 要素x, yが同じグループかどうか判定する public bool Same(long x, long y) { return this.Find(x) == this.Find(y); } // 要素x, yが属するグループを同じグループにまとめる public bool Union(long x, long y) { // x, y のルート x = this.Find(x); y = this.Find(y); // すでに同じグループの場合処理しない if (x == y) return false; // 要素数が少ないグループを多いほうに書き換えたい if (this.Size(x) < this.Size(y)) { var tmp = x; x = y; y = tmp; } // まとめる先のグループの要素数を更新 this.Parents[x] += this.Parents[y]; // まとめられるグループのルートの親を書き換え this.Parents[y] = x; return true; } } public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 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], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
1,178
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_134 { class E { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int n = ReadInt(); int[] array = new int[n]; int[][] sortedArray = new int [n][]; for (int i = 0; i < n; i++) { array[i] = ReadInt(); sortedArray[i] = new int[2] { array[i], i }; } sortedArray = sortedArray.OrderBy(a => a[0]).ToArray(); int[] indexes = new int[n]; for (int i = 0; i < n; i++) { indexes[sortedArray[i][1]] = i; } int[] prevs = new int[n]; int prev = -1; prevs[0] = -1; for (int i = 1; i < n; i++) { if (sortedArray[i - 1][0] != sortedArray[i][0]) { prev = i - 1; } prevs[i] = prev; } SegTree<int> segTree = new SegTree<int>(n, -1, Max, -1); int res = 0; for (int i = 0; i < n; i++) { int index = indexes[i]; int val = segTree.Scan(0, prevs[index] + 1); if (val == -1 || sortedArray[val][0] == sortedArray[i][0]) { res++; } else { segTree.Update(val, -1); } segTree.Update(i, i); } WriteLine(res); } class SegTree<T> { int totalLength; T[] tree; Func<T, T, T> integrate; T exValue; public SegTree(int length, Func<T, T, T> integrate, T exValue) { this.integrate = integrate; this.exValue = exValue; totalLength = 1; while (totalLength < length) totalLength *= 2; tree = new T[2 * totalLength - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = exValue; } public SegTree(int length, T initialValue, Func<T, T, T> integrate, T exValue) : this(length, integrate, exValue) { for (int i = 0; i < length; i++) { tree[i + totalLength - 1] = initialValue; } UpdateAll(); } public void AssignWithoutUpdate(int i, T value) { tree[i + totalLength - 1] = value; } public void Update(int i, T value) { int now = i + totalLength - 1; tree[now] = value; while (now > 0) { now = (now - 1) / 2; tree[now] = integrate(tree[now * 2 + 1], tree[now * 2 + 2]); } } public void UpdateAll() { for (int i = totalLength - 2; i >= 0; i--) { tree[i] = integrate(tree[i * 2 + 1], tree[i * 2 + 2]); } } public T Look(int i) { return tree[i + totalLength - 1]; } //[top,last) public T Scan(int top, int last) { return Query(top, last, 0, 0, totalLength); } T Query(int top, int last, int i, int left, int right) { if (right <= top || last <= left) return exValue; if (top <= left && right <= last) return tree[i]; T leftValue = Query(top, last, i * 2 + 1, left, (left + right) / 2); T rightValue = Query(top, last, (i + 1) * 2, (left + right) / 2, right); return integrate(leftValue, rightValue); } } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_134 { class E { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int n = ReadInt(); int[] array = new int[n]; int[][] sortedArray = new int [n][]; for (int i = 0; i < n; i++) { array[i] = ReadInt(); sortedArray[i] = new int[2] { array[i], i }; } sortedArray = sortedArray.OrderBy(a => a[0]).ToArray(); int[] indexes = new int[n]; for (int i = 0; i < n; i++) { indexes[sortedArray[i][1]] = i; } int[] prevs = new int[n]; int prev = -1; prevs[0] = -1; for (int i = 1; i < n; i++) { if (sortedArray[i - 1][0] != sortedArray[i][0]) { prev = i - 1; } prevs[i] = prev; } SegTree<int> segTree = new SegTree<int>(n, -1, Max, -1); int res = 0; for (int i = 0; i < n; i++) { int index = indexes[i]; int val = segTree.Scan(0, prevs[index] + 1); if (val == -1) { res++; } else { segTree.Update(val, -1); } segTree.Update(index, index); } WriteLine(res); } class SegTree<T> { int totalLength; T[] tree; Func<T, T, T> integrate; T exValue; public SegTree(int length, Func<T, T, T> integrate, T exValue) { this.integrate = integrate; this.exValue = exValue; totalLength = 1; while (totalLength < length) totalLength *= 2; tree = new T[2 * totalLength - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = exValue; } public SegTree(int length, T initialValue, Func<T, T, T> integrate, T exValue) : this(length, integrate, exValue) { for (int i = 0; i < length; i++) { tree[i + totalLength - 1] = initialValue; } UpdateAll(); } public void AssignWithoutUpdate(int i, T value) { tree[i + totalLength - 1] = value; } public void Update(int i, T value) { int now = i + totalLength - 1; tree[now] = value; while (now > 0) { now = (now - 1) / 2; tree[now] = integrate(tree[now * 2 + 1], tree[now * 2 + 2]); } } public void UpdateAll() { for (int i = totalLength - 2; i >= 0; i--) { tree[i] = integrate(tree[i * 2 + 1], tree[i * 2 + 2]); } } public T Look(int i) { return tree[i + totalLength - 1]; } //[top,last) public T Scan(int top, int last) { return Query(top, last, 0, 0, totalLength); } T Query(int top, int last, int i, int left, int right) { if (right <= top || last <= left) return exValue; if (top <= left && right <= last) return tree[i]; T leftValue = Query(top, last, i * 2 + 1, left, (left + right) / 2); T rightValue = Query(top, last, (i + 1) * 2, (left + right) / 2, right); return integrate(leftValue, rightValue); } } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 15, 16, 12, 16, 31, 204, 205, 204, 205, 22], ["-", 12, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["-", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 15, 16, 12, 16, 12, 204, 205, 204, 205, 22], ["-", 12, 16, 12, 204, 205, 204, 206, 207, 0, 70], ["-", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["-", 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, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
1,094
20
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); // WriteLine(Solve()); } static void Solve() { var num = Input.num; var ar = Input.ar1D(num); var dic = new Dictionary<int, int>(); var d = 0; foreach (var a in ar.OrderBy(v => v)) if (!dic.ContainsKey(a)) dic[a] = ++d; for (var i = 0; i < num; i++) ar[i] = dic[ar[i]]; var seg = new SegmentTree<int>(num + 1, 0, Max); var res = new int[num + 1]; for (var i = 0; i < num; i++) { var m = seg.Query(0, ar[i]); res[m + 1]++; seg.Update(ar[i], m + 1); } WriteLine(res.Max()); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] gred(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); if (t == typeof(int[])) return (T)(object)ar; if (t == typeof(long[])) return (T)(object)arL; return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>() { sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return GetValue<T>(sc.Dequeue()); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class SegmentTree<T> { private readonly T[] item; private readonly int _num; private readonly Func<T, T, T> _func; private readonly Func<T, T, T> updateFunc; private readonly T _init; private int Parent(int index) => (index - 1) >> 1; private int Left(int index) => (index << 1) + 1; private int Right(int index) => (index + 1) << 1; public T this[int i] { get { return item[i + _num - 1]; } set { item[i + _num - 1] = value; } } public SegmentTree(int num, T init, Func<T, T, T> func, Func<T, T, T> updateFunc = null) { _func = func; _num = 1; _init = init; this.updateFunc = updateFunc ?? ((T val1, T val2) => val2); while (_num <= num) _num *= 2; item = new T[2 * _num - 1]; for (var i = 0; i < 2 * _num - 1; i++) item[i] = init; } public void Update(int index, T value) { index += _num - 1; item[index] = updateFunc(item[index], value); while (index > 0) { index = Parent(index); item[index] = _func(item[Left(index)], item[Right(index)]); } } public void Update(int left, int right, T value) => Update(left, right, 0, 0, _num, value); private void Update(int left, int right, int k, int l, int r, T value) { if (r <= left || right <= l) return; if (left <= l && r <= right) item[k] = updateFunc(item[k], value); else { Update(left, right, Left(k), l, (l + r) >> 1, value); Update(left, right, Right(k), (l + r) >> 1, r, value); } } public void All_Update() { for (int i = _num - 2; i >= 0; i--) item[i] = _func(item[Left(i)], item[Right(i)]); } public T Query(int index) { index += _num - 1; var value = _func(_init, item[index]); while (index > 0) { index = Parent(index); value = _func(value, item[index]); } return value; } //[left,right) public T Query(int left, int right) => Query(left, right, 0, 0, _num); private T Query(int left, int right, int k, int l, int r) { if (r <= left || right <= l) return _init; if (left <= l && r <= right) return item[k]; else return _func(Query(left, right, Left(k), l, (l + r) >> 1), Query(left, right, Right(k), (l + r) >> 1, r)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); // WriteLine(Solve()); } static void Solve() { var num = Input.num; var ar = Input.ar1D(num); var dic = new Dictionary<int, int>(); var d = 0; foreach (var a in ar.OrderBy(v => v)) if (!dic.ContainsKey(a)) dic[a] = d++; for (var i = 0; i < num; i++) ar[i] = dic[ar[i]]; var seg = new SegmentTree<int>(num + 1, 0, Max); var res = 1; for (var i = 0; i < num; i++) { var m = seg.Query(ar[i], num); res = Max(m + 1, res); seg.Update(ar[i], m + 1); } WriteLine(res); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] gred(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); if (t == typeof(int[])) return (T)(object)ar; if (t == typeof(long[])) return (T)(object)arL; return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>() { sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return GetValue<T>(sc.Dequeue()); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class SegmentTree<T> { private readonly T[] item; private readonly int _num; private readonly Func<T, T, T> _func; private readonly Func<T, T, T> updateFunc; private readonly T _init; private int Parent(int index) => (index - 1) >> 1; private int Left(int index) => (index << 1) + 1; private int Right(int index) => (index + 1) << 1; public T this[int i] { get { return item[i + _num - 1]; } set { item[i + _num - 1] = value; } } public SegmentTree(int num, T init, Func<T, T, T> func, Func<T, T, T> updateFunc = null) { _func = func; _num = 1; _init = init; this.updateFunc = updateFunc ?? ((T val1, T val2) => val2); while (_num <= num) _num *= 2; item = new T[2 * _num - 1]; for (var i = 0; i < 2 * _num - 1; i++) item[i] = init; } public void Update(int index, T value) { index += _num - 1; item[index] = updateFunc(item[index], value); while (index > 0) { index = Parent(index); item[index] = _func(item[Left(index)], item[Right(index)]); } } public void Update(int left, int right, T value) => Update(left, right, 0, 0, _num, value); private void Update(int left, int right, int k, int l, int r, T value) { if (r <= left || right <= l) return; if (left <= l && r <= right) item[k] = updateFunc(item[k], value); else { Update(left, right, Left(k), l, (l + r) >> 1, value); Update(left, right, Right(k), (l + r) >> 1, r, value); } } public void All_Update() { for (int i = _num - 2; i >= 0; i--) item[i] = _func(item[Left(i)], item[Right(i)]); } public T Query(int index) { index += _num - 1; var value = _func(_init, item[index]); while (index > 0) { index = Parent(index); value = _func(value, item[index]); } return value; } //[left,right) public T Query(int left, int right) => Query(left, right, 0, 0, _num); private T Query(int left, int right, int k, int l, int r) { if (r <= left || right <= l) return _init; if (left <= l && r <= right) return item[k]; else return _func(Query(left, right, Left(k), l, (l + r) >> 1), Query(left, right, Right(k), (l + r) >> 1, r)); } }
[["-", 8, 57, 64, 1, 0, 11, 12, 241, 0, 29], ["+", 8, 57, 64, 1, 0, 11, 12, 223, 0, 29], ["-", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 223, 0, 204, 206, 207, 0, 70], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 223, 0, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 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], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
1,842
25
using System; using System.Collections.Generic; using System.Linq; using static Common; public static class Common { public static int BinSearchIndex<T>(T v, IEnumerable<T> list) where T : IComparable { int minRange = 0; int maxRange = list.Count(); while (minRange != maxRange) { var center = (minRange + maxRange) / 2; if (list.ElementAt(center).CompareTo(v) < 0) { minRange = center + 1; } else { maxRange = center; } } return minRange; } } public class Solution { public static void Main() { var N = int.Parse(Console.ReadLine()); var A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } var list = new List<int>(); foreach (var a in A.Reverse()) { var index = BinSearchIndex(a, list); if (index < list.Count) { if (list[index] == a) { list.Insert(index + 1, a); } else { list[index] = a; } } else { list.Add(a); } } Console.WriteLine(list.Count); } }
using System; using System.Collections.Generic; using System.Linq; using static Common; public static class Common { public static int BinSearchIndex<T>(T v, IEnumerable<T> list) where T : IComparable { int minRange = 0; int maxRange = list.Count(); while (minRange != maxRange) { var center = (minRange + maxRange) / 2; if (list.ElementAt(center).CompareTo(v) < 0) { minRange = center + 1; } else { maxRange = center; } } return minRange; } } public class Solution { public static void Main() { var N = int.Parse(Console.ReadLine()); var A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } var list = new List<int>(); foreach (var a in A.Reverse()) { var index = BinSearchIndex(a + 1, list); if (index < list.Count) { list[index] = a; } else { list.Add(a); } } Console.WriteLine(list.Count); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 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, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 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], ["-", 75, 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], ["-", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
278
27
using System; using System.Collections.Generic; using System.Linq; namespace cs { public class Program { public static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var currentLine = new int[N + 1]; currentLine[1] = int.MinValue; var currentMin = int.MaxValue; int cnt = 1; int x; for (int i = 0; i < N; i++) { x = int.Parse(Console.ReadLine()); if (x > currentLine[1]) { currentLine[1] = x; } else if (x <= currentMin) { cnt++; currentLine[cnt] = x; } else { for (int k = 2; k <= cnt; k++) { if (x > currentLine[k]) { currentLine[k] = x; } } } currentMin = Math.Min(currentMin, currentLine[cnt]); } Console.WriteLine(cnt); // Console.ReadKey(); } public static long modder() { return (long)Math.Pow(10, 9) + 7; } public static long GCD(long n, long m) { if (m % n == 0) return n; else return GCD(m % n, n); } public static long LCD(long n, long m) { return m * n / GCD(n, m); } } }
using System; using System.Collections.Generic; using System.Linq; namespace cs { public class Program { public static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var input = new int[N]; var currentLine = new int[N + 1]; currentLine[1] = int.MinValue; var currentMin = int.MaxValue; int cnt = 1; int x; for (int i = N - 1; i >= 0; i--) { x = int.Parse(Console.ReadLine()); if (x > currentLine[1]) { currentLine[1] = x; } else if (x <= currentLine[cnt]) { cnt++; currentLine[cnt] = x; } else { for (int k = 2; k <= cnt; k++) { if (x > currentLine[k]) { currentLine[k] = x; break; } } } /* for(int j = 1; j < cnt+1; j++){ Console.Write(currentLine[j] + ","); } */ // Console.WriteLine(); } Console.WriteLine(cnt); // Console.ReadKey(); } public static long modder() { return (long)Math.Pow(10, 9) + 7; } public static long GCD(long n, long m) { if (m % n == 0) return n; else return GCD(m % n, n); } public static long LCD(long n, long m) { return m * n / GCD(n, m); } } }
[["+", 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, 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], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 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, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
293
40
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); // WriteLine(Solve()); } static void Solve() { var num = Input.num; var ar = Input.ar; if (ar.All(v => v == 0)) { WriteLine("Yes"); return; } var q = ar.Distinct(); if (q.Count() == 2) { WriteLine(q.Contains(0) && ar.Count(v => v == 0) == num / 2 && num % 2 == 0 ? "Yes" : "No"); return; } if (q.Count() != 3) { WriteLine("No"); return; } var xor = 0; if (q.Select(v => ar.Count(u => v == u)).Distinct().Count() != 1) { WriteLine("No"); return; } foreach (var a in q) xor ^= a; WriteLine(xor == 0 ? "Yes" : "No"); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] gred(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc = new Queue<string>(); public static T Next<T>() { if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return GetValue<T>(sc.Dequeue()); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; using System.Text; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); // WriteLine(Solve()); } static void Solve() { var num = Input.num; var ar = Input.ar; if (ar.All(v => v == 0)) { WriteLine("Yes"); return; } var q = ar.Distinct(); if (q.Count() == 2) { var c = ar.Count(v => v == 0); WriteLine(q.Contains(0) && ((c == num / 2 && num % 2 == 0) || (c == num / 3 && num % 3 == 0)) ? "Yes" : "No"); return; } if (q.Count() != 3) { WriteLine("No"); return; } var xor = 0; if (q.Select(v => ar.Count(u => v == u)).Distinct().Count() != 1) { WriteLine("No"); return; } foreach (var a in q) xor ^= a; WriteLine(xor == 0 ? "Yes" : "No"); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] gred(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc = new Queue<string>(); public static T Next<T>() { if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return GetValue<T>(sc.Dequeue()); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["+", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 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, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["-", 31, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["-", 31, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["-", 31, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 12, 203], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 98], ["+", 31, 23, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 31, 23, 0, 16, 12, 16, 31, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 12, 16, 17, 60], ["+", 0, 41, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 15, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 15, 16, 31, 16, 12, 16, 12, 16, 12, 203], ["+", 12, 23, 0, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 41, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 12, 23, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 15, 16, 12, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 28, 0, 41, 15, 16, 12, 23, 0, 25]]
8
1,122
39
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var A = sc.ReadLongArray(N); if (A.All(a => a == 0)) { Console.WriteLine("Yes"); return; } if (N % 3 > 0) { Console.WriteLine("No"); return; } var u = A.Distinct().ToArray(); if (u.Length == 2) { if (A.Count(a => a == 0) == N / 3) { Console.WriteLine("Yes"); return; } } if (u.Length == 3) { if (A.Count(a => a == u[0]) == A.Count(a => a == u[1]) && A.Count(a => a == u[1]) == A.Count(a => a == u[2])) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var A = sc.ReadLongArray(N); if (A.All(a => a == 0)) { Console.WriteLine("Yes"); return; } if (N % 3 > 0) { Console.WriteLine("No"); return; } var u = A.Distinct().ToArray(); if (u.Length == 2) { if (A.Count(a => a == 0) == N / 3) { Console.WriteLine("Yes"); return; } } if (u.Length == 3) { if (A.Count(a => a == u[0]) == A.Count(a => a == u[1]) && A.Count(a => a == u[1]) == A.Count(a => a == u[2]) && (u[0] ^ u[1]) == u[2]) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 140], ["+", 12, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
8
1,264
17
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 N = Int1; var a = Ints; if (a.All(x => x == 0)) { Put("Yes"); return; } if (a.Distinct().Count() > 3) { Put("No"); return; } if (N % 3 != 0) { Put("No"); return; } var b = a.Distinct().ToArray(); if (a.Distinct().Count() == 1) { if (a[0] != 0) Put("No"); return; } if (b.Length == 2) { int cnt1 = 0; int cnt2 = 0; for (int i = 0; i < N; ++i) { if (a[i] == b[0]) cnt1++; else if (a[i] == b[1]) cnt2++; } if (b[0] == 0 && cnt1 == N / 3) { Put("Yes"); return; } else if (b[1] == 0 && cnt2 == N / 3) { Put("Yes"); return; } } else { if ((b[0] ^ b[1] ^ b[2]) != 0) { Put("No"); return; } int cnt1 = 0; int cnt2 = 0; for (int i = 0; i < N; ++i) { if (a[i] == b[0]) cnt1++; else if (a[i] == b[1]) cnt2++; } if (cnt1 == N / 3 && cnt2 == N / 3) { Put("Yes"); return; } } } } 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) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } 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 long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } 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 Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void VerticalPut<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("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 N = Int1; var a = Ints; if (a.All(x => x == 0)) { Put("Yes"); return; } if (a.Distinct().Count() > 3) { Put("No"); return; } if (N % 3 != 0) { Put("No"); return; } var b = a.Distinct().ToArray(); if (a.Distinct().Count() == 1) { if (a[0] != 0) { Put("No"); return; } } if (b.Length == 2) { int cnt1 = 0; int cnt2 = 0; for (int i = 0; i < N; ++i) { if (a[i] == b[0]) cnt1++; else if (a[i] == b[1]) cnt2++; } if (b[0] == 0 && cnt1 == N / 3) { Put("Yes"); return; } else if (b[1] == 0 && cnt2 == N / 3) { Put("Yes"); return; } else { Put("No"); return; } } else { if ((b[0] ^ b[1] ^ b[2]) != 0) { Put("No"); return; } int cnt1 = 0; int cnt2 = 0; for (int i = 0; i < N; ++i) { if (a[i] == b[0]) cnt1++; else if (a[i] == b[1]) cnt2++; } if (cnt1 == N / 3 && cnt2 == N / 3) { Put("Yes"); return; } else { Put("No"); return; } } } } 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) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } 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 long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } 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 Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void VerticalPut<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } }
[["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 75, 57, 64, 196, 0, 37, 0, 35], ["+", 64, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 95], ["+", 64, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 75, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22]]
8
1,322
26
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200313.Agc035_A.Cin; using static _20200313.Agc035_A.Util; using Pair = _20200313.Agc035_A.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200313 { public class Agc035_A { public static void Main(string[] args) { long n = rl; long[] a = rla; HashMap<long, long> hm = new HashMap<long, long>(); for (int i = 0; i < n; i++) { hm[a[i]]++; } if (hm.Count == 1) { string ans = (hm.Keys.First() == 0) ? "Yes" : "No"; Console.WriteLine(ans); } else if (hm.Count == 2) { var keys = hm.Keys.OrderBy(x => x).ToList(); if (keys[0] == 0 && hm[0] * 3 == n && hm[keys[1]] * 3 == n * 2) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else if (hm.Count == 3) { var keys = hm.Keys.ToList(); if (hm[keys[0]] == hm[keys[1]] && hm[keys[1]] == hm[keys[2]]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); return; } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200313.Agc035_A.Cin; using static _20200313.Agc035_A.Util; using Pair = _20200313.Agc035_A.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200313 { public class Agc035_A { public static void Main(string[] args) { long n = rl; long[] a = rla; HashMap<long, long> hm = new HashMap<long, long>(); for (int i = 0; i < n; i++) { hm[a[i]]++; } if (hm.Count == 1) { string ans = (hm.Keys.First() == 0) ? "Yes" : "No"; Console.WriteLine(ans); } else if (hm.Count == 2) { var keys = hm.Keys.OrderBy(x => x).ToList(); if (keys[0] == 0 && hm[0] * 3 == n && hm[keys[1]] * 3 == n * 2) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else if (hm.Count == 3) { var keys = hm.Keys.ToList(); if (hm[keys[0]] == hm[keys[1]] && hm[keys[1]] == hm[keys[2]] && (keys[0] ^ keys[1] ^ keys[2]) == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); return; } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
[["+", 75, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 140], ["+", 31, 23, 0, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 140], ["+", 12, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
2,429
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_A(); } public static void Solve_A() { ll n; MyIO.ReadMulti(out n); ll[] a; MyIO.ReadArray(out a); Dictionary<ll, ll> dic = new Dictionary<ll, ll>(); foreach (var e in a) { if (!dic.ContainsKey(e)) dic[e] = 0; dic[e]++; } string ans = "No"; if (dic.Count == 1) { foreach (var e in dic) { if (e.Key == 0) ans = "Yes"; } } if ((dic.Count == 2) && (n % 3 == 0)) { ll v = n / 3; foreach (var e in dic) { if ((e.Key == 0) && (e.Value == v)) ans = "Yes"; } } if ((dic.Count == 3) && (n % 3 == 0)) { ans = "Yes"; ll v = n / 3; foreach (var e in dic) { if (e.Value != v) ans = "No"; } } MyIO.WriteMulti(ans); } public static void Solve_B() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_A(); } public static void Solve_A() { ll n; MyIO.ReadMulti(out n); ll[] a; MyIO.ReadArray(out a); Dictionary<ll, ll> dic = new Dictionary<ll, ll>(); foreach (var e in a) { if (!dic.ContainsKey(e)) dic[e] = 0; dic[e]++; } string ans = "No"; if (dic.Count == 1) { foreach (var e in dic) { if (e.Key == 0) ans = "Yes"; } } if ((dic.Count == 2) && (n % 3 == 0)) { ll v = n / 3; foreach (var e in dic) { if ((e.Key == 0) && (e.Value == v)) ans = "Yes"; } } if ((dic.Count == 3) && (n % 3 == 0)) { ans = "Yes"; ll v = n / 3; ll b = 0; foreach (var e in dic) { if (e.Value != v) ans = "No"; b = b ^ e.Key; } if (b != 0) ans = "No"; } MyIO.WriteMulti(ans); } public static void Solve_B() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { ll n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
[["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 22], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 210, 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, 140], ["+", 0, 1, 0, 11, 12, 16, 12, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 16, 12, 214, 141, 22], ["+", 64, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 62], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35]]
8
2,580
25
using System; namespace question1 { class Program { static void Main(string[] args) { int largeN; largeN = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int a = -1; int b = -1; int c = -1; //本当に 3 種類か? foreach (string tempstr in str) { int test = int.Parse(tempstr); if (test != a && test != b && test != c) { if (a == -1) a = test; else if (b == -1) b = test; else if (c == -1) c = test; else { Console.WriteLine("No"); Environment.Exit(0); } } } //数のカウント int ac = 0; int bc = 0; int cc = 0; foreach (string tempstr in str) { int test = int.Parse(tempstr); if (test == a) ac += 1; else if (test == b) bc += 1; else if (test == c) cc += 1; } if (ac == bc && bc == cc) { if ((a ^ b ^ c) == 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else if (bc == 0 && cc == 0) Console.WriteLine("No"); else if (bc != 0 && cc == 0) { if ((b == 0) && (ac * 2 == bc)) Console.WriteLine("Yes"); else if ((a == 0) && (bc * 2 == ac)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else Console.WriteLine("No"); Console.ReadLine(); } } }
using System; namespace question1 { class Program { static void Main(string[] args) { int largeN; largeN = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int a = -1; int b = -1; int c = -1; //本当に 3 種類以内か? foreach (string tempstr in str) { int test = int.Parse(tempstr); if (test != a && test != b && test != c) { if (a == -1) a = test; else if (b == -1) b = test; else if (c == -1) c = test; else { Console.WriteLine("No"); Environment.Exit(0); } } } //数のカウント int ac = 0; int bc = 0; int cc = 0; foreach (string tempstr in str) { int test = int.Parse(tempstr); if (test == a) ac += 1; else if (test == b) bc += 1; else if (test == c) cc += 1; } // Console.WriteLine("ac={0},bc={1},cc={2}", ac, bc, cc); if (ac == bc && bc == cc) { if ((a ^ b ^ c) == 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else if (bc == 0 && cc == 0) { if (a == 0) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else if (bc != 0 && cc == 0) { if ((a == 0) && (ac * 2 == bc)) Console.WriteLine("Yes"); else if ((b == 0) && (bc * 2 == ac)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } else Console.WriteLine("No"); Console.ReadLine(); } } }
[["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 24], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["-", 75, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 31, 22]]
8
384
22
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { Action exit = () => { Console.WriteLine("No"); Environment.Exit(0); }; int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); Dictionary<int, int> dict = new Dictionary<int, int>(); foreach (var item in a) { if (!dict.ContainsKey(item)) dict.Add(item, 0); dict[item]++; } int first = a[0]; int ll = first; int l = a[1]; dict[ll]--; dict[l]--; if (dict[ll] == 0) dict.Remove(ll); if (dict[l] == 0) dict.Remove(l); while (dict.Count > 0) { var next = l ^ ll; if (!dict.ContainsKey(next)) exit(); dict[next]--; if (dict[next] == 0) dict.Remove(next); ll = l; l = next; } if (first != (l ^ ll)) exit(); Console.WriteLine("Yes"); } }
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { Action exit = () => { Console.WriteLine("No"); Environment.Exit(0); }; int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); Dictionary<int, int> dict = new Dictionary<int, int>(); foreach (var item in a) { if (!dict.ContainsKey(item)) dict.Add(item, 0); dict[item]++; } int ll = dict.First().Key; int l = dict.Last().Key; int first = ll; dict[ll]--; dict[l]--; if (dict[ll] == 0) dict.Remove(ll); if (dict[l] == 0) dict.Remove(l); while (dict.Count > 0) { var next = l ^ ll; if (!dict.ContainsKey(next)) exit(); dict[next]--; if (dict[next] == 0) dict.Remove(next); ll = l; l = next; } if (first != (l ^ ll)) exit(); Console.WriteLine("Yes"); } }
[["-", 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, 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, 212, 0, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
355
30
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.NetworkInformation; using System.Security.Cryptography; using System.Text; using System.Threading; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here int N = Cin; var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); if (N % 3 == 0) { bool flg = true; for (int i = 0; flg; i++) { flg = false; int cnt0 = 0, cnt1 = 0; long compare = -1L; for (var r = 0; r < a.Length; r++) { if (((a[r] >> i) & 1) == 1) cnt1++; else { cnt0++; if (compare == -1) compare = a[r]; if ((compare ^ a[r]) != 0) { Coutln("No"); return; } } flg |= a[r] >> (i + 1) != 0; } if (cnt0 * 2 != cnt1 && cnt1 != 0) { Coutln("No"); return; } } Coutln("Yes"); } else { foreach (var i in a) { if (i != 0) { Coutln("No"); return; } } Coutln("Yes"); } } // Other Functions Here } // Other Classes Here #if !DEBUG class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } #endif class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public int Count { get; private set; } = 0; public PriorityQueue() { _list.Add(null); _list.Add(null); _list.Add(null); } public void Push(T item, int priority) { var itemIndex = Count++; _list[itemIndex] = Tuple.Create(priority, item); while (_list.Count < Count + 2) _list.Add(null); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { if (_list.Count <= 0 || _list[0] == null) throw new IndexOutOfRangeException(); var item = _list[0].Item2; _list[0] = null; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null && (_list[childrenIndex.Item1] != null || _list[childrenIndex.Item2] != null)) { if ((_list[childrenIndex.Item1] != null && _list[childrenIndex.Item2] != null && _list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) || _list[childrenIndex.Item2] == null) { _list[index] = _list[childrenIndex.Item1]; _list[childrenIndex.Item1] = null; index = childrenIndex.Item1; } else { two: _list[index] = _list[childrenIndex.Item2]; _list[childrenIndex.Item2] = null; index = childrenIndex.Item2; } } Count--; return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } struct ModInt { public long Value { get; } public static long Mod { get; set; } = 1000000000L + 7; public ModInt(long l) { long value = l % Mod; while (value < 0) value += Mod; Value = value % Mod; } public static implicit operator long(ModInt m) { return m.Value; } public static explicit operator ModInt(long l) { return new ModInt(l); } public static ModInt operator +(ModInt a, ModInt b) { return new ModInt(a.Value + b.Value); } public static ModInt operator -(ModInt a, ModInt b) { return new ModInt(a.Value - b.Value); } public static ModInt operator *(ModInt a, ModInt b) { return new ModInt(a.Value * b.Value); } public static ModInt operator /(ModInt a, ModInt b) { return new ModInt(a * b.Inverse()); } public override string ToString() { return Value.ToString(); } } static class ModIntMath { public static ModInt Pow(this ModInt a, ModInt b) { var pow = b.Value; var m = a; ModInt ans = new ModInt(1); while (pow != 0) { if ((pow & 1) == 1) { ans *= m; } pow >>= 1; m *= m; } return ans; } public static ModInt Inverse(this ModInt m) { return m.Pow((ModInt)(ModInt.Mod - 2)); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StringBuilder _builder = new StringBuilder(); public static void Cout(object o) { _builder.Append(o); } public static void CoutF(object o) { _builder.Append(o); Flush(); } public static void Coutln(object o) { _builder.Append(o); _builder.Append('\n'); } public static void Coutln() { _builder.Append('\n'); } public static void CoutlnF(object o) { _builder.Append(o); _builder.Append('\n'); Flush(); } public static void Flush() { Console.Write(_builder.ToString()); _builder.Clear(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.NetworkInformation; using System.Security.Cryptography; using System.Text; using System.Threading; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here int N = Cin; var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); if (N % 3 == 0) { bool flg = true; for (int i = 0; flg; i++) { flg = false; int cnt0 = 0, cnt1 = 0; long compare = -1L; bool isError = false; for (var r = 0; r < a.Length; r++) { if (((a[r] >> i) & 1) == 1) cnt1++; else { cnt0++; if (compare == -1) compare = a[r]; if ((compare ^ a[r]) != 0) { isError = true; } } flg |= a[r] >> (i + 1) != 0; } if (isError && cnt1 != 0) { Coutln("No"); return; } if (cnt0 * 2 != cnt1 && cnt1 != 0) { Coutln("No"); return; } } Coutln("Yes"); } else { foreach (var i in a) { if (i != 0) { Coutln("No"); return; } } Coutln("Yes"); } } // Other Functions Here } // Other Classes Here #if !DEBUG class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } #endif class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public int Count { get; private set; } = 0; public PriorityQueue() { _list.Add(null); _list.Add(null); _list.Add(null); } public void Push(T item, int priority) { var itemIndex = Count++; _list[itemIndex] = Tuple.Create(priority, item); while (_list.Count < Count + 2) _list.Add(null); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { if (_list.Count <= 0 || _list[0] == null) throw new IndexOutOfRangeException(); var item = _list[0].Item2; _list[0] = null; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null && (_list[childrenIndex.Item1] != null || _list[childrenIndex.Item2] != null)) { if ((_list[childrenIndex.Item1] != null && _list[childrenIndex.Item2] != null && _list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) || _list[childrenIndex.Item2] == null) { _list[index] = _list[childrenIndex.Item1]; _list[childrenIndex.Item1] = null; index = childrenIndex.Item1; } else { two: _list[index] = _list[childrenIndex.Item2]; _list[childrenIndex.Item2] = null; index = childrenIndex.Item2; } } Count--; return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } struct ModInt { public long Value { get; } public static long Mod { get; set; } = 1000000000L + 7; public ModInt(long l) { long value = l % Mod; while (value < 0) value += Mod; Value = value % Mod; } public static implicit operator long(ModInt m) { return m.Value; } public static explicit operator ModInt(long l) { return new ModInt(l); } public static ModInt operator +(ModInt a, ModInt b) { return new ModInt(a.Value + b.Value); } public static ModInt operator -(ModInt a, ModInt b) { return new ModInt(a.Value - b.Value); } public static ModInt operator *(ModInt a, ModInt b) { return new ModInt(a.Value * b.Value); } public static ModInt operator /(ModInt a, ModInt b) { return new ModInt(a * b.Inverse()); } public override string ToString() { return Value.ToString(); } } static class ModIntMath { public static ModInt Pow(this ModInt a, ModInt b) { var pow = b.Value; var m = a; ModInt ans = new ModInt(1); while (pow != 0) { if ((pow & 1) == 1) { ans *= m; } pow >>= 1; m *= m; } return ans; } public static ModInt Inverse(this ModInt m) { return m.Pow((ModInt)(ModInt.Mod - 2)); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StringBuilder _builder = new StringBuilder(); public static void Cout(object o) { _builder.Append(o); } public static void CoutF(object o) { _builder.Append(o); Flush(); } public static void Coutln(object o) { _builder.Append(o); _builder.Append('\n'); } public static void Coutln() { _builder.Append('\n'); } public static void CoutlnF(object o) { _builder.Append(o); _builder.Append('\n'); Flush(); } public static void Flush() { Console.Write(_builder.ToString()); _builder.Clear(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
[["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 64, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 64, 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, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 64, 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, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
8
2,427
35
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine().Split(' '); var a = new int[n]; int ashurui = 1; a[0] = int.Parse(s[0]); var savedas = new int[3] { a[0], 0, 0 }; var anum = new int[3] { 1, 0, 0 }; for (int i = 1; i < n; i++) { a[i] = int.Parse(s[i]); bool isdifferent = true; for (int j = 0; j < ashurui; j++) { if (a[i] == savedas[j]) { isdifferent = false; anum[j]++; break; } } if (isdifferent) { if (ashurui == 3) { Console.WriteLine("No"); ashurui++; break; } else { savedas[ashurui] = a[i]; anum[ashurui] = 1; ashurui++; } } } if (ashurui < 3) { if (ashurui == 1) { Console.WriteLine("No"); } else if (anum[0] == anum[1] * 2) { if (savedas[1] == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else if (anum[0] * 2 == anum[1]) { if (savedas[0] == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } else if (ashurui == 3) { if ((savedas[0] ^ savedas[1]) == savedas[2] && anum[0] == anum[1] && anum[1] == anum[2]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } #if DEBUG Console.ReadKey(); #endif } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine().Split(' '); var a = new int[n]; int ashurui = 1; a[0] = int.Parse(s[0]); var savedas = new int[3] { a[0], 0, 0 }; var anum = new int[3] { 1, 0, 0 }; for (int i = 1; i < n; i++) { a[i] = int.Parse(s[i]); bool isdifferent = true; for (int j = 0; j < ashurui; j++) { if (a[i] == savedas[j]) { isdifferent = false; anum[j]++; break; } } if (isdifferent) { if (ashurui == 3) { Console.WriteLine("No"); ashurui++; break; } else { savedas[ashurui] = a[i]; anum[ashurui] = 1; ashurui++; } } } if (ashurui < 3) { if (ashurui == 1) { Console.WriteLine(savedas[0] == 0 ? "Yes" : "No"); } else if (anum[0] == anum[1] * 2) { if (savedas[1] == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else if (anum[0] * 2 == anum[1]) { if (savedas[0] == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } else { Console.WriteLine("No"); } } else if (ashurui == 3) { if ((savedas[0] ^ savedas[1]) == savedas[2] && anum[0] == anum[1] && anum[1] == anum[2]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } #if DEBUG Console.ReadKey(); #endif } } }
[["+", 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], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 57, 75, 57, 75, 57, 0, 95], ["+", 0, 57, 75, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 75, 196, 0, 1, 0, 35]]
8
450
23
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Numerics; using System.Threading.Tasks; using static System.Console; using static System.Math; using static Func; 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(); uint[] GU => Strs.Select(uint.Parse).ToArray(); decimal[] GD => Strs.Select(decimal.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); static ulong One(int k) => 1ul << k; static ulong All(int k) => One(k) - 1; static bool Has(ulong s, int k) => (s & One(k)) != 0; const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { N = F; A = G; WriteLine(Calc(0, N - 1, 1, 1) + A[0] + A[N - 1]); } int N; int[] A; Dictionary<Pair, long> memo = new Dictionary<Pair, long>(); long Calc(int l, int r, int wl, int wr) => Calc(new Pair(l, r, wl, wr)); long Calc(Pair p) { if (p.r - p.l <= 1) return 0; if (!memo.ContainsKey(p)) { var w = p.wl + p.wr; memo[p] = long.MaxValue; for (var i = p.l + 1; i < p.r; i++) memo[p] = Min(memo[p], w * A[i] + Calc(p.l, i, p.wl, w) + Calc(i, p.r, w, p.wr)); } return memo[p]; } } struct Pair : IEquatable<Pair> { public readonly int l, r, wl, wr; public Pair(int l, int r, int wl, int wr) { this.l = l; this.r = r; this.wl = wl; this.wr = wr; } public bool Equals(Pair other) => l == other.l && r == other.r && wl == other.wl && wr == other.wr; public override int GetHashCode() => CombineHashCodes(l.GetHashCode(), r.GetHashCode(), wl.GetHashCode(), wr.GetHashCode()); static int CombineHashCodes(int h1, int h2) => (((h1 << 5) + h1) ^ h2); static int CombineHashCodes(int h1, int h2, int h3, int h4) => CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4)); } static class Func { public static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; } public static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; } public static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; } public static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; } public static int FirstBinary(int min, int max, Predicate<int> pred) { while (min < max) { var mid = (min + max) / 2; if (pred(mid)) max = mid; else min = mid + 1; } return min; } public static long GCD(long a, long b) { var n = (ulong)Abs(a); var m = (ulong)Abs(b); if (n == 0) return (long)m; if (m == 0) return (long)n; int zm = 0, zn = 0; while ((n & 1) == 0) { n >>= 1; zn++; } while ((m & 1) == 0) { m >>= 1; zm++; } while (m != n) { if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; } else { n -= m; while ((n & 1) == 0) n >>= 1; } } return (long)n << Min(zm, zn); } public static long Mod(long a, long mod) => (a % mod + mod) % mod; public static long Inverse(long a, long mod) => Mod(SolveLinear(Mod(a, mod), mod)[0], mod); public static long Pow(long a, long b, long mod) { var p = 1L; var x = a; while (b > 0) { if ((b & 1) == 1) p = (p * x) % mod; b >>= 1; x = (x * x) % mod; } return p; } public static long[] SolveLinear(long n, long m) { var A = new long[,] { { n < 0 ? -1 : 1, 0 }, { 0, m < 0 ? -1 : 1 } }; n = Abs(n); m = Abs(m); while (m > 0) { long q = n / m, r = n % m; n = m; m = r; for (var i = 0; i < 2; i++) { var x = A[i, 1]; A[i, 1] = A[i, 0] - q * x; A[i, 0] = x; } } return new long[] { A[0, 0], A[1, 0] }; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Numerics; using System.Threading.Tasks; using static System.Console; using static System.Math; using static Func; 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(); uint[] GU => Strs.Select(uint.Parse).ToArray(); decimal[] GD => Strs.Select(decimal.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); static ulong One(int k) => 1ul << k; static ulong All(int k) => One(k) - 1; static bool Has(ulong s, int k) => (s & One(k)) != 0; const int MOD = 1000000007; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { N = F; A = G; WriteLine(Calc(0, N - 1, 1, 1) + A[0] + A[N - 1]); } int N; int[] A; Dictionary<Pair, long> memo = new Dictionary<Pair, long>(); long Calc(int l, int r, long wl, long wr) => Calc(new Pair(l, r, wl, wr)); long Calc(Pair p) { if (p.r - p.l <= 1) return 0; if (!memo.ContainsKey(p)) { var w = p.wl + p.wr; memo[p] = long.MaxValue; for (var i = p.l + 1; i < p.r; i++) memo[p] = Min(memo[p], w * A[i] + Calc(p.l, i, p.wl, w) + Calc(i, p.r, w, p.wr)); } return memo[p]; } } struct Pair : IEquatable<Pair> { public readonly int l, r; public readonly long wl, wr; public Pair(int l, int r, long wl, long wr) { this.l = l; this.r = r; this.wl = wl; this.wr = wr; } public bool Equals(Pair other) => l == other.l && r == other.r && wl == other.wl && wr == other.wr; public override int GetHashCode() => CombineHashCodes(l.GetHashCode(), r.GetHashCode(), wl.GetHashCode(), wr.GetHashCode()); static int CombineHashCodes(int h1, int h2) => (((h1 << 5) + h1) ^ h2); static int CombineHashCodes(int h1, int h2, int h3, int h4) => CombineHashCodes(CombineHashCodes(h1, h2), CombineHashCodes(h3, h4)); } static class Func { public static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; } public static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; } public static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; } public static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; } public static int FirstBinary(int min, int max, Predicate<int> pred) { while (min < max) { var mid = (min + max) / 2; if (pred(mid)) max = mid; else min = mid + 1; } return min; } public static long GCD(long a, long b) { var n = (ulong)Abs(a); var m = (ulong)Abs(b); if (n == 0) return (long)m; if (m == 0) return (long)n; int zm = 0, zn = 0; while ((n & 1) == 0) { n >>= 1; zn++; } while ((m & 1) == 0) { m >>= 1; zm++; } while (m != n) { if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; } else { n -= m; while ((n & 1) == 0) n >>= 1; } } return (long)n << Min(zm, zn); } public static long Mod(long a, long mod) => (a % mod + mod) % mod; public static long Inverse(long a, long mod) => Mod(SolveLinear(Mod(a, mod), mod)[0], mod); public static long Pow(long a, long b, long mod) { var p = 1L; var x = a; while (b > 0) { if ((b & 1) == 1) p = (p * x) % mod; b >>= 1; x = (x * x) % mod; } return p; } public static long[] SolveLinear(long n, long m) { var A = new long[,] { { n < 0 ? -1 : 1, 0 }, { 0, m < 0 ? -1 : 1 } }; n = Abs(n); m = Abs(m); while (m > 0) { long q = n / m, r = n % m; n = m; m = r; for (var i = 0; i < 2; i++) { var x = A[i, 1]; A[i, 1] = A[i, 0] - q * x; A[i, 0] = x; } } return new long[] { A[0, 0], A[1, 0] }; } }
[["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 270, 8, 201, 0, 124, 0, 198, 0, 21], ["+", 0, 208, 0, 270, 8, 201, 0, 124, 0, 35], ["+", 0, 270, 8, 201, 0, 124, 0, 251, 0, 259], ["+", 0, 270, 8, 201, 0, 124, 0, 251, 0, 262], ["+", 0, 270, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 263, 54, 55, 0, 220, 39, 199]]
8
1,516
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC145A { class Program { static void Main(string[] args) { int a, b, c, x; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); x = a * b; if (x < c) Console.WriteLine(x); else if (c < x) Console.WriteLine(c); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC145A { class Program { static void Main(string[] args) { int a, b, c, x; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); x = a * b; if (x < c) Console.WriteLine(x); else if (c < x) Console.WriteLine(c); else Console.WriteLine(x); Console.ReadKey(); } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 57, 75, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 75, 1, 0, 35]]
8
146
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC133 { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if ((a * b) < c) { Console.WriteLine(a * b); } else if ((a * b) > c) { Console.WriteLine(c); } Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC133 { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if ((a * b) < c) { Console.WriteLine(a * b); } else if ((a * b) > c) { Console.WriteLine(c); } else if ((a * b) == c) { Console.WriteLine(c); } Console.ReadLine(); } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 15, 16, 31, 23, 0, 24], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 17, 48], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 12, 22], ["+", 75, 57, 75, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["+", 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, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
8
152
20
using System; using System.Text; using System.Collections.Generic; using System.Linq; public class Remainder { static public void Main() { var HW = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var N = HW[0]; var A = HW[1]; var B = HW[2]; if (N * A <= B) { Console.WriteLine(B); } else { Console.WriteLine(N * A); } } } public class Node { public List<long> child; public long fnum = long.MaxValue; public long snum = long.MaxValue; public Node() { this.child = new List<long>(); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; public class Remainder { static public void Main() { var HW = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var N = HW[0]; var A = HW[1]; var B = HW[2]; if (N * A <= B) { Console.WriteLine(N * A); } else { Console.WriteLine(B); } } } public class Node { public List<long> child; public long fnum = long.MaxValue; public long snum = long.MaxValue; public Node() { this.child = new List<long>(); } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
164
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC133A { class Program { static void Main(string[] args) { var word = Console.ReadLine().Split(' '); int N = int.Parse(word[0]); int A = int.Parse(word[1]); int B = int.Parse(word[2]); if (N * A < B) { Console.WriteLine(N * A); } else if (N * A > B) { Console.WriteLine(B); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC133A { class Program { static void Main(string[] args) { var word = Console.ReadLine().Split(' '); int N = int.Parse(word[0]); int A = int.Parse(word[1]); int B = int.Parse(word[2]); if (N * A < B) { Console.WriteLine(N * A); } else if (N * A > B) { Console.WriteLine(B); } else if (N * A == B) { Console.WriteLine(B); } Console.ReadKey(); } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 48], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 57, 75, 57, 64, 196, 0, 46]]
8
144
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace attocoda { class Program { static void Main(string[] args) { int n, a, b; var word = Console.ReadLine().Split(' '); n = int.Parse(word[0]); a = int.Parse(word[1]); b = int.Parse(word[2]); if (n * a < b) Console.WriteLine(n * a); else if (n * a > b) Console.WriteLine(b); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace attocoda { class Program { static void Main(string[] args) { int n, a, b; var word = Console.ReadLine().Split(' '); n = int.Parse(word[0]); a = int.Parse(word[1]); b = int.Parse(word[2]); if (n * a < b) Console.WriteLine(n * a); else if (n * a > b) Console.WriteLine(b); else if (n * a == b) Console.WriteLine(b); Console.ReadKey(); } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 48], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 75, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
8
144
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_133A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a * b > c) { Console.WriteLine(a * b); } else { Console.WriteLine(c); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_133A { class Program { static void Main(string[] args) { int a, b, c; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); if (a * b > c) { Console.WriteLine(c); } else { Console.WriteLine(a * b); } Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
140
8
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); //仕事を登録する辞書 Dictionary<int, int> jobs = new Dictionary<int, int>(); //仕事をした合計時間 int time = 0; //結果 string result = "Yes"; //仕事を登録 for (int i = 0; i < N; i++) { var AB = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var A = AB[0]; var B = AB[1]; if (!jobs.ContainsKey(B)) { jobs.Add(B, A); } else { jobs[B] += A; } } jobs.OrderBy(x => x.Key); //貪欲法で各状態ごとの最善手を打つ foreach (KeyValuePair<int, int> job in jobs) { //仕事後の時間が納期に間に合う場合 if (time + job.Value <= job.Key) { //何もしないんか } else { result = "No"; } } Console.WriteLine(result); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); //仕事を登録する辞書 Dictionary<int, int> jobs = new Dictionary<int, int>(); //仕事をした合計時間 int time = 0; //結果 string result = "Yes"; //仕事を登録 for (int i = 0; i < N; i++) { var AB = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var A = AB[0]; var B = AB[1]; if (!jobs.ContainsKey(B)) { jobs.Add(B, A); } else { jobs[B] += A; } } IOrderedEnumerable<KeyValuePair<int, int>> jobs2 = jobs.OrderBy(x => x.Key); //貪欲法で各状態ごとの最善手を打つ foreach (KeyValuePair<int, int> job in jobs2) { //仕事後の時間が納期に間に合う場合 if (time + job.Value <= job.Key) { //何もしないんか time += job.Value; // Console.WriteLine(time); } else { // Console.WriteLine(job.Key); result = "No"; } // Console.WriteLine("納期:"+job.Key+"仕事時間"+job.Value+"合計時間:"+time); } Console.WriteLine(result); } }
[["+", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 18], ["+", 0, 198, 39, 236, 237, 238, 0, 236, 141, 22], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 18], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 21], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 47], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 47], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
245
19
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var AB = sc.ReadTupArray_int2(N); var ok = true; var now = 0; for (int i = 0; i < N; i++) { now += AB[i].Item1; if (now > AB[i].Item2) { ok = false; break; } } Console.WriteLine(ok ? "Yes" : "No"); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup_int2() { return Tuple.Create(this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int> ReadTup_int3() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int, int> ReadTup_int4() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt(), this.ReadInt()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<int, int>[] ReadTupArray_int2(int n) { var array = new Tuple<int, int>[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadTup_int2(); } return array; } public Tuple<int, int, int>[] ReadTupArray_int3(int n) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadTup_int3(); } return array; } public Tuple<int, int, int, int>[] ReadTupArray_int4(int n) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadTup_int4(); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var AB = sc.ReadTupArray_int2(N); AB = AB.OrderBy(ab => ab.Item2).ToArray(); var ok = true; var now = 0; for (int i = 0; i < N; i++) { now += AB[i].Item1; if (now > AB[i].Item2) { ok = false; break; } } Console.WriteLine(ok ? "Yes" : "No"); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup_int2() { return Tuple.Create(this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int> ReadTup_int3() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int, int> ReadTup_int4() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt(), this.ReadInt()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<int, int>[] ReadTupArray_int2(int n) { var array = new Tuple<int, int>[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadTup_int2(); } return array; } public Tuple<int, int, int>[] ReadTupArray_int3(int n) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadTup_int3(); } return array; } public Tuple<int, int, int, int>[] ReadTupArray_int4(int n) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadTup_int4(); } return array; } }
[["+", 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], ["+", 12, 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, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 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, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
943
17
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static List<int> A = new List<int>(); static List<int> B = new List<int>(); static decimal result; static Hashtable ht = new Hashtable(); static StringBuilder sb = new StringBuilder(); static int N, M, K; static long[,] table; static void Main() { PriorityQueue<int, int> pr = new PriorityQueue< int, int>(); //優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。 Read1(); Read5(); //後ろから見ていく。 int limit = 0; for (int i = 0; i < N; i++) { pr.Add(-B[i], i); } for (int i = 0; i < N; i++) { int tmp = pr.Dequeue().Value; if (i == 0) { limit = B[tmp]; } result += A[tmp]; if (result > limit) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } static void Read1() // 1項 { string tmp = Console.ReadLine(); N = int.Parse(tmp); } static void Read5() // N行K項 { for (int i = 0; i < N; i++) { string[] tmp = Console.ReadLine().Split(' '); A.Add(int.Parse(tmp[0])); B.Add(int.Parse(tmp[1])); } } } class PriorityQueue<TKey, TValue> { SortedDictionary<TKey, Queue<TValue>> dict = new SortedDictionary<TKey, Queue<TValue>>(); int count = 0; public int Count { get { return count; } } public void Add(TKey key, TValue value) { if (!dict.ContainsKey(key)) { dict[key] = new Queue<TValue>(); } dict[key].Enqueue(value); count++; } public KeyValuePair<TKey, TValue> Dequeue() { var queue = dict.First(); if (queue.Value.Count <= 1) { dict.Remove(queue.Key); } count--; return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue()); } }
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static List<int> A = new List<int>(); static List<int> B = new List<int>(); static decimal result; static Hashtable ht = new Hashtable(); static StringBuilder sb = new StringBuilder(); static int N, M, K; static long[,] table; static void Main() { PriorityQueue<int, int> pr = new PriorityQueue< int, int>(); //優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。 Read1(); Read5(); //後ろから見ていく。 int limit = 0; for (int i = 0; i < N; i++) { pr.Add(-B[i], i); } for (int i = 0; i < N; i++) { int tmp = pr.Dequeue().Value; if (i == 0) { limit = B[tmp]; } if (result < limit - B[tmp]) { result = limit - B[tmp]; } result += A[tmp]; if (result > limit) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } static void Read1() // 1項 { string tmp = Console.ReadLine(); N = int.Parse(tmp); } static void Read5() // N行K項 { for (int i = 0; i < N; i++) { string[] tmp = Console.ReadLine().Split(' '); A.Add(int.Parse(tmp[0])); B.Add(int.Parse(tmp[1])); } } } class PriorityQueue<TKey, TValue> { SortedDictionary<TKey, Queue<TValue>> dict = new SortedDictionary<TKey, Queue<TValue>>(); int count = 0; public int Count { get { return count; } } public void Add(TKey key, TValue value) { if (!dict.ContainsKey(key)) { dict[key] = new Queue<TValue>(); } dict[key].Enqueue(value); count++; } public KeyValuePair<TKey, TValue> Dequeue() { var queue = dict.First(); if (queue.Value.Count <= 1) { dict.Remove(queue.Key); } count--; return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue()); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 12, 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], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
508
22
using System; using System.Collections.Generic; using System.Linq; namespace CsTest { public class Program { public class Comparer : IComparer<int[]> { public int Compare(int[] x, int[] y) => x[1] - y[1]; } static void Main(string[] args) { int N = int.Parse(Console.ReadLine().Trim()); int[][] works = new int [N][]; for (int i = 0; i < N; ++i) { works[i] = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } Array.Sort(works, new Comparer()); int time = works[works.Length - 1][1]; for (int i = works.Length - 1; i >= 0; --i) { time -= works[i][0]; time = Math.Min(works[i][1], time); if (time < 0) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace CsTest { public class Program { public class Comparer : IComparer<int[]> { public int Compare(int[] x, int[] y) => x[1] - y[1]; } static void Main(string[] args) { int N = int.Parse(Console.ReadLine().Trim()); int[][] works = new int [N][]; for (int i = 0; i < N; ++i) { works[i] = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } Array.Sort(works, new Comparer()); int time = works[works.Length - 1][1]; for (int i = works.Length - 1; i >= 0; --i) { time = Math.Min(works[i][1], time); time -= works[i][0]; if (time < 0) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 0, 1, 0, 11, 12, 204, 205, 204, 205, 22], ["-", 0, 11, 12, 204, 205, 204, 206, 207, 0, 70], ["-", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 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], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 1, 0, 11, 12, 204, 205, 204, 205, 22], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 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]]
8
257
20
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here int N = Cin; var list = new List<Tuple<int, int>>(); for (int i = 0; i < N; i++) list.Add(Tuple.Create<int, int>(Cin, Cin)); var works = list.OrderBy(val => val.Item2).ToArray(); for (var i = 1; i < works.Length; i++) { works[i] = Tuple.Create(works[i - 1].Item1 + works[i].Item1, works[i].Item2); if (works[i].Item1 > works[i].Item2) { Coutln("No"); return; } } Coutln("Yes"); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here int N = Cin; var list = new List<Tuple<int, int>>(); for (int i = 0; i < N; i++) list.Add(Tuple.Create<int, int>(Cin, Cin)); var works = list.OrderBy(val => val.Item2).ToArray(); for (var i = 0; i < works.Length; i++) { if (i > 0) works[i] = Tuple.Create(works[i - 1].Item1 + works[i].Item1, works[i].Item2); if (works[i].Item1 > works[i].Item2) { Coutln("No"); return; } } Coutln("Yes"); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
8
1,802
8
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc130 /// 2020/02/04 /// </summary> namespace ABC130 { public class Program { public static void Main(string[] args) { // A(); // B(); // C(); // D(); // E(); // F(); } public static void F() {} public static void E() {} public static void D() {} public static void C() {} public static void B() {} public static void A() { long X = rl; long A = rl; if (X < A) Console.WriteLine("0"); else Console.WriteLine("10"); } } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; using Pair = System.Tuple<long, long>; /// <summary> /// https://atcoder.jp/contests/abc130 /// 2020/02/04 R1022 /// </summary> namespace ABC130 { public class Program { public static void Main(string[] args) { // 1回目 R1022 // A(); 3m // B(); 14m // C(); 37m // D(); 99m // E(); // F(); // 2回目 A(); // B(); // C(); // D(); // E(); // F(); } public static void F() {} public static void E() {} public static void D() {} public static void C() {} public static void B() {} public static void A() { long X = rl; long A = rl; if (X < A) { Console.WriteLine("0"); } else { Console.WriteLine("10"); } } // public static void F() //{ //} // public static void E() //{ //} // public static void D() //{ // long N = rl; // long K = rl; // long[] A = rla; // long sum = 0; // int cnt = 0; // long ans = 0; // for (int i = 0; i < N; i++) // { // sum += A[i]; // cnt++; // if (sum < K) // { // ans += cnt; // continue; // } // while (K <= sum && 0 < cnt) // { // sum -= A[i - cnt + 1]; // cnt--; // } // ans += cnt; // } // ans = N * (N + 1) / 2 - ans; // Console.WriteLine(ans); //} // public static void C() //{ // long W = rl; // long H = rl; // long x = rl; // long y = rl; // string ans = (W * H / 2.0).ToString() + " "; // if (W / 2.0 == x && H / 2.0 == y) // { // ans += "1"; // } // else // { // ans += "0"; // } // Console.WriteLine(ans); //} // public static void B() //{ // long N = rl; // long M = rl; // long[] A = rla; // long l = 0; // for (int i = 0; i < N; i++) // { // l += A[i]; // if (l > M) // { // Console.WriteLine(i+1); // return; // } // } // Console.WriteLine(N+1); //} // public static void A() //{ // long X = rl; // long A = rl; // if(X < A) // Console.WriteLine("0"); // else // Console.WriteLine("10"); //} } } namespace Ha2ne2Util { public static class Cin { private static string[] Tokens { get; set; } private static int Pointer { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } public static int ReadInt() { return int.Parse(Next()); } public static long rl => ReadLong(); public static long[] rla => ReadLongArray(); public static double rd => ReadDouble(); public static double[] rda => ReadDoubleArray(); public static string rs => ReadString(); public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadArrays(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadArrays(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 降順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static long ModAdd(long a, long b) { long res = a + b; if (res >= MOD) return res % MOD; return res; } public static long ModMul(long a, long b) { long res = a * b; if (res >= MOD) return res % MOD; return res; } public static void ModAddEqual(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { public int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 36, 36, 0, 208, 0, 209, 8, 201, 0, 46], ["+", 0, 277, 51, 306, 0, 213, 3, 4, 0, 24], ["+", 0, 277, 51, 306, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 235, 8, 201, 0, 277, 0, 35], ["+", 0, 235, 8, 201, 0, 277, 0, 251, 0, 259], ["+", 0, 235, 8, 201, 0, 277, 0, 251, 0, 115], ["+", 8, 201, 0, 235, 8, 201, 0, 277, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 277, 141, 22], ["+", 0, 235, 8, 201, 0, 277, 51, 306, 0, 221], ["+", 8, 201, 0, 277, 51, 306, 0, 213, 63, 22]]
8
3,329
17
using System; using System.Collections.Generic; using System.Linq; namespace ProgramingStudying2 { class Program { static void Main(string[] args) { var nx = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nx[0]; var x = nx[1]; var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); var d = 0; var ans = 0; var i = 0; while (i <= n && d <= x) { ans++; d += l[i]; i++; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ProgramingStudying2 { class Program { static void Main(string[] args) { var nx = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nx[0]; var x = nx[1]; var l = Console.ReadLine().Split().Select(int.Parse).ToList(); l.Add(0); var d = 0; var ans = 0; var i = 0; while (i <= n && d <= x) { ans++; d += l[i]; i++; } Console.WriteLine(ans); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
145
9
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var NX = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var (N, X) = (NX[0], NX[1]); var L = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var d = 0; var ans = 0; for (int i = 0; i < N; i++) { if (X < d) break; ans++; d += L[i]; } WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var NX = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var (N, X) = (NX[0], NX[1]); var L = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var d = 0; var ans = 0; for (int i = 0; i < N; i++) { if (d <= X) ans++; d += L[i]; } if (d <= X) ans++; WriteLine(ans); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 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, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
164
15
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Remoting; using System.Security.Cryptography; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineIntSpilit(); var l = ReadLineIntSpilit(); var dis = 0; var count = 0; for (int i = 0; i < n[0]; i++) { if (dis > n[1]) { break; } dis += l[i]; count++; } Console.WriteLine(count); ReadLine(); } //メモ //アルゴリズム //・全探索解 /* * 例 [A, B, C] * * A - B, A - C * B - C * * for (int i = 0; i < n; i++) { * * for (int j = i + 1; j < n; j++) { * * array[i], array[j] * * } * } */ // ・配列の前後を見る /* * 例 array[1, 2, 3, 4, 5] * * r = 3; * * array[i - 1] => 1 * array[i] => 2 * array[i + 1] => 3 * * //範囲 * int r = 3; * * for(int i = 1; i <= array.Length - r; i++) { } * */ //配列 -------------------- //降順 // Array.Sort(h); // Array.Reverse(h); //合計値 // array.Sum(); //最大値 // List.Sort(); List[Count() - 1] //連続の整数配列を作成 // // 1, 2, 3, 4, 5,..., n // var continuous = Enumerable.Range(1, n).ToList(); //-------------------- //切り捨て // double d = Math.Floor(n); //切り上げ // double d = Math.Celling(n); // kのn乗 //(int) Math.Pow(k, n); // for文の逆 // for(int i = array.Length - 1; i >= 0; i--) { } /// <summary> /// 最大公約数 /// </summary> public static long Gcd(long a, long b) { while (true) { if (a < b) { long tmp = b; b = a; a = tmp; } if (a % b == 0) return b; var x = a; a = b; b = x % b; } } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) => a / Gcd(a, b) * b; /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } /// <summary> /// 数字配列の重複をカウント /// </summary> public static int DistinctInt(IEnumerable<int> array) { var q = array.Distinct().Count(); return array.Count() - q; } /// <summary> /// 文字配列の重複をカウント /// </summary> /// <param name="array"></param> /// <returns></returns> public static int DistinctString(IEnumerable<string> array) { var q = array.Distinct().Count(); return array.Count() - q; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAlphaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAlphaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Remoting; using System.Security.Cryptography; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineIntSpilit(); var l = ReadLineIntSpilit(); var d = 0; var count = 1; for (int i = 0; i < n[0]; i++) { if (d + l[i] > n[1]) { break; } d += l[i]; count++; } Console.WriteLine(count); ReadLine(); } //メモ //アルゴリズム //・全探索解 /* * 例 [A, B, C] * * A - B, A - C * B - C * * for (int i = 0; i < n; i++) { * * for (int j = i + 1; j < n; j++) { * * array[i], array[j] * * } * } */ // ・配列の前後を見る /* * 例 array[1, 2, 3, 4, 5] * * r = 3; * * array[i - 1] => 1 * array[i] => 2 * array[i + 1] => 3 * * //範囲 * int r = 3; * * for(int i = 1; i <= array.Length - r; i++) { } * */ //配列 -------------------- //降順 // Array.Sort(h); // Array.Reverse(h); //合計値 // array.Sum(); //最大値 // List.Sort(); List[Count() - 1] //連続の整数配列を作成 // // 1, 2, 3, 4, 5,..., n // var continuous = Enumerable.Range(1, n).ToList(); //-------------------- //切り捨て // double d = Math.Floor(n); //切り上げ // double d = Math.Celling(n); // kのn乗 //(int) Math.Pow(k, n); // for文の逆 // for(int i = array.Length - 1; i >= 0; i--) { } /// <summary> /// 最大公約数 /// </summary> public static long Gcd(long a, long b) { while (true) { if (a < b) { long tmp = b; b = a; a = tmp; } if (a % b == 0) return b; var x = a; a = b; b = x % b; } } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) => a / Gcd(a, b) * b; /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } /// <summary> /// 数字配列の重複をカウント /// </summary> public static int DistinctInt(IEnumerable<int> array) { var q = array.Distinct().Count(); return array.Count() - q; } /// <summary> /// 文字配列の重複をカウント /// </summary> /// <param name="array"></param> /// <returns></returns> public static int DistinctString(IEnumerable<string> array) { var q = array.Distinct().Count(); return array.Count() - q; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAlphaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAlphaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 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], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22]]
8
770
13
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int X = int.Parse(input[1]); string[] inputL = Console.ReadLine().Split(' '); List<int> list = new List<int>(); for (int i = 0; i < N; i++) { list.Add(int.Parse(inputL[i])); } int loc = 0; int cnt = 0; { while (loc <= X && list.Count > 0) { loc = loc + list[0]; cnt++; list.RemoveAt(0); if (list.Count == 0) { cnt++; } } Console.WriteLine(cnt); } } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int X = int.Parse(input[1]); string[] inputL = Console.ReadLine().Split(' '); List<int> list = new List<int>(); for (int i = 0; i < N; i++) { list.Add(int.Parse(inputL[i])); } int loc = 0; int cnt = 1; for (int i = 0; i < N; i++) { loc = loc + list[0]; list.RemoveAt(0); if (loc <= X) { cnt++; } } /*while (loc <= X && list.Count > 0) { loc = loc + list[0]; cnt++; list.RemoveAt(0); if (list.Count == 0) { cnt++; } }*/ Console.WriteLine(cnt); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 0, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["-", 0, 196, 0, 52, 15, 16, 31, 16, 17, 19], ["-", 0, 196, 0, 52, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 196, 0, 52, 15, 16, 17, 98], ["-", 0, 52, 15, 16, 12, 16, 31, 214, 205, 22], ["-", 0, 52, 15, 16, 12, 16, 31, 214, 0, 131], ["-", 0, 52, 15, 16, 12, 16, 31, 214, 141, 22], ["-", 0, 196, 0, 52, 15, 16, 12, 16, 17, 47], ["+", 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], ["+", 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, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["-", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 196, 0, 46]]
8
224
35