buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; public class Program { public static void Main() { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[0]); int C = int.Parse(str[0]); if (B + C > A) { Console.WriteLine(B + C - A); } else { Console.WriteLine(0); } } }
using System; using System.Collections.Generic; public class Program { public static void Main() { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); if ((B + C) > A) { Console.WriteLine((B + C) - A); } else { Console.WriteLine(0); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
8
111
8
using System; namespace Answer { class Program { public static void Main(string[] args) { char[] charSeparators = new char[] { ',' }; var values = Console.ReadLine().Split( charSeparators, StringSplitOptions.RemoveEmptyEntries); var A = int.Parse(values[0]); var B = int.Parse(values[1]); var C = int.Parse(values[2]); var ans = Math.Max(0, C - (A - B)); Console.WriteLine(ans); } } }
using System; namespace Answer { class Program { public static void Main(string[] args) { char[] charSeparators = new char[] { ' ' }; var values = Console.ReadLine().Split( charSeparators, StringSplitOptions.RemoveEmptyEntries); var A = int.Parse(values[0]); var B = int.Parse(values[1]); var C = int.Parse(values[2]); var ans = Math.Max(0, C - (A - B)); Console.WriteLine(ans); } } }
[["-", 0, 212, 0, 227, 0, 229, 0, 252, 0, 253], ["+", 0, 212, 0, 227, 0, 229, 0, 252, 0, 253]]
8
120
2
using System; using System.Text; using System.Linq; class Program { static void Main(string[] args) { #if DEBUG System.Diagnostics.Debug.WriteLine("-----TextFile1"); System.Diagnostics.Debug.WriteLine(process("../TextFile1.txt")); System.Diagnostics.Debug.WriteLine("-----TextFile2"); System.Diagnostics.Debug.WriteLine(process("../TextFile2.txt")); System.Diagnostics.Debug.WriteLine("-----TextFile3"); System.Diagnostics.Debug.WriteLine(process("../TextFile3.txt")); #endif #if !DEBUG String ret = process(new System.IO.StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static string process(string filePath) { using (var input = new System.IO.StreamReader(filePath)) { if (input.EndOfStream) return "NO PROC"; return process(input); } } static string process(System.IO.TextReader input) { var s = input.ReadLine(); var spl = s.Split(' '); int a = int.Parse(spl[0]); int b = int.Parse(spl[1]); int c = int.Parse(spl[2]); return Math.Min((c - (a - b)), 0).ToString(); } static int[] ToIntArray(string strs, int n) { int[] ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
using System; using System.Text; using System.Linq; class Program { static void Main(string[] args) { #if DEBUG System.Diagnostics.Debug.WriteLine("-----TextFile1"); System.Diagnostics.Debug.WriteLine(process("../TextFile1.txt")); System.Diagnostics.Debug.WriteLine("-----TextFile2"); System.Diagnostics.Debug.WriteLine(process("../TextFile2.txt")); System.Diagnostics.Debug.WriteLine("-----TextFile3"); System.Diagnostics.Debug.WriteLine(process("../TextFile3.txt")); #endif #if !DEBUG String ret = process(new System.IO.StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static string process(string filePath) { using (var input = new System.IO.StreamReader(filePath)) { if (input.EndOfStream) return "NO PROC"; return process(input); } } static string process(System.IO.TextReader input) { var s = input.ReadLine(); var spl = s.Split(' '); int a = int.Parse(spl[0]); int b = int.Parse(spl[1]); int c = int.Parse(spl[2]); return Math.Max((c - (a - b)), 0).ToString(); } static int[] ToIntArray(string strs, int n) { int[] ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
8
360
2
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int r = sc.intarr[0]; wr.wri(3 * r * r * r); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int r = sc.intarr[0]; wr.wri(3 * r * r); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
246
2
using System; using System.Collections.Generic; using System.Linq; public class Solution { public static void Main() { var r = long.Parse(Console.ReadLine()); var s = 3 * r ^ 2; Console.WriteLine($"{s}"); } }
using System; using System.Collections.Generic; using System.Linq; public class Solution { public static void Main() { var r = int.Parse(Console.ReadLine()); var s = 3 * r * r; Console.WriteLine($"{s}"); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 140], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
62
6
using System; namespace CSharpTest { class MainClass { public static void Main(string[] args) { var mainclass = new MainClass(); mainclass.calc(); } private void calc() { int inp = int.Parse(Console.ReadLine()); Console.WriteLine(3 * (inp ^ 2)); } } }
using System; namespace CSharpTest { class MainClass { public static void Main(string[] args) { var mainclass = new MainClass(); mainclass.calc(); } private void calc() { Int64 inp = int.Parse(Console.ReadLine()); Console.WriteLine(3 * Math.Pow(inp, 2)); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 140], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21]]
8
71
7
using System; using static System.Console; namespace AC_Field { class AtCoder { static void Main() { int r; r = int.Parse(ReadLine()); WriteLine(3 * r ^ 2); } } }
using System; using static System.Console; namespace AC_Field { class AtCoder { static void Main() { int r; r = int.Parse(ReadLine()); WriteLine(3 * r * r); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 140], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
47
4
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 public long GCD(long a, long b) => (a < b) ? GCD(b, a) : ((b == 0) ? a : GCD(b, a % b)); static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a); static private readonly long _m = 1000000000 + 7; static public long Mod(long val) => (val % _m + _m) % _m; static private long extGCD(long a, long b, ref long x, ref long y) => (b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0) : (extGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0); static public long ModInverse(long a, long dummy1 = 0, long dummy2 = 0) => extGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static void Main() { int r = Console.ReadLine().ToInt(); Console.WriteLine(3 * r * r * r); } }
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 public long GCD(long a, long b) => (a < b) ? GCD(b, a) : ((b == 0) ? a : GCD(b, a % b)); static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a); static private readonly long _m = 1000000000 + 7; static public long Mod(long val) => (val % _m + _m) % _m; static private long extGCD(long a, long b, ref long x, ref long y) => (b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0) : (extGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0); static public long ModInverse(long a, long dummy1 = 0, long dummy2 = 0) => extGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static void Main() { int r = Console.ReadLine().ToInt(); Console.WriteLine(3 * r * r); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
644
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var wrong_answer = new wrong_answer(); wrong_answer.Solve(); } } public class wrong_answer { const int INF = 1 << 30; const long INFL = 1L << 60; const int MOD = 1000000007; const int MOD2 = 998244353; myinout IO = new myinout(); Math2 mmath = new Math2(); public void Solve() { //ここから var o = IO.doublem; var n = o[0]; var d = o[1]; d *= 2; d += 1; IO.wri((n + d - 1) / d); } } // b-aで降順 public class Math2 { public long[] fact; public long[] invfact; public void factoricalmodset(long N, long MOD = 1000000007) { fact = new long[N + 1]; invfact = new long[N + 1]; fact[0] = 1; for (long i = 1; i <= N; ++i) { fact[i] = fact[i - 1] * i % MOD; } invfact[N] = pow(fact[N], MOD - 2); for (long i = N; i > 0; --i) { invfact[i - 1] = invfact[i] * i % MOD; } } public long nCr(long n, long r, long MOD = 1000000007) { return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD); } public long pow(long i, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * i % MOD; i = i * i % MOD; n >>= 1; } return res; } public long gcd(long i, long y) { while (y != 0) { var r = i % y; i = y; y = r; } return i; } public long lcm(long i, long y) { return i * y / gcd(i, y); } public Dictionary<long, int> primefactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public List<long> divisorenumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } public void swap<T>(ref T a, ref T b) { var i = a; a = b; b = i; } } class myinout { // in public string str => Console.ReadLine(); public string[] strm => str.Split(' '); public long[] longm => strm.Select(long.Parse).ToArray(); public int[] intm => strm.Select(int.Parse).ToArray(); public char[] charm => str.ToArray(); public double[] doublem => strm.Select(double.Parse).ToArray(); public long long1 => longm[0]; public int int1 => intm[0]; public char char1 => charm[0]; public double double1 => doublem[0]; // out public void wri<T>(T i) { Console.WriteLine(i); } public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); } public void yn(bool i) { if (i) wri("Yes"); else wri("No"); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var wrong_answer = new wrong_answer(); wrong_answer.Solve(); } } public class wrong_answer { const int INF = 1 << 30; const long INFL = 1L << 60; const int MOD = 1000000007; const int MOD2 = 998244353; myinout IO = new myinout(); Math2 mmath = new Math2(); public void Solve() { //ここから var o = IO.longm; var n = o[0]; var d = o[1]; d *= 2; d += 1; IO.wri((n + d - 1) / d); } } // b-aで降順 public class Math2 { public long[] fact; public long[] invfact; public void factoricalmodset(long N, long MOD = 1000000007) { fact = new long[N + 1]; invfact = new long[N + 1]; fact[0] = 1; for (long i = 1; i <= N; ++i) { fact[i] = fact[i - 1] * i % MOD; } invfact[N] = pow(fact[N], MOD - 2); for (long i = N; i > 0; --i) { invfact[i - 1] = invfact[i] * i % MOD; } } public long nCr(long n, long r, long MOD = 1000000007) { return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD); } public long pow(long i, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * i % MOD; i = i * i % MOD; n >>= 1; } return res; } public long gcd(long i, long y) { while (y != 0) { var r = i % y; i = y; y = r; } return i; } public long lcm(long i, long y) { return i * y / gcd(i, y); } public Dictionary<long, int> primefactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public List<long> divisorenumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } public void swap<T>(ref T a, ref T b) { var i = a; a = b; b = i; } } class myinout { // in public string str => Console.ReadLine(); public string[] strm => str.Split(' '); public long[] longm => strm.Select(long.Parse).ToArray(); public int[] intm => strm.Select(int.Parse).ToArray(); public char[] charm => str.ToArray(); public double[] doublem => strm.Select(double.Parse).ToArray(); public long long1 => longm[0]; public int int1 => intm[0]; public char char1 => charm[0]; public double double1 => doublem[0]; // out public void wri<T>(T i) { Console.WriteLine(i); } public void wri<T>(T[] i) { Console.WriteLine(string.Join(" ", i)); } public void yn(bool i) { if (i) wri("Yes"); else wri("No"); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
874
2
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 ND = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int N = ND[0]; int D = ND[1]; double ans = N / (2 * D + 1); Console.WriteLine(Math.Ceiling(ans)); } } }
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 ND = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); double N = ND[0]; double D = ND[1]; double ans = N / (2 * D + 1); Console.WriteLine(Math.Ceiling(ans)); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
112
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp23 { class Program { static void Main(string[] args) { //入力 string s = Console.ReadLine(); int N = int.Parse(s.Split(' ')[0]); int D = int.Parse(s.Split(' ')[1]); //検証 Console.WriteLine(Math.Ceiling((N + 0.001f) / (float)(D * 2 + 1))); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp23 { class Program { static void Main(string[] args) { //入力 string s = Console.ReadLine(); int N = int.Parse(s.Split(' ')[0]); int D = int.Parse(s.Split(' ')[1]); //検証 Console.WriteLine(Math.Ceiling((N - 0.001f) / (float)(D * 2 + 1))); } } }
[["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33]]
8
124
2
using System; using System.Collections.Generic; using System.Linq; public class Solution { public static void Main() { string str = Console.ReadLine(); string[] arr = str.Split(' '); var N = double.Parse(arr[0]); var D = double.Parse(arr[1]); // 1人が確認できる木の本数は、(i+D) - (i-D) + 1 = 2D+1のため、 // 求まる人数をa人とすると、a(2D+1)>=Nとなる // 2D+1>0のため、a>=N/(2D+1)を満たす最小の整数をもとめればよい double cal = N / (2 * D + 1); var result = Math.Ceiling(cal); Console.WriteLine($"{cal} {result}"); } }
using System; using System.Collections.Generic; using System.Linq; public class Solution { public static void Main() { string str = Console.ReadLine(); string[] arr = str.Split(' '); var N = double.Parse(arr[0]); var D = double.Parse(arr[1]); // 1人が確認できる木の本数は、(i+D) - (i-D) + 1 = 2D+1のため、 // 求まる人数をa人とすると、a(2D+1)>=Nとなる // 2D+1>0のため、a>=N/(2D+1)を満たす最小の整数をもとめればよい double cal = N / (2 * D + 1); var result = Math.Ceiling(cal); Console.WriteLine($"{result}"); } }
[["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45]]
8
118
4
using System; using System.Linq; namespace Welcome_to_AtCoder { class Program { static void Main(string[] args) { string input = Console.ReadLine(); var array = input.Split(' ').Select(_ => int.Parse(_)).ToArray(); var n = array[0]; var d = array[1]; var hoge = d * 2; int result = n % hoge == 0 ? (n / hoge) : (n / hoge) + 1; Console.WriteLine(result); } } }
using System; using System.Linq; namespace Welcome_to_AtCoder { class Program { static void Main(string[] args) { string input = Console.ReadLine(); var array = input.Split(' ').Select(_ => int.Parse(_)).ToArray(); var n = array[0]; var d = array[1]; var hoge = d * 2 + 1; int result = n % hoge == 0 ? (n / hoge) : (n / hoge) + 1; Console.WriteLine(result); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
117
2
using System; using System.IO; using System.Collections.Generic; namespace _134 { class Program { static void Main(string[] args) { // Console.SetIn(new StreamReader("input.txt")); solve_134B(); } public static void solve_134B() { string[] nd = Console.ReadLine().Split(' '); int n = Convert.ToInt32(nd[0]); int d = Convert.ToInt32(nd[1]); int res = n % (d * 2 + 1) == 0 ? n / (d * 2) : n / (d * 2 + 1) + 1; Console.WriteLine(res); } public static void solve_134A() { int r = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(3 * r * r); } } }
using System; using System.IO; using System.Collections.Generic; namespace _134 { class Program { static void Main(string[] args) { // Console.SetIn(new StreamReader("input.txt")); solve_134B(); } public static void solve_134B() { string[] nd = Console.ReadLine().Split(' '); int n = Convert.ToInt32(nd[0]); int d = Convert.ToInt32(nd[1]); int res = n % (d * 2 + 1) == 0 ? n / (d * 2 + 1) : n / (d * 2 + 1) + 1; Console.WriteLine(res); } public static void solve_134A() { int r = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(3 * r * r); } } }
[["+", 0, 41, 64, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 41, 64, 16, 12, 23, 0, 16, 12, 203]]
8
166
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program_B { static void Main(string[] args) { float N = 0; var D = 0; { var input = Console.ReadLine().Split(' '); N = float.Parse(input[0]); D = Int32.Parse(input[1]); } Console.WriteLine(Math.Ceiling(N / (D + 1))); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program_B { static void Main(string[] args) { float N = 0; var D = 0; { var input = Console.ReadLine().Split(' '); N = float.Parse(input[0]); D = Int32.Parse(input[1]); } Console.WriteLine(Math.Ceiling(N / (D * 2 + 1))); } }
[["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 203]]
8
112
2
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]), d = int.Parse(s[1]); int ans = n / (2 * d); if (n % (2 * d) != 0) ans++; Console.WriteLine(ans); } } // mcs Main.cs // mono Main.exe
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]), d = int.Parse(s[1]); int ans = n / (2 * d + 1); if (n % (2 * d + 1) != 0) ans++; Console.WriteLine(ans); } } // mcs Main.cs // mono Main.exe
[["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 12, 203]]
8
103
4
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 a = CinTAr(); double one = a[1] * 2; Cout(Math.Ceiling(a[0] / one)); Cin(); } 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 a = CinTAr(); double one = a[1] * 2 + 1; Cout(Math.Ceiling(a[0] / one)); Cin(); } 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)); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
439
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = new List<int>(); for (int i = 0; i < N; i++) { A.Add(int.Parse(Console.ReadLine())); } // 降順ソートする var maxList = new List<int>(A); maxList.Sort((a, b) => (b - a)); // 先頭二つを保存 var max = maxList[0]; var subMax = maxList[1]; for (int i = 0; i < N - 1; i++) { if (A[i] == max) Console.WriteLine(subMax); Console.WriteLine(max); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = new List<int>(); for (int i = 0; i < N; i++) { A.Add(int.Parse(Console.ReadLine())); } // 降順ソートする var maxList = new List<int>(A); maxList.Sort((a, b) => (b - a)); // 先頭二つを保存 var max = maxList[0]; var subMax = maxList[1]; for (int i = 0; i < N; i++) { if (A[i] == max) Console.WriteLine(subMax); else Console.WriteLine(max); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
8
180
3
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace C { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] A = new int[n]; for (int i = 0; i < n; i++) { int a = int.Parse(Console.ReadLine()); A[i] = a; } var SA = A.OrderByDescending(x => x).ToArray(); int max = SA[0]; for (int i = 0; i < n; i++) { if (max == A[i]) Console.WriteLine(SA[i]); else Console.WriteLine(max); } } } } // WA //ここまでする必要ない気がする // namespace C //{ // class Program // { // static void Main(string[] args) // { // int n = int.Parse(Console.ReadLine()); // int[] A = new int[n]; // var q = new PriorityQueue<int>(n); // for(int i=0; i < n; i++) // { // int a = int.Parse(Console.ReadLine()); // A[i] = a; // q.Push(a); // } // for(int i=0; i < n; i++) // { // int temp =q.Peek(); // if (temp == // A[i])//二番目に大きい数を知りたいので、最大の数をいったん出して戻す、そうそう頻発しないからこれで平気? // { // int max = q.Pop(); // int ans = q.Pop(); // q.Push(max); // Console.WriteLine(ans); // } // else Console.WriteLine(temp); // } // } // } // class PriorityQueue<T> where T : IComparable<T> // { // private readonly T[] _array; // private readonly IComparer _comparer; // public int Count { get; private set; } = 0; // public T Root => _array[0]; // public PriorityQueue(int capacity, IComparer comparer = null) // { // _array = new T[capacity]; // _comparer = comparer; // } // /// <summary> // /// 要素を挿入する // /// </summary> // public void Push(T item) // { // _array[this.Count] = item; // Count += 1; // var n = Count - 1; // // 末尾(追加した)のノードの番号 while (n != 0) // { // var parent = (n - 1) / 2; // 親ノードの番号 // if (Compare(_array[n], _array[parent]) > 0) // { // Swap(n, parent); // n = parent; // } // else // { // break; // } // } // } // /// <summary> // /// 優先度の一番高いものを取り出す // /// </summary> // public T Pop() // { // Swap(0, this.Count - 1); // 先頭要素を末尾にする // Count -= 1; // var parent = 0; // 親ノードの番号 // while (true) // { // var child = 2 * parent + 1; // 子ノードの番号 // if (child > Count - 1) break; // // 値の大きい方の子を選ぶ // if (child < Count - 1 && Compare(_array[child], _array[child + // 1]) < 0) child += 1; // // 子の方が親より大きければ入れ替える // if (Compare(_array[parent], _array[child]) < 0) // { // Swap(parent, child); // parent = child; // } // else // { // break; // } // } // return _array[Count]; // } // /// <summary> // /// 優先度の一番高いものを参照する // /// </summary> // public T Peek() // { // return _array[0]; // } // /// <summary> // /// 大きいものから列挙していく // /// withPop = // falseのときは順番関係なく取り出しもしないが素早く全要素を取得できる  // /// </summary> // public IEnumerable<T> GetAllElements(bool withPop = true) // { // int count = Count; // for (int i = 0; i < count; i++) // { // if (withPop) yield return Pop(); // else yield return _array[count - i - 1]; // } // } // private int Compare(T a, T b) // { // if (_comparer == null) return a.CompareTo(b); // return _comparer.Compare(a, b); // } // private void Swap(int a, int b) // { // var tmp = _array[a]; // _array[a] = _array[b]; // _array[b] = tmp; // } // } //}
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace C { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] A = new int[n]; for (int i = 0; i < n; i++) { int a = int.Parse(Console.ReadLine()); A[i] = a; } var SA = A.OrderByDescending(x => x).ToArray(); int max = SA[0]; for (int i = 0; i < n; i++) { if (max == A[i]) Console.WriteLine(SA[1]); else Console.WriteLine(max); } } } } // WA //ここまでする必要ない気がする // namespace C //{ // class Program // { // static void Main(string[] args) // { // int n = int.Parse(Console.ReadLine()); // int[] A = new int[n]; // var q = new PriorityQueue<int>(n); // for(int i=0; i < n; i++) // { // int a = int.Parse(Console.ReadLine()); // A[i] = a; // q.Push(a); // } // for(int i=0; i < n; i++) // { // int temp =q.Peek(); // if (temp == // A[i])//二番目に大きい数を知りたいので、最大の数をいったん出して戻す、そうそう頻発しないからこれで平気? // { // int max = q.Pop(); // int ans = q.Pop(); // q.Push(max); // Console.WriteLine(ans); // } // else Console.WriteLine(temp); // } // } // } // class PriorityQueue<T> where T : IComparable<T> // { // private readonly T[] _array; // private readonly IComparer _comparer; // public int Count { get; private set; } = 0; // public T Root => _array[0]; // public PriorityQueue(int capacity, IComparer comparer = null) // { // _array = new T[capacity]; // _comparer = comparer; // } // /// <summary> // /// 要素を挿入する // /// </summary> // public void Push(T item) // { // _array[this.Count] = item; // Count += 1; // var n = Count - 1; // // 末尾(追加した)のノードの番号 while (n != 0) // { // var parent = (n - 1) / 2; // 親ノードの番号 // if (Compare(_array[n], _array[parent]) > 0) // { // Swap(n, parent); // n = parent; // } // else // { // break; // } // } // } // /// <summary> // /// 優先度の一番高いものを取り出す // /// </summary> // public T Pop() // { // Swap(0, this.Count - 1); // 先頭要素を末尾にする // Count -= 1; // var parent = 0; // 親ノードの番号 // while (true) // { // var child = 2 * parent + 1; // 子ノードの番号 // if (child > Count - 1) break; // // 値の大きい方の子を選ぶ // if (child < Count - 1 && Compare(_array[child], _array[child + // 1]) < 0) child += 1; // // 子の方が親より大きければ入れ替える // if (Compare(_array[parent], _array[child]) < 0) // { // Swap(parent, child); // parent = child; // } // else // { // break; // } // } // return _array[Count]; // } // /// <summary> // /// 優先度の一番高いものを参照する // /// </summary> // public T Peek() // { // return _array[0]; // } // /// <summary> // /// 大きいものから列挙していく // /// withPop = // falseのときは順番関係なく取り出しもしないが素早く全要素を取得できる  // /// </summary> // public IEnumerable<T> GetAllElements(bool withPop = true) // { // int count = Count; // for (int i = 0; i < count; i++) // { // if (withPop) yield return Pop(); // else yield return _array[count - i - 1]; // } // } // private int Compare(T a, T b) // { // if (_comparer == null) return a.CompareTo(b); // return _comparer.Compare(a, b); // } // private void Swap(int a, int b) // { // var tmp = _array[a]; // _array[a] = _array[b]; // _array[b] = tmp; // } // } //}
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
295
2
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_134 { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var N = Sarray()[0]; var Ai = new long[N]; for (var i = 0; i < N; ++i) { Ai[i] = Sarray()[0]; } var max = new long[N]; var revmax = new long[N]; max[0] = Ai[0]; revmax[0] = Ai[N - 1]; for (var i = 1; i < N; ++i) { max[i] = Math.Max(max[i - 1], Ai[i]); revmax[i] = Math.Max(max[i - 1], Ai[N - 1 - i]); } WriteLine(revmax[N - 2]); for (var i = 0; i < N - 2; ++i) { WriteLine(Math.Max(max[i], revmax[N - 3 - i])); } WriteLine(max[N - 2]); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_134 { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var N = Sarray()[0]; var Ai = new long[N]; for (var i = 0; i < N; ++i) { Ai[i] = Sarray()[0]; } var max = new long[N]; var revmax = new long[N]; max[0] = Ai[0]; revmax[0] = Ai[N - 1]; for (var i = 1; i < N; ++i) { max[i] = Math.Max(max[i - 1], Ai[i]); revmax[i] = Math.Max(revmax[i - 1], Ai[N - 1 - i]); } WriteLine(revmax[N - 2]); for (var i = 0; i < N - 2; ++i) { WriteLine(Math.Max(max[i], revmax[N - 3 - i])); } WriteLine(max[N - 2]); } } }
[["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22]]
8
355
2
// C - Exception Handling // 20190912 using System; using System.Linq; using System.Collections.Generic; namespace C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } var ACopy = A.OrderByDescending(a => -a).ToList(); for (int i = 0; i < N; i++) { if (A[i] == ACopy[0]) Console.WriteLine(ACopy[1]); else Console.WriteLine(ACopy[0]); } // for(int i=0;i<N;i++) // { // int max = 0; // for(int j=0;j<i;j++) // { // if(A[j]>max) max = A[j]; // } // for(int j=i+1;j<N;j++) // { // if(A[i]>max) max = A[j]; // } // Console.WriteLine(max); // } } } }
// C - Exception Handling // 20190912 using System; using System.Linq; using System.Collections.Generic; namespace C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } var ACopy = A.OrderBy(a => -a).ToList(); for (int i = 0; i < N; i++) { if (A[i] == ACopy[0]) Console.WriteLine(ACopy[1]); else Console.WriteLine(ACopy[0]); } } } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
8
170
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace lineAralgebra { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var list = new List<int>(); for (int i = 0; i < n; i++) { list.Add(int.Parse(Console.ReadLine())); } var tempArray = new List<int>(list); tempArray.Sort(); var max = tempArray.Last(); // Console.WriteLine(""); for (var i = 0; i < n; i++) { if (list[i] != max) { Console.WriteLine(max); } else { Console.WriteLine(tempArray[tempArray.Count - 1]); } } } } } // 3 // 1 // 4 // 3
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace lineAralgebra { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var list = new List<int>(); for (int i = 0; i < n; i++) { list.Add(int.Parse(Console.ReadLine())); } var tempArray = new List<int>(list); tempArray.Sort(); var max = tempArray.Last(); // Console.WriteLine(""); for (var i = 0; i < n; i++) { if (list[i] != max) { Console.WriteLine(max); } else { Console.WriteLine(tempArray[tempArray.Count - 2]); } } } } } // 3 // 1 // 4 // 3
[["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
179
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var N = int.Parse(Console.ReadLine()); var A = new List<int>(); for (int i = 0; i < N; ++i) A.Add(int.Parse(Console.ReadLine())); var B = new List<int>(A); B.Remove(B.Max()); var max = A.Max(); var secondmax = B.Max(); if (max == secondmax) for (int i = 0; i < N; ++i) Console.WriteLine(max); else { var indx = A.IndexOf(A.Max()); if (indx == 0) { Console.WriteLine(secondmax); for (int i = indx + 1; i < N; ++i) { Console.WriteLine(max); } } else if (indx == N - 1) { for (int i = 0; i < indx - 1; ++i) { Console.WriteLine(max); } Console.WriteLine(secondmax); } else { for (int i = 0; i < indx; ++i) { Console.WriteLine(max); } Console.WriteLine(secondmax); for (int i = indx + 1; i < N; ++i) { Console.WriteLine(max); } } } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var N = int.Parse(Console.ReadLine()); var A = new List<int>(); for (int i = 0; i < N; ++i) A.Add(int.Parse(Console.ReadLine())); var B = new List<int>(A); B.Remove(B.Max()); var max = A.Max(); var secondmax = B.Max(); if (max == secondmax) for (int i = 0; i < N; ++i) Console.WriteLine(max); else { var indx = A.IndexOf(A.Max()); if (indx == 0) { Console.WriteLine(secondmax); for (int i = indx + 1; i < N; ++i) { Console.WriteLine(max); } } else if (indx == N - 1) { for (int i = 0; i < indx; ++i) { Console.WriteLine(max); } Console.WriteLine(secondmax); } else { for (int i = 0; i < indx; ++i) { Console.WriteLine(max); } Console.WriteLine(secondmax); for (int i = indx + 1; i < N; ++i) { Console.WriteLine(max); } } } } }
[["-", 64, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 64, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
307
2
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { public class Prog { const int MOD = 1000000007; public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Prog().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; var d = cin.ReadIntArray(n); var max = d.Max(); var maxCount = d.Count(x => x == max); if (maxCount >= 2) { for (int i = 0; i < n; i++) { Console.WriteLine(max); } } else { var second = 0; foreach (var item in d) { if (second < n && n < max) { second = n; } } foreach (var item in d) { if (item == max) { Console.WriteLine(second); } else { Console.WriteLine(max); } } } } } class Modulo { private const int M = 2019; 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; } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { public class Prog { const int MOD = 1000000007; public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Prog().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; var d = cin.ReadIntArray(n); var max = d.Max(); var maxCount = d.Count(x => x == max); if (maxCount >= 2) { for (int i = 0; i < n; i++) { Console.WriteLine(max); } } else { var second = 0; foreach (var item in d) { if (second < item && item < max) { second = item; } } foreach (var item in d) { if (item == max) { Console.WriteLine(second); } else { Console.WriteLine(max); } } } } } class Modulo { private const int M = 2019; 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; } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
8
959
6
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { partial class Program { static void Main(string[] args) { //↓ var s = Console.ReadLine(); var r = new int[s.Length]; var prev = 'L'; var a = 0; var b = 0; var count = 0; var lastR = 0; var firstL = 0; for (int i = 0; i < s.Length; i++) { var c = s[i]; if (prev == 'R') { if (c == 'R') { //...RR lastR = i; if (count % 2 == 0) { a++; } else { b++; } } else { //...RL firstL = i; if (count % 2 == 0) { a++; } else { b++; } } } else { if (c == 'R') { //...LR if ((i + firstL) % 2 == 0) { r[lastR] = a; r[firstL] = b; } else { r[lastR] = b; r[firstL] = a; } // reset a = 1; b = 0; count = 1; lastR = i; prev = c; continue; } else { //...LL if (count % 2 == 0) { a++; } else { b++; } } } prev = c; count++; } if ((count + lastR) % 2 != 0) { r[lastR] = a; r[firstL] = b; } else { r[lastR] = b; r[firstL] = a; } for (int i = 0; i < r.Length; i++) { Console.Write(r[i]); Console.Write(' '); } Console.WriteLine(); //↑ } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { partial class Program { static void Main(string[] args) { //↓ var s = Console.ReadLine(); var r = new int[s.Length]; var prev = 'L'; var a = 0; var b = 0; var count = 0; var lastR = 0; var firstL = 0; for (int i = 0; i < s.Length; i++) { var c = s[i]; if (prev == 'R') { if (c == 'R') { //...RR lastR = i; if (count % 2 == 0) { a++; } else { b++; } } else { //...RL firstL = i; if (count % 2 == 0) { a++; } else { b++; } } } else { if (c == 'R') { //...LR if ((i + firstL) % 2 == 0) { r[lastR] = a; r[firstL] = b; } else { r[lastR] = b; r[firstL] = a; } // reset a = 1; b = 0; count = 1; lastR = i; prev = c; continue; } else { //...LL if (count % 2 == 0) { a++; } else { b++; } } } prev = c; count++; } //...LR if ((r.Length + firstL) % 2 == 0) { r[lastR] = a; r[firstL] = b; } else { r[lastR] = b; r[firstL] = a; } for (int i = 0; i < r.Length; i++) { Console.Write(r[i]); Console.Write(' '); } Console.WriteLine(); //↑ } } }
[["-", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 31, 16, 31, 23, 0, 16, 31, 214, 205, 22], ["+", 31, 16, 31, 23, 0, 16, 31, 214, 0, 131], ["+", 31, 16, 31, 23, 0, 16, 31, 214, 141, 22], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60]]
8
386
8
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } private const int MOD = 1000000007; private const int MAX = 100001; static long[] fac = new long[MAX]; static long[] finv = new long[MAX]; static long[] inv = new long[MAX]; public class Info { public int idx; public int cntR; public int cntL; } static void Solve() { var s = Input.Next(); var infos = new List<Info>(); var curInfo = new Info() { idx = 0, cntR = 1 }; infos.Add(curInfo); for (int i = 1; i < s.Length; ++i) { var c = s[i]; if (s[i - 1] == 'R') { if (c == 'R') { curInfo.cntR++; curInfo.idx = i; } else { curInfo.cntL++; } } else // Lだよ { if (c == 'R') { curInfo = new Info() { idx = i, cntR = 1 }; infos.Add(curInfo); } else { curInfo.cntL++; } } } var ans = new int[s.Length]; foreach (var info in infos) { int total = info.cntR + info.cntL; int r = 0; int l = 0; if ((total) % 2 == 0) { r = total / 2; l = total / 2; } else if (info.cntR > info.cntL) { r = total / 2 + 1; l = total / 2; } else { r = total / 2; l = total / 2 + 1; } ans[info.idx] = l; ans[info.idx + 1] = r; } Console.WriteLine(string.Join(" ", ans)); } #region よく使う便利関数 static void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long COM(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static void Swap<T>(ref T x, ref T y) { T t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } private const int MOD = 1000000007; private const int MAX = 100001; static long[] fac = new long[MAX]; static long[] finv = new long[MAX]; static long[] inv = new long[MAX]; public class Info { public int idx; public int cntR; public int cntL; } static void Solve() { var s = Input.Next(); var infos = new List<Info>(); var curInfo = new Info() { idx = 0, cntR = 1 }; infos.Add(curInfo); for (int i = 1; i < s.Length; ++i) { var c = s[i]; if (s[i - 1] == 'R') { if (c == 'R') { curInfo.cntR++; curInfo.idx = i; } else { curInfo.cntL++; } } else // Lだよ { if (c == 'R') { curInfo = new Info() { idx = i, cntR = 1 }; infos.Add(curInfo); } else { curInfo.cntL++; } } } var ans = new int[s.Length]; foreach (var info in infos) { int total = info.cntR + info.cntL; int r = 0; int l = 0; if ((total) % 2 == 0) { r = total / 2; l = total / 2; } else if (info.cntR % 2 == 0) { r = total / 2 + 1; l = total / 2; } else { r = total / 2; l = total / 2 + 1; } ans[info.idx] = l; ans[info.idx + 1] = r; } Console.WriteLine(string.Join(" ", ans)); } #region よく使う便利関数 static void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long COM(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static void Swap<T>(ref T x, ref T y) { T t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["-", 0, 57, 75, 57, 15, 16, 12, 214, 205, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 214, 0, 131], ["-", 0, 57, 75, 57, 15, 16, 12, 214, 141, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 109], ["+", 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]]
8
2,588
8
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { int N, K; int[] A; public void Solve(Scanner sc) { sc.Make(out N, out K); A = sc.ArrInt; var S = A.Sum(); var res = 0; for (int i = 1; i * i <= S; i++) { if (S % i != 0) continue; if (ch(i)) chmax(ref res, i); if (ch(S / i)) chmax(ref res, S / i); } WriteLine(res); } bool ch(int g) { var B = A.Select(v => v % g).ToArray(); Array.Sort(B); int[] R = new int[N + 1]; for (int i = N - 1; i >= 0; i--) { R[i] = R[i + 1] + g - B[i]; } var l = 0; for (int i = 0; i < N; i++) { l += B[i]; if (R[i + 1] <= K && l <= K) return true; } return false; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public 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 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 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>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { int N, K; int[] A; public void Solve(Scanner sc) { sc.Make(out N, out K); A = sc.ArrInt; var S = A.Sum(); var res = 0; for (int i = 1; i * i <= S; i++) { if (S % i != 0) continue; if (ch(i)) chmax(ref res, i); if (ch(S / i)) chmax(ref res, S / i); } WriteLine(res); } bool ch(int g) { var B = A.Select(v => v % g).ToArray(); Array.Sort(B); long[] R = new long[N + 1]; for (int i = N - 1; i >= 0; i--) { R[i] = R[i + 1] + g - B[i]; } var l = 0L; for (int i = 0; i < N; i++) { l += B[i]; if (R[i + 1] <= K && l <= K) return true; } return false; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public 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 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 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>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
[["-", 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
1,793
6
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_13 { class Program { //配列にする static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } // Listにする static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Slist(); var sum = Ai.Sum(); var max = Ai.Max(); if (0 == max) { WriteLine(0); return; } var dc = yaku(sum).OrderByDescending(e => e.Key); foreach (var pk in dc) { Ai.Sort((l, r) => (int)(r % pk.Key - l % pk.Key)); var b = 0; var e = (int)N - 1; var ln = Ai[b] % pk.Key; var rn = Ai[e] % pk.Key; var ope = 0L; while (b < e) { if (K < ope) break; if (pk.Key == ln + rn) { ope += rn; ln = Ai[++b] % pk.Key; rn = Ai[--e] % pk.Key; ; if (e <= b) { if (ope <= K) { WriteLine(pk.Key); return; } } } else if (pk.Key < ln + rn) { ope += pk.Key - ln; rn = ln + rn - pk.Key; ln = Ai[++b] % pk.Key; } else { ope += rn; ln += rn; rn = Ai[--e] % pk.Key; } } } } static Dictionary<long, long> yaku(long n) { var ret = new Dictionary<long, long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret[i] = 1; ret[n / i] = 1; } } return ret; } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_13 { class Program { //配列にする static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } // Listにする static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Slist(); var sum = Ai.Sum(); var max = Ai.Max(); if (0 == max) { WriteLine(0); return; } var dc = yaku(sum).OrderByDescending(e => e.Key); foreach (var pk in dc) { Ai.Sort((l, r) => (int)(r % pk.Key - l % pk.Key)); var b = 0; var e = (int)N - 1; var ln = Ai[b] % pk.Key; var rn = Ai[e] % pk.Key; var ope = 0L; while (b < e) { if (K < ope) break; if (pk.Key == ln + rn) { ope += rn; ln = Ai[++b] % pk.Key; rn = Ai[--e] % pk.Key; ; if (e <= b) { if (ope <= K) { WriteLine(pk.Key); return; } } } else if (pk.Key < ln + rn) { ope += pk.Key - ln; rn = ln + rn - pk.Key; ln = Ai[++b] % pk.Key; } else { ope += rn; ln += rn; rn = Ai[--e] % pk.Key; } } } WriteLine(1); } static Dictionary<long, long> yaku(long n) { var ret = new Dictionary<long, long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret[i] = 1; ret[n / i] = 1; } } return ret; } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
529
5
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace CSharp { static class Program { static void Main(string[] args) { long n, k; ReadLong(out n, out k); int[] A = ReadIntArray(); int ans = Solve(A, k); Console.WriteLine(ans); } private static int Solve(int[] A, long k) { int[] divisors = EnumerateDivisors(A.Sum()).OrderByDescending(x => x).ToArray(); foreach (var d in divisors) { int[] R = A.Select(a => a % d).OrderBy(x => x).ToArray(); int[] add = new int[A.Length + 1]; int[] sub = new int[A.Length + 1]; for (int i = 0; i < A.Length; i++) { int ri = A.Length - i - 1; add[i + 1] = add[i] + R[i]; sub[ri] = sub[ri + 1] + (d - R[ri]); } // Console.WriteLine($"sub: {string.Join(", ", sub)}"); // Console.WriteLine($"add: {string.Join(", ", add)}"); for (int i = 0; i < A.Length; i++) { // Console.WriteLine($"d = {d}, {sub[i]} {add[i]}"); if (sub[i] == add[i] && sub[i] < k) { return d; } } } return 1; } static IEnumerable<int> EnumerateDivisors(int n) { for (int i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; if (n / i != i) { yield return n / i; } } } } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count) .Select(_ => int.Parse(Console.ReadLine())) .ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count) .Select(_ => long.Parse(Console.ReadLine())) .ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace CSharp { static class Program { static void Main(string[] args) { long n, k; ReadLong(out n, out k); int[] A = ReadIntArray(); int ans = Solve(A, k); Console.WriteLine(ans); } private static int Solve(int[] A, long k) { int[] divisors = EnumerateDivisors(A.Sum()).OrderByDescending(x => x).ToArray(); foreach (var d in divisors) { int[] R = A.Select(a => a % d).OrderBy(x => x).ToArray(); int[] add = new int[A.Length + 1]; int[] sub = new int[A.Length + 1]; for (int i = 0; i < A.Length; i++) { int ri = A.Length - i - 1; add[i + 1] = add[i] + R[i]; sub[ri] = sub[ri + 1] + (d - R[ri]); } // Console.WriteLine($"sub: {string.Join(", ", sub)}"); // Console.WriteLine($"add: {string.Join(", ", add)}"); for (int i = 0; i < A.Length; i++) { // Console.WriteLine($"d = {d}, {sub[i]} {add[i]}"); if (sub[i] == add[i] && sub[i] <= k) { return d; } } } return 1; } static IEnumerable<int> EnumerateDivisors(int n) { for (int i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; if (n / i != i) { yield return n / i; } } } } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count) .Select(_ => int.Parse(Console.ReadLine())) .ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count) .Select(_ => long.Parse(Console.ReadLine())) .ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } #endregion } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
883
2
using System; using System.Linq; class F { static void Main() { var n = int.Parse(Console.ReadLine()); var t = new int [n] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .OrderBy(p => p[0]) .Select(p => p[1]) .ToArray(); var yx = Enumerable.Range(0, n).ToArray(); var xy = (int[])yx.Clone(); Array.Sort(t, yx); yx.CopyTo(t, n); Array.Sort(t, xy); int ss = 64, sc = n / ss + 1; var s = new int[sc, sc]; for (int i = 0; i < n; i++) s[i / ss, xy[i] / ss]++; for (int i = 0; i < sc; i++) for (int j = 1; j < sc; j++) s[i, j] += s[i, j - 1]; for (int j = 0; j < sc; j++) for (int i = 1; i < sc; i++) s[i, j] += s[i - 1, j]; var c = MInt(n * MPow(2, n) - n); for (int i = 0; i < n; i++) { var v = xy[i]; var li = i >= ss && v >= ss ? s[i / ss - 1, v / ss - 1] : 0; var ix = i - i % ss; for (int i2 = ix; i2 < i; i2++) if (xy[i2] < v) li++; for (int j2 = v - v % ss; j2 < v; j2++) if (yx[j2] < ix) li++; c -= MPow(2, i) + MPow(2, n - 1 - i) + MPow(2, v) + MPow(2, n - 1 - v); c += MPow(2, li) + MPow(2, i - li) + MPow(2, v - li) + MPow(2, n - 1 + li - i - v); c = MInt(c); } Console.WriteLine(c); } const int M = 998244353; static long MPow(long b, long i) { for (var r = 1L;; b = b * b % M) { if (i % 2 > 0) r = r * b % M; if ((i /= 2) < 1) return r; } } static long MInt(long x) => (x %= M) < 0 ? x + M : x; }
using System; using System.Linq; class F { static void Main() { var n = int.Parse(Console.ReadLine()); var t = new int [n] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .OrderBy(p => p[0]) .Select(p => p[1]) .ToArray(); var yx = Enumerable.Range(0, n).ToArray(); var xy = (int[])yx.Clone(); Array.Sort(t, yx); yx.CopyTo(t, 0); Array.Sort(t, xy); int ss = 64, sc = n / ss + 1; var s = new int[sc, sc]; for (int i = 0; i < n; i++) s[i / ss, xy[i] / ss]++; for (int i = 0; i < sc; i++) for (int j = 1; j < sc; j++) s[i, j] += s[i, j - 1]; for (int j = 0; j < sc; j++) for (int i = 1; i < sc; i++) s[i, j] += s[i - 1, j]; var c = MInt(n * MPow(2, n) - n); for (int i = 0; i < n; i++) { var v = xy[i]; var li = i >= ss && v >= ss ? s[i / ss - 1, v / ss - 1] : 0; var ix = i - i % ss; for (int i2 = ix; i2 < i; i2++) if (xy[i2] < v) li++; for (int j2 = v - v % ss; j2 < v; j2++) if (yx[j2] < ix) li++; c -= MPow(2, i) + MPow(2, n - 1 - i) + MPow(2, v) + MPow(2, n - 1 - v); c += MPow(2, li) + MPow(2, i - li) + MPow(2, v - li) + MPow(2, n - 1 + li - i - v); c = MInt(c); } Console.WriteLine(c); } const int M = 998244353; static long MPow(long b, long i) { for (var r = 1L;; b = b * b % M) { if (i % 2 > 0) r = r * b % M; if ((i /= 2) < 1) return r; } } static long MInt(long x) => (x %= M) < 0 ? x + M : x; }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
605
2
using System; using System.Collections.Generic; using System.Linq; namespace easy_Atcoder { class Program { static void Main(string[] args) { float[] ab = Array.ConvertAll(Console.ReadLine().Split(), float.Parse); float resf = (ab[0] + ab[1]) / 2; int res = (int)resf; if (res == resf) { Console.WriteLine(res); } else { Console.WriteLine("IMPOSSIBLE"); } } // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse); // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // long N = NK[0]; // long K = NK[1]; // long K = long.Parse(Console.ReadLine()); // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // string S = Console.ReadLine(); // int x = int.Parse(Console.ReadLine()); // int b = int.Parse(Console.ReadLine()); // int N = int.Parse(Console.ReadLine()); // float N = float.Parse(Console.ReadLine()); // string c = Console.ReadLine(); // string B = Console.ReadLine(); // string[] s = Console.ReadLine().Split(); // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), // Console.ReadLine() }).Select(float.Parse); float[] a = // Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X = // Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new // int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[] // s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new // Dictionary<long,long>(); for(int i=0;i<s[0];i++){ // long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];} // else{hs.Add(q[0],q[1]);} // } // //最小公倍数 // static long Lcm(long a, long b) // { // return a/Gcd(a,b)*b; // } // //最大公約数 // static long Gcd(long m, long n) // { // if(n==0)return m; // return Gcd(n,m%n); // } } }
using System; using System.Collections.Generic; using System.Linq; namespace easy_Atcoder { class Program { static void Main(string[] args) { double[] ab = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); double resf = (ab[0] + ab[1]) / 2; int res = (int)resf; if (res == resf) { Console.WriteLine(res); } else { Console.WriteLine("IMPOSSIBLE"); } } // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse); // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // long N = NK[0]; // long K = NK[1]; // long K = long.Parse(Console.ReadLine()); // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // string S = Console.ReadLine(); // int x = int.Parse(Console.ReadLine()); // int b = int.Parse(Console.ReadLine()); // int N = int.Parse(Console.ReadLine()); // float N = float.Parse(Console.ReadLine()); // string c = Console.ReadLine(); // string B = Console.ReadLine(); // string[] s = Console.ReadLine().Split(); // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), // Console.ReadLine() }).Select(float.Parse); float[] a = // Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X = // Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new // int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[] // s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new // Dictionary<long,long>(); for(int i=0;i<s[0];i++){ // long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];} // else{hs.Add(q[0],q[1]);} // } // //最小公倍数 // static long Lcm(long a, long b) // { // return a/Gcd(a,b)*b; // } // //最大公約数 // static long Gcd(long m, long n) // { // if(n==0)return m; // return Gcd(n,m%n); // } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
146
6
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] ab = ReadLineIntArray(); int min = Math.Min(ab[0], ab[1]); int max = Math.Max(ab[0], ab[1]); if ((max - min) % 2 == 0) { Console.WriteLine(max - (max - min)); } else { Console.WriteLine("IMPOSSIBLE"); } } static string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] salphabet = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<int, long> myTable = new Dictionary<int, long>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static long[,] Combi = new long[2001, 2001]; static long div = 1000000007; static int[] atest = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private decimal ReadLineDecimal() { return decimal.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } static private long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } else if (Combi[n, r] == 0) { Combi[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return Combi[n, r]; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] ab = ReadLineIntArray(); int min = Math.Min(ab[0], ab[1]); int max = Math.Max(ab[0], ab[1]); if ((max - min) % 2 == 0) { Console.WriteLine(max - ((max - min) / 2)); } else { Console.WriteLine("IMPOSSIBLE"); } } static string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] salphabet = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" }; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<int, long> myTable = new Dictionary<int, long>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static long[,] Combi = new long[2001, 2001]; static long div = 1000000007; static int[] atest = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private decimal ReadLineDecimal() { return decimal.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } static private long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } else if (Combi[n, r] == 0) { Combi[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return Combi[n, r]; } }
[["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 85], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203]]
8
1,193
4
using System; using System.Collections.Generic; using System.Linq; namespace ABC135A { class Program { static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { public Solver() { Input input = new Input(); var ab = input.ArrayLong(); A = ab[0]; B = ab[1]; } private long A; private long B; public void Solve() { if ((A - B) % 2 == 1) { Console.WriteLine("IMPOSSIBLE"); return; } Console.WriteLine(Math.Min(A, B) + Math.Abs(A - B) / 2); } } class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public string String() { return Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public string[] ArrayString(int rowNumber) { string[] s = new string[rowNumber]; for (int i = 0; i < rowNumber; i++) { s[i] = String(); } return s; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public int Int() { return int.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の配列</returns> public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <param name="rowNumber">行数</param> /// <returns>int型の配列</returns> public int[] ArrayInt(int rowNumber) { int[] ints = new int[rowNumber]; for (int i = 0; i < rowNumber; i++) { ints[i] = Int(); } return ints; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の値</returns> public long Long() { return long.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の配列</returns> public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); } public long[] ArrayLong(int rowNumber) { long[] longs = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { longs[i] = Long(); } return longs; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public double Double() { return double.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public double[] ArrayDouble() { return Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { return String().Split(' '); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC135A { class Program { static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { public Solver() { Input input = new Input(); var ab = input.ArrayLong(); A = ab[0]; B = ab[1]; } private long A; private long B; public void Solve() { if ((A - B) % 2 != 0) { Console.WriteLine("IMPOSSIBLE"); return; } Console.WriteLine(Math.Min(A, B) + Math.Abs(A - B) / 2); } } class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public string String() { return Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public string[] ArrayString(int rowNumber) { string[] s = new string[rowNumber]; for (int i = 0; i < rowNumber; i++) { s[i] = String(); } return s; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public int Int() { return int.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の配列</returns> public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <param name="rowNumber">行数</param> /// <returns>int型の配列</returns> public int[] ArrayInt(int rowNumber) { int[] ints = new int[rowNumber]; for (int i = 0; i < rowNumber; i++) { ints[i] = Int(); } return ints; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の値</returns> public long Long() { return long.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の配列</returns> public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); } public long[] ArrayLong(int rowNumber) { long[] longs = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { longs[i] = Long(); } return longs; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public double Double() { return double.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public double[] ArrayDouble() { return Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { return String().Split(' '); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
507
4
using System; using System.Collections.Generic; using System.Linq; public class AtCoderA { static void Main() { long a; long b; { var line = Console.ReadLine(); var words = line.Split(' '); a = long.Parse(words[0]); b = long.Parse(words[1]); } Console.WriteLine((a + b % 2 == 0) ? ((a + b) / 2).ToString() : "IMPOSSIBLE"); } }
using System; using System.Collections.Generic; using System.Linq; public class AtCoderA { static void Main() { long a; long b; { var line = Console.ReadLine(); var words = line.Split(' '); a = long.Parse(words[0]); b = long.Parse(words[1]); } Console.WriteLine((a + b) % 2 == 0 ? ((a + b) / 2).ToString() : "IMPOSSIBLE"); } }
[["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 3, 4, 0, 28, 0, 41, 15, 23, 0, 25]]
8
113
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int K; K = A + B; if (K % 2 == 0) { Console.WriteLine(K); } else { Console.WriteLine("IMPOSSIVLE"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int K; K = A + B; if (K % 2 == 0) { Console.WriteLine(K / 2); } else { Console.WriteLine("IMPOSSIBLE"); } } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
128
4
namespace AtCoder.ABC.A135 { using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.IO; using AtCoder.ABC.IO; public class Quest { public object Solve(Parser parser) { long a = parser.Long(); long b = parser.Long(); return (a - b) % 2 == 0 ? (Math.Abs(a - b) / 2).ToString() : "IMPOSSIBLE"; } } static class Program { static void Main(string[] args) { var i = new Parser(Console.OpenStandardInput()); var o = new Printer(Console.OpenStandardOutput()); var got = new Quest().Solve(i); o.WriteLine(got); o.Flush(); } } } namespace AtCoder.ABC.IO { #region IO using System; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Globalization; public class Parser { public Parser(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } public IEnumerable<Parser> Take(int n) { return Enumerable.Range(1, n).Select(_ => this); } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } #endregion }
namespace AtCoder.ABC.A135 { using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.IO; using AtCoder.ABC.IO; public class Quest { public object Solve(Parser parser) { long a = parser.Long(); long b = parser.Long(); return (a - b) % 2 == 0 ? ((a + b) / 2).ToString() : "IMPOSSIBLE"; } } static class Program { static void Main(string[] args) { var i = new Parser(Console.OpenStandardInput()); var o = new Printer(Console.OpenStandardOutput()); var got = new Quest().Solve(i); o.WriteLine(got); o.Flush(); } } } namespace AtCoder.ABC.IO { #region IO using System; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Globalization; public class Parser { public Parser(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } public IEnumerable<Parser> Take(int n) { return Enumerable.Range(1, n).Select(_ => this); } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } #endregion }
[["-", 205, 23, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 205, 23, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 205, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 205, 23, 0, 16, 31, 23, 0, 16, 17, 72]]
8
1,010
5
using System; using static System.Math; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int t = a + b; if (t % 2 == 0) { Console.WriteLine("IMPOSSIBLE"); } else { Console.WriteLine(t / 2); } } }
using System; using static System.Math; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int t = a + b; if (t % 2 == 1) { Console.WriteLine("IMPOSSIBLE"); } else { Console.WriteLine(t / 2); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
102
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[0]); int k; k = (a + b) / 2; int ans = Math.Abs(a - k) - Math.Abs(b - k); if (ans == 0) { Console.WriteLine(k.ToString()); } else { Console.WriteLine("IMPOSSIBLE"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int k; k = (a + b) / 2; int ans = Math.Abs(a - k) - Math.Abs(b - k); if (ans == 0) { Console.WriteLine(k.ToString()); } else { Console.WriteLine("IMPOSSIBLE"); } } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
155
2
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[0]); int k1, k2, k3, k4; k1 = (a + b) / 2; k2 = (a - b) / 2; k3 = -(a + b) / 2; k4 = -(a - b) / 2; int ans1 = Math.Abs(a - k1) - Math.Abs(b - k1); int ans2 = Math.Abs(a - k2) - Math.Abs(b - k2); int ans3 = Math.Abs(a - k3) - Math.Abs(b - k3); int ans4 = Math.Abs(a - k4) - Math.Abs(b - k4); if (ans1 == 0) { Console.WriteLine(k1.ToString()); } else if (ans2 == 0) { Console.WriteLine(k2.ToString()); } else if (ans3 == 0) { Console.WriteLine(k3.ToString()); } else if (ans4 == 0) { Console.WriteLine(k3.ToString()); } else { Console.WriteLine("IMPOSSIBLE"); } } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int k1, k2, k3, k4; k1 = (a + b) / 2; k2 = (a - b) / 2; k3 = -(a + b) / 2; k4 = -(a - b) / 2; int ans1 = Math.Abs(a - k1) - Math.Abs(b - k1); int ans2 = Math.Abs(a - k2) - Math.Abs(b - k2); int ans3 = Math.Abs(a - k3) - Math.Abs(b - k3); int ans4 = Math.Abs(a - k4) - Math.Abs(b - k4); if (ans1 == 0) { Console.WriteLine(k1.ToString()); } else if (ans2 == 0) { Console.WriteLine(k2.ToString()); } else if (ans3 == 0) { Console.WriteLine(k3.ToString()); } else if (ans4 == 0) { Console.WriteLine(k3.ToString()); } else { Console.WriteLine("IMPOSSIBLE"); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
288
2
using System; class atcoder { public static void Main() { string[] s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]); int m = int.Parse(s[1]); if ((n + m) % 2 == 0) { Console.WriteLine((n + m) / 2); } else { Console.WriteLine("IMPOSSOBLE"); } } }
using System; class atcoder { public static void Main() { string[] s = Console.ReadLine().Split(' '); int n = int.Parse(s[0]); int m = int.Parse(s[1]); if ((n + m) % 2 == 0) { Console.WriteLine((n + m) / 2); } else { Console.WriteLine("IMPOSSIBLE"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
98
2
using System; using System.Collections.Generic; using System.Linq; public class Program { static void Main(string[] args) { var array = Console.ReadLine() .Split(' ') .Select(int.Parse) .OrderBy(x => x) .ToArray(); var answer = array[1] - array[0]; if (answer % 2 == 0) { Console.WriteLine(answer + array[0]); } else { Console.WriteLine("IMPOSSIBLE"); } } }
using System; using System.Collections.Generic; using System.Linq; public class Program { static void Main(string[] args) { var array = Console.ReadLine() .Split(' ') .Select(int.Parse) .OrderBy(x => x) .ToArray(); var answer = array[1] - array[0]; if (answer % 2 == 0) { Console.WriteLine((answer / 2) + array[0]); } else { Console.WriteLine("IMPOSSIBLE"); } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 85], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
8
112
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0033 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); List<int> Nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>(); List<int> aft = new List<int>(); for (int i = 0; i < Nums.Count(); i++) { aft.Add(Nums[i]); } aft.Sort(); int cnt = 0; for (int i = 0; i < Nums.Count(); i++) { if (Nums[i] != aft[i]) { cnt++; } if (3 <= cnt) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0033 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); List<int> Nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>(); List<int> aft = new List<int>(); for (int i = 0; i < Nums.Count(); i++) { aft.Add(Nums[i]); } aft.Sort(); int cnt = 0; for (int i = 0; i < Nums.Count(); i++) { if (Nums[i] != aft[i]) { cnt++; } if (3 <= cnt) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
213
4
using System; using System.Collections.Generic; using System.Linq; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } public static List<long> GeneratePrime(long max) { long prime; double sqrtMax = Math.Sqrt(max); var primeList = new List<long>(); List<long> searchList = new List<long>(); for (long i = 2; i <= max - 1; i++) { searchList.Add(i); } do { prime = searchList.First(); primeList.Add(prime); searchList.RemoveAll(n => n % prime == 0); } while (prime < sqrtMax); primeList.AddRange(searchList); return primeList; } // 最小公倍数 public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static readonly string Yes = "Yes"; public static readonly string YES = "YES"; public static readonly string No = "No"; public static readonly string NO = "NO"; public static readonly string OK = "OK"; public static readonly string NG = "NG"; void Omame() { cin = new Scanner(); long N = cin.nextLong(); long count = 0; for (int i = 0; i < N; i++) { long tmp = cin.nextLong(); if (tmp != i + 1) { count++; } if (count > 2) { Console.WriteLine(No); return; } } if (count == 0 || count == 2) { Console.WriteLine(Yes); } else { Console.WriteLine(No); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } public static List<long> GeneratePrime(long max) { long prime; double sqrtMax = Math.Sqrt(max); var primeList = new List<long>(); List<long> searchList = new List<long>(); for (long i = 2; i <= max - 1; i++) { searchList.Add(i); } do { prime = searchList.First(); primeList.Add(prime); searchList.RemoveAll(n => n % prime == 0); } while (prime < sqrtMax); primeList.AddRange(searchList); return primeList; } // 最小公倍数 public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static readonly string Yes = "Yes"; public static readonly string YES = "YES"; public static readonly string No = "No"; public static readonly string NO = "NO"; public static readonly string OK = "OK"; public static readonly string NG = "NG"; void Omame() { cin = new Scanner(); long N = cin.nextLong(); long count = 0; for (int i = 0; i < N; i++) { long tmp = cin.nextLong(); if (tmp != i + 1) { count++; } if (count > 2) { Console.WriteLine(NO); return; } } if (count == 0 || count == 2) { Console.WriteLine(YES); } else { Console.WriteLine(NO); } } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
734
6
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace B { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var n = int.Parse(Console.ReadLine()); var pi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var count = 0; for (var i = 0; i < pi.Length; i++) { if (i + 1 != pi[i]) count++; } Console.WriteLine(count / 2 < 2 ? "YES" : "NO"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace B { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var n = int.Parse(Console.ReadLine()); var pi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var count = 0; for (var i = 0; i < pi.Length; i++) { if (i + 1 != pi[i]) count++; } Console.WriteLine(count <= 2 ? "YES" : "NO"); } } }
[["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 85], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19]]
8
191
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { var N = IO.GetInt(); var p = IO.GetIntList(); var n = 0; var ans = "YES"; for (int i = 0; i < N - 1; i++) { if (p[i] != i + 1) n++; if (n > 2) ans = "NO"; break; } Console.WriteLine(ans); } } static class IO { static public string GetString() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main() { Solve(); Console.ReadKey(); } static void Solve() { var N = IO.GetInt(); var p = IO.GetIntList(); var n = 0; var ans = "YES"; for (int i = 0; i < N; i++) { if (p[i] != i + 1) n++; if (n > 2) { ans = "NO"; break; } } Console.WriteLine(ans); } } static class IO { static public string GetString() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
375
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // using ProCon.Util; namespace ProCon { class Program { static void Main(string[] args) { AC135B(); } static void AC135B() { // https://atcoder.jp/contests/abc135/tasks string answer = "Yes"; int failCount = 0; var n = int.Parse(Console.ReadLine()); var listP = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < n; i++) { if (listP[i] != i + 1) { failCount++; if (failCount > 2) { answer = "No"; break; } } } Console.WriteLine(answer); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // using ProCon.Util; namespace ProCon { class Program { static void Main(string[] args) { AC135B(); } static void AC135B() { // https://atcoder.jp/contests/abc135/tasks string answer = "YES"; int failCount = 0; var n = int.Parse(Console.ReadLine()); var listP = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < n; i++) { if (listP[i] != i + 1) { failCount++; if (failCount > 2) { answer = "NO"; break; } } } Console.WriteLine(answer); Console.ReadKey(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
170
4
using System; using System.Linq; using System.Collections.Generic; namespace Competition { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); for (var i = 1; i <= N; i++) { if (i != p[i - 1]) { for (var j = i + 1; j <= N; j++) { if (j != p[j - 1]) { var tmp = p[j - 1]; p[j - 1] = p[i - 1]; p[i - 1] = tmp; } break; } break; } } var ok = true; for (var i = 1; i <= N; i++) { if (i != p[i - 1]) ok = false; } if (ok) Console.WriteLine("YES"); else Console.WriteLine("NO"); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Competition { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); for (var i = 1; i <= N; i++) { if (i != p[i - 1]) { for (var j = i + 1; j <= N; j++) { if (j != p[j - 1]) { var tmp = p[j - 1]; p[j - 1] = p[i - 1]; p[i - 1] = tmp; break; } } break; } } var ok = true; for (var i = 1; i <= N; i++) { if (i != p[i - 1]) ok = false; } if (ok) Console.WriteLine("YES"); else Console.WriteLine("NO"); } } }
[["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
231
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var p = Input().ToInt(); var q = new int[p.Length]; Array.Copy(p, q, n); Array.Sort(q); int c = 0; for (int i = 0; i < n; i++) { if (p[i] != q[i]) c++; } Console.WriteLine(c == 2 ? "YES" : "NO"); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var p = Input().ToInt(); var q = new int[p.Length]; Array.Copy(p, q, n); Array.Sort(q); int c = 0; for (int i = 0; i < n; i++) { if (p[i] != q[i]) c++; } Console.WriteLine((c == 2 || c == 0) ? "YES" : "NO"); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
[["+", 3, 4, 0, 28, 0, 41, 15, 23, 0, 24], ["+", 0, 28, 0, 41, 15, 23, 0, 16, 17, 106], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 17, 60], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 23, 0, 25]]
8
375
6
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int k = int.Parse(Console.ReadLine()); string[] strarray = Console.ReadLine().Split(' '); int[] array = new int[strarray.Length]; int start = -1; int end = -1; for (int t = 0; t < strarray.Length; t++) { array[t] = int.Parse(strarray[t]); } for (int t = 0; t < strarray.Length; t++) { array[t] = int.Parse(strarray[t]); if (t != strarray.Length - 1 && array[t] > array[t + 1]) { start = t; break; } } for (int t = 0; t < strarray.Length; t++) { if (t != strarray.Length - 1 && array[strarray.Length - 1 - t] < array[strarray.Length - 2 - t]) { end = strarray.Length - 1 - t; break; } } if (start == -1) { Console.WriteLine("Yes"); return; } int tmp = array[start]; array[start] = array[end]; array[end] = tmp; for (int t = 0; t < strarray.Length; t++) { if (t != strarray.Length - 1 && array[t] > array[t + 1]) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); return; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int k = int.Parse(Console.ReadLine()); string[] strarray = Console.ReadLine().Split(' '); int[] array = new int[strarray.Length]; int start = -1; int end = -1; for (int t = 0; t < strarray.Length; t++) { array[t] = int.Parse(strarray[t]); } for (int t = 0; t < strarray.Length; t++) { array[t] = int.Parse(strarray[t]); if (t != strarray.Length - 1 && array[t] > array[t + 1]) { start = t; break; } } for (int t = 0; t < strarray.Length; t++) { if (t != strarray.Length - 1 && array[strarray.Length - 1 - t] < array[strarray.Length - 2 - t]) { end = strarray.Length - 1 - t; break; } } if (start == -1) { Console.WriteLine("YES"); return; } int tmp = array[start]; array[start] = array[end]; array[end] = tmp; for (int t = 0; t < strarray.Length; t++) { if (t != strarray.Length - 1 && array[t] > array[t + 1]) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); return; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
356
2
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); Console.WriteLine(check(a, n) ? "YES" : "NO"); } static bool check(int[] a, int n) { var count = 0; for (int i = 0; i < n; i++) { if (a[i] + 1 != i + 1) { count++; if (count > 2) return false; } } return true; } }
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); Console.WriteLine(check(a, n) ? "YES" : "NO"); } static bool check(int[] a, int n) { var count = 0; for (int i = 0; i < n; i++) { if (a[i] != i + 1) { count++; if (count > 2) return false; } } return true; } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
155
2
using System; using System.Linq; namespace ABC135 { class A { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); int[] array = new int[N]; for (int i = 0; i < N; i++) { array[i] = int.Parse(input[i]); } int conut = 0; for (int i = 0; i < N; i++) { if (array[i] != i + 1) conut++; } if (conut == 0 || conut == 2) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Linq; namespace ABC135 { class A { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); int[] array = new int[N]; for (int i = 0; i < N; i++) { array[i] = int.Parse(input[i]); } int conut = 0; for (int i = 0; i < N; i++) { if (array[i] != i + 1) conut++; } if (conut == 0 || conut == 2) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
169
4
using System; using System.Linq; namespace _0or1_Swap { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] p = new int[N]; int[] q = new int[N]; int count = 0; p = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < N; i++) { q[i] = i + 1; if (p[i] != q[i]) { count++; } } if (count <= 2) { Console.WriteLine("yes"); } else { Console.WriteLine("no"); } } } }
using System; using System.Linq; namespace _0or1_Swap { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] p = new int[N]; int[] q = new int[N]; int count = 0; p = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < N; i++) { q[i] = i + 1; if (p[i] != q[i]) { count++; } } if (count <= 2) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
162
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderPre { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var p = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var count = 0; for (int i = 0; i < N; i++) if (p[i] != i + 1) count++; Console.WriteLine(count <= 2 ? "Yes" : "NO"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderPre { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var p = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var count = 0; for (int i = 0; i < N; i++) if (p[i] != i + 1) count++; Console.WriteLine(count <= 2 ? "YES" : "NO"); } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222]]
8
135
2
using System; using System.Linq; namespace ABC135B { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var ans = 0; for (var i = 1; i < p.Length; i++) { if (p[i] != i + 1) ans++; } Console.WriteLine(ans <= 2 ? "YES" : "NO"); } } }
using System; using System.Linq; namespace ABC135B { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var ans = 0; for (var i = 0; i < p.Length; i++) { if (p[i] != i + 1) ans++; } Console.WriteLine(ans <= 2 ? "YES" : "NO"); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
124
2
using System; using System.Linq; namespace Test { class Program { static void Main(string[] args) { var len = int.Parse(Console.ReadLine()); var vec = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList(); var res = vec.ToList(); res.Sort(); int count = 0; for (int i = 0; i < len; i++) { if (vec[i] != res[i]) { count++; if (count >= 3) { Console.WriteLine("No"); return; } } } Console.WriteLine("Yes"); } } }
using System; using System.Linq; namespace Test { class Program { static void Main(string[] args) { var len = int.Parse(Console.ReadLine()); var vec = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList(); var res = vec.ToList(); res.Sort(); int count = 0; for (int i = 0; i < len; i++) { if (vec[i] != res[i]) { count++; if (count >= 3) { Console.WriteLine("NO"); return; } } } Console.WriteLine("YES"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
154
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = GetInputInt(); int[] P = GetInputsInt(); int count = 0; for (int i = 0; i < N; i++) { if (i + 1 == P[i]) continue; if (++count <= 3) continue; Console.WriteLine("NO"); return; } Console.WriteLine("YES"); } public static int GetInputInt() { return int.Parse(Console.ReadLine()); } public static int[] GetInputsInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static List<int> GetInputsIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } public static long GetInputLong() { return long.Parse(Console.ReadLine()); } public static long[] GetInputsLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = GetInputInt(); int[] P = GetInputsInt(); int count = 0; for (int i = 0; i < N; i++) { if (i + 1 == P[i]) continue; if (++count <= 2) continue; Console.WriteLine("NO"); return; } Console.WriteLine("YES"); } public static int GetInputInt() { return int.Parse(Console.ReadLine()); } public static int[] GetInputsInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static List<int> GetInputsIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } public static long GetInputLong() { return long.Parse(Console.ReadLine()); } public static long[] GetInputsLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
8
267
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { static List<string> cons = new List<string>(); static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int[] arr = new int[n]; int[] arr2 = new int[n]; for (int i = 0; i < n; i++) { arr[i] = int.Parse(str[i]); } arr2[0] = arr[0]; int reversed1 = -1; int reversed2 = -1; for (int i = 1; i < n; i++) { arr2[i] = arr[i]; if (arr[i - 1] > arr[i]) { if (reversed1 == -1) { reversed1 = i - 1; } else if (reversed2 == -1) { reversed2 = i; } else { Console.WriteLine("No"); return; } } } if (reversed1 == -1) { Console.WriteLine("Yes"); return; } else { if (reversed2 == -1) { reversed2 = reversed1 + 1; } arr2[reversed1] = arr[reversed2]; arr2[reversed2] = arr[reversed1]; } for (int i = 1; i < n; i++) { if (arr2[i - 1] > arr2[i]) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { static List<string> cons = new List<string>(); static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int[] arr = new int[n]; int[] arr2 = new int[n]; for (int i = 0; i < n; i++) { arr[i] = int.Parse(str[i]); } arr2[0] = arr[0]; int reversed1 = -1; int reversed2 = -1; for (int i = 1; i < n; i++) { arr2[i] = arr[i]; if (arr[i - 1] > arr[i]) { if (reversed1 == -1) { reversed1 = i - 1; } else if (reversed2 == -1) { reversed2 = i; } else { Console.WriteLine("NO"); return; } } } if (reversed1 == -1) { Console.WriteLine("YES"); return; } else { if (reversed2 == -1) { reversed2 = reversed1 + 1; } arr2[reversed1] = arr[reversed2]; arr2[reversed2] = arr[reversed1]; } for (int i = 1; i < n; i++) { if (arr2[i - 1] > arr2[i]) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
389
8
using System; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { int N = int.Parse(ReadLine()); string[] strp = ReadLine().Split(' '); int[] p = strp.Select(int.Parse).ToArray(); int count = 0; for (int i = 0; i < N; i++) { if (p[i] != i + 1) { count++; } } if (count == 2 || count == 0) { WriteLine("Yes"); } else { WriteLine("No"); } } }
using System; using System.Linq; using static System.Console; class Program { static void Main(string[] args) { int N = int.Parse(ReadLine()); string[] strp = ReadLine().Split(' '); int[] p = strp.Select(int.Parse).ToArray(); int count = 0; for (int i = 0; i < N; i++) { if (p[i] != i + 1) { count++; } } if (count == 2 || count == 0) { WriteLine("YES"); } else { WriteLine("NO"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
141
4
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); int c = 0; for (int i = 0; i < N; i++) { if (i + 1 != int.Parse(s[i])) { c++; } } if (c > 2) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); int c = 0; for (int i = 0; i < N; i++) { if (i + 1 != int.Parse(s[i])) { c++; } } if (c > 2) { Console.WriteLine("NO"); return; } Console.WriteLine("YES"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
146
4
using System; using System.Linq; namespace ABC { using System.Collections.Generic; using System.Runtime.InteropServices; #if USE_STUB using static Stub.Console; #else using static System.Console; #endif using static System.Math; public class Program { static void Main(string[] args) { WriteLine(Solve()); } static object Solve() { var N = int.Parse(ReadLine()); var Pn = ReadLine().Split().Select(int.Parse).ToArray(); var s = Pn.OrderBy(x => x).ToArray(); if (Pn.Zip(s, (n, i) => new { n, i }).Count(x => x.n != x.i) > 3) return "NO"; return "YES"; } } }
using System; using System.Linq; namespace ABC { using System.Collections.Generic; using System.Runtime.InteropServices; #if USE_STUB using static Stub.Console; #else using static System.Console; #endif using static System.Math; public class Program { static void Main(string[] args) { WriteLine(Solve()); } static object Solve() { var N = int.Parse(ReadLine()); var Pn = ReadLine().Split().Select(int.Parse).ToArray(); var s = Pn.OrderBy(x => x).ToArray(); if (Pn.Zip(s, (n, i) => new { n, i }).Count(x => x.n != x.i) > 2) return "NO"; return "YES"; } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
178
2
using System; using static System.Console; using static System.Math; using System.IO; using System.Collections.Generic; namespace I_am_the_green_coder { class Inonoa { static void Main() { long n = ILongs()[0]; long[] p = ILongs(); bool muri_ = false; for (int k = 1; k < n; k++) { if (p[k] <= p[k - 1]) { muri_ = true; break; } } if (!muri_) { Console.WriteLine("Yes"); return; } for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { long tmp = p[i]; p[i] = p[j]; p[j] = tmp; bool muri = false; for (int k = 1; k < n; k++) { if (p[k] <= p[k - 1]) { muri = true; break; } } if (!muri) { Console.WriteLine("Yes"); return; } tmp = p[i]; p[i] = p[j]; p[j] = tmp; } } Console.WriteLine("No"); } static readonly long MOD = 1000000007; ///< summary>a_1, a_2, a_3, ...みたいなの</summary> static long[] ILongs() { string[] s = 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 ReadLine().ToCharArray(); } ///< summary>n m とかをちょっとはやくかくだけ</summary> static string[] IStrings() { return ReadLine().Split(); } ///< summary>n行の入力を取ったり</summary> static long[][] ILongLongs(long n) { long[][] re = new long [n][]; for (long i = 0; i < n; i++) { string[] s = 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; } ///< summary>n行の文字列を取ったり</summary> static char[][] ICharsChars(long n) { char[][] re = new char [n][]; for (long i = 0; i < n; i++) { re[i] = ReadLine().ToCharArray(); } return re; } } }
using System; using static System.Console; using static System.Math; using System.IO; using System.Collections.Generic; namespace I_am_the_green_coder { class Inonoa { static void Main() { long n = ILongs()[0]; long[] p = ILongs(); bool muri_ = false; for (int k = 1; k < n; k++) { if (p[k] <= p[k - 1]) { muri_ = true; break; } } if (!muri_) { Console.WriteLine("YES"); return; } for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { long tmp = p[i]; p[i] = p[j]; p[j] = tmp; bool muri = false; for (int k = 1; k < n; k++) { if (p[k] <= p[k - 1]) { muri = true; break; } } if (!muri) { Console.WriteLine("YES"); return; } tmp = p[i]; p[i] = p[j]; p[j] = tmp; } } Console.WriteLine("NO"); } static readonly long MOD = 1000000007; ///< summary>a_1, a_2, a_3, ...みたいなの</summary> static long[] ILongs() { string[] s = 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 ReadLine().ToCharArray(); } ///< summary>n m とかをちょっとはやくかくだけ</summary> static string[] IStrings() { return ReadLine().Split(); } ///< summary>n行の入力を取ったり</summary> static long[][] ILongLongs(long n) { long[][] re = new long [n][]; for (long i = 0; i < n; i++) { string[] s = 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; } ///< summary>n行の文字列を取ったり</summary> static char[][] ICharsChars(long n) { char[][] re = new char [n][]; for (long i = 0; i < n; i++) { re[i] = ReadLine().ToCharArray(); } return re; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
565
6
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var ps = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var k = 0; for (int i = 0; i < ps.Length; ++i) { if (k > 1 && ps[i] == i + 1) { Console.WriteLine("NO"); return; } if (ps[i] == i + 1) { continue; } ++k; } Console.WriteLine("YES"); } }
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var ps = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); var k = 0; for (int i = 0; i < ps.Length; ++i) { if (k > 1 && ps[i] != i + 1) { Console.WriteLine("NO"); return; } if (ps[i] == i + 1) { continue; } ++k; } Console.WriteLine("YES"); } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79]]
8
158
2
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_134 { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var N = Sarray()[0]; var Ai = Sarray(); var v = new long[N]; var num = 0; for (var i = N; 0 < i; --i) { var sum = 0L; for (var j = N / i; 1 < j; --j) { sum += v[j * i - 1]; } if (sum % 2 != Ai[i - 1]) { v[i - 1] = 1; ++num; } else { v[i - 1] = 0; } } WriteLine(num); for (var i = 0; i < N; ++i) { if (1 == v[i]) Write($"{i} "); } } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_134 { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var N = Sarray()[0]; var Ai = Sarray(); var v = new long[N]; var num = 0; for (var i = N; 0 < i; --i) { var sum = 0L; for (var j = N / i; 1 < j; --j) { sum += v[j * i - 1]; } if (sum % 2 != Ai[i - 1]) { v[i - 1] = 1; ++num; } else { v[i - 1] = 0; } } WriteLine(num); for (var i = 0; i < N; ++i) { if (1 == v[i]) Write($"{i+1} "); } } } }
[["+", 0, 28, 0, 283, 0, 284, 0, 16, 17, 72], ["+", 0, 28, 0, 283, 0, 284, 0, 16, 12, 203]]
8
304
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace Atcoder { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public int x; public int y; public Pair(int X, int Y) { x = X; y = Y; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.y <= p2.y; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.y >= p2.y; } } } class Program { public static List<Pair>[ , ] pairs; public static int[,] ans; static void Main(string[] args) { long mod = 1000000007; StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); int n = scan.Integer(); int[] a = scan.Integer(n); int[] memo = new int[n + 1]; List<int> ones = new List<int>(); for (int i = n; i > 0; i--) { int amari = 0; for (int j = 2; j < n; j++) { if (i * j > n) { break; } amari += memo[i * j]; amari %= 2; } if (amari != a[i - 1]) { memo[i] = 1; ones.Add(i); } } Console.WriteLine(ones.Count); if (ones.Count > 0) { Console.WriteLine(string.Join(" ", ones)); } } static int[] Togo; static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } static int nibutan(int med, int[] a) // med以上が何個あるか { int mae = 0; int ato = a.Length; while (true) { if (ato - mae <= 1) { return mae; } int mid = (mae + ato) / 2; if (a[mid] > med) { ato = mid; } if (a[mid] <= med) { mae = mid; } } } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } } 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 char[] Char(int n) { char[] kore = new char[n]; for (int i = 0; i < n; i++) { kore[i] = Char(); } return kore; } 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 long[] Long(long n) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); } return kore; } public int[,] Integer(long h, long w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { private static long mod = 1000000007; public long num; public Mlong(long num) { this.num = num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } 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(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; using System.Collections; namespace Atcoder { public class CPair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { CPair<T, U> castedObj = (CPair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public CPair(T t, U u) { Item1 = t; Item2 = u; } } class Pair : IComparable { public int x; public int y; public Pair(int X, int Y) { x = X; y = Y; } public int CompareTo(object obj) { Pair kore = (Pair)obj; return x.CompareTo(kore.x); } public static bool operator <=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x <= p2.x; } else { return p1.y <= p2.y; } } public static bool operator >=(Pair p1, Pair p2) { if (p1.x != p2.x) { return p1.x >= p2.x; } else { return p1.y >= p2.y; } } } class Program { public static List<Pair>[ , ] pairs; public static int[,] ans; static void Main(string[] args) { long mod = 1000000007; StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); int n = scan.Integer(); int[] a = scan.Integer(n); int[] memo = new int[n + 1]; List<int> ones = new List<int>(); for (int i = n; i > 0; i--) { int amari = 0; for (int j = 2; j <= n; j++) { if (i * j > n) { break; } amari += memo[i * j]; amari %= 2; } if (amari != a[i - 1]) { memo[i] = 1; ones.Add(i); } } Console.WriteLine(ones.Count); if (ones.Count > 0) { Console.WriteLine(string.Join(" ", ones)); } } static int[] Togo; static int binary_search<T>(T key, T[] moto, Func<int, T, T[], bool> isok) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isok(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static int binary_search(int key, int[] moto) { int ng = -1; int ok = moto.Length; while (Math.Abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, moto)) { ok = mid; } else { ng = mid; } } return ok; } static bool CheckBipartite(int now, int prev, List<int>[] g, int c = 0) // 0,-1が想定 { if (Togo == null) Togo = Enumerable.Repeat(-1, g.Length).ToArray(); foreach (var next in g[now]) { if (next == prev) continue; var nextc = Togo[next]; if (nextc >= 0 && nextc == c) return false; if (nextc >= 0) continue; Togo[next] = (c + 1) % 2; var res = CheckBipartite(next, now, g, (c + 1) % 2); if (res == false) return false; } return true; } static bool isOK(int index, int key, int[] moto) { return moto[index] > key; } public static int bitCount(int k) { uint i = (uint)k; i = i - ((i >> 1) & 0x55555555); i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = (i + (i >> 4)) & 0x0f0f0f0f; i = i + (i >> 8); i = i + (i >> 16); return (int)i & 0x3f; } static int check(long moto, long tai) { if (tai % moto != 0) { return 0; } while (tai > 1) { if (tai % moto == 0) { tai /= moto; } else if (tai > moto) { tai %= moto; } else { tai -= moto; } } if (tai == 1) { return 1; } else { return 0; } } static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } static long Syakutori( int[] a, long k) //しゃくとり法モデル:連続部分列に含まれるすべての要素の値の和がK以上 { long sum = 0; int right = 0; long ans = 0; for (int left = 0; left < a.Length; left++) { while (right < a.Length && sum < k) { sum += a[right]; right++; } if (k <= sum) { ans += a.Length - right + 1; } if (left == right) { right++; } else { sum -= a[left]; } } return ans; } static int[] zalgo(String s) { int n = s.Length; int[] ret = new int[n]; ret[0] = n; int i = 1, j = 0; while (i < n) { while (i + j < n && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } int k = 1; while (i + k < n && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static int gcd(int a, int b) { if (a % b == 0) { return b; } return gcd(b, a % b); } static long gcd(long a, long b) { if (a % b == 0) { return b; } return gcd(b, a % b); } public static List<long> factorialMemo = new List<long>() { 1 }; static long Fact(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } static int[] yousogotoplus(int[] a, int[] b) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[i]; } return c; } static int[] yousogotoplus(int[] a, int[,] b, int l) { int[] c = new int[a.Length]; for (int i = 0; i < a.Length; i++) { c[i] = a[i] + b[l, i]; } return c; } static int[] yousogotoplus(int[,] a, int l) { int[] c = new int[a.GetLength(1)]; for (int i = 0; i < a.GetLength(1); i++) { c[i] = a[l, i]; } return c; } static int nibutan(int med, int[] a) // med以上が何個あるか { int mae = 0; int ato = a.Length; while (true) { if (ato - mae <= 1) { return mae; } int mid = (mae + ato) / 2; if (a[mid] > med) { ato = mid; } if (a[mid] <= med) { mae = mid; } } } static long DivideWith(long m, long n, List<long> primes) { while (m % n == 0) { primes.Add(n); m = m / n; } return m; } static List<CPair<long, long>> SoinsuBunkai(long num) { List<CPair<long, long>> primes = new List<CPair<long, long>>(); List<long> yakusu = new List<long>(); List<long> yakusu2 = new List<long>(); for (int i = 2; i * i <= num; i++) { if (num % i != 0) { continue; } yakusu.Add(i); if (i * i != num) { yakusu2.Add(num / i); } } for (int i = 0; i < yakusu.Count; i++) { if (num % yakusu[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu[i] == 0; j++) { num /= yakusu[i]; } primes.Add(new CPair<long, long>(yakusu[i], j)); } for (int i = yakusu2.Count - 1; i > 0; i--) { if (num % yakusu2[i] != 0) { continue; } int j = 0; for (j = 0; num % yakusu2[i] == 0; j++) { num /= yakusu2[i]; } primes.Add(new CPair<long, long>(yakusu2[i], j)); } return primes; } static IEnumerable<int> Primes(int maxnum) { // var sieve = new BitArray(maxnum + 1, true); bool[] sieve = Enumerable.Repeat(true, maxnum + 1).ToArray(); int squareroot = (int)Math.Sqrt(maxnum); for (int i = 2; i <= squareroot; i++) { if (sieve[i] == false) continue; for (int n = i * 2; n <= maxnum; n += i) sieve[n] = false; } for (int i = 2; i <= maxnum; i++) if (sieve[i] == true) yield return i; } /* static long[] SoinsuBunkai(long num) { if (num == 1) return new long[] { 1 }; List<long> primes = new List<long>(); long n = DivideWith(num, 2, primes); n = DivideWith(n, 3, primes); n = DivideWith(n, 5, primes); long i = 0; while (n > 1) { int[] ps = { 7, 11, 13, 17, 19, 23, 29, 31 }; foreach (var p in ps) { // 30m+2, 30m+3, 30m+4, 30m+5, 30m+6、30m+8... は割る必要はない。 n = DivideWith(n, i + p, primes); if (n == 1) break; } i += 30; } return primes.ToArray(); }*/ public static int h; public static int w; public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } } 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 char[] Char(int n) { char[] kore = new char[n]; for (int i = 0; i < n; i++) { kore[i] = Char(); } return kore; } 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 long[] Long(long n) { long[] kore = new long[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public Mlong[] MLong(long n) { Mlong[] kore = new Mlong[n]; for (int i = 0; i < n; i++) { kore[i] = Long(); } return kore; } public long[,] Long(long h, long w) { long[,] kore = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = Long(); } } return kore; } public int Integer() { return (int)Long(); } public Mint[] MInteger(long n) { Mint[] kore = new Mint[n]; for (int i = 0; i < n; i++) { kore[i] = Integer(); } return kore; } public int[] Integer(long n) { int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = (int)Long(); } return kore; } public int[,] Integer(long h, long w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { kore[i, j] = (int)Long(); } } return kore; } public int[] StringToInt(int n) { char[] s = Scan().ToCharArray(); int[] kore = new int[n]; for (int i = 0; i < n; i++) { kore[i] = s[i] - '0'; } return kore; } public int[,] StringToInt(int h, int w) { int[,] kore = new int[h, w]; for (int i = 0; i < h; i++) { char[] s = Scan().ToCharArray(); for (int j = 0; j < w; j++) { kore[i, j] = s[j] - '0'; } } return kore; } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } public class Mlong : IComparable { private static long mod = 1000000007; public long num; public Mlong(long num) { this.num = num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mlong operator +(Mlong x, Mlong y) { return new Mlong((x.num + y.num) % mod); } public static Mlong operator -(Mlong x, Mlong y) { return new Mlong((x.num - y.num + mod) % mod); } public static Mlong operator *(Mlong x, Mlong y) { return new Mlong((long)(((1L * x.num) * y.num) % mod)); } public Mlong hutujyo(Mlong x) { return new Mlong(num / x.num); } static long GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mlong modjyo(Mlong x) { return num * GetInverse(x.num) % mod; } public static implicit operator Mlong(long x) { return new Mlong(x); } public static Mlong operator %(Mlong x, Mlong y) { return new Mlong(x.num % y.num); } public static explicit operator long(Mlong x) { return x.num; } public static bool operator ==(Mlong x, Mlong y) { return x.num == y.num; } public static bool operator !=(Mlong x, Mlong y) { return x.num != y.num; } public static bool operator<(Mlong x, Mlong y) { return x.num < y.num; } public static bool operator>(Mlong x, Mlong y) { return x.num > y.num; } public static bool operator <=(Mlong x, Mlong y) { return x.num <= y.num; } public static bool operator >=(Mlong x, Mlong y) { return x.num >= y.num; } public Mlong Pow(Mlong n) { Mlong pow = this; Mlong res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mlong Pow(Mlong a, Mlong n) { return a.Pow(n); } public static List<Mlong> factorialMemo = new List<Mlong>() { 1 }; static Mlong Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mlong Comb(Mlong n, Mlong a) { Mlong buf1 = 1; Mlong buf2 = 1; for (long i = 0; i < a.num; i++) { buf1 *= n - i; buf2 *= (i + 1); } return buf1.modjyo(buf2); } public static Mlong Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mlong x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mlong kore = (Mlong)obj; return num.CompareTo(kore.num); } } public class Mint : IComparable { public static int mod = 1000000007; public int num; public Mint(int Num) { num = Num; } public override int GetHashCode() { return num.GetHashCode(); } public override bool Equals(object obj) { return num.Equals(obj); } public static Mint operator +(Mint x, Mint y) { return new Mint((x.num + y.num) % mod); } public static Mint operator -(Mint x, Mint y) { return new Mint((x.num - y.num + mod) % mod); } public static Mint operator *(Mint x, Mint y) { return new Mint((int)(((1L * x.num) * y.num) % mod)); } public Mint hutujyo(Mint x) { return new Mint(num / x.num); } static int GetInverse(long a) { long div, p = mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return (int)(x2 + mod); div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return (int)(x1 + mod); div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } public Mint modjyo(Mint x) { return num * GetInverse(x.num) % mod; } /* public Mint modjyo(Mint x) { return num * x.Pow(mod - 2); }*/ public static implicit operator Mint(int x) { return new Mint(x); } public static Mint[] Toarray(int[] x) { Mint[] buf = new Mint[x.Length]; for (int i = 0; i < x.Length; i++) { buf[i] = x[i]; } return buf; } public static explicit operator int(Mint x) { return x.num; } public static Mint operator %(Mint x, Mint y) { return new Mint(x.num % y.num); } public static bool operator ==(Mint x, Mint y) { return x.num == y.num; } public static bool operator !=(Mint x, Mint y) { return x.num != y.num; } public static bool operator<(Mint x, Mint y) { return x.num < y.num; } public static bool operator>(Mint x, Mint y) { return x.num > y.num; } public static bool operator <=(Mint x, Mint y) { return x.num <= y.num; } public static bool operator >=(Mint x, Mint y) { return x.num >= y.num; } public Mint Pow(Mint n) { Mint pow = this; Mint res = 1; while (n > 0) { if (n % 2 == 1) { res *= pow; } pow *= pow; n.hutujyo(2); } /* if (n == 1) { return this % mod; } if (n % 2 == 1) { return (this * Pow(n - 1)) % mod; } Mint buf = Pow(n.hutujyo(2)); return (buf * buf) % mod;*/ return res; } public static Mint Pow(Mint a, Mint n) { return a.Pow(n); } public static List<Mint> factorialMemo = new List<Mint>() { 1 }; static Mint Factorial(int x) { for (int i = factorialMemo.Count; i <= x; i++) factorialMemo.Add(factorialMemo.Last() * i); return factorialMemo[x]; } public static Mint Comb(int n, int r) { return Factorial(n).modjyo(Factorial(r)).modjyo(Factorial(n - r)); } public static void WriteLine(Mint x) { Console.WriteLine(x.num); } public int CompareTo(object obj) { Mint kore = (Mint)obj; return num.CompareTo(kore.num); } } 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(); } public class Tree { public Node[] Nodes; public List<int[]> hen; public class Node { public int? parent = null; public List<int[]> children = new List<int[]>(); public int parentcolor = -1; } public Tree(int kosu) { Nodes = new Node[kosu]; for (int i = 0; i < Nodes.Length; i++) { Nodes[i] = new Node(); } hen = new List<int[]>(); } public void Connect(int oya, int ko, int id) { hen.Add(new int[] { oya, ko, 0 }); Nodes[oya].children.Add(new int[] { ko, id }); Nodes[ko].parent = oya; } } /// <summary> /// Self-Balancing Binary Search Tree /// (using Randamized BST) /// </summary> public class SB_BinarySearchTree<T> where T : IComparable { public class Node { public T Value; public Node LChild; public Node RChild; public int Count; // size of the sub tree public Node(T v) { Value = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.LChild) + Count(t.RChild) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.RChild = Merge(l.RChild, r); return Update(l); } else { r.LChild = Merge(l, r.LChild); return Update(r); } } /// <summary> /// split as [0, k), [k, n) /// </summary> public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.LChild)) { var s = Split(t.LChild, k); t.LChild = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.RChild, k - Count(t.LChild) - 1); t.RChild = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) t = t.LChild; else if (cmp < 0) t = t.RChild; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.RChild) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.LChild; currentIdx -= (Count(t == null ? null : t.RChild) + 1); } else { t = t.RChild; currentIdx += (Count(t == null ? null : t.LChild) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.RChild) - 1; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.LChild; idx -= (Count(t == null ? null : t.RChild) + 1); } else if (cmp <= 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.RChild) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.Value.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.LChild; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.RChild) + 1); } else if (cmp < 0) { t = t.RChild; idx += (Count(t == null ? null : t.LChild) + 1); if (t == null) return idx; } } // return ret; return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.LChild, ret); ret.Add(t.Value); Enumerate(t.RChild, ret); } } /// <summary> /// C-like set /// </summary> public class Set<T> where T : IComparable { protected SB_BinarySearchTree<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return SB_BinarySearchTree<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else { if (SB_BinarySearchTree<T>.Find(_root, v) != null) return; _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = SB_BinarySearchTree<T>.Remove(_root, v); } public bool Contains(T v) { return SB_BinarySearchTree<T>.Contains(_root, v); } public T ElementAt(int k) { var node = SB_BinarySearchTree<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.Value; } public int Count(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v) - SB_BinarySearchTree<T>.LowerBound(_root, v); } public int LowerBound(T v) { return SB_BinarySearchTree<T>.LowerBound(_root, v); } public int UpperBound(T v) { return SB_BinarySearchTree<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(SB_BinarySearchTree<T>.LowerBound(_root, v), SB_BinarySearchTree<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(SB_BinarySearchTree<T>.Enumerate(_root)); } } /// <summary> /// C-like multiset /// </summary> public class MultiSet<T> : Set<T> where T : IComparable { public override void Insert(T v) { if (_root == null) _root = new SB_BinarySearchTree<T>.Node(v); else _root = SB_BinarySearchTree<T>.Insert(_root, v); } } public class RollingHashSlow { public const long B = (long)1e5 + 7; public const long MOD = (long)1e9 + 7; public string S { get; set; } public int N { get; set; } public long[] Power { get; set; } public long[] Hash { get; set; } public RollingHashSlow(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new long[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = (this.Power[i] * B) % MOD; } // ハッシュを前計算する this.Hash = new long[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = (this.Hash[i] * B + S[i]) % MOD; } } // S[l, r) のハッシュ値を求める public long Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l] % MOD); if (hash < 0) hash += MOD; return hash; } } class RollingHashFast { public const ulong B = (ulong)1e9 + 7; public string S { get; set; } public int N { get; set; } public ulong[] Power { get; set; } public ulong[] Hash { get; set; } public RollingHashFast(string s) { this.S = s; this.N = s.Length; // B^nを計算しておく this.Power = new ulong[this.N + 1]; this.Power[0] = 1; for (int i = 0; i < N; i++) { this.Power[i + 1] = this.Power[i] * B; } // ハッシュを前計算する this.Hash = new ulong[this.N + 1]; for (int i = 0; i < N; i++) { this.Hash[i + 1] = this.Hash[i] * B + S[i]; } } // [l, r) のハッシュ値を求める public ulong Get(int l, int r) { var hash = this.Hash[r] - (this.Hash[l] * this.Power[r - l]); return hash; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } // [s, t) public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class WarshallFloyd { public int V { get; set; } public long[,] DP { get; set; } public long INF = long.MaxValue; public bool[] Negative; public WarshallFloyd(int v) { this.V = v; this.DP = new long[V, V]; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { this.DP[i, j] = INF; } this.DP[i, i] = 0; } } public void SetCost(int a, int b, int c = 1) { this.DP[a, b] = c; } public long[,] CalcMinCost() { this.Negative = new bool[V]; for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; DP[i, j] = Math.Min(DP[i, j], DP[i, k] + DP[k, j]); } } } for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (DP[i, k] == INF || DP[k, j] == INF) continue; if (DP[i, j] > DP[i, k] + DP[k, j]) { this.Negative[i] = true; this.Negative[j] = true; this.Negative[k] = true; } } } } return DP; } public long GetMinCost(int a, int b) { return DP[a, b]; } public bool IsINF(int a, int b) { return DP[a, b] >= INF; } public bool IsNegative(params int[] vs) { if (vs.Length == 0) vs = Enumerable.Range(0, V).ToArray(); foreach (var v in vs) { if (Negative[v]) return true; } return false; } } /// <summary> /// Get min cost between two points /// </summary> public class Dijkstra { private int maxIndex = -1; private const int INF = Int32.MaxValue; private int[,] _edgeArray; /// <summary> /// Dijkstra, get min cost between two points /// should not contain negatie cost path /// </summary> /// <param name="size">max index of vertices</param> public Dijkstra(int size) { maxIndex = size + 1; _edgeArray = new int[maxIndex, maxIndex]; for (int i = 0; i < _edgeArray.GetLength(0); i++) { for (int j = 0; j < _edgeArray.GetLength(1); j++) { _edgeArray[i, j] = INF; if (i == j) _edgeArray[i, j] = 0; } } } // Add a path(no direction) with its cost public void AddPath(int s, int t, int cost) { _edgeArray[s, t] = Math.Min(_edgeArray[s, t], cost); _edgeArray[t, s] = _edgeArray[s, t]; } // Get the min cost between s and t // return Int32.MaxValue if no path public int GetMinCost(int s, int t) { int[] cost = new int[maxIndex]; for (int i = 0; i < cost.Length; i++) cost[i] = INF; cost[s] = 0; var priorityQueue = new PriorityQueue<CPair<int, int>>(); priorityQueue.Enqueue(new CPair<int, int>(0, s)); while (priorityQueue.Count() > 0) { var costDestinationPair = priorityQueue.Dequeue(); if (cost[costDestinationPair.Item2] < costDestinationPair.Item1) continue; for (int i = 0; i < maxIndex; i++) { int newCostToi = _edgeArray[costDestinationPair.Item2, i] == INF ? INF : costDestinationPair.Item1 + _edgeArray[costDestinationPair.Item2, i]; if (newCostToi < cost[i]) { cost[i] = newCostToi; priorityQueue.Enqueue(new CPair<int, int>(newCostToi, i)); } } } return cost[t]; } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
9,681
2
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Program { static List<int>[] Sub; static int[] Salary; static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray(); var B = new long[N + 1]; var C = new List<long>(); var res = 0; for (int i = (N / 2) + 1; i <= N; i++) { B[i] = A[N - 1]; if (B[i] == 1) { C.Add(i); res++; } } for (int i = (N / 2); i > 0; i--) { var tmp = i; var org = tmp; var sum = 0L; while (tmp <= N) { sum += B[tmp]; tmp += org; } if (sum % 2 != A[i - 1]) { B[i] = 1; res++; C.Add(i); } } // var C = new long[N]; // Array.Copy(B, 1, C, 0, B.Length - 1); var D = C.ToArray(); Array.Sort(D); Console.WriteLine(res); Console.WriteLine(String.Join(" ", D)); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Program { static List<int>[] Sub; static int[] Salary; static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray(); var B = new long[N + 1]; var C = new List<long>(); var M = 0L; for (int i = (N / 2) + 1; i <= N; i++) { B[i] = A[i - 1]; if (B[i] == 1) { C.Add(i); M++; } } for (int i = (N / 2); i > 0; i--) { var tmp = i; var org = tmp; var sum = 0L; while (tmp <= N) { sum += B[tmp]; tmp += org; } if (sum % 2 != A[i - 1]) { B[i] = 1; M++; C.Add(i); } } // var C = new long[N]; // Array.Copy(B, 1, C, 0, B.Length - 1); var D = C.ToArray(); Array.Sort(D); Console.WriteLine(M); Console.WriteLine(String.Join(" ", D)); } }
[["-", 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], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
302
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; public static class Program { private static readonly long INF = long.MaxValue / 2; private static readonly int MOD = 1000000007; struct Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } public class PriorityQueue<T> where T : IComparable<T> { private List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int CountItem() { return Q.Count(); } public bool IsEmpty() { return !Q.Any(); } } static long ModInv(long a, long m) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; long tmp = a; a = b; b = tmp; u -= t * v; tmp = u; u = v; v = tmp; } u %= m; if (u < 0) u += m; return u; } public static long CalcComb(long n, long m) { //条件チェック if (n < m) return 0; if (n < 0 || m < 0) return 0; // nCm = nCm-1 ×(n-m+1)/ m // return CalcFact(n) / (CalcFact(m) * CalcFact(n - m)); // MODで割ってbの逆元を求める return CalcFact(n) * ModInv((CalcFact(m) * CalcFact(n - m)) % MOD, MOD) % MOD; } /// <summary> /// 階乗を計算する。 /// </summary> /// <param name="n">n</param> /// <returns>nの階乗(n!)</returns> public static long CalcFact(long n) { if (n <= 0) { return 1; } return n * CalcFact(n - 1) % MOD; } struct Pos { public int x; public int y; public Pos(int x, int y) { this.x = x; this.y = y; } public static Pos operator +(Pos p1, Pos p2) { var result = new Pos(); result.x = p2.x + p1.x; result.y = p2.y + p1.y; return result; } public static Pos operator -(Pos p1, Pos p2) { var result = new Pos(); result.x = p2.x - p1.x; result.y = p2.y - p1.y; return result; } } class Modular { private const int M = 1000000007; private long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } static class Permutation<T> { private static void Search(List<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) { perms.Add(stack.Reverse().ToArray()); } else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) { b[i] = a[i]; } stack.Pop(); } } } public static IEnumerable<T[]> All(IEnumerable<T> src) { var perms = new List<T[]>(); Search(perms, new Stack<T>(), src.ToArray()); return perms; } } public static int ReadLineToInt() { return int.Parse(ReadLine()); } public static long ReadLineToLong() { return long.Parse(ReadLine()); } public static int[] ReadLineToInts() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int nibunn(int[] array, int target) { int L = 0; int R = array.Length; while (R - L > 1) { int mid = (R + L) / 2; if (array[mid] > target) L = mid; else R = mid; } return L; } public static void Main(string[] args) { int n = ReadLineToInt(); var list = ReadLineToInts(); // var dp = new List<int>(); var ans = new List<int>(); for (int i = 0; i < n; i++) { ans.Add(0); } for (int i = n; i > 0; i--) { int have_ball = 0; int sum = 0; for (int j = 2; j * i <= n; j++) { // WriteLine(j * i - 1); sum += ans[j * i - 1]; } if (sum % 2 == list[i - 1]) { have_ball = 1; } else { have_ball = 0; } // WriteLine(have_ball); ans[i - 1] = have_ball; } int count = ans.Where(x => x == 1).Count(); WriteLine(count); if (count > 0) { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= n; i++) { // WriteLine(i + "番の箱: " + i); if (ans[i - 1] == 1) { sb.Append(i); sb.Append(" "); } } WriteLine(sb.ToString()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; public static class Program { private static readonly long INF = long.MaxValue / 2; private static readonly int MOD = 1000000007; struct Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } public class PriorityQueue<T> where T : IComparable<T> { private List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int CountItem() { return Q.Count(); } public bool IsEmpty() { return !Q.Any(); } } static long ModInv(long a, long m) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; long tmp = a; a = b; b = tmp; u -= t * v; tmp = u; u = v; v = tmp; } u %= m; if (u < 0) u += m; return u; } public static long CalcComb(long n, long m) { //条件チェック if (n < m) return 0; if (n < 0 || m < 0) return 0; // nCm = nCm-1 ×(n-m+1)/ m // return CalcFact(n) / (CalcFact(m) * CalcFact(n - m)); // MODで割ってbの逆元を求める return CalcFact(n) * ModInv((CalcFact(m) * CalcFact(n - m)) % MOD, MOD) % MOD; } /// <summary> /// 階乗を計算する。 /// </summary> /// <param name="n">n</param> /// <returns>nの階乗(n!)</returns> public static long CalcFact(long n) { if (n <= 0) { return 1; } return n * CalcFact(n - 1) % MOD; } struct Pos { public int x; public int y; public Pos(int x, int y) { this.x = x; this.y = y; } public static Pos operator +(Pos p1, Pos p2) { var result = new Pos(); result.x = p2.x + p1.x; result.y = p2.y + p1.y; return result; } public static Pos operator -(Pos p1, Pos p2) { var result = new Pos(); result.x = p2.x - p1.x; result.y = p2.y - p1.y; return result; } } class Modular { private const int M = 1000000007; private long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % M; return new Modular((m < 0) ? m + M : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } static class Permutation<T> { private static void Search(List<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) { perms.Add(stack.Reverse().ToArray()); } else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) { b[i] = a[i]; } stack.Pop(); } } } public static IEnumerable<T[]> All(IEnumerable<T> src) { var perms = new List<T[]>(); Search(perms, new Stack<T>(), src.ToArray()); return perms; } } public static int ReadLineToInt() { return int.Parse(ReadLine()); } public static long ReadLineToLong() { return long.Parse(ReadLine()); } public static int[] ReadLineToInts() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int nibunn(int[] array, int target) { int L = 0; int R = array.Length; while (R - L > 1) { int mid = (R + L) / 2; if (array[mid] > target) L = mid; else R = mid; } return L; } public static void Main(string[] args) { int n = ReadLineToInt(); var list = ReadLineToInts(); // var dp = new List<int>(); var ans = new List<int>(); for (int i = 0; i < n; i++) { ans.Add(0); } for (int i = n; i > 0; i--) { int have_ball = 0; int sum = 0; for (int j = 2; j * i <= n; j++) { // WriteLine(j * i - 1); sum += ans[j * i - 1]; } if (sum % 2 == list[i - 1]) { have_ball = 0; } else { have_ball = 1; } // WriteLine(have_ball); ans[i - 1] = have_ball; } int count = ans.Where(x => x == 1).Count(); WriteLine(count); if (count > 0) { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= n; i++) { // WriteLine(i + "番の箱: " + i); if (ans[i - 1] == 1) { sb.Append(i); sb.Append(" "); } } WriteLine(sb.ToString()); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
8
1,888
4
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>(int len1, int len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, len2).ToArray(); return m; } static T[][][] InitMat<T>(int len1, int len2, int 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 static void Main() { Solve_D(); } public static void Solve_A() { int n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_B() { int n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { int n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { int n; MyIO.ReadMulti(out n); int[] a; MyIO.ReadArray(out a); int[] box = new int[n + 1]; for (int i = n; 0 < i; i--) { if (n < i * 2) { box[i] = a[i - 1]; } else { int sum = 0; for (int j = 2 * i; j <= n; j += i) { sum += box[i]; } box[i] = (sum + a[i - 1]) % 2; } } List<int> ans = new List<int>(); for (int i = 1; i <= n; i++) { if (box[i] == 1) ans.Add(i); } MyIO.WriteMulti(ans.Count); if (0 < ans.Count) MyIO.WriteArray(ans.ToArray()); } public static void Solve_E() { int n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { int 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>(int len1, int len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, len2).ToArray(); return m; } static T[][][] InitMat<T>(int len1, int len2, int 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 static void Main() { Solve_D(); } public static void Solve_A() { int n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_B() { int n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { int n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { int n; MyIO.ReadMulti(out n); int[] a; MyIO.ReadArray(out a); int[] box = new int[n + 1]; for (int i = n; 0 < i; i--) { if (n < i * 2) { box[i] = a[i - 1]; } else { int sum = 0; for (int j = 2 * i; j <= n; j += i) { sum += box[j]; } box[i] = (sum + a[i - 1]) % 2; } } List<int> ans = new List<int>(); for (int i = 1; i <= n; i++) { if (box[i] == 1) ans.Add(i); } MyIO.WriteMulti(ans.Count); if (0 < ans.Count) MyIO.WriteArray(ans.ToArray()); } public static void Solve_E() { int n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { int 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, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22]]
8
2,534
2
using System; using System.Collections.Generic; using System.Linq; namespace debug { public static partial class Program { public static void Main() { var n = Console.ReadLine().ToLong(); var ais = Console.ReadLine().ToLongArray(); var array = new bool[n]; for (var i = n; i > 0; i--) { var sum = 0; var num = 1; while (num * i <= n) { sum += array[i - 1] ? 1 : 0; num++; } if (sum % 2 != ais[i - 1]) { array[i - 1] = true; } } Console.WriteLine(array.Count(x => x)); if (array.Any(x => x)) { Console.WriteLine(array.Select((x, idx) => new { x, idx }) .Where(x => x.x) .Select(x => x.idx + 1) .JoinToStr()); } } } public static partial class Program { //テンプレここから private static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb); private static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb); private static long ToLong(this double ddd) => (long)ddd; private static long ToLong(this string str) => long.Parse(str); private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray(); private static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong(); private static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb)); private static long Sign(this long iii) => Math.Sign(iii); private static bool IsEven(this long iii) => iii % 2 == 0; private static readonly int[] Dx = { 0, -1, 0, 1 }; private static readonly int[] Dy = { -1, 0, 1, 0 }; public const int MOD = 1000000007; public const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static long ToLong(this char ccc) => ccc.ToString().ToLong(); public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array); public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array); public static string JoinToStr(this IEnumerable<long> array, string sep = "") => array.Select(xxx => xxx.ToString()).Join(sep); public static string JoinToStr(this IEnumerable<int> array, string sep = "") => array.Select(xxx => xxx.ToString()).Join(sep); //テンプレここまで } }
using System; using System.Collections.Generic; using System.Linq; namespace debug { public static partial class Program { public static void Main() { var n = Console.ReadLine().ToLong(); var ais = Console.ReadLine().ToLongArray(); var array = new bool[n]; for (var i = n; i > 0; i--) { var sum = 0; var num = 1; while (num * i <= n) { sum += array[num * i - 1] ? 1 : 0; num++; } if (sum % 2 != ais[i - 1]) { array[i - 1] = true; } } Console.WriteLine(array.Count(x => x)); if (array.Any(x => x)) { Console.WriteLine(array.Select((x, idx) => new { x, idx }) .Where(x => x.x) .Select(x => x.idx + 1) .JoinToStr(" ")); } } } public static partial class Program { //テンプレここから private static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb); private static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb); private static long ToLong(this double ddd) => (long)ddd; private static long ToLong(this string str) => long.Parse(str); private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray(); private static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong(); private static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb)); private static long Sign(this long iii) => Math.Sign(iii); private static bool IsEven(this long iii) => iii % 2 == 0; private static readonly int[] Dx = { 0, -1, 0, 1 }; private static readonly int[] Dy = { -1, 0, 1, 0 }; public const int MOD = 1000000007; public const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static long ToLong(this char ccc) => ccc.ToString().ToLong(); public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array); public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array); public static string JoinToStr(this IEnumerable<long> array, string sep = "") => array.Select(xxx => xxx.ToString()).Join(sep); public static string JoinToStr(this IEnumerable<int> array, string sep = "") => array.Select(xxx => xxx.ToString()).Join(sep); //テンプレここまで } }
[["+", 206, 207, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
653
5
using System; using System.Linq; class D { static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var b = new int[n]; var m = n / 2; for (var i = m; i < n; i++) b[i] = a[i]; for (var i = m - 1; i >= 0; i--) b[i] = (a[i] + Enumerable.Range(2, n / (i + 1) - 1).Sum(j => a[j * (i + 1) - 1])) % 2; var c = b.Select((x, i) => new { x, i }) .Where(_ => _.x == 1) .Select(_ => _.i + 1) .ToArray(); Console.WriteLine(c.Length); Console.WriteLine(string.Join(" ", c)); } }
using System; using System.Linq; class D { static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var b = new int[n]; var m = n / 2; for (var i = m; i < n; i++) b[i] = a[i]; for (var i = m - 1; i >= 0; i--) b[i] = (a[i] + Enumerable.Range(2, n / (i + 1) - 1).Sum(j => b[j * (i + 1) - 1])) % 2; var c = b.Select((x, i) => new { x, i }) .Where(_ => _.x == 1) .Select(_ => _.i + 1) .ToArray(); Console.WriteLine(c.Length); Console.WriteLine(string.Join(" ", c)); } }
[["-", 3, 4, 0, 28, 0, 218, 8, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 204, 205, 22]]
8
237
2
using System; using System.Text; using System.Linq; class Program { static void Main(string[] args) { String ret; ret = process(new System.IO.StreamReader(Console.OpenStandardInput())); // ret = process("5\n0 0 0 0 0"); Console.WriteLine(ret); // Console.ReadLine(); } static string process(System.IO.TextReader input) { int n = int.Parse(input.ReadLine()); int[] ary = ToIntArray(input.ReadLine(), n); int[] ans = new int[n]; for (int i = n; i >= 1; i--) { int c = ary[idx(i)]; for (int k = 0;; k++) { if (idx(i * k) > idx(n)) { break; } else { c += ans[idx(i * k)]; } } ans[idx(i)] = c % 2; } int count = ans.Count(x => x == 1); StringBuilder ret = new StringBuilder(); ret.AppendLine(count.ToString()); for (int i = 0; i < n; i++) { if (ans[i] == 1) { ret.Append(i + 1); ret.Append(' '); } } return ret.ToString(); } static int idx(int n) { return n - 1; } static string process(string input) { return process(new System.IO.StringReader(input)); } static int[] ToIntArray(string strs, int n) { int[] ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
using System; using System.Text; using System.Linq; class Program { static void Main(string[] args) { String ret; ret = process(new System.IO.StreamReader(Console.OpenStandardInput())); // ret = process("3\n1 0 0"); Console.WriteLine(ret); // Console.ReadLine(); } static string process(System.IO.TextReader input) { int n = int.Parse(input.ReadLine()); int[] ary = ToIntArray(input.ReadLine(), n); int[] ans = new int[n]; for (int i = n; i >= 1; i--) { int c = ary[idx(i)]; for (int k = 2;; k++) { if (idx(i * k) > idx(n)) { break; } else { c += ans[idx(i * k)]; } } ans[idx(i)] = c % 2; } int count = ans.Count(x => x == 1); StringBuilder ret = new StringBuilder(); ret.AppendLine(count.ToString()); for (int i = 0; i < n; i++) { if (ans[i] == 1) { ret.Append(i + 1); ret.Append(' '); } } return ret.ToString(); } static int idx(int n) { return n - 1; } static string process(string input) { return process(new System.IO.StringReader(input)); } static int[] ToIntArray(string strs, int n) { int[] ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
389
2
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] v = new int[N]; int M = 0; string[] s = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { v[i] = int.Parse(s[i]); if (v[i] != 0) { M = i + 1; } } int[] a = new int[M]; for (int i = M - 1; i >= 0; i--) { int mulMax = M / (i + 1); int ans = 0; for (int j = mulMax; j > 1; j--) { ans ^= a[(i + 1) * j - 1]; } ans ^= v[i]; a[i] = ans; } int c = 0; for (int i = 0; i < M; i++) { if (a[i] != 0) { c = i + 1; } } Console.WriteLine(c); if (c != 0) { for (int i = 0; i < M; i++) { if (a[i] != 0) { Console.Write("{0} ", i + 1); } } Console.WriteLine(); } } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] v = new int[N]; int M = 0; string[] s = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { v[i] = int.Parse(s[i]); if (v[i] != 0) { M = i + 1; } } int[] a = new int[M]; for (int i = M - 1; i >= 0; i--) { int mulMax = M / (i + 1); int ans = 0; for (int j = mulMax; j > 1; j--) { ans ^= a[(i + 1) * j - 1]; } ans ^= v[i]; a[i] = ans; } int c = 0; for (int i = 0; i < M; i++) { if (a[i] != 0) { c++; } } Console.WriteLine(c); if (c != 0) { for (int i = 0; i < M; i++) { if (a[i] != 0) { Console.Write("{0} ", i + 1); } } Console.WriteLine(); } } } }
[["-", 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, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29]]
8
329
5
using System; namespace AtCoderABC134D { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); int[] a = new int[N + 1]; int[] b = new int[N + 1]; for (int i = 0; i < N; i++) { a[i + 1] = int.Parse(s[i]); } int total = 0; for (int i = N; i > 0; i--) { b[i] = a[i]; for (int j = 2; j * i < N; j++) { b[i] = (b[i] + b[j * i]) % 2; } if (b[i] == 1) total++; } Console.WriteLine(total.ToString()); if (total != 0) { bool space = false; for (int i = 1; i <= N; i++) { if (b[i] == 1) { if (space) { Console.Write(" "); } else { space = true; } Console.Write(i.ToString()); } } Console.WriteLine(); } } } }
using System; namespace AtCoderABC134D { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); int[] a = new int[N + 1]; int[] b = new int[N + 1]; for (int i = 0; i < N; i++) { a[i + 1] = int.Parse(s[i]); } int total = 0; for (int i = N; i > 0; i--) { b[i] = a[i]; for (int j = 2; j * i <= N; j++) { b[i] = (b[i] + b[j * i]) % 2; } if (b[i] == 1) total++; } Console.WriteLine(total.ToString()); if (total != 0) { bool space = false; for (int i = 1; i <= N; i++) { if (b[i] == 1) { if (space) { Console.Write(" "); } else { space = true; } Console.Write(i.ToString()); } } Console.WriteLine(); } } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
285
2
using System; using System.Linq; namespace abc134_d { static class Program { static void Main(string[] args) { var n = Console.ReadLine().ToInteger(); var a = Console.ReadLine().ToIntArray(); // 偶数か奇数かなので、ボールを1つ入れるか入れないかだけを考えればいい。 var boxes = new int[n]; for (int i = 0; i < a.Length; i++) { // 逆さから考える。 var number = a.Length - i; var index = number - 1; if (number > n / 2) { // 後ろ半分は、倍数は他に存在しないので、確定。 boxes[index] = a[index]; } else { // 倍数がいくつあるか var div = n / number - 1; // 倍数の総和 var sum = 0; for (int j = 0; j < div; j++) { sum += boxes[number * (j + 2) - 1]; } if (sum % 2 != a[index]) { // 総和が条件に一致しないときだけ1を足す boxes[index] = 1; } } } Console.WriteLine($"{boxes.Where(m => m > 0).Count()}"); Console.WriteLine( $"{string.Join(" ", boxes.Select((m, i) => m > 0 ? "" : i.ToString()))}"); } static int ToInteger(this string s) { return int.Parse(s); } static int[] ToIntArray(this string s, char separator = ' ') { return s.Split(separator).Select(m => m.ToInteger()).ToArray(); } } }
using System; using System.Linq; namespace abc134_d { static class Program { static void Main(string[] args) { var n = Console.ReadLine().ToInteger(); var a = Console.ReadLine().ToIntArray(); // 偶数か奇数かなので、ボールを1つ入れるか入れないかだけを考えればいい。 var boxes = new int[n]; for (int i = 0; i < a.Length; i++) { // 逆さから考える。 var number = a.Length - i; var index = number - 1; if (number > n / 2) { // 後ろ半分は、倍数は他に存在しないので、確定。 boxes[index] = a[index]; } else { // 倍数がいくつあるか var div = n / number - 1; // 倍数の総和 var sum = 0; for (int j = 0; j < div; j++) { sum += boxes[number * (j + 2) - 1]; } if (sum % 2 != a[index]) { // 総和が条件に一致しないときだけ1を足す boxes[index] = 1; } } } Console.WriteLine($"{boxes.Where(m => m > 0).Count()}"); Console.WriteLine( $"{string.Join(" ", boxes.Select((m, i) => m > 0 ? (i + 1).ToString() : ""))}"); } static int ToInteger(this string s) { return int.Parse(s); } static int[] ToIntArray(this string s, char separator = ' ') { return s.Split(separator).Select(m => m.ToInteger()).ToArray(); } } }
[["-", 0, 28, 0, 218, 8, 41, 64, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 218, 8, 41, 0, 102], ["+", 8, 41, 64, 213, 63, 214, 205, 23, 0, 24], ["+", 64, 213, 63, 214, 205, 23, 0, 16, 17, 72], ["+", 64, 213, 63, 214, 205, 23, 0, 16, 12, 203], ["+", 8, 41, 64, 213, 63, 214, 205, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 218, 8, 41, 0, 102], ["+", 0, 28, 0, 218, 8, 41, 75, 5, 0, 62]]
8
317
10
using System; using System.Collections.Generic; public class ABC134D { public static void Main() { int N, M = 0, sum = 0; string ans = ""; List<int> a = new List<int>(), b = new List<int>(); N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { a.Add(int.Parse(str[i])); b.Add(0); } for (int i = N - 1; i >= 0; i--) { sum = 0; for (int j = 2; j * (i + 1) <= N; j++) { sum += b[j * (i + 1) - 1]; } sum %= 2; if (sum == a[i]) b[i] = 0; else { b[i] = 1; M++; } } Console.WriteLine(M); for (int i = 0; i < N; i++) { if (b[i] == 1) { Console.Write(i); Console.Write(" "); } } } }
using System; using System.Collections.Generic; public class ABC134D { public static void Main() { int N, M = 0, sum = 0; string ans = ""; List<int> a = new List<int>(), b = new List<int>(); N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { a.Add(int.Parse(str[i])); b.Add(0); } for (int i = N - 1; i >= 0; i--) { sum = 0; for (int j = 2; j * (i + 1) <= N; j++) { sum += b[j * (i + 1) - 1]; } sum %= 2; if (sum == a[i]) b[i] = 0; else { b[i] = 1; M++; } } Console.WriteLine(M); for (int i = 0; i < N; i++) { if (b[i] == 1) { Console.Write(i + 1); Console.Write(" "); } } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
275
2
using System; using System.Linq; using System.Collections.Generic; class Program { static int N; static void Main() { N = Int32.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var ball = new int[N]; for (int i = N - 1; 0 <= i; --i) { var other = (calc(ball, i + 1)) % 2; ball[i] = other == 0 ? a[i] : a[i] == 0 ? 1 : 0; } ball = ball.Where(x => x == 1).ToArray(); var count = ball.Count(); if (count == 0) { Console.WriteLine(0); return; } Console.WriteLine(count); var c = 0; for (int i = 0; i < N; ++i) { if (ball[i] == 1) { Console.Write(i + 1); c++; } if (c != count) Console.Write(" "); } Console.WriteLine(); } static int calc(int[] ball, int num) { var index = num; var n = 0; for (int i = 2;; ++i) { if (N < index * i) break; n += ball[index * i - 1]; } return n; } }
using System; using System.Linq; using System.Collections.Generic; class Program { static int N; static void Main() { N = Int32.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var ball = new int[N]; for (int i = N - 1; 0 <= i; --i) { var other = (calc(ball, i + 1)) % 2; ball[i] = other == 0 ? a[i] : a[i] == 0 ? 1 : 0; } var b = ball.Where(x => x == 1).ToArray(); var count = b.Count(); if (count == 0) { Console.WriteLine(0); return; } Console.WriteLine(count); var c = 0; for (int i = 0; i < N; ++i) { if (ball[i] == 1) { Console.Write(i + 1); c++; } if (c != count) Console.Write(" "); } Console.WriteLine(); } static int calc(int[] ball, int num) { var index = num; var n = 0; for (int i = 2;; ++i) { if (N < index * i) break; n += ball[index * i - 1]; } return n; } }
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22]]
8
319
5
using System; using System.Collections.Generic; using System.IO; using System.Linq; 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 = new long[N]; for (int i = 0; i < N; i++) A[i] = Cin; var boxes = new bool[N]; for (int i = N - 1; i >= 0; i--) { bool xor = false; var times = i + 1; for (int j = 2; times * j < N; j++) { xor ^= boxes[times * j - 1]; } var b = A[i] == 1; if (xor ^ b) boxes[i] = true; } var count = boxes.Count(val => val); Coutln(count); for (int i = 0; i < N; i++) { if (boxes[i]) Cout(i + 1 + " "); } } // 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.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 = new long[N]; for (int i = 0; i < N; i++) A[i] = Cin; var boxes = new bool[N]; for (int i = N - 1; i >= 0; i--) { bool xor = false; var times = i + 1; for (int j = 2; times * j <= N; j++) { xor ^= boxes[times * j - 1]; } var b = A[i] == 1; if (xor ^ b) boxes[i] = true; } var count = boxes.Count(val => val); Coutln(count); for (int i = 0; i < N; i++) { if (boxes[i]) Cout(i + 1 + " "); } } // 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, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
2,347
2
using System; using System.Collections.Generic; namespace D___Preparing_Boxes { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var ai = new int[N + 1]; for (int i = 1; i < N + 1; i++) ai[i] = read[i - 1]; var bi = new int[N + 1]; var M = 0; var output = new List<int>(); for (int i = N; i > 0; i--) { bi[i] = ai[i]; for (int j = 2; j * i < N; j++) { bi[i] ^= bi[j * i]; } if (bi[i] == 1) { M += 1; output.Add(i); } } Console.WriteLine(M); Console.WriteLine(string.Join(" ", output)); } } }
using System; using System.Collections.Generic; namespace D___Preparing_Boxes { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var read = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var ai = new int[N + 1]; for (int i = 1; i < N + 1; i++) ai[i] = read[i - 1]; var bi = new int[N + 1]; var M = 0; var output = new List<int>(); for (int i = N; i > 0; i--) { bi[i] = ai[i]; for (int j = 2; j * i <= N; j++) { bi[i] ^= bi[j * i]; } if (bi[i] == 1) { M += 1; output.Add(i); } } Console.WriteLine(M); Console.WriteLine(string.Join(" ", output)); } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
235
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { int N = RInt(); var A = new long[N]; for (int i = 0; i < N; i++) { A[i] = RLong(); } var dp = new List<long>() { A[0] }; for (int i = 1; i < N; i++) { if (dp.Last() >= A[i]) { dp.Add(A[i]); } else { var (lb, ub) = (-1, dp.Count); while (ub - lb > 1) { var mid = (lb + ub) / 2; if (dp[mid] > A[i]) lb = mid; else ub = mid; } dp[ub] = A[i]; } } WriteLine(dp.Count); } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { int N = RInt(); var A = new long[N]; for (int i = 0; i < N; i++) { A[i] = RLong(); } var dp = new List<long>() { A[0] }; for (int i = 1; i < N; i++) { if (dp.Last() >= A[i]) { dp.Add(A[i]); } else { var (lb, ub) = (-1, dp.Count); while (ub - lb > 1) { var mid = (lb + ub) / 2; if (dp[mid] >= A[i]) lb = mid; else ub = mid; } dp[ub] = A[i]; } } WriteLine(dp.Count); } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20]]
8
840
2
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 Ans { static public int mod = 1000000007; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var n = rint(); var list = new List<int>(); list.Add(rint()); for (int i = 1; i < n; i++) { var temp = rint(); var l = 0; var r = list.Count - 1; while (r - l > 1) { var mid = (l + r) / 2; if (list[mid] > temp) { r = mid; } else { l = mid; } } if (list[r] < temp) { list[r] = temp; } else if (list[l] < temp) { list[l] = temp; } else { list.Insert(0, temp); } } // WriteLine(string.Join(" ",list)); WriteLine(list.Count); } 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) { if (n < r) return 0; 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] = double.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- 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 Ans { static public int mod = 1000000007; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var n = rint(); var list = new List<int>(); list.Add(rint()); for (int i = 1; i < n; i++) { var temp = rint(); var l = 0; var r = list.Count - 1; while (r - l > 1) { var mid = (l + r) / 2; if (list[mid] >= temp) { r = mid; } else { l = mid; } } if (list[r] < temp) { list[r] = temp; } else if (list[l] < temp) { list[l] = temp; } else { list.Insert(0, temp); } } // WriteLine(string.Join(" ",list)); WriteLine(list.Count); } 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) { if (n < r) return 0; 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] = double.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- 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(); } } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20]]
8
1,234
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { Scanner cin = new Scanner(); int n = cin.Int(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = cin.Int(); } SortedList<int, long> sl = new SortedList<int, long>(n); sl.Add(a[n - 1], 1); for (int i = n - 2; i >= 0; --i) { if (sl.Keys[sl.Keys.Count() - 1] <= a[i]) { if (sl.ContainsKey(a[i])) { sl[a[i]] += 1; } else { sl.Add(a[i], 1); } } else { int index = BinarySearch(sl, a[i]); int key = sl.Keys[index]; long num = sl[key]; if (num == 1) { sl.Remove(key); if (sl.ContainsKey(a[i])) { sl[a[i]] += num; } else { sl.Add(a[i], num); } } else { sl[key] -= 1; if (sl.ContainsKey(a[i])) { sl[a[i]] += 1; } else { sl.Add(a[i], 1); } } } } long ans = sl.Values.Sum(); Console.WriteLine(ans); } static int BinarySearch(SortedList<int, long> sl, int ai) { int left = -1; int right = sl.Count(); while (right - left > 1) { int mid = left + (right - left) / 2; if (sl.Keys[mid] >= ai) { right = mid; } else { left = mid; } } return right; } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { Scanner cin = new Scanner(); int n = cin.Int(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = cin.Int(); } SortedList<int, long> sl = new SortedList<int, long>(n); sl.Add(a[n - 1], 1); for (int i = n - 2; i >= 0; --i) { if (sl.Keys[sl.Keys.Count() - 1] <= a[i]) { if (sl.ContainsKey(a[i])) { sl[a[i]] += 1; } else { sl.Add(a[i], 1); } } else { int index = BinarySearch(sl, a[i]); int key = sl.Keys[index]; long num = sl[key]; if (num == 1) { sl.Remove(key); if (sl.ContainsKey(a[i])) { sl[a[i]] += num; } else { sl.Add(a[i], num); } } else { sl[key] -= 1; if (sl.ContainsKey(a[i])) { sl[a[i]] += 1; } else { sl.Add(a[i], 1); } } } } long ans = sl.Values.Sum(); Console.WriteLine(ans); } static int BinarySearch(SortedList<int, long> sl, int ai) { int left = -1; int right = sl.Count(); while (right - left > 1) { int mid = left + (right - left) / 2; if (sl.Keys[mid] > ai) { right = mid; } else { left = mid; } } return right; } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47]]
8
820
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long[] A = new long[N]; for (long i = 0; i < N; i++) { A[i] = long.Parse(Console.ReadLine()); } var List = new List<long>(); List.Add(A[0]); int len = 1; for (int i = 1; i < N; i++) { // for (int j = 0; j < len; j++) Console.Write(List[j]); // Console.WriteLine(' '); if (List[len - 1] >= A[i]) { List.Add(A[i]); len++; } else if (List[0] < A[i]) { List[0] = A[i]; } else { int min = 0, max = len - 1; while (true) { if ((max - min) == 1) { List[max] = A[i]; break; } int mid = (min + max) / 2; if (A[i] <= List[mid]) { max = mid; } else { min = mid; } } } } // for (int i = 0; i < len; i++) Console.Write(List[i]); Console.WriteLine(List.Count); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long[] A = new long[N]; for (long i = 0; i < N; i++) { A[i] = long.Parse(Console.ReadLine()); } var List = new List<long>(); List.Add(A[0]); int len = 1; for (int i = 1; i < N; i++) { // for (int j = 0; j < len; j++) Console.Write(List[j]); // Console.WriteLine(' '); if (List[len - 1] >= A[i]) { List.Add(A[i]); len++; } else if (List[0] < A[i]) { List[0] = A[i]; } else { int min = 0, max = len - 1; while (true) { if ((max - min) == 1) { List[max] = A[i]; break; } int mid = (min + max) / 2; if (A[i] > List[mid]) { max = mid; } else { min = mid; } } } } // for (int i = 0; i < len; i++) Console.Write(List[i]); Console.WriteLine(List.Count); Console.ReadLine(); } } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47]]
8
297
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { long n = int.Parse(Console.ReadLine()); long[] a = new long[n]; List<long> color = new List<long>(); for (int i = 0; i < n; i++) { a[i] = int.Parse(Console.ReadLine()); } // colorは昇順だとinsertが遅いので降順にする color.Add(a[0]); for (int i = 1; i < n; i++) { int cnt = color.Count; if (a[i] <= color[cnt - 1]) { color.Add(a[i]); } else if (a[i] > color[0]) { color[0] = a[i]; } else { // 2分探査 int iS, iM, iL; iS = cnt - 1; // 最小値なのでこれにかぶせる可能性はある iL = 0; // 最大値なのでこれにかぶせる可能性はない for (int j = 0; j < cnt; j++) { iM = (iS + iL) / 2; if (iS == iM) { color[iS] = a[i]; break; } if (color[iM] >= a[i]) { iL = iM; } else { iS = iM; } } } }         Console.WriteLine(color.Count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { long n = int.Parse(Console.ReadLine()); long[] a = new long[n]; List<long> color = new List<long>(); for (int i = 0; i < n; i++) { a[i] = int.Parse(Console.ReadLine()); } // colorは昇順だとinsertが遅いので降順にする color.Add(a[0]); for (int i = 1; i < n; i++) { int cnt = color.Count; if (a[i] <= color[cnt - 1]) { color.Add(a[i]); } else if (a[i] > color[0]) { color[0] = a[i]; } else { // 2分探査 int iS, iM, iL; iS = cnt - 1; // 最小値なのでこれにかぶせる可能性はある iL = 0; // 最大値なのでこれにかぶせる可能性はない for (int j = 0; j < cnt; j++) { iM = (iS + iL + 1) / 2; if (iS == iM) { color[iS] = a[i]; break; } if (color[iM] >= a[i]) { iL = iM; } else { iS = iM; } } } } Console.WriteLine(color.Count); } } }
[["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 8, 196], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 197], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 198], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 199, 0, 200], ["-", 0, 197, 0, 198, 39, 199, 0, 200, 0, 197], ["-", 0, 198, 39, 199, 0, 200, 0, 197, 0, 198], ["-", 39, 199, 0, 200, 0, 197, 0, 198, 39, 224], ["-", 0, 200, 0, 197, 0, 198, 39, 224, 0, 200], ["-", 0, 197, 0, 198, 39, 224, 0, 200, 0, 197], ["-", 0, 198, 39, 224, 0, 200, 0, 197, 0, 198], ["-", 39, 224, 0, 200, 0, 197, 0, 198, 39, 236], ["-", 0, 200, 0, 197, 0, 198, 39, 236, 0, 200], ["-", 0, 197, 0, 198, 39, 236, 0, 200, 0, 7], ["-", 0, 198, 39, 236, 0, 200, 0, 7, 10, 198], ["-", 39, 236, 0, 200, 0, 7, 10, 198, 39, 199], ["-", 0, 200, 0, 7, 10, 198, 39, 199, 0, 200], ["-", 0, 7, 10, 198, 39, 199, 0, 200, 15, 16], ["-", 10, 198, 39, 199, 0, 200, 15, 16, 31, 22], ["-", 39, 199, 0, 200, 15, 16, 31, 22, 12, 22], ["-", 0, 200, 15, 16, 31, 22, 12, 22, 26, 223], ["-", 15, 16, 31, 22, 12, 22, 26, 223, 0, 22], ["-", 31, 22, 12, 22, 26, 223, 0, 22, 8, 196], ["-", 12, 22, 26, 223, 0, 22, 8, 196, 0, 1], ["-", 26, 223, 0, 22, 8, 196, 0, 1, 0, 169], ["-", 0, 22, 8, 196, 0, 1, 0, 169, 0, 1], ["-", 8, 196, 0, 1, 0, 169, 0, 1, 0, 213], ["-", 0, 1, 0, 169, 0, 1, 0, 213, 63, 214], ["-", 0, 169, 0, 1, 0, 213, 63, 214, 3, 4], ["-", 0, 1, 0, 213, 63, 214, 3, 4, 0, 7], ["-", 0, 213, 63, 214, 3, 4, 0, 7, 10, 198], ["-", 63, 214, 3, 4, 0, 7, 10, 198, 39, 199], ["-", 3, 4, 0, 7, 10, 198, 39, 199, 0, 200], ["-", 12, 22, 26, 223, 0, 22, 8, 196, 0, 197], ["-", 26, 223, 0, 22, 8, 196, 0, 197, 0, 57], ["-", 0, 22, 8, 196, 0, 197, 0, 57, 0, 1], ["-", 8, 196, 0, 197, 0, 57, 0, 1, 0, 213], ["-", 0, 197, 0, 57, 0, 1, 0, 213, 63, 214], ["-", 0, 57, 0, 1, 0, 213, 63, 214, 3, 4]]
8
311
3
using System; using System.Collections.Generic; namespace abc134_e { static class Program { static void Main(string[] args) { var n = Console.ReadLine().ToInteger(); var a = new int[n]; for (int i = 0; i < a.Length; i++) { a[i] = Console.ReadLine().ToInteger(); } // 各色の最大値(最後の値)を小さい順に入れて置く var colors = new List<int>(); colors.Plus(0, a[0]); for (int i = 1; i < a.Length; i++) { // 各色の最後の値より大きいものの中で、最大の値を採用 // どの色の最後の値よりも小さかったら、色を足す。 var color = colors.Smaller(a[i] - 1); colors.Minus(color); colors.Plus(color, a[i]); } Console.WriteLine($"{colors.Count}"); } static int ToInteger(this string s) { return int.Parse(s); } static int Smaller(this List<int> list, int key) { // 開始位置 var first = 0; // 終了位置+1 var last = list.Count; while (first < last) { // 中央位置 var middle = (last + first) / 2; // 中央位置を比較して、範囲を狭めていく if (list[middle] < key) { first = middle + 1; } else { last = middle; } if (list[middle] == key) { first = middle; last = middle; break; } } if (first < 0) { first = 0; } if (first >= list.Count) { first = list.Count - 1; } if (list[first] > key) { first = -1; } return first; } static int Larger(this List<int> list, int start, int key) { var ret = -1; if (start < 0) { start = 0; } var count = list.Count; for (int i = start; i < count; i++) { if (list[i] >= key) { ret = i; break; } } return ret; } static void Plus(this List<int> list, int later, int key) { var index = list.Larger(later, key); if (index >= 0) { list.Insert(index, key); } else { list.Add(key); } } static void Minus(this List<int> list, int index) { if (index >= 0) { list.RemoveAt(index); } } } }
using System; using System.Collections.Generic; namespace abc134_e { static class Program { static void Main(string[] args) { var n = Console.ReadLine().ToInteger(); var a = new int[n]; for (int i = 0; i < a.Length; i++) { a[i] = Console.ReadLine().ToInteger(); } // 各色の最大値(最後の値)を小さい順に入れて置く var colors = new List<int>(); colors.Plus(0, a[0]); for (int i = 1; i < a.Length; i++) { // 各色の最後の値より大きいものの中で、最大の値を採用 // どの色の最後の値よりも小さかったら、色を足す。 var color = colors.Smaller(a[i] - 1); colors.Minus(color); colors.Plus(color, a[i]); } Console.WriteLine($"{colors.Count}"); } static int ToInteger(this string s) { return int.Parse(s); } static int Smaller(this List<int> list, int key) { // 開始位置 var first = 0; // 終了位置+1 var last = list.Count; while (first < last) { // 中央位置 var middle = (last + first) / 2; // 中央位置を比較して、範囲を狭めていく if (list[middle] < key) { first = middle + 1; } else { last = middle; } if (list[middle] == key) { first = middle; last = middle; break; } } if (first < 0) { first = 0; } if (first >= list.Count) { first = list.Count - 1; } if (list[first] > key) { first -= 1; } return first; } static int Larger(this List<int> list, int start, int key) { var ret = -1; if (start < 0) { start = 0; } var count = list.Count; for (int i = start; i < count; i++) { if (list[i] >= key) { ret = i; break; } } return ret; } static void Plus(this List<int> list, int later, int key) { var index = list.Larger(later, key); if (index >= 0) { list.Insert(index, key); } else { list.Add(key); } } static void Minus(this List<int> list, int index) { if (index >= 0) { list.RemoveAt(index); } } } }
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110]]
8
508
3
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var A = sc.ReadIntArray(N); var g = A.GroupBy(a => a); var count = g.Count(); var ok = false; if (count == 1) { ok = A.All(x => x == 0); } else if (count == 2 && N % 3 == 0) { ok = A.Count(x => x == 0) == N / 3; } else if (count == 3 && N % 3 == 0) { var xs = g.Select(x => x.Key).ToArray(); ok = (xs[0] ^ xs[1] ^ xs[0]) == 0 && g.All(x => x.Count() == N / 3); } Console.WriteLine(ok ? "Yes" : "No"); } static int MOD = (int)1e9 + 7; static int INF = (int)1e7 + 1; static long LINF = (long)1e13 + 1; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var A = sc.ReadIntArray(N); var g = A.GroupBy(a => a); var count = g.Count(); var ok = false; if (count == 1) { ok = A.All(x => x == 0); } else if (count == 2 && N % 3 == 0) { ok = A.Count(x => x == 0) == N / 3; } else if (count == 3 && N % 3 == 0) { var xs = g.Select(x => x.Key).ToArray(); ok = (xs[0] ^ xs[1] ^ xs[2]) == 0 && g.All(x => x.Count() == N / 3); } Console.WriteLine(ok ? "Yes" : "No"); } static int MOD = (int)1e9 + 7; static int INF = (int)1e7 + 1; static long LINF = (long)1e13 + 1; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
[["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
760
2
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { class CountedHashSet { public class Counter { public Counter() { count = 1; } public int count { get; set; } } public Dictionary<int, Counter> keySet; public CountedHashSet() { keySet = new Dictionary<int, Counter>(); } public void Add(int key) { Counter c; if (keySet.TryGetValue(key, out c)) { c.count++; } else { keySet.Add(key, new Counter()); } } public int GetKeyCount(int key) { Counter c; if (keySet.TryGetValue(key, out c)) { return c.count; } return 0; } } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); CountedHashSet hs = new CountedHashSet(); for (int i = 0; i < N; i++) { hs.Add(int.Parse(s[i])); } if (hs.keySet.Count == 1) { if (hs.keySet.ContainsKey(0)) { Console.WriteLine("Yes"); return; } Console.WriteLine("No"); return; } if (hs.keySet.Count <= 2) { int countZ = 0; int countNZ = 0; foreach (KeyValuePair<int, CountedHashSet.Counter> e in hs.keySet) { if (e.Key == 0) { countZ = e.Value.count; } else { countNZ = e.Value.count; } } if (countZ < countNZ) { Console.WriteLine("Yes"); return; } Console.WriteLine("No"); return; } if (hs.keySet.Count != 3) { Console.WriteLine("No"); return; } if (hs.keySet.ContainsKey(0)) { Console.WriteLine("No"); return; } int ans = 0; int prevCount = -1; foreach (KeyValuePair<int, CountedHashSet.Counter> e in hs.keySet) { ans ^= e.Key; if (prevCount > 0) { if (prevCount != e.Value.count) { Console.WriteLine("No"); return; } } prevCount = e.Value.count; } if (0 != ans) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { class CountedHashSet { public class Counter { public Counter() { count = 1; } public int count { get; set; } } public Dictionary<int, Counter> keySet; public CountedHashSet() { keySet = new Dictionary<int, Counter>(); } public void Add(int key) { Counter c; if (keySet.TryGetValue(key, out c)) { c.count++; } else { keySet.Add(key, new Counter()); } } public int GetKeyCount(int key) { Counter c; if (keySet.TryGetValue(key, out c)) { return c.count; } return 0; } } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] s = Console.ReadLine().Split(' '); CountedHashSet hs = new CountedHashSet(); for (int i = 0; i < N; i++) { hs.Add(int.Parse(s[i])); } if (hs.keySet.Count == 1) { if (hs.keySet.ContainsKey(0)) { Console.WriteLine("Yes"); return; } Console.WriteLine("No"); return; } if (hs.keySet.Count <= 2) { int countZ = 0; int countNZ = 0; foreach (KeyValuePair<int, CountedHashSet.Counter> e in hs.keySet) { if (e.Key == 0) { countZ = e.Value.count; } else { countNZ = e.Value.count; } } if (countZ * 2 != countNZ) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); return; } if (hs.keySet.Count != 3) { Console.WriteLine("No"); return; } if (hs.keySet.ContainsKey(0)) { Console.WriteLine("No"); return; } int ans = 0; int prevCount = -1; foreach (KeyValuePair<int, CountedHashSet.Counter> e in hs.keySet) { ans ^= e.Key; if (prevCount > 0) { if (prevCount != e.Value.count) { Console.WriteLine("No"); return; } } prevCount = e.Value.count; } if (0 != ans) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } } }
[["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
545
8
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var A = sc.ReadInt(); var B = sc.ReadInt(); var ans = N * Math.Min(A, B); Console.WriteLine(ans); } static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } } 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 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 char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var A = sc.ReadInt(); var B = sc.ReadInt(); var ans = Math.Min(N * A, B); Console.WriteLine(ans); } static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } } 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 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 char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48]]
8
707
4
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 NAB = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var N = NAB[0]; var A = NAB[1]; var B = NAB[2]; var ans = Math.Max(N * A, B); Console.WriteLine(ans); } } }
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 NAB = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var N = NAB[0]; var A = NAB[1]; var B = NAB[2]; var ans = Math.Min(N * A, B); Console.WriteLine(ans); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
113
2
using System; using System.Linq; namespace atcoder { class Program { static void Main(string[] args) { A.TorT(); } } class A { public static void TorT() { int[] num = Input.getIntArray(); int train = num[0] * num[1]; if (train > num[1]) { Output.writeInt(num[2]); } else { Output.writeInt(train); } } } class Input { public static int getInt() { int i = int.Parse(Console.ReadLine()); return i; } public static string getString() { string s = Console.ReadLine(); return s; } public static int[] getIntArray() { string[] s = Console.ReadLine().Split(' '); int[] num = s.Select(x => int.Parse(x)).ToArray(); return num; } } class Output { public static void writeInt(int i) { Console.WriteLine(i); } } }
using System; using System.Linq; namespace atcoder { class Program { static void Main(string[] args) { A.TorT(); } } class A { public static void TorT() { int[] num = Input.getIntArray(); int train = num[0] * num[1]; if (train > num[2]) { Output.writeInt(num[2]); } else { Output.writeInt(train); } } } class Input { public static int getInt() { int i = int.Parse(Console.ReadLine()); return i; } public static string getString() { string s = Console.ReadLine(); return s; } public static int[] getIntArray() { string[] s = Console.ReadLine().Split(' '); int[] num = s.Select(x => int.Parse(x)).ToArray(); return num; } } class Output { public static void writeInt(int i) { Console.WriteLine(i); } } }
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
224
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC132 { class Program { static void Main(string[] args) { string Str = Console.ReadLine().Trim(); int n = int.Parse(Str); Str = Console.ReadLine().Trim(); string[] StrArr = Str.Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); int[] d = StrArr.Select(int.Parse).ToArray(); int k = 0; int tmp = n / 2; d.OrderBy(value => value); if (d[tmp - 1] == d[tmp]) { k = 0; } else { k = d[tmp] - d[tmp - 1]; } Console.WriteLine(k); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC132 { class Program { static void Main(string[] args) { string Str = Console.ReadLine().Trim(); int n = int.Parse(Str); Str = Console.ReadLine().Trim(); string[] StrArr = Str.Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries); int[] d = StrArr.Select(int.Parse).ToArray(); int k = 0; int tmp = n / 2; // d.OrderByDescending(value =>value); Array.Sort(d); if (d[tmp - 1] == d[tmp]) { k = 0; } else { k = d[tmp] - d[tmp - 1]; } Console.WriteLine(k); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
189
8
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var array = Console.ReadLine().Split().Select(int.Parse).ToArray(); var max = array.Max(); Array.Sort(array); var center = N / 2 - 1; var count = 0; for (var i = 1; i < max; i++) { if (array[center] < i && i <= array[center + 1]) count++; } Console.WriteLine(count); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var array = Console.ReadLine().Split().Select(int.Parse).ToArray(); var max = array.Max(); Array.Sort(array); var center = N / 2 - 1; var count = 0; for (var i = 1; i <= max; i++) { if (array[center] < i && i <= array[center + 1]) count++; } Console.WriteLine(count); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
146
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var n = long.Parse(input[0]); var blue = long.Parse(input[1]); var red = n - blue; var list = new List<long>(); for (long i = 1; i < blue + 1; i++) { long ans = 0; if (i < red + 2) { ans = ModCombination(red + 1, i) * ModCombination(blue - 1, i - 1); } list.Add(ans); } foreach (var num in list) { Console.WriteLine(num); } Console.ReadLine(); } public static long ModFactorial(long n, long mod) { var result = n; if (n > 0) { while (n > 1) { n--; result *= n; result %= mod; } return result; } else { //マイナス時も1でいいのか? return 1; } } public static long ModPow(long b, long pow, long mod) { if (pow == 1) { return b % mod; } long n = ModPow(b, pow / 2, mod) % mod; if (pow % 2 == 0) { return (n * n) % mod; } else { return (b * ((n * n) % mod)) % mod; } } public static long ModCombination(long sum, long num) { long x = 1; for (var i = 0; i < num; i++) { x *= (sum - i); x %= 1000000007; } var result = (x * (ModPow(ModFactorial(num, 1000000007), 1000000005, 1000000007))) % 1000000007; return result; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var n = long.Parse(input[0]); var blue = long.Parse(input[1]); var red = n - blue; var list = new List<long>(); for (long i = 1; i < blue + 1; i++) { long ans = 0; if (i < red + 2) { ans = ModCombination(red + 1, i) * ModCombination(blue - 1, i - 1) % 1000000007; } list.Add(ans); } foreach (var num in list) { Console.WriteLine(num); } Console.ReadLine(); } public static long ModFactorial(long n, long mod) { var result = n; if (n > 0) { while (n > 1) { n--; result *= n; result %= mod; } return result; } else { //マイナス時も1でいいのか? return 1; } } public static long ModPow(long b, long pow, long mod) { if (pow == 1) { return b % mod; } long n = ModPow(b, pow / 2, mod) % mod; if (pow % 2 == 0) { return (n * n) % mod; } else { return (b * ((n * n) % mod)) % mod; } } public static long ModCombination(long sum, long num) { long x = 1; for (var i = 0; i < num; i++) { x *= (sum - i); x %= 1000000007; } var result = (x * (ModPow(ModFactorial(num, 1000000007), 1000000005, 1000000007))) % 1000000007; return result; } }
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
387
2
using System; using System.Linq; namespace ABC132 { class D2 { static long[,] c; static void Main(string[] args) { // input var nk = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nk[0]; var k = nk[1]; var mod = 1000000007; //パスカルの三角形 var c = init(4005); // for i: 0 - K // n-k_C_i * n-1_C_i for (long i = 1; i <= k; i++) { if (n - k + 1 < i) Console.Write(0); else Console.WriteLine( (CalcCombination(n - k + 1, i) * CalcCombination(k - 1, i - 1)) % mod); } } public static long[,] init(long x) { c = new long[x + 5, x + 5]; c[0, 0] = 1; for (long i = 1; i <= x; i++) { for (long j = 0; j <= i; j++) { if (j == 0) c[i, j] = c[i - 1, j]; else c[i, j] = (c[i - 1, j] + c[i - 1, j - 1]) % 1000000007; } } return c; } public static long CalcCombination(long n, long k) { return c[n, k]; } } }
using System; using System.Linq; namespace ABC132 { class D2 { static long[,] c; static void Main(string[] args) { // input var nk = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nk[0]; var k = nk[1]; var mod = 1000000007; init(4005); // for i: 0 - k // n-k_C_i * n-1_C_i for (long i = 1; i <= k; i++) { if (n - k + 1 < i) Console.WriteLine(0); else Console.WriteLine( (CalcCombination(n - k + 1, i) * CalcCombination(k - 1, i - 1)) % mod); } } public static long[,] init(long x) { c = new long[x + 5, x + 5]; c[0, 0] = 1; for (long i = 1; i <= x; i++) { for (long j = 0; j <= i; j++) { if (j == 0) c[i, j] = c[i - 1, j]; else c[i, j] = (c[i - 1, j] + c[i - 1, j - 1]) % 1000000007; } } return c; } public static long CalcCombination(long n, long k) { return c[n, k]; } } }
[["-", 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, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22]]
8
302
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderD { private static int n; private static List<Tuple<int, long>>[] to; private static long[] d; static void Main() { int n; int k; { var line = Console.ReadLine(); var words = line.Split(' '); n = int.Parse(words[0]); k = int.Parse(words[1]); } int blue = n; int red = n - k; int mod = 1000000007; for (int i = 1; i <= k; i++) { long answer = CombinationMod(red + 1, i, mod) * CombinationMod(blue - 1, i - 1, mod) % mod; Console.WriteLine(answer); } } private static long CombinationMod(long m, long n, long mod) { Func<long, long, long> ModPow = (x1, x2) => { long ans = 1; while (x2 > 0) { if (x2 % 2 == 1) { ans = (ans * x1) % mod; } x1 = (x1 * x1) % mod; x2 /= 2; } return ans % mod; }; var a = 1L; var b = 1L; for (long i = 1; i <= n; i++) { a = (a * (m - i + 1)) % mod; b = (b * i) % mod; } long bb = ModPow(b, mod - 2); return (a * bb) % mod; } // Comnibation(mod版) private static long Combination(int n, int k, int d) { long answer = 1; for (int i = n; i > n - k; i--) { answer = Mul(answer, i, d); } for (int i = 1; i <= k; i++) { answer = Div(answer, i, d); } return answer; } // 掛け算(mod版) private static long Mul(long a, long b, long c) { return ((a % c) * (b % c)) % c; } // 割り算(mod版) private static long Div(long a, long b, long c) { return Mul(a, Pow(b, c - 2, c), c); } // べき乗(mod版) private static long Pow(long a, long b, long c) { if (b == 0) { return 1; } else if (b == 1) { return a % c; } else if (b % 2 == 0) { long d = Pow(a, b / 2, c); return d * d % c; } else { return a * Pow(a, b - 1, c) % c; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderD { private static int n; private static List<Tuple<int, long>>[] to; private static long[] d; static void Main() { int n; int k; { var line = Console.ReadLine(); var words = line.Split(' '); n = int.Parse(words[0]); k = int.Parse(words[1]); } int blue = k; int red = n - k; int mod = 1000000007; for (int i = 1; i <= k; i++) { long answer = CombinationMod(red + 1, i, mod) * CombinationMod(blue - 1, i - 1, mod) % mod; Console.WriteLine(answer); } } private static long CombinationMod(long m, long n, long mod) { Func<long, long, long> ModPow = (x1, x2) => { long ans = 1; while (x2 > 0) { if (x2 % 2 == 1) { ans = (ans * x1) % mod; } x1 = (x1 * x1) % mod; x2 /= 2; } return ans % mod; }; var a = 1L; var b = 1L; for (long i = 1; i <= n; i++) { a = (a * (m - i + 1)) % mod; b = (b * i) % mod; } long bb = ModPow(b, mod - 2); return (a * bb) % mod; } // Comnibation(mod版) private static long Combination(int n, int k, int d) { long answer = 1; for (int i = n; i > n - k; i--) { answer = Mul(answer, i, d); } for (int i = 1; i <= k; i++) { answer = Div(answer, i, d); } return answer; } // 掛け算(mod版) private static long Mul(long a, long b, long c) { return ((a % c) * (b % c)) % c; } // 割り算(mod版) private static long Div(long a, long b, long c) { return Mul(a, Pow(b, c - 2, c), c); } // べき乗(mod版) private static long Pow(long a, long b, long c) { if (b == 0) { return 1; } else if (b == 1) { return a % c; } else if (b % 2 == 0) { long d = Pow(a, b / 2, c); return d * d % c; } else { return a * Pow(a, b - 1, c) % c; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
585
2
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var s = sc.Ia; Cb r = new Cb(s[0] << 1); for (int i = 1; i <= s[1]; i++) { Console.WriteLine("{0}", r.C1(s[1] - 1, i - 1) * (s[0] - s[1] - i + 1 < 0 ? 0 : r.C1(i + 1 + s[0] - s[1] - i, (s[0] - s[1] - i + 1)))); } } } public class Cb { private const int mod = (int)1e9 + 7; public long[] r; public Cb(int n) { r = new long[n]; r[0] = 1; for (int i = 1; i < n; i++) { r[i] = (r[i - 1] * i) % mod; } } public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } public long C2(long n, long k) { long l = 1; n %= mod; for (int i = 1; i <= k; i++) { l = (l * (n - i + 1)) % mod; l = (l * Mi(i)) % mod; } return l; } public long P1(long n, long k) { return n < k ? 0 : (r[n] * Mi(r[n - k])) % mod; } public long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public struct Mint { const int mod = (int)1e9 + 7; private long d; public Mint(long d) { this.d = d; } public static implicit operator Mint(long d) { return new Mint(d % mod); } public static explicit operator long(Mint d) { return d.d; } public override string ToString() { return d.ToString(); } public static Mint operator +(Mint a, long b) { a.d = (a.d + b) % mod; return a; } public static Mint operator +(Mint a, Mint b) { a.d = (a.d + b.d) % mod; return a; } public static Mint operator -(Mint a, long b) { a.d = (mod + a.d - b) % mod; return a; } public static Mint operator -(Mint a, Mint b) { a.d = (mod + a.d - b.d) % mod; return a; } public static Mint operator *(Mint a, long b) { a.d = (a.d * b) % mod; return a; } public static Mint operator *(Mint a, Mint b) { a.d = (a.d * b.d) % mod; return a; } public static Mint operator /(Mint a, long b) { a.d = (a.d * Mi(b)) % mod; return a; } public static Mint operator /(Mint a, Mint b) { a.d = (a.d * Mi(b.d)) % mod; return a; } private static long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var s = sc.Ia; Cb r = new Cb(s[0] << 1); for (int i = 1; i <= s[1]; i++) { Console.WriteLine( "{0}", (r.C1(s[1] - 1, i - 1) * (s[0] - s[1] - i + 1 < 0 ? 0 : r.C1(i + 1 + s[0] - s[1] - i, (s[0] - s[1] - i + 1)))) % mod); } } } public class Cb { private const int mod = (int)1e9 + 7; public long[] r; public Cb(int n) { r = new long[n]; r[0] = 1; for (int i = 1; i < n; i++) { r[i] = (r[i - 1] * i) % mod; } } public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } public long C2(long n, long k) { long l = 1; n %= mod; for (int i = 1; i <= k; i++) { l = (l * (n - i + 1)) % mod; l = (l * Mi(i)) % mod; } return l; } public long P1(long n, long k) { return n < k ? 0 : (r[n] * Mi(r[n - k])) % mod; } public long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public struct Mint { const int mod = (int)1e9 + 7; private long d; public Mint(long d) { this.d = d; } public static implicit operator Mint(long d) { return new Mint(d % mod); } public static explicit operator long(Mint d) { return d.d; } public override string ToString() { return d.ToString(); } public static Mint operator +(Mint a, long b) { a.d = (a.d + b) % mod; return a; } public static Mint operator +(Mint a, Mint b) { a.d = (a.d + b.d) % mod; return a; } public static Mint operator -(Mint a, long b) { a.d = (mod + a.d - b) % mod; return a; } public static Mint operator -(Mint a, Mint b) { a.d = (mod + a.d - b.d) % mod; return a; } public static Mint operator *(Mint a, long b) { a.d = (a.d * b) % mod; return a; } public static Mint operator *(Mint a, Mint b) { a.d = (a.d * b.d) % mod; return a; } public static Mint operator /(Mint a, long b) { a.d = (a.d * Mi(b)) % mod; return a; } public static Mint operator /(Mint a, Mint b) { a.d = (a.d * Mi(b.d)) % mod; return a; } private static long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 75, 213, 3, 4, 0, 28, 0, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
1,940
4
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); int[] s = sc.Ia; Cb r = new Cb(s[0]); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= s[1]; i++) { long p = s[0] - s[1] + 1 < i ? 0 : ((r.C1(s[0] - s[1] + 1, i) * r.C1(s[1] - 1, i - 1)) % mod); sb.Append(p + "\n"); } Console.Write(sb); } } public class Cb { private const int mod = (int)1e9 + 7; public long[] r; public Cb(int n) { r = new long[n]; r[0] = 1; for (int i = 1; i < n; i++) { r[i] = (r[i - 1] * i) % mod; } } public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } public long C2(long n, long k) { long l = 1; n %= mod; for (int i = 1; i <= k; i++) { l = (l * (n - i + 1)) % mod; l = (l * Mi(i)) % mod; } return l; } public long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); int[] s = sc.Ia; Cb r = new Cb(s[0] + 1); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= s[1]; i++) { long p = s[0] - s[1] + 1 < i ? 0 : ((r.C1(s[0] - s[1] + 1, i) * r.C1(s[1] - 1, i - 1)) % mod); sb.Append(p + "\n"); } Console.Write(sb); } } public class Cb { private const int mod = (int)1e9 + 7; public long[] r; public Cb(int n) { r = new long[n]; r[0] = 1; for (int i = 1; i < n; i++) { r[i] = (r[i - 1] * i) % mod; } } public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } public long C2(long n, long k) { long l = 1; n %= mod; for (int i = 1; i <= k; i++) { l = (l * (n - i + 1)) % mod; l = (l * Mi(i)) % mod; } return l; } public long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["+", 0, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 12, 203]]
8
1,291
2
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static void Write(object obj) { #if DEBUG Debug.Write(obj.ToString()); #else Console.Write(obj.ToString()); #endif } static void WriteLine(object obj) { #if DEBUG Debug.WriteLine(obj.ToString()); #else Console.WriteLine(obj.ToString()); #endif } static long mod = 1000000007; static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var n = int.Parse(spl[0]); var k = int.Parse(spl[1]); var l = n - k; for (int i = 1; i <= k; i++) { WriteLine(Calc(k, l, i)); } return null; } static long Calc(long b, long r, long i) { var ptn = CombinationMod(r + 1, i); var oneptn = CombinationMod(b - 1, i - 1); return ptn * oneptn; } static long CombinationMod(long m, long n) { Func<long, long, long> ModPow = (x1, x2) => { long ans = 1; while (x2 > 0) { if (x2 % 2 == 1) { ans = (ans * x1) % mod; } x1 = (x1 * x1) % mod; x2 /= 2; } return ans % mod; }; var a = 1L; var b = 1L; for (long i = 1; i <= n; i++) { a = (a * (m - i + 1)) % mod; b = (b * i) % mod; } long bb = ModPow(b, mod - 2); return (a * bb) % mod; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static void Write(object obj) { #if DEBUG Debug.Write(obj.ToString()); #else Console.Write(obj.ToString()); #endif } static void WriteLine(object obj) { #if DEBUG Debug.WriteLine(obj.ToString()); #else Console.WriteLine(obj.ToString()); #endif } static long mod = 1000000007; static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var n = int.Parse(spl[0]); var k = int.Parse(spl[1]); var l = n - k; for (int i = 1; i <= k; i++) { WriteLine(Calc(k, l, i)); } return null; } static long Calc(long b, long r, long i) { var ptn = CombinationMod(r + 1, i); var oneptn = CombinationMod(b - 1, i - 1); return ptn * oneptn % mod; } static long CombinationMod(long m, long n) { Func<long, long, long> ModPow = (x1, x2) => { long ans = 1; while (x2 > 0) { if (x2 % 2 == 1) { ans = (ans * x1) % mod; } x1 = (x1 * x1) % mod; x2 /= 2; } return ans % mod; }; var a = 1L; var b = 1L; for (long i = 1; i <= n; i++) { a = (a * (m - i + 1)) % mod; b = (b * i) % mod; } long bb = ModPow(b, mod - 2); return (a * bb) % mod; } }
[["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 109], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 22]]
8
461
2
using System; class Program { const int MOD = 1000000007; static int[,] c; static void Main(string[] args) { initc(); var nk = Console.ReadLine().Split(); var n = int.Parse(nk[0]); var k = int.Parse(nk[1]); for (int i = 1; i <= k; i++) { var red = 0; red += f(n - k, i - 1); red %= MOD; red += f(n - k, i); red %= MOD; red += f(n - k, i); red %= MOD; red += f(n - k, i + 1); red %= MOD; var ans = f(k, i) * red; ans %= MOD; Console.WriteLine(ans); } } static void initc() { c = new int[4005, 4005]; c[0, 0] = 1; for (int i = 0; i <= 4000; i++) { for (int j = 0; j <= i; j++) { c[i + 1, j] += c[i, j]; c[i + 1, j] %= MOD; c[i + 1, j + 1] += c[i, j]; c[i + 1, j + 1] %= MOD; } } } static int f(int n, int k) { if (n < k) return 0; if (n == 0 && k == 0) return 1; if (k < 1) return 0; return f2(n - k, k); } static int f2(int n, int k) { return comb(n + k - 1, k - 1); } static int comb(int x, int y) { return c[x, y]; } }
using System; class Program { const int MOD = 1000000007; static long[,] c; static void Main(string[] args) { initc(); var nk = Console.ReadLine().Split(); var n = int.Parse(nk[0]); var k = int.Parse(nk[1]); for (int i = 1; i <= k; i++) { var red = 0L; red += f(n - k, i - 1); red %= MOD; red += f(n - k, i); red %= MOD; red += f(n - k, i); red %= MOD; red += f(n - k, i + 1); red %= MOD; var ans = f(k, i) * red; ans %= MOD; Console.WriteLine(ans); } } static void initc() { c = new long[4005, 4005]; c[0, 0] = 1; for (int i = 0; i <= 4000; i++) { for (int j = 0; j <= i; j++) { c[i + 1, j] += c[i, j]; c[i + 1, j] %= MOD; c[i + 1, j + 1] += c[i, j]; c[i + 1, j + 1] %= MOD; } } } static long f(int n, int k) { if (n < k) return 0; if (n == 0 && k == 0) return 1; if (k < 1) return 0; return f2(n - k, k); } static long f2(int n, int k) { return comb(n + k - 1, k - 1); } static long comb(int x, int y) { return c[x, y]; } }
[["-", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["+", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["-", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199]]
8
397
12
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int K = int.Parse(input[1]); const long mod = 1000000007; long[,] C = new long[N, N]; C[0, 0] = 1; int Cmax = Math.Max(K - 1, N - K + 1); for (int i = 1; i <= Cmax; i++) { for (int j = 0; j <= i; j++) { if (j == 0) C[i, j] = C[i - 1, j]; else C[i, j] = (C[i - 1, j - 1] + C[i - 1, j]) % mod; } } for (int i = 1; i <= K; i++) { long blue = C[K - 1, i - 1]; long red; if (N - K + 1 < i) red = 0; else red = C[N - K + 1, i]; Console.WriteLine((blue * red) % mod); } } }
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int K = int.Parse(input[1]); const long mod = 1000000007; long[,] C = new long[N + 1, N + 1]; C[0, 0] = 1; int Cmax = Math.Max(K - 1, N - K + 1); for (int i = 1; i <= Cmax; i++) { for (int j = 0; j <= i; j++) { if (j == 0) C[i, j] = C[i - 1, j]; else C[i, j] = (C[i - 1, j - 1] + C[i - 1, j]) % mod; } } for (int i = 1; i <= K; i++) { long blue = C[K - 1, i - 1]; long red; if (N - K + 1 < i) red = 0; else red = C[N - K + 1, i]; Console.WriteLine((blue * red) % mod); } } }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
8
265
4
using System; using System.Linq; using System.Collections.Generic; class Program { private const int mod = 1000000007; //パスカルの三角形 static long[,] pascalsTriangle = new long[4005, 4005]; static void Main() { var nk = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); var N = nk[0]; var K = nk[1]; pascalsTriangle[0, 0] = 1; for (int i = 0; i <= 4000; i++) { for (int j = 0; j <= 4000; j++) { pascalsTriangle[i + 1, j] = (pascalsTriangle[i + 1, j] + pascalsTriangle[i, j]) % mod; pascalsTriangle[i + 1, j + 1] = (pascalsTriangle[i + 1, j + 1] + pascalsTriangle[i, j]) % mod; } } for (var i = 1; i <= K; ++i) { var blue = F(K, i); var red = 0L; //青の間 red = (red + F(N - K, i - 1)) % mod; //青の間と左 red = (red + F(N - K, i)) % mod; //青の間と右 red = (red + F(N - K, i)) % mod; //青の間と両端 red = (red + F(N - K, i + 1)) % mod; Console.WriteLine(blue * red); } } // 0個のグループを許容する static long F(long whole, long parts) { if (whole < parts) return 0; if (whole == 0 && parts == 0) return 1; if (parts <= 0) return 0; return F2(whole - parts, parts); //=f(whole,parts) } //玉と仕切りを置く場所の選び方 static long F2(long whole, long parts) { return pascalsTriangle[whole + parts - 1, parts - 1]; } }
using System; using System.Linq; using System.Collections.Generic; class Program { private const int mod = 1000000007; //パスカルの三角形 static long[,] pascalsTriangle = new long[4005, 4005]; static void Main() { var nk = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); var N = nk[0]; var K = nk[1]; pascalsTriangle[0, 0] = 1; for (int i = 0; i <= 4000; i++) { for (int j = 0; j <= 4000; j++) { pascalsTriangle[i + 1, j] = (pascalsTriangle[i + 1, j] + pascalsTriangle[i, j]) % mod; pascalsTriangle[i + 1, j + 1] = (pascalsTriangle[i + 1, j + 1] + pascalsTriangle[i, j]) % mod; } } for (var i = 1; i <= K; ++i) { var blue = F(K, i); var red = 0L; //青の間 red = (red + F(N - K, i - 1)) % mod; //青の間と左 red = (red + F(N - K, i)) % mod; //青の間と右 red = (red + F(N - K, i)) % mod; //青の間と両端 red = (red + F(N - K, i + 1)) % mod; Console.WriteLine((blue * red) % mod); } } // 0個のグループを許容する static long F(long whole, long parts) { if (whole < parts) return 0; if (whole == 0 && parts == 0) return 1; if (parts <= 0) return 0; return F2(whole - parts, parts); //=f(whole,parts) } //玉と仕切りを置く場所の選び方 static long F2(long whole, long parts) { return pascalsTriangle[whole + parts - 1, parts - 1]; } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
398
4
using static System.Console; public class Hello { const long p = 1000000007; static string l = ReadLine(); static readonly long N = long.Parse(l.Split()[0]); static readonly long K = long.Parse(l.Split()[1]); public static void Main() { long[,] Comb = new long[N, K + 1]; // nCm = n-1Cm-1 + n-1Cm for (int i = 0; i < N; i++) { for (int j = 0; j < K + 1; j++) { // Comb[i,j]を計算 if (j == 0) Comb[i, j] = 1; else if (i == 0) Comb[i, j] = 0; else Comb[i, j] = (Comb[i - 1, j - 1] + Comb[i - 1, j]) % p; } } for (long i = 0; i < K; i++) { WriteLine(Comb[N - K + 1, i + 1] * Comb[K - 1, i] % p); } } }
using static System.Console; public class Hello { const long p = 1000000007; static string l = ReadLine(); static readonly long N = long.Parse(l.Split()[0]); static readonly long K = long.Parse(l.Split()[1]); public static void Main() { long[,] Comb = new long[N + 1, K + 1]; // nCm = n-1Cm-1 + n-1Cm for (int i = 0; i < N + 1; i++) { for (int j = 0; j < K + 1; j++) { // Comb[i,j]を計算 if (j == 0) Comb[i, j] = 1; else if (i == 0) Comb[i, j] = 0; else Comb[i, j] = (Comb[i - 1, j - 1] + Comb[i - 1, j]) % p; } } for (long i = 0; i < K; i++) { WriteLine(Comb[N - K + 1, i + 1] * Comb[K - 1, i] % p); } } }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
229
4