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; public class Hello { public static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int A = input[0]; int B = input[1]; int C = input[2]; var nums = new long[1000]; nums[0] = 0; nums[1] = A; for (var i = 2; i < nums.Length; i++) { nums[i] = nums[i - 1] + i * A; if (nums[i] % B == C) { Console.WriteLine("YES"); return; } } Console.WriteLine("NO"); } }
using System; public class Hello { public static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int A = input[0]; int B = input[1]; int C = input[2]; var nums = new long[1000]; nums[0] = 0; for (var i = 1; i < nums.Length; i++) { nums[i] = i * A; if (nums[i] % B == C) { Console.WriteLine("YES"); return; } } Console.WriteLine("NO"); } }
[["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
8
155
16
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int A = cin.nextInt(); int B = cin.nextInt(); int C = cin.nextInt(); if (gcd(A, B) == gcd(C, B)) { Console.WriteLine("YES"); } else Console.WriteLine("NO"); } long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int A = cin.nextInt(); int B = cin.nextInt(); int C = cin.nextInt(); if (gcd(C, B) % gcd(A, B) == 0) { Console.WriteLine("YES"); } else Console.WriteLine("NO"); } long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 31, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 31, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
530
8
#pragma warning disable using System.Collections.Generic; using System.IO; using System.Linq; using System; using System.Collections; using static System.Math; using static System.Console; class E { static void Main() => new J(); } class J { int F() => int.Parse(ReadLine()); int[] G() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); public J() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var I = G(); int A = I[0], B = I[1], C = I[2]; for (var k = 1; k <= B; k++) if (k * A % B == C) WriteLine("YES"); WriteLine("NO"); } long GCD(long a, long b) { var n = (ulong)Abs(a); var m = (ulong)Abs(b); if (n == 0) return (long)m; if (m == 0) return (long)n; int zm = 0, zn = 0; while ((n & 1) == 0) { n >>= 1; zn++; } while ((m & 1) == 0) { m >>= 1; zm++; } while (m != n) { if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; } else { n -= m; while ((n & 1) == 0) n >>= 1; } } return (long)n << Min(zm, zn); } }
#pragma warning disable using System.Collections.Generic; using System.IO; using System.Linq; using System; using System.Collections; using static System.Math; using static System.Console; class E { static void Main() => new J(); } class J { int F() => int.Parse(ReadLine()); int[] G() => ReadLine() .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); public J() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var I = G(); int A = I[0], B = I[1], C = I[2]; var g = GCD(A, B); WriteLine(C % g == 0 ? "YES" : "NO"); } long GCD(long a, long b) { var n = (ulong)Abs(a); var m = (ulong)Abs(b); if (n == 0) return (long)m; if (m == 0) return (long)n; int zm = 0, zn = 0; while ((n & 1) == 0) { n >>= 1; zn++; } while ((m & 1) == 0) { m >>= 1; zm++; } while (m != n) { if (m > n) { m -= n; while ((m & 1) == 0) m >>= 1; } else { n -= m; while ((n & 1) == 0) n >>= 1; } } return (long)n << Min(zm, zn); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 57, 0, 121], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 8, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 8, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 7, 8, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 8, 196, 0, 7, 8, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 7, 8, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["-", 8, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 57, 64, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102]]
8
394
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; 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 = new Scanner(); 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() { long N = cin.nextLong(); long T = cin.nextLong(); long now = cin.nextLong(); long ans = 0; for (int i = 1; i < N; i++) { long next = cin.nextLong(); if (next >= now + T) { ans += T; } else { ans += next - now; } if (i == N - 1) { ans += T; } now = next; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; 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 = new Scanner(); 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() { long N = cin.nextLong(); long T = cin.nextLong(); if (N == 1) { Console.WriteLine(T); return; } long now = cin.nextLong(); long ans = 0; for (int i = 1; i < N; i++) { long next = cin.nextLong(); if (next >= now + T) { ans += T; } else { ans += next - now; } if (i == N - 1) { ans += T; } now = next; } Console.WriteLine(ans); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
744
17
using System; using System.Collections.Generic; using System.Linq; class MainClass { public static void Main(string[] args) { //入力3 var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var list = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = temp[0]; var T = temp[1]; var sumtime = 0; var stoptime = 0; for (var i = 0; i < N; i++) { if (i == N - 1) { sumtime += stoptime - list[i - 1]; break; } if (list[i + 1] - list[i] < T) { sumtime += list[i + 1] - list[i]; } else { sumtime += T; } stoptime = list[i] + T; } Console.WriteLine(sumtime); } }
using System; using System.Collections.Generic; using System.Linq; class MainClass { public static void Main(string[] args) { //入力3 var temp = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var list = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = temp[0]; var T = temp[1]; if (N == 1) { Console.WriteLine(T); return; } var sumtime = 0; var stoptime = 0; for (var i = 0; i < N; i++) { if (i == N - 1) { sumtime += stoptime - list[i - 1]; break; } if (list[i + 1] - list[i] < T) { sumtime += list[i + 1] - list[i]; } else { sumtime += T; } stoptime = list[i] + T; } Console.WriteLine(sumtime); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
206
17
using System; class P { static void Main(string[] args) { var kari = Console.ReadLine().Split(' '); int ninzu = int.Parse(kari[0]); int oyu = int.Parse(kari[1]); var timeS = Console.ReadLine().Split(' '); int[] time = new int[ninzu]; for (int i = 0; i < ninzu; i++) { time[i] = int.Parse(timeS[i]); } int sum_time = 0; for (int i = 1; i < time.Length; i++) { if ((time[i] - time[i - 1]) > oyu) { sum_time += time[i]; } else { sum_time += oyu; } } Console.WriteLine(sum_time); } }
using System; class P { static void Main(string[] args) { var kari = Console.ReadLine().Split(' '); int ninzu = int.Parse(kari[0]); int oyu = int.Parse(kari[1]); var timeS = Console.ReadLine().Split(' '); int[] time = new int[ninzu]; for (int i = 0; i < ninzu; i++) { time[i] = int.Parse(timeS[i]); } int sum_time = 0; for (int i = 1; i < time.Length; i++) { if ((time[i] - time[i - 1]) < oyu) { sum_time += (time[i] - time[i - 1]); } else { sum_time += oyu; } } sum_time += oyu; Console.WriteLine(sum_time); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 64, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
182
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class AC073C { #if true static void Main(string[] args) { string s1 = Console.ReadLine(); string s2 = Console.ReadLine(); Console.WriteLine(funcMain(s1, s2)); #if DEBUG Console.ReadKey(); #endif } #else static void Main(string[] args) { test(); } #endif static private string funcMain(string arg1, string arg2) { string[] bufarray; bufarray = arg1.Split(); int Ninzu = int.Parse(bufarray[0]); long OneTime = long.Parse(bufarray[1]); long TotalTime = 0; long NowTime = 0; foreach (string buf in arg2.Split()) { long t = long.Parse(buf); if (t == 0) continue; if (t > OneTime) { TotalTime += OneTime; } else { TotalTime += t - NowTime; } NowTime = t; } TotalTime += OneTime; return TotalTime.ToString(); } static private void test() { string arg1, arg2; arg1 = "2 4"; arg2 = "0 3"; Console.WriteLine("7" == funcMain(arg1, arg2)); arg1 = "2 4"; arg2 = "0 5"; Console.WriteLine("8" == funcMain(arg1, arg2)); arg1 = "4 1000000000"; arg2 = "0 1000 1000000 1000000000"; Console.WriteLine("2000000000" == funcMain(arg1, arg2)); arg1 = "1 1"; arg2 = "0"; Console.WriteLine("1" == funcMain(arg1, arg2)); arg1 = "9 10"; arg2 = "0 3 5 7 100 110 200 300 311"; Console.WriteLine("67" == funcMain(arg1, arg2)); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class AC073C { #if true static void Main(string[] args) { string s1 = Console.ReadLine(); string s2 = Console.ReadLine(); Console.WriteLine(funcMain(s1, s2)); #if DEBUG Console.ReadKey(); #endif } #else static void Main(string[] args) { test(); } #endif static private string funcMain(string arg1, string arg2) { string[] bufarray; bufarray = arg1.Split(); int Ninzu = int.Parse(bufarray[0]); long OneTime = long.Parse(bufarray[1]); long TotalTime = 0; long NowTime = 0; foreach (long t in arg2.Split().Select(f => long.Parse(f))) { TotalTime += Math.Min(t - NowTime, OneTime); NowTime = t; } TotalTime += OneTime; return TotalTime.ToString(); } static private void test() { string arg1, arg2; arg1 = "2 4"; arg2 = "0 3"; Console.WriteLine("7" == funcMain(arg1, arg2)); arg1 = "2 4"; arg2 = "0 5"; Console.WriteLine("8" == funcMain(arg1, arg2)); arg1 = "4 1000000000"; arg2 = "0 1000 1000000 1000000000"; Console.WriteLine("2000000000" == funcMain(arg1, arg2)); arg1 = "1 1"; arg2 = "0"; Console.WriteLine("1" == funcMain(arg1, arg2)); arg1 = "9 10"; arg2 = "0 3 5 7 100 110 200 300 311"; Console.WriteLine("67" == funcMain(arg1, arg2)); Console.ReadKey(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["-", 8, 196, 0, 210, 12, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 45], ["-", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 218, 8, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 210, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 210, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 210, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["-", 0, 210, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 0, 210, 8, 196, 0, 57, 75, 196, 0, 46]]
8
397
30
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class AC073C { #if true static void Main(string[] args) { string s1 = Console.ReadLine(); string s2 = Console.ReadLine(); Console.WriteLine(funcMain(s1, s2)); #if DEBUG Console.ReadKey(); #endif } #else static void Main(string[] args) { test(); } #endif static private string funcMain(string arg1, string arg2) { string[] bufarray; bufarray = arg1.Split(); int Ninzu = int.Parse(bufarray[0]); long OneTime = long.Parse(bufarray[1]); long TotalTime = 0; long NowTime = 0; foreach (string buf in arg2.Split()) { long t = long.Parse(buf); if (t == 0) continue; if (t > OneTime) { TotalTime += OneTime; } else { TotalTime += t - NowTime; } NowTime = t; } TotalTime += OneTime; return TotalTime.ToString(); } static private void test() { string arg1, arg2; arg1 = "2 4"; arg2 = "0 3"; Console.WriteLine("7" == funcMain(arg1, arg2)); arg1 = "2 4"; arg2 = "0 5"; Console.WriteLine("8" == funcMain(arg1, arg2)); arg1 = "4 1000000000"; arg2 = "0 1000 1000000 1000000000"; Console.WriteLine("2000000000" == funcMain(arg1, arg2)); arg1 = "1 1"; arg2 = "0"; Console.WriteLine("1" == funcMain(arg1, arg2)); arg1 = "9 10"; arg2 = "0 3 5 7 100 110 200 300 311"; Console.WriteLine("67" == funcMain(arg1, arg2)); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class AC073C { #if true static void Main(string[] args) { string s1 = Console.ReadLine(); string s2 = Console.ReadLine(); Console.WriteLine(funcMain(s1, s2)); #if DEBUG Console.ReadKey(); #endif } #else static void Main(string[] args) { test(); } #endif static private string funcMain(string arg1, string arg2) { string[] bufarray; bufarray = arg1.Split(); int Ninzu = int.Parse(bufarray[0]); long OneTime = long.Parse(bufarray[1]); long TotalTime = 0; long NowTime = 0; foreach (string buf in arg2.Split()) { long t = long.Parse(buf); TotalTime += Math.Min(t - NowTime, OneTime); NowTime = t; } TotalTime += OneTime; return TotalTime.ToString(); } static private void test() { string arg1, arg2; arg1 = "2 4"; arg2 = "0 3"; Console.WriteLine("7" == funcMain(arg1, arg2)); arg1 = "2 4"; arg2 = "0 5"; Console.WriteLine("8" == funcMain(arg1, arg2)); arg1 = "4 1000000000"; arg2 = "0 1000 1000000 1000000000"; Console.WriteLine("2000000000" == funcMain(arg1, arg2)); arg1 = "1 1"; arg2 = "0"; Console.WriteLine("1" == funcMain(arg1, arg2)); arg1 = "9 10"; arg2 = "0 3 5 7 100 110 200 300 311"; Console.WriteLine("67" == funcMain(arg1, arg2)); Console.ReadKey(); } } }
[["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["-", 0, 210, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 210, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["-", 0, 210, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 0, 210, 8, 196, 0, 57, 75, 196, 0, 46]]
8
397
30
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); int count = (int)inpt[0]; long addTime = inpt[1]; inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); long ans = addTime; for (int i = 1; i < count; i++) { if (inpt[i] < addTime) { ans += inpt[i]; } else { ans += addTime; } } Console.WriteLine(ans); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 4 0 3 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); int count = (int)inpt[0]; long addTime = inpt[1]; inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); long ans = 0; long tmpTime = addTime; for (int i = 1; i < count; i++) { if (inpt[i] - inpt[i - 1] < tmpTime) { ans += (inpt[i] - inpt[i - 1]); tmpTime = addTime; } else { ans += tmpTime; tmpTime = addTime; } } ans += tmpTime; Console.WriteLine(ans); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 9 10 0 3 5 7 100 110 200 300 311 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
8
280
37
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; private const long INFINITY = 9223372036854775807; public static void Main() { // w1から3しか重さが違わない int N = NextInt(); long W = NextLong(); long[] w = new long[N]; int[] v = new int[N]; long w1 = NextInt(); w[0] = 0; v[0] = NextInt(); for (int i = 1; i < N; i++) { w[i] = NextInt() - w1; v[i] = NextInt(); } // i 個目の要素までの解 , 適当に , w1に相当する重さが何個あるか long[,,] dp = new long[N + 1, N + 1, 500]; for (int i = 0; i <= N; i++) for (int j = 0; j <= N; j++) for (int k = 0; k < 500; k++) dp[i, j, k] = -INF; dp[0, 0, 0] = 0; for (int i = 0; i < N; i++) for (int j = 0; j <= N; j++) for (int k = 0; k < 500; k++) { if (dp[i, j, k] == -INF) continue; dp[i + 1, j, k] = dp[i, j, k]; //現在j個使ってて余剰分 = k if ((j + 1) * w1 + k + w[i] > W) break; dp[i + 1, j + 1, k + w[i]] = Math.Max(dp[i, j + 1, k + w[i]], dp[i + 1, j, k] + v[i]); } long ans = 0; for (int j = 0; j <= N; j++) for (int k = 0; k < 500; k++) ans = Math.Max(dp[N, j, k], ans); Console.WriteLine(ans); } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; private const long INFINITY = 9223372036854775807; public static void Main() { // w1から3しか重さが違わない int N = NextInt(); long W = NextLong(); long[] w = new long[N]; int[] v = new int[N]; long w1 = NextInt(); w[0] = 0; v[0] = NextInt(); for (int i = 1; i < N; i++) { w[i] = NextInt() - w1; v[i] = NextInt(); } // i 個目の要素までの解 , 適当に , w1に相当する重さが何個あるか long[,,] dp = new long[N + 1, N + 1, 500]; for (int i = 0; i <= N; i++) for (int j = 0; j <= N; j++) for (int k = 0; k < 500; k++) dp[i, j, k] = -INF; dp[0, 0, 0] = 0; for (int i = 0; i < N; i++) for (int j = N; j != -1; j--) for (int k = 400; k != -1; k--) { if (dp[i, j, k] == -INF) continue; dp[i + 1, j, k] = dp[i, j, k]; //現在j個使ってて余剰分 = k if ((j + 1) * w1 + k + w[i] > W) continue; dp[i + 1, j + 1, k + w[i]] = Math.Max(dp[i, j + 1, k + w[i]], dp[i + 1, j, k] + v[i]); } long ans = 0; for (int j = 0; j <= N; j++) for (int k = 0; k < 500; k++) ans = Math.Max(dp[N, j, k], ans); Console.WriteLine(ans); } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
[["-", 8, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 7, 15, 16, 17, 79], ["+", 0, 7, 8, 7, 15, 16, 12, 241, 0, 33], ["+", 0, 7, 8, 7, 15, 16, 12, 241, 0, 203], ["-", 8, 196, 0, 7, 8, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 7, 26, 223, 0, 68], ["+", 8, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 7, 8, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 7, 8, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 7, 8, 7, 15, 16, 17, 79], ["+", 8, 7, 8, 7, 15, 16, 12, 241, 0, 33], ["+", 8, 7, 8, 7, 15, 16, 12, 241, 0, 203], ["-", 0, 7, 8, 7, 8, 7, 26, 223, 0, 29], ["+", 0, 7, 8, 7, 8, 7, 26, 223, 0, 68], ["-", 8, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 8, 7, 8, 196, 0, 57, 64, 116, 0, 117]]
8
730
20
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long n = long.Parse(input[0]); long w = long.Parse(input[1]); long[,] vertexes = new long[n, 2]; //ここに受け取る long[,,] dp = new long[n + 1, 101, 301]; // dp[見た数、とった数、超過の重さ] = 価値の最大値 long answer = 0; for (long i = 0; i < n; i++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); //1行ごとに受け取る vertexes[i, 0] = nums[0]; vertexes[i, 1] = nums[1]; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= 100; j++) { for (int k = 0; k <= 300; k++) { dp[i, j, k] = dp[i - 1, j, k]; //取らない場合 if (j - 1 >= 0 && k - (vertexes[i - 1, 0] - vertexes[0, 0]) >= 0) dp[i, j, k] = dp[i - 1, j - 1, k - (vertexes[i - 1, 0] - vertexes[0, 0])] + vertexes[i - 1, 1]; } } } for (int i = 0; i <= n; i++) { for (int j = 0; j <= 100; j++) { for (int k = 0; k <= 300; k++) { if (vertexes[0, 0] * j + k <= w) answer = Math.Max(dp[i, j, k], answer); } } } Console.WriteLine(answer); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long n = long.Parse(input[0]); long w = long.Parse(input[1]); long[,] vertexes = new long[n, 2]; //ここに受け取る long[,,] dp = new long[n + 1, n + 1, 3 * n + 1]; // dp[見た数、とった数、超過の重さ] = 価値の最大値 long answer = 0; for (long i = 0; i < n; i++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); //1行ごとに受け取る vertexes[i, 0] = nums[0]; vertexes[i, 1] = nums[1]; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= 3 * n; k++) { dp[i, j, k] = dp[i - 1, j, k]; //取らない場合 if (j - 1 >= 0 && k - (vertexes[i - 1, 0] - vertexes[0, 0]) >= 0) { dp[i, j, k] = Math.Max( dp[i, j, k], dp[i - 1, j - 1, k - (vertexes[i - 1, 0] - vertexes[0, 0])] + vertexes[i - 1, 1]); } } } } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= 3 * n; k++) { if (vertexes[0, 0] * j + k <= w) answer = Math.Max(dp[i, j, k], answer); } } } Console.WriteLine(answer); } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 39, 224, 225, 226, 0, 16, 31, 16, 31, 203], ["+", 39, 224, 225, 226, 0, 16, 31, 16, 17, 48], ["+", 39, 224, 225, 226, 0, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 21], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
422
38
using System; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.IO; using CodeChallenges; using System.Diagnostics; namespace CodeChallenges.Boilerplate.IO { #region helpers class FormattedStreamWriter : StreamWriter { public FormattedStreamWriter(Stream stream) : base(stream) {} public FormattedStreamWriter(string filePath) : base(filePath) {} public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } } static class IOExtensions { public static string ReadString(this StreamReader reader) { return reader.ReadToken(); } public static string[] ReadStringArray(this StreamReader reader, int n) { var array = new string[n]; for (int i = 0; i < n; ++i) { array[i] = reader.ReadToken(); } return array; } public static int ReadInt(this StreamReader reader) { return int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray(this StreamReader reader, int n) { var array = new int[n]; for (int i = 0; i < n; ++i) { array[i] = int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static uint ReadUnsignedInt(this StreamReader reader) { return uint.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static long ReadLong(this StreamReader reader) { return long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static long[] ReadLongArray(this StreamReader reader, int n) { var array = new long[n]; for (int i = 0; i < n; ++i) { array[i] = long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static ulong ReadUnsignedLong(this StreamReader reader) { return ulong.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static double ReadDouble(this StreamReader reader) { return double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static double[] ReadDoubleArray(this StreamReader reader, int n) { var array = new double[n]; for (int i = 0; i < n; ++i) { array[i] = double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static decimal ReadDecimal(this StreamReader reader) { return decimal.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static decimal[] ReadDecimalArray(this StreamReader reader, int n) { var array = new decimal[n]; for (int i = 0; i < n; ++i) { array[i] = decimal.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static void ResetBuffer() { buffer = new Queue<string>(1000); } static Queue<string> buffer = new Queue<string>(1000); static string ReadToken(this StreamReader reader) { while (buffer.Count == 0) { reader.ReadLine() .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .ToList() .ForEach((t) => { buffer.Enqueue(t); }); } return buffer.Dequeue(); } } #endregion } #region launch class Program { static void Main(string[] args) { #if SOLVER_ATWORKSPACE var run = true; var outputFile = "output.txt"; var inputFile = "input.txt"; switch (args[0]) { case "g": run = false; outputFile = "input.txt"; inputFile = "output.txt"; break; case "r": default: run = true; inputFile = "input.txt"; outputFile = "output.txt"; break; } #endif using (var writer = new CodeChallenges.Boilerplate.IO.FormattedStreamWriter( #if SOLVER_ATWORKSPACE outputFile #else Console.OpenStandardOutput() #endif )) { using (var reader = new StreamReader( #if SOLVER_ATWORKSPACE inputFile #else Console.OpenStandardInput() #endif )) { #if SOLVER_ATWORKSPACE var stopw = new Stopwatch(); stopw.Start(); #endif #if SOLVER_ATWORKSPACE if (run) new Solver(reader, writer).Do(); else new Generator(reader, writer).Create(); #else new Solver(reader, writer).Do(); #endif #if SOLVER_ATWORKSPACE stopw.Stop(); writer.WriteLine("> {0}ms", stopw.ElapsedMilliseconds); #endif } } } } #endregion namespace CodeChallenges { using CodeChallenges.Boilerplate.IO; public class Solver { private readonly StreamReader reader; private readonly StreamWriter writer; public Solver(StreamReader reader, StreamWriter writer) { this.reader = reader; this.writer = writer; } // public int Solve(int W, int K, int N) //{ // if (K == 0) // return 0; // if (dim[N][K][W] > 0) // return dim[N][K][W] - 1; // var one = K < N ? Solve(W, K, N - 1): 0; // var two = (W >= w[N - 1])? (v[N - 1] + Solve(W - w[N - 1], K - 1, N - // 1)): 0; dim[N][K][W] = Math.Max(one, two) + 1; return dim[N][K][W] - 1; //} public void Do() { const int DELTA = 3; int N = reader.ReadInt(); int W = reader.ReadInt(); int[][][] dim = new int [N + 1][][]; int[] w = new int[N]; int[] v = new int[N]; for (int i = 0; i < N; ++i) { w[i] = reader.ReadInt(); v[i] = reader.ReadInt(); } var w0 = w[0]; for (int i = 0; i <= N; ++i) { dim[i] = new int [N + 1][]; for (int j = 0; j <= N; ++j) { dim[i][j] = new int[DELTA * N + 1]; for (int k = 0; k <= DELTA * N; ++k) dim[i][j][k] = int.MinValue; } } for (int i = 0; i <= N; ++i) { for (int k = 0; k <= DELTA * N; ++k) dim[i][0][k] = 0; if (i > 0) w[i - 1] -= w0; for (int j = 1; j <= i; ++j) for (int k = 0; k <= DELTA * N; ++k) { if (k >= w[i - 1]) dim[i][j][k] = Math.Max(dim[i][j][k], v[i - 1] + dim[i - 1][j - 1][k - w[i - 1]]); if (i > j) dim[i][j][k] = Math.Max(dim[i][j][k], dim[i - 1][j][k]); } } int total = int.MinValue; for (int ii = 1; ii <= N; ++ii) for (int j = Math.Min(W - ii * w0, ii * DELTA); j >= 0; --j) total = Math.Max(total, dim[N][ii][j]); writer.WriteLine(total); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Globalization; using System.IO; using CodeChallenges; using System.Diagnostics; namespace CodeChallenges.Boilerplate.IO { #region helpers class FormattedStreamWriter : StreamWriter { public FormattedStreamWriter(Stream stream) : base(stream) {} public FormattedStreamWriter(string filePath) : base(filePath) {} public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } } static class IOExtensions { public static string ReadString(this StreamReader reader) { return reader.ReadToken(); } public static string[] ReadStringArray(this StreamReader reader, int n) { var array = new string[n]; for (int i = 0; i < n; ++i) { array[i] = reader.ReadToken(); } return array; } public static int ReadInt(this StreamReader reader) { return int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray(this StreamReader reader, int n) { var array = new int[n]; for (int i = 0; i < n; ++i) { array[i] = int.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static uint ReadUnsignedInt(this StreamReader reader) { return uint.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static long ReadLong(this StreamReader reader) { return long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static long[] ReadLongArray(this StreamReader reader, int n) { var array = new long[n]; for (int i = 0; i < n; ++i) { array[i] = long.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static ulong ReadUnsignedLong(this StreamReader reader) { return ulong.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static double ReadDouble(this StreamReader reader) { return double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static double[] ReadDoubleArray(this StreamReader reader, int n) { var array = new double[n]; for (int i = 0; i < n; ++i) { array[i] = double.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static decimal ReadDecimal(this StreamReader reader) { return decimal.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } public static decimal[] ReadDecimalArray(this StreamReader reader, int n) { var array = new decimal[n]; for (int i = 0; i < n; ++i) { array[i] = decimal.Parse(reader.ReadToken(), CultureInfo.InvariantCulture); } return array; } public static void ResetBuffer() { buffer = new Queue<string>(1000); } static Queue<string> buffer = new Queue<string>(1000); static string ReadToken(this StreamReader reader) { while (buffer.Count == 0) { reader.ReadLine() .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries) .ToList() .ForEach((t) => { buffer.Enqueue(t); }); } return buffer.Dequeue(); } } #endregion } #region launch class Program { static void Main(string[] args) { #if SOLVER_ATWORKSPACE var run = true; var outputFile = "output.txt"; var inputFile = "input.txt"; switch (args[0]) { case "g": run = false; outputFile = "input.txt"; inputFile = "output.txt"; break; case "r": default: run = true; inputFile = "input.txt"; outputFile = "output.txt"; break; } #endif using (var writer = new CodeChallenges.Boilerplate.IO.FormattedStreamWriter( #if SOLVER_ATWORKSPACE outputFile #else Console.OpenStandardOutput() #endif )) { using (var reader = new StreamReader( #if SOLVER_ATWORKSPACE inputFile #else Console.OpenStandardInput() #endif )) { #if SOLVER_ATWORKSPACE var stopw = new Stopwatch(); stopw.Start(); #endif #if SOLVER_ATWORKSPACE if (run) new Solver(reader, writer).Do(); else new Generator(reader, writer).Create(); #else new Solver(reader, writer).Do(); #endif #if SOLVER_ATWORKSPACE stopw.Stop(); writer.WriteLine("> {0}ms", stopw.ElapsedMilliseconds); #endif } } } } #endregion namespace CodeChallenges { using CodeChallenges.Boilerplate.IO; public class Solver { private readonly StreamReader reader; private readonly StreamWriter writer; public Solver(StreamReader reader, StreamWriter writer) { this.reader = reader; this.writer = writer; } // public int Solve(int W, int K, int N) //{ // if (K == 0) // return 0; // if (dim[N][K][W] > 0) // return dim[N][K][W] - 1; // var one = K < N ? Solve(W, K, N - 1): 0; // var two = (W >= w[N - 1])? (v[N - 1] + Solve(W - w[N - 1], K - 1, N - // 1)): 0; dim[N][K][W] = Math.Max(one, two) + 1; return dim[N][K][W] - 1; //} public void Do() { const int DELTA = 3; int N = reader.ReadInt(); int W = reader.ReadInt(); int[][][] dim = new int [N + 1][][]; int[] w = new int[N]; int[] v = new int[N]; for (int i = 0; i < N; ++i) { w[i] = reader.ReadInt(); v[i] = reader.ReadInt(); } var w0 = w[0]; for (int i = 0; i <= N; ++i) { dim[i] = new int [N + 1][]; for (int j = 0; j <= N; ++j) { dim[i][j] = new int[DELTA * N + 1]; for (int k = 0; k <= DELTA * N; ++k) dim[i][j][k] = int.MinValue; } } for (int i = 0; i <= N; ++i) { for (int k = 0; k <= DELTA * N; ++k) dim[i][0][k] = 0; if (i > 0) w[i - 1] -= w0; for (int j = 1; j <= i; ++j) for (int k = 0; k <= DELTA * N; ++k) { if (k >= w[i - 1]) dim[i][j][k] = Math.Max(dim[i][j][k], v[i - 1] + dim[i - 1][j - 1][k - w[i - 1]]); if (i > j) dim[i][j][k] = Math.Max(dim[i][j][k], dim[i - 1][j][k]); } } int total = 0; for (int ii = 1; ii <= N; ++ii) if (W - 1L * ii * w0 >= 0) { var WN = Math.Min(W - ii * w0, ii * DELTA); total = Math.Max(total, dim[N][ii][WN]); } writer.WriteLine(total); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 8, 7, 0, 88], ["+", 0, 195, 8, 196, 0, 7, 8, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 7, 10, 198, 39, 199], ["-", 0, 7, 8, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 8, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 7, 8, 57, 15, 16, 31, 16, 17, 33], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 203], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 48], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["+", 8, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 7, 8, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 57, 0, 25], ["+", 8, 196, 0, 7, 8, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 31, 22], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 17, 20], ["-", 8, 196, 0, 7, 8, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 8, 7, 0, 35], ["-", 8, 196, 0, 7, 8, 7, 26, 241, 0, 68], ["-", 8, 196, 0, 7, 8, 7, 26, 241, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 8, 7, 0, 25], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 196, 0, 7, 8, 57, 64, 196, 0, 46]]
8
1,502
31
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); long W = int.Parse(str[1]); str = Console.ReadLine().Split(' '); long w1 = int.Parse(str[0]); List<long>[] v = new List<long>[4]; for (int i = 0; i < 4; i++) { v[i] = new List<long>(); } v[0].Add(int.Parse(str[1])); for (int i = 1; i < N; i++) { str = Console.ReadLine().Split(' '); v[int.Parse(str[0]) - w1].Add(int.Parse(str[1])); } long[][] V = new long [4][]; for (int i = 0; i < 4; i++) { V[i] = v[i].ToArray(); Array.Sort(V[i]); } long count = 0; long sum1 = 0; long nw1 = 0; for (int i = 0; i <= V[0].Length; i++) { if (nw1 > W) { break; } long sum2 = sum1; long nw2 = nw1; for (int j = 0; j <= V[1].Length; j++) { if (nw2 > W) { break; } long sum3 = sum2; long nw3 = nw2; for (int k = 0; k <= V[2].Length; k++) { if (nw3 > W) { break; } long sum4 = sum3; long nw4 = nw3; for (int l = 0; l <= V[3].Length; l++) { if (nw4 > W) { break; } count = Math.Max(count, sum4); if (l != V[3].Length) { sum4 += V[3][l]; nw4 += w1 + 3; } } if (k != V[2].Length) { sum3 += V[2][k]; nw3 += w1 + 2; } } if (j != V[1].Length) { sum2 += V[1][j]; nw2 += w1 + 1; } } if (i != V[0].Length) { sum1 += V[0][i]; nw1 += w1; } } sb.Append(count + "\n"); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); long W = int.Parse(str[1]); str = Console.ReadLine().Split(' '); long w1 = int.Parse(str[0]); List<long>[] v = new List<long>[4]; for (int i = 0; i < 4; i++) { v[i] = new List<long>(); } v[0].Add(int.Parse(str[1])); for (int i = 1; i < N; i++) { str = Console.ReadLine().Split(' '); v[int.Parse(str[0]) - w1].Add(int.Parse(str[1])); } long[][] V = new long [4][]; for (int i = 0; i < 4; i++) { V[i] = v[i].ToArray(); Array.Sort(V[i], (a, b) => (a > b ? -1 : (a < b ? 1 : 0))); } long count = 0; long sum1 = 0; long nw1 = 0; for (int i = 0; i <= V[0].Length; i++) { if (nw1 > W) { break; } long sum2 = sum1; long nw2 = nw1; for (int j = 0; j <= V[1].Length; j++) { if (nw2 > W) { break; } long sum3 = sum2; long nw3 = nw2; for (int k = 0; k <= V[2].Length; k++) { if (nw3 > W) { break; } long sum4 = sum3; long nw4 = nw3; for (int l = 0; l <= V[3].Length; l++) { if (nw4 > W) { break; } count = Math.Max(count, sum4); if (l != V[3].Length) { sum4 += V[3][l]; nw4 += w1 + 3; } } if (k != V[2].Length) { sum3 += V[2][k]; nw3 += w1 + 2; } } if (j != V[1].Length) { sum2 += V[1][j]; nw2 += w1 + 1; } } if (i != V[0].Length) { sum1 += V[0][i]; nw1 += w1; } } sb.Append(count + "\n"); } }
[["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 23, 0, 24], ["+", 0, 218, 8, 23, 0, 41, 15, 16, 31, 22], ["+", 0, 218, 8, 23, 0, 41, 15, 16, 17, 47], ["+", 0, 218, 8, 23, 0, 41, 15, 16, 12, 22], ["+", 0, 28, 0, 218, 8, 23, 0, 41, 0, 101], ["+", 0, 218, 8, 23, 0, 41, 64, 241, 0, 33], ["+", 0, 218, 8, 23, 0, 41, 64, 241, 0, 203], ["+", 0, 28, 0, 218, 8, 23, 0, 41, 0, 102], ["+", 0, 218, 8, 23, 0, 41, 75, 23, 0, 24], ["+", 0, 41, 75, 23, 0, 41, 15, 16, 31, 22], ["+", 0, 41, 75, 23, 0, 41, 15, 16, 17, 18], ["+", 0, 41, 75, 23, 0, 41, 15, 16, 12, 22], ["+", 8, 23, 0, 41, 75, 23, 0, 41, 0, 101], ["+", 8, 23, 0, 41, 75, 23, 0, 41, 64, 203], ["+", 8, 23, 0, 41, 75, 23, 0, 41, 0, 102], ["+", 8, 23, 0, 41, 75, 23, 0, 41, 75, 203], ["+", 0, 218, 8, 23, 0, 41, 75, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 218, 8, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
642
25
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { long W0 = W.Min(); List<long>[] L = new List<long>[4]; for (int i = 0; i < 4; i++) L[i] = new List<long>(); for (int i = 0; i < N; i++) { L[W[i] - W0].Add(V[i]); } for (int i = 0; i < 4; i++) { L[i].Sort(); L[i].Reverse(); } long[][] Ls = new long [4][]; for (int i = 0; i < 4; i++) { Ls[i] = new long[N + 1]; for (int j = 0; j < L[i].Count; j++) { Ls[i][j + 1] = L[i][j] + Ls[i][j]; } } long max = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i + j > N || (W0 * i + (W0 + 1) * j) > Wl) break; for (int k = 0; k < N; k++) { if (i + j + k > N || (W0 * i + (W0 + 1) * j + (W0 + 2) * k) > Wl) break; int rest = (int)Math.Min( N - i - j - k, ((Wl - (W0 * i + (W0 + 1) * j + (W0 + 2) * k)) / (W0 + 3))); long val = Ls[0][i] + Ls[1][j] + Ls[2][k] + Ls[3][rest]; max = Math.Max(max, val); } } } Console.WriteLine(max); } int N; long Wl; long[] W, V; public Sol() { var d = ria(); N = d[0]; Wl = d[1]; W = new long[N]; V = new long[N]; for (int i = 0; i < N; i++) { d = ria(); W[i] = d[0]; V[i] = d[1]; } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { long W0 = W.Min(); List<long>[] L = new List<long>[4]; for (int i = 0; i < 4; i++) L[i] = new List<long>(); for (int i = 0; i < N; i++) { L[W[i] - W0].Add(V[i]); } for (int i = 0; i < 4; i++) { L[i].Sort(); L[i].Reverse(); } long[][] Ls = new long [4][]; for (int i = 0; i < 4; i++) { Ls[i] = new long[N + 1]; for (int j = 0; j < L[i].Count; j++) { Ls[i][j + 1] = L[i][j] + Ls[i][j]; } } long max = 0; for (int i = 0; i <= L[0].Count; i++) { for (int j = 0; j <= L[1].Count; j++) { if (i + j > N || (W0 * i + (W0 + 1) * j) > Wl) break; for (int k = 0; k <= L[2].Count; k++) { if (i + j + k > N || (W0 * i + (W0 + 1) * j + (W0 + 2) * k) > Wl) break; int rest = (int)Math.Min( N - i - j - k, ((Wl - (W0 * i + (W0 + 1) * j + (W0 + 2) * k)) / (W0 + 3))); long val = Ls[0][i] + Ls[1][j] + Ls[2][k] + Ls[3][rest]; max = Math.Max(max, val); } } } Console.WriteLine(max); } int N; long Wl; long[] W, V; public Sol() { var d = ria(); N = d[0]; Wl = d[1]; W = new long[N]; V = new long[N]; for (int i = 0; i < N; i++) { d = ria(); W[i] = d[0]; V[i] = d[1]; } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 15, 16, 12, 214, 205, 204, 205, 22], ["+", 15, 16, 12, 214, 205, 204, 206, 207, 0, 70], ["+", 12, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 214, 205, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
813
27
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static void Main() { Sc sc = new Sc(); int n = sc.I; long[][] a = new long [n][]; long c = int.MaxValue, d = 0; for (int i = 0; i < n; i++) { a[i] = sc.La; if (a[i][0] > a[i][1]) { a[i][0] ^= a[i][1]; a[i][1] ^= a[i][0]; a[i][0] ^= a[i][1]; } c = Math.Min(c, a[i][1]); d = Math.Max(d, a[i][1]); } Array.Sort(a, Ca); long ans = (a[n - 1][0] - a[0][0]) * (d - c); c = a[0][1]; d = a[0][1]; for (int i = 1; i < n; i++) { ans = Math.Min(ans, (a[n - 1][1] - a[0][0]) * (Math.Max(d, a[n - 1][0]) - Math.Min(c, a[i][0]))); c = Math.Min(c, a[i][1]); d = Math.Max(d, a[i][1]); } Console.WriteLine(ans); } static int Ca(long[] a, long[] b) { if (a[0] > b[0]) { return 1; } else if (a[0] < b[0]) { return -1; } else if (a[1] > b[1]) { return 1; } else if (a[1] < b[1]) { return -1; } else { return 0; } } } 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 int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static void Main() { Sc sc = new Sc(); int n = sc.I; long[][] a = new long [n][]; long c = int.MaxValue, d = 0, e = 0; for (int i = 0; i < n; i++) { a[i] = sc.La; if (a[i][0] > a[i][1]) { a[i][0] ^= a[i][1]; a[i][1] ^= a[i][0]; a[i][0] ^= a[i][1]; } c = Math.Min(c, a[i][1]); e = Math.Max(e, a[i][1]); } Array.Sort(a, Ca); long ans = (a[n - 1][0] - a[0][0]) * (e - c); c = a[0][1]; d = a[0][1]; for (int i = 1; i < n; i++) { ans = Math.Min(ans, (e - a[0][0]) * (Math.Max(d, a[n - 1][0]) - Math.Min(c, a[i][0]))); c = Math.Min(c, a[i][1]); d = Math.Max(d, a[i][1]); } Console.WriteLine(ans); } static int Ca(long[] a, long[] b) { if (a[0] > b[0]) { return 1; } else if (a[0] < b[0]) { return -1; } else if (a[1] > b[1]) { return 1; } else if (a[1] < b[1]) { return -1; } else { return 0; } } } 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 int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + 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(); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 31, 23, 0, 16, 31, 204, 205, 204, 205, 22], ["-", 0, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["-", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22]]
8
747
20
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n = sc.Int; var l = new long[n]; var s = new long[n]; long lma = -1, lmi = M, sma = -1, smi = M; for (int i = 0; i < n; i++) { sc.Multi(out l[i], out s[i]); if (l[i] < s[i]) { swap(ref l[i], ref s[i]); } lma = Math.Max(lma, l[i]); lmi = Math.Min(lmi, l[i]); sma = Math.Max(sma, s[i]); smi = Math.Min(smi, s[i]); } var ans = Math.Min((lma - lmi) * (sma - smi), (lma - smi) * Math.Abs(sma - lmi)); var d = lma - smi; Array.Sort(s, l); long lmin = M, lmax = 0; for (int i = 0; i < n - 1; i++) { lmin = Math.Min(lmin, l[i]); lmax = Math.Max(lmax, l[i]); ans = Math.Min(ans, d * (Math.Max(s[n - 1], lmax) - Math.Min(s[i + 1], lmin))); } Prt(ans); sw.Flush(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ // static string Join<T>(string sep, IEnumerable<T> a) { return // string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void // DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params // object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { // Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", // a)); } } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { return v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); } public override string ToString() { return v1 + " " + v2; } } static class util { public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> { return new pair<T, U>(v1, v2); } public static T Max<T>(params T[] a) { return a.Max(); } public static T Min<T>(params T[] a) { return a.Min(); } public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n = sc.Int; var l = new long[n]; var s = new long[n]; long lma = -1, lmi = M, sma = -1, smi = M; for (int i = 0; i < n; i++) { sc.Multi(out l[i], out s[i]); if (l[i] < s[i]) { swap(ref l[i], ref s[i]); } lma = Math.Max(lma, l[i]); lmi = Math.Min(lmi, l[i]); sma = Math.Max(sma, s[i]); smi = Math.Min(smi, s[i]); } var ans = (lma - lmi) * (sma - smi); var d = lma - smi; Array.Sort(s, l); long lmin = M, lmax = 0; for (int i = 0; i < n - 1; i++) { if (s[i] >= lmin) break; lmin = Math.Min(lmin, l[i]); lmax = Math.Max(lmax, l[i]); ans = Math.Min(ans, d * (Math.Max(s[n - 1], lmax) - Math.Min(s[i + 1], lmin))); } Prt(ans); sw.Flush(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ // static string Join<T>(string sep, IEnumerable<T> a) { return // string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void // DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params // object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { // Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", // a)); } } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { return v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); } public override string ToString() { return v1 + " " + v2; } } static class util { public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> { return new pair<T, U>(v1, v2); } public static T Max<T>(params T[] a) { return a.Max(); } public static T Min<T>(params T[] a) { return a.Min(); } public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 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, 213, 3, 4, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35]]
8
4,281
31
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static IO io = new IO(); static void Main(string[] args) { io.Read(); int N = io.Int(); List<Item> items = new List<Item>(); for (int i = 0; i < N; ++i) { io.ReadSplit(); Item item = new Item(); item.x = io.Int(); item.y = io.Int(); if (item.y < item.x) { item.Swap_xy(); } items.Add(item); } items = items.OrderBy(item => item.x).ToList(); int maxR = items.Max(item => item.y); int minR = items.Min(item => item.y); int maxB = items[items.Count - 1].x; int minB = items[0].x; long solution1 = (long)(maxR - minR) * (maxB - minB); minR = minB; int min_difference_maxBminB = int.MaxValue; int minBfromR = items[0].y; for (int i = 1; i < items.Count - 1; ++i) { maxB = Math.Max(maxB, items[i].y); minBfromR = Math.Min(minBfromR, items[i].y); minB = Math.Min(minBfromR, items[i + 1].x); min_difference_maxBminB = Math.Min(min_difference_maxBminB, maxB - minB); } long solution2 = (long)(maxR - minR) * min_difference_maxBminB; io.WriteLine(Math.Min(solution1, solution2).ToString()); } } class Item { public int x; public int y; public void Swap_xy() { int tmp = this.x; this.x = this.y; this.y = tmp; } } class IO { private string[] _Inputs; private int _Index; public void Read() { _Inputs = new string[1]; _Inputs[0] = Console.ReadLine(); _Index = 0; } public void ReadSplit() { _Inputs = Console.ReadLine().Split(' '); _Index = 0; } public string String() { return _Inputs[_Index++]; } public string[] String(int xCount) { string[] rv = new string[xCount]; Array.Copy(_Inputs, _Index, rv, 0, xCount); _Index += xCount; return rv; } public int Int() { return int.Parse(_Inputs[_Index++]); } public int[] Int(int xCount) { int[] rv = new int[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = int.Parse(_Inputs[_Index++]); } return rv; } public long Long() { return long.Parse(_Inputs[_Index++]); } public long[] Long(int xCount) { long[] rv = new long[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = long.Parse(_Inputs[_Index++]); } return rv; } public void Write(string xStr) { Console.Write(xStr); } public void WriteLine(string xStr) { Console.WriteLine(xStr); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static IO io = new IO(); static void Main(string[] args) { io.Read(); int N = io.Int(); List<Item> items = new List<Item>(); for (int i = 0; i < N; ++i) { io.ReadSplit(); Item item = new Item(); item.x = io.Int(); item.y = io.Int(); if (item.y < item.x) { item.Swap_xy(); } items.Add(item); } items = items.OrderBy(item => item.x).ToList(); int maxR = items.Max(item => item.y); int minR = items.Min(item => item.y); int maxB = items[items.Count - 1].x; int minB = items[0].x; long solution1 = (long)(maxR - minR) * (maxB - minB); minR = minB; int minBfromR = int.MaxValue; int min_difference_maxBminB = int.MaxValue; for (int i = 0; i < items.Count - 1; ++i) { maxB = Math.Max(maxB, items[i].y); minBfromR = Math.Min(minBfromR, items[i].y); minB = Math.Min(minBfromR, items[i + 1].x); min_difference_maxBminB = Math.Min(min_difference_maxBminB, maxB - minB); } long solution2 = (long)(maxR - minR) * min_difference_maxBminB; io.WriteLine(Math.Min(solution1, solution2).ToString()); } } class Item { public int x; public int y; public void Swap_xy() { int tmp = this.x; this.x = this.y; this.y = tmp; } } class IO { private string[] _Inputs; private int _Index; public void Read() { _Inputs = new string[1]; _Inputs[0] = Console.ReadLine(); _Index = 0; } public void ReadSplit() { _Inputs = Console.ReadLine().Split(' '); _Index = 0; } public string String() { return _Inputs[_Index++]; } public string[] String(int xCount) { string[] rv = new string[xCount]; Array.Copy(_Inputs, _Index, rv, 0, xCount); _Index += xCount; return rv; } public int Int() { return int.Parse(_Inputs[_Index++]); } public int[] Int(int xCount) { int[] rv = new int[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = int.Parse(_Inputs[_Index++]); } return rv; } public long Long() { return long.Parse(_Inputs[_Index++]); } public long[] Long(int xCount) { long[] rv = new long[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = long.Parse(_Inputs[_Index++]); } return rv; } public void Write(string xStr) { Console.Write(xStr); } public void WriteLine(string xStr) { Console.WriteLine(xStr); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 214, 205, 204, 205, 22], ["-", 0, 212, 0, 214, 205, 204, 206, 207, 0, 70], ["-", 0, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
722
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp43 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split(' ').ToArray(); Console.WriteLine(st[0].ToUpper()[0] + st[1].ToUpper()[0] + st[2].ToUpper()[0]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp43 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split(' ').ToArray(); Console.WriteLine(st[0].ToUpper() [0].ToString() + st[1].ToUpper() [0].ToString() + st[2].ToUpper() [0].ToString()); } } }
[["+", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
8
107
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Language { class Program { static void Main(string[] args) { string[] lan = Console.ReadLine().Split(' '); string a = lan[0]; string b = lan[1]; string c = lan[2]; string upper1 = a.ToUpper(); string upper2 = b.ToUpper(); string upper3 = c.ToUpper(); char Target1 = upper1[0]; char Target2 = upper2[0]; char Target3 = upper3[0]; Console.WriteLine(Target1 + Target2 + Target3); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Language { class Program { static void Main(string[] args) { string[] lan = Console.ReadLine().Split(' '); string a = lan[0]; string b = lan[1]; string c = lan[2]; string upper1 = a.ToUpper(); string upper2 = b.ToUpper(); string upper3 = c.ToUpper(); char Target1 = upper1[0]; char Target2 = upper2[0]; char Target3 = upper3[0]; Console.Write(Target1); Console.Write(Target2); Console.WriteLine(Target3); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
150
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { string line = Console.ReadLine().ToUpper(); string s1 = line.Split(' ')[0]; string s2 = line.Split(' ')[1]; string s3 = line.Split(' ')[2]; Console.WriteLine(s1[0] + s2[0] + s3[0]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { string line = Console.ReadLine().ToUpper(); string s1 = line.Split(' ')[0]; string s2 = line.Split(' ')[1]; string s3 = line.Split(' ')[2]; Console.WriteLine(s1[0].ToString() + s2[0].ToString() + s3[0].ToString()); } } }
[["+", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
8
117
12
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var count = 0; var a = Console.ReadLine(); var b = Console.ReadLine(); if (a.Length > b.Length) Console.WriteLine("GREATER"); if (a.Length < b.Length) Console.WriteLine("LESS"); if (a.Length == b.Length) { for (int i = a.Length - 1; i >= 0; i++) { if (a[i] > b[i]) { Console.WriteLine("GREATER"); break; } if (a[i] < b[i]) { Console.WriteLine("LESS"); break; } count++; } } if (count == a.Length) Console.WriteLine("EQUAL"); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var count = 0; var a = Console.ReadLine(); var b = Console.ReadLine(); if (a.Length > b.Length) Console.WriteLine("GREATER"); if (a.Length < b.Length) Console.WriteLine("LESS"); if (a.Length == b.Length) { for (int i = 0; i < a.Length; i++) { if (a[i] > b[i]) { Console.WriteLine("GREATER"); break; } if (a[i] < b[i]) { Console.WriteLine("LESS"); break; } count++; } } if (count == a.Length) Console.WriteLine("EQUAL"); Console.Out.Flush(); } } }
[["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 35], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 7, 0, 35], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 20], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 203]]
8
287
10
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { string s1 = Console.ReadLine(); string s2 = Console.ReadLine(); s1 = s1.PadLeft(s2.Length, '0'); s2 = s2.PadLeft(s1.Length, '0'); Console.WriteLine(s1); Console.WriteLine(s2); bool equal = true; for (int i = 0; i < s1.Length; i++) { if (s1[i] > s2[i]) { Console.WriteLine("GREATER"); equal = false; break; } else if (s1[i] < s2[i]) { Console.WriteLine("LESS"); equal = false; break; } } if (equal) Console.WriteLine("EQUAL"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { string s1 = Console.ReadLine(); string s2 = Console.ReadLine(); s1 = s1.PadLeft(s2.Length, '0'); s2 = s2.PadLeft(s1.Length, '0'); bool equal = true; for (int i = 0; i < s1.Length; i++) { if (s1[i] > s2[i]) { Console.WriteLine("GREATER"); equal = false; break; } else if (s1[i] < s2[i]) { Console.WriteLine("LESS"); equal = false; break; } } if (equal) Console.WriteLine("EQUAL"); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
198
14
using System; public class Hello { public static void Main() { string s = Console.ReadLine(); string t = Console.ReadLine(); if (s.Length > t.Length) { Console.WriteLine("GREATER"); } else if (s.Length < t.Length) { Console.WriteLine("LESS"); } else { for (var i = 0; i < s.Length; i++) { if (s[i] > t[i]) { Console.WriteLine("GREATER"); return; } else if (s[i] < t[i]) { Console.WriteLine("LESS"); return; } else { } } } } }
using System; public class Hello { public static void Main() { string s = Console.ReadLine(); string t = Console.ReadLine(); if (s.Length > t.Length) { Console.WriteLine("GREATER"); } else if (s.Length < t.Length) { Console.WriteLine("LESS"); } else { for (var i = 0; i < s.Length; i++) { if (s[i] > t[i]) { Console.WriteLine("GREATER"); return; } else if (s[i] < t[i]) { Console.WriteLine("LESS"); return; } else { } } Console.WriteLine("EQUAL"); } } }
[["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35]]
8
152
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var a = Console.ReadLine(); var b = Console.ReadLine(); if (a.Length > b.Length) Console.WriteLine("GREATER"); if (a.Length < b.Length) Console.WriteLine("LESS"); if (a.Length == b.Length) { for (int i = 0; i < b.Length; i++) { if (a[i] > b[i]) { Console.WriteLine("GREATER"); break; } if (a[i] < b[i]) { Console.WriteLine("LESS"); break; } } Console.WriteLine("EQUAL"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var a = Console.ReadLine(); var b = Console.ReadLine(); if (a.Length > b.Length) Console.WriteLine("GREATER"); if (a.Length < b.Length) Console.WriteLine("LESS"); if (a.Length == b.Length) { for (int i = 0; i < b.Length; i++) { if (a[i] > b[i]) { Console.WriteLine("GREATER"); break; } if (a[i] < b[i]) { Console.WriteLine("LESS"); break; } if (a[i] == b[i] && i == b.Length - 1) Console.WriteLine("EQUAL"); } } } } }
[["-", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 15, 16, 12, 16, 12, 16, 31, 214, 205, 22], ["+", 15, 16, 12, 16, 12, 16, 31, 214, 0, 131], ["+", 15, 16, 12, 16, 12, 16, 31, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46]]
8
191
22
using System; namespace B_002_59 { internal class Program { private static void Main(string[] args) { new Logic_B().Start(); } public class Logic_B { public void Start() { var a = Console.ReadLine(); var b = Console.ReadLine(); if (a.Length != b.Length) { Console.WriteLine(a.Length > b.Length ? "GREATER" : "LESS"); } else { for (int i = 0; i < a.Length; i++) { if (a[i] == b[i]) { continue; } else { if (a[i] > b[i]) { Console.WriteLine("GREATER"); break; } else { Console.WriteLine("LESS"); break; } } } } } } } }
using System; namespace B_002_59 { internal class Program { private static void Main(string[] args) { new Logic_B().Start(); } public class Logic_B { public void Start() { var a = Console.ReadLine(); var b = Console.ReadLine(); if (a.Length != b.Length) { Console.WriteLine(a.Length > b.Length ? "GREATER" : "LESS"); } else { for (int i = 0; i < a.Length; i++) { if (a[i] == b[i]) { continue; } else { if (a[i] > b[i]) { Console.WriteLine("GREATER"); return; } else { Console.WriteLine("LESS"); return; } } } Console.WriteLine("EQUAL"); } } } } }
[["-", 75, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 75, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 75, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["+", 75, 196, 0, 57, 75, 196, 0, 37, 0, 38], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
8
175
13
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var n = Sarray()[0]; var ai = Sarray(); var sum = new long[2] { ai[0], ai[0] }; var cnt = new long[2] { 0, 0 }; if (ai[0] == 0) { sum[0] = 1; sum[1] = -1; cnt[0] = cnt[1] = 1; } for (var c = 0; c < 2; ++c) { for (var i = 1; i < n; ++i) { var preSum = sum[c]; sum[c] += ai[i]; if (sum[c] * preSum < 0) continue; cnt[c] += Abs(preSum + ai[i]) + 1; sum[c] = (0 < preSum) ? -1 : 1; } } WriteLine(Min(cnt[0], cnt[1])); } static long Mod = (long)1e9 + 7; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var n = Sarray()[0]; var ai = Sarray(); var sum = new long[] { ai[0], ai[0], -1, 1 }; var cnt = new long[] { 0, 0, Abs(ai[0] + 1), Abs(ai[0] - 1) }; if (ai[0] == 0) { sum[0] = 1; sum[1] = -1; cnt[0] = cnt[1] = 1; } for (var c = 0; c < 4; ++c) { for (var i = 1; i < n; ++i) { var preSum = sum[c]; sum[c] += ai[i]; if (sum[c] * preSum < 0) continue; cnt[c] += Abs(preSum + ai[i]) + 1; sum[c] = (0 < preSum) ? -1 : 1; } } WriteLine(cnt.Min()); } static long Mod = (long)1e9 + 7; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 200, 0, 212, 0, 227, 0, 229, 0, 21], ["+", 0, 212, 0, 227, 0, 229, 0, 241, 0, 33], ["+", 0, 212, 0, 227, 0, 229, 0, 241, 0, 203], ["+", 0, 200, 0, 212, 0, 227, 0, 229, 0, 203], ["+", 0, 212, 0, 227, 0, 229, 0, 213, 63, 22], ["+", 0, 227, 0, 229, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 227, 0, 229, 0, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21]]
8
577
40
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Program { static List<long> rep; static void Main(string[] args) { //入力を受け取る var N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray(); var B = new long[N];  Array.Copy(A, B, A.Length); long ans = 0; long sum = A[0]; for (int i = 1; i < N; i++) { if (sum > 0) { if (sum + A[i] >= 0) { var aim = sum * (-1) - 1; ans += (long)Math.Abs(A[i] - aim); A[i] = aim; } } else { if (sum + A[i] <= 0) { var aim = sum * (-1) + 1; ans += (long)Math.Abs(A[i] - aim); A[i] = aim; } } sum += A[i]; } long ans2 = (long)Math.Abs(B[0]) + 1; long sum2 = 0; if (B[0] > 0) { sum2 = -1; } else { sum2 = 1; } for (int i = 1; i < N; i++) { if (sum2 > 0) { if (sum2 + B[i] >= 0) { var aim = sum2 * (-1) - 1; ans2 += (long)Math.Abs(B[i] - aim); B[i] = aim; } } else { // Console.WriteLine(B[i]); if (sum2 + B[i] <= 0) { var aim = sum2 * (-1) + 1; ans2 += (long)Math.Abs(B[i] - aim); B[i] = aim; } } sum2 += B[i]; } if (ans2 < ans) { Console.WriteLine(ans2); } else { Console.WriteLine(ans); }   } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Program { static List<long> rep; static void Main(string[] args) { //入力を受け取る var N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(a => long.Parse(a)).ToArray(); var B = new long[N];  Array.Copy(A, B, A.Length); long ans = 0; long sum = A[0]; if (A[0] == 0) { ans = 1; sum = -1; } for (int i = 1; i < N; i++) { if (sum > 0) { if (sum + A[i] >= 0) { var aim = sum * (-1) - 1; ans += (long)Math.Abs(A[i] - aim); A[i] = aim; } } else { if (sum + A[i] <= 0) { var aim = sum * (-1) + 1; ans += (long)Math.Abs(A[i] - aim); A[i] = aim; } } sum += A[i]; } long ans2 = (long)Math.Abs(B[0]) + 1; long sum2 = 0; if (B[0] > 0) { sum2 = -1; } else { sum2 = 1; } for (int i = 1; i < N; i++) { if (sum2 > 0) { if (sum2 + B[i] >= 0) { var aim = sum2 * (-1) - 1; ans2 += (long)Math.Abs(B[i] - aim); B[i] = aim; } } else { // Console.WriteLine(B[i]); if (sum2 + B[i] <= 0) { var aim = sum2 * (-1) + 1; ans2 += (long)Math.Abs(B[i] - aim); B[i] = aim; } } sum2 += B[i]; } if (ans2 < ans) { Console.WriteLine(ans2); } else { Console.WriteLine(ans); }   } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
459
20
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, long.Parse); Console.WriteLine(Math.Min(culc0m(a), culc0p(a))); } public static long culc0m(long[] a) { var count = 0L; var sum = a[0]; if (sum >= 0) { count += -sum + 1; sum = -1; } for (int i = 1; i < a.Length; i++) { if (i % 2 == 1) { if (sum + a[i] > 0) sum += a[i]; else { count += -(sum + a[i]) + 1; sum = 1; } } else { if (sum + a[i] < 0) sum += a[i]; else { count += (sum + a[i]) + 1; sum = -1; } } } return count; } public static long culc0p(long[] a) { var count = 0L; var sum = a[0]; if (sum <= 0) { count += -sum + 1; sum = 1; } for (int i = 1; i < a.Length; i++) { if (i % 2 == 1) { if (sum + a[i] < 0) sum += a[i]; else { count += (sum + a[i]) + 1; sum = -1; } } else { if (sum + a[i] > 0) sum += a[i]; else { count += -(sum + a[i]) + 1; sum = 1; } } } return count; } }
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, long.Parse); var ret0 = culc0m(a); var ret1 = culc0p(a); Console.WriteLine(Math.Min(ret0, ret1)); } public static long culc0m(long[] a) { var count = 0L; var sum = a[0]; if (sum >= 0) { count += sum + 1; sum = -1; } for (int i = 1; i < a.Length; i++) { if (i % 2 == 1) { if (sum + a[i] > 0) sum += a[i]; else { count += -(sum + a[i]) + 1; sum = 1; } } else { if (sum + a[i] < 0) sum += a[i]; else { count += (sum + a[i]) + 1; sum = -1; } } } return count; } public static long culc0p(long[] a) { var count = 0L; var sum = a[0]; if (sum <= 0) { count += -sum + 1; sum = 1; } for (int i = 1; i < a.Length; i++) { if (i % 2 == 1) { if (sum + a[i] < 0) sum += a[i]; else { count += (sum + a[i]) + 1; sum = -1; } } else { if (sum + a[i] > 0) sum += a[i]; else { count += -(sum + a[i]) + 1; sum = 1; } } } return count; } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 241, 0, 33]]
8
403
27
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("4"); WillReturn.Add("1 -3 1 0"); // 4 } else if (InputPattern == "Input2") { WillReturn.Add("5"); WillReturn.Add("3 -6 4 -5 7"); // 0 } else if (InputPattern == "Input3") { WillReturn.Add("6"); WillReturn.Add("-1 4 3 2 -5 4"); // 8 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray(); long Cost1 = Solve(AArr, true); long Cost2 = Solve(AArr, false); Console.WriteLine(Math.Min(Cost1, Cost2)); } //最初の符号を引数として、コストを求める static long Solve(int[] pArr, bool pIsFirstPlus) { long Cost = 0; long RunSum = 0; for (int I = 0; I <= pArr.GetUpperBound(0); I++) { RunSum += pArr[I]; if (I % 2 == 0 && pIsFirstPlus) { if (RunSum > 0) continue; Cost += Math.Abs(RunSum) + 1; RunSum = 1; } else { if (RunSum < 0) continue; Cost += Math.Abs(RunSum) + 1; RunSum = -1; } } return Cost; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("4"); WillReturn.Add("1 -3 1 0"); // 4 } else if (InputPattern == "Input2") { WillReturn.Add("5"); WillReturn.Add("3 -6 4 -5 7"); // 0 } else if (InputPattern == "Input3") { WillReturn.Add("6"); WillReturn.Add("-1 4 3 2 -5 4"); // 8 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray(); long Cost1 = Solve(AArr, true); long Cost2 = Solve(AArr, false); Console.WriteLine(Math.Min(Cost1, Cost2)); } //最初の符号を引数として、コストを求める static long Solve(int[] pArr, bool pIsFirstPlus) { long Cost = 0; long RunSum = 0; for (int I = 0; I <= pArr.GetUpperBound(0); I++) { RunSum += pArr[I]; if (I % 2 == 0 && pIsFirstPlus || I % 2 == 1 && pIsFirstPlus == false) { if (RunSum > 0) continue; Cost += Math.Abs(RunSum) + 1; RunSum = 1; } else { if (RunSum < 0) continue; Cost += Math.Abs(RunSum) + 1; RunSum = -1; } } return Cost; } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 17, 109], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 60], ["+", 15, 16, 12, 16, 12, 16, 12, 211, 0, 147]]
8
369
10
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var (X, Y) = ReadTuple<long, long>(); if (X <= 1 && Y <= 1) { WriteLine("Brown"); return; } if (X % 2 == 0 || Y % 2 == 0) WriteLine("Alice"); else WriteLine("Brown"); } } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<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) ReadTuple<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) ReadTuple<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() { var (x, y) = ReadTuple<long, long>(); if (x <= 1 && y <= 1) { WriteLine("Brown"); } else if (Abs(x - y) <= 1) { WriteLine("Brown"); } else { WriteLine("Alice"); } } } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<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) ReadTuple<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) ReadTuple<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, 197, 0, 198, 0, 200, 0, 289, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 289, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 57, 15, 16, 31, 213, 63, 22], ["+", 75, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 75, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 46]]
8
714
38
using Yorukatsu049.Questions; using Yorukatsu049.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu049.Questions { /// <summary> /// ABC059 D /// </summary> public class QuestionF : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var xy = inputStream.ReadLongArray(); var x = xy[0]; var y = xy[1]; if (x % 2 == 0 && y % 2 == 0) { } else if (x % 2 == 0 || y % 2 == 0) { yield return "Brown"; } else { yield return "Alice"; } } } } namespace Yorukatsu049 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionF(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu049.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Yorukatsu049.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using Yorukatsu049.Questions; using Yorukatsu049.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Yorukatsu049.Questions { /// <summary> /// ABC059 D /// </summary> public class QuestionF : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var xy = inputStream.ReadLongArray(); var x = xy[0]; var y = xy[1]; if (Math.Abs(x - y) <= 1) { yield return "Brown"; } else { yield return "Alice"; } } } } namespace Yorukatsu049 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionF(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace Yorukatsu049.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace Yorukatsu049.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 75, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["-", 75, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 106], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
530
32
using System; using System.Collections.Generic; using System.Linq; namespace Asakatsu20200313F { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public void String(out string s) { s = Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public void String(long rowNumber, out string[] s) { s = new String[rowNumber]; for (long i = 0; i < rowNumber; i++) { String(out s[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public void Int(out int i) { string s; String(out s); i = int.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <param name="a"></param> public void Long(out long a) { string s; String(out s); a = long.Parse(s); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> public void Long(out long a, out long b) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(out long a, out long b, out long c) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(out long a, out long b, out long c, out long d) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; } public void Long(out long[] lArr) { lArr = Split().Select(long.Parse).ToArray(); } public void Long(long rowNumber, out long[] lArr) { lArr = new long[rowNumber]; for (long i = 0; i < rowNumber; i++) { Long(out lArr[i]); } } /// <summary> /// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> public void Long(long rowNumber, out long[] a, out long[] b) { a = new long[rowNumber]; b = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i]); } } /// <summary> /// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i]); } } /// <summary> /// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c, out long[] d) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; d = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i], out d[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public void Double(out double d) { string s; String(out s); d = double.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public void Double(out double[] dArr) { dArr = Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { string s; String(out s); return s.Split(' '); } } class Program { public static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { private Input input; public Solver() { input = new Input(); input.Long(out X, out Y); } private long X; private long Y; public void Solve() { // 操作不可 if (Math.Max(X, Y) < 2) { Console.WriteLine("Brown"); return; } Console.WriteLine("Alice"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Asakatsu20200313F { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public void String(out string s) { s = Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public void String(long rowNumber, out string[] s) { s = new String[rowNumber]; for (long i = 0; i < rowNumber; i++) { String(out s[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public void Int(out int i) { string s; String(out s); i = int.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <param name="a"></param> public void Long(out long a) { string s; String(out s); a = long.Parse(s); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> public void Long(out long a, out long b) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(out long a, out long b, out long c) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(out long a, out long b, out long c, out long d) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; } public void Long(out long[] lArr) { lArr = Split().Select(long.Parse).ToArray(); } public void Long(long rowNumber, out long[] lArr) { lArr = new long[rowNumber]; for (long i = 0; i < rowNumber; i++) { Long(out lArr[i]); } } /// <summary> /// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> public void Long(long rowNumber, out long[] a, out long[] b) { a = new long[rowNumber]; b = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i]); } } /// <summary> /// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i]); } } /// <summary> /// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c, out long[] d) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; d = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i], out d[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public void Double(out double d) { string s; String(out s); d = double.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public void Double(out double[] dArr) { dArr = Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { string s; String(out s); return s.Split(' '); } } class Program { public static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { private Input input; public Solver() { input = new Input(); input.Long(out X, out Y); } private long X; private long Y; public void Solve() { // 操作不可 if (Math.Max(X, Y) < 2) { Console.WriteLine("Brown"); return; } if (Math.Abs(X - Y) < 2) { Console.WriteLine("Brown"); return; } Console.WriteLine("Alice"); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
898
26
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_D { class D059 { static HashSet<string> lose = new HashSet<string>(); static HashSet<string> win = new HashSet<string>(); static void Main(string[] args) { long[] h = Console.ReadLine().Split(' ').Select(z => long.Parse(z)).ToArray(); long X = h[0], Y = h[1]; string w = "Alice"; if (Math.Abs(X - Y) == 1 || (X <= 1 && Y <= 1)) w = "Brown"; Console.WriteLine(w); // if (Y > X) //{ // long z = X;X = Y;Y = z; //} // string winner = IsWin(X, Y) ? "Alice" : "Brown"; // Console.WriteLine(winner); } // x>=y static bool IsWin(long x, long y) { if (x <= 1 && y <= 1) return false; string pair = x + "-" + y; if (lose.Contains(pair)) return false; else if (win.Contains(pair)) return true; long i = x / 2; while (i > 0) { long x1 = x - 2 * i; long y1 = y + i; if (y1 > x1) { long z = x1; x1 = y1; y1 = z; } if (!IsWin(x1, y1)) { win.Add(pair); return true; } i--; } long j = y / 2; while (j > 0) { long x1 = x + j; long y1 = y - 2 * j; if (y1 > x1) { long z = x1; x1 = y1; y1 = z; } if (!IsWin(x1, y1)) { win.Add(pair); return true; } j--; } lose.Add(pair); return false; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_D { class D059 { static HashSet<string> lose = new HashSet<string>(); static HashSet<string> win = new HashSet<string>(); static void Main(string[] args) { long[] h = Console.ReadLine().Split(' ').Select(z => long.Parse(z)).ToArray(); long X = h[0], Y = h[1]; string w = "Alice"; if (Math.Abs(X - Y) <= 1) w = "Brown"; Console.WriteLine(w); // if (Y > X) //{ // long z = X;X = Y;Y = z; //} // string winner = IsWin(X, Y) ? "Alice" : "Brown"; // Console.WriteLine(winner); } // x>=y static bool IsWin(long x, long y) { if (x <= 1 && y <= 1) return false; string pair = x + "-" + y; if (lose.Contains(pair)) return false; else if (win.Contains(pair)) return true; long i = x / 2; while (i > 0) { long x1 = x - 2 * i; long y1 = y + i; if (y1 > x1) { long z = x1; x1 = y1; y1 = z; } if (!IsWin(x1, y1)) { win.Add(pair); return true; } i--; } long j = y / 2; while (j > 0) { long x1 = x + j; long y1 = y - 2 * j; if (y1 > x1) { long z = x1; x1 = y1; y1 = z; } if (!IsWin(x1, y1)) { win.Add(pair); return true; } j--; } lose.Add(pair); return false; } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 19], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
8
400
10
using System; namespace AtCoder { class Program { static IO io = new IO(); static void Main(string[] args) { //入力 io.ReadSplit(); long X = io.Long(); long Y = io.Long(); //計算 string output = Winner(X, Y); //出力 io.WriteLine(output); } static string Winner(long X, long Y) { if ((X < 2) && (Y < 2)) { return "Brown"; } else if (X * Y == 2) { return "Brown"; } else { return "Alice"; } } } class IO { private string[] _Inputs; private int _Index; public void Read() { _Inputs = new string[1]; _Inputs[0] = Console.ReadLine(); _Index = 0; } public void ReadSplit() { _Inputs = Console.ReadLine().Split(' '); _Index = 0; } public string String() { return _Inputs[_Index++]; } public string[] String(int xCount) { string[] rv = new string[xCount]; Array.Copy(_Inputs, _Index, rv, 0, xCount); _Index += xCount; return rv; } public int Int() { return int.Parse(_Inputs[_Index++]); } public int[] Int(int xCount) { int[] rv = new int[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = int.Parse(_Inputs[_Index++]); } return rv; } public long Long() { return long.Parse(_Inputs[_Index++]); } public long[] Long(int xCount) { long[] rv = new long[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = long.Parse(_Inputs[_Index++]); } return rv; } public void Write(string xStr) { Console.Write(xStr); } public void WriteLine(string xStr) { Console.WriteLine(xStr); } } }
using System; namespace AtCoder { class Program { static IO io = new IO(); static void Main(string[] args) { //入力 io.ReadSplit(); long X = io.Long(); long Y = io.Long(); //計算 string output = Winner(X, Y); //出力 io.WriteLine(output); } static string Winner(long X, long Y) { if (X + Y < 2) { return "Brown"; } else if (Math.Abs(X - Y) < 2) { return "Brown"; } else { return "Alice"; } } } class IO { private string[] _Inputs; private int _Index; public void Read() { _Inputs = new string[1]; _Inputs[0] = Console.ReadLine(); _Index = 0; } public void ReadSplit() { _Inputs = Console.ReadLine().Split(' '); _Index = 0; } public string String() { return _Inputs[_Index++]; } public string[] String(int xCount) { string[] rv = new string[xCount]; Array.Copy(_Inputs, _Index, rv, 0, xCount); _Index += xCount; return rv; } public int Int() { return int.Parse(_Inputs[_Index++]); } public int[] Int(int xCount) { int[] rv = new int[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = int.Parse(_Inputs[_Index++]); } return rv; } public long Long() { return long.Parse(_Inputs[_Index++]); } public long[] Long(int xCount) { long[] rv = new long[xCount]; for (int i = 0; i < xCount; ++i) { rv[i] = long.Parse(_Inputs[_Index++]); } return rv; } public void Write(string xStr) { Console.Write(xStr); } public void WriteLine(string xStr) { Console.WriteLine(xStr); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 17, 18], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 75, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 48], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 75, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18]]
8
444
17
using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var xs = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); var sum = new long[2]; var sign = new[] { Math.Sign(1), Math.Sign(-1) }; var adjust = new[] { xs[0] == 0 ? 1 : 0, Math.Abs(xs[0]) + 1 }; for (int i = 0; i < n; ++i) { for (int j = 0; j < 2; ++j) { var t = sum[j] + xs[i]; var k = t * sign[j]; if (k >= 0) { adjust[j] += k + 1; sum[j] = -1 * sign[j]; } else { sum[j] = t; } sign[j] = Math.Sign(sum[j]); } } Console.WriteLine(adjust.Min()); } }
using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var xs = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); var adjust = new long[2]; var sum = new long[2]; var sign = new[] { Math.Sign(1), Math.Sign(-1) }; for (int i = 0; i < n; ++i) { for (int j = 0; j < 2; ++j) { var t = sum[j] + xs[i]; var k = t * sign[j]; if (k >= 0) { adjust[j] += k + 1; sum[j] = -1 * sign[j]; } else { sum[j] = t; } sign[j] = Math.Sign(sum[j]); } } Console.WriteLine(adjust.Min()); } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["-", 0, 297, 0, 229, 0, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 297, 0, 229, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 297, 0, 228], ["-", 0, 198, 0, 200, 0, 212, 0, 297, 0, 70], ["-", 0, 198, 0, 200, 0, 212, 0, 297, 0, 73], ["-", 0, 200, 0, 212, 0, 297, 0, 229, 0, 45], ["-", 0, 229, 0, 41, 15, 16, 31, 204, 205, 22], ["-", 0, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 297, 0, 229, 0, 41, 15, 16, 17, 60], ["-", 0, 297, 0, 229, 0, 41, 15, 16, 12, 203], ["-", 0, 212, 0, 297, 0, 229, 0, 41, 0, 101], ["-", 0, 212, 0, 297, 0, 229, 0, 41, 0, 102], ["-", 0, 212, 0, 297, 0, 229, 0, 41, 75, 203], ["-", 0, 200, 0, 212, 0, 297, 0, 229, 0, 21], ["-", 0, 229, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 229, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 229, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 229, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 31, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 212, 0, 297, 0, 229, 0, 16, 17, 72], ["-", 0, 212, 0, 297, 0, 229, 0, 16, 12, 203]]
8
255
40
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static long GCM(long x, long y) { if (x < y) GCM(y, x); while (y > 0) { var z = y; y = x % y; x = z; } return x; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); var a = Reads(); long f = 0; if (n > 1 && a[0] < a[1]) f = 1; long ans = 1; long count = 2; for (int i = 1; i < n - 1; i++) { if (a[i] < a[i + 1]) { if (f == 0 && count != 1) { ans++; count = 0; } f = 1; count++; } else if (a[i] > a[i + 1]) { if (f == 1 && count != 1) { ans++; count = 0; } f = 0; count++; } else { f = 2; count++; } } WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static long GCM(long x, long y) { if (x < y) GCM(y, x); while (y > 0) { var z = y; y = x % y; x = z; } return x; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); var a = Reads(); long count = 2; long f = 0; if (n > 1 && a[0] < a[1]) f = 1; if (n > 1 && a[0] == a[1]) count = 1; long ans = 1; for (int i = 1; i < n - 1; i++) { if (a[i] < a[i + 1]) { if (f == 0 && count != 1) { ans++; count = 0; } f = 1; count++; } else if (a[i] > a[i + 1]) { if (f == 1 && count != 1) { ans++; count = 0; } f = 0; count++; } } WriteLine(ans); Console.Out.Flush(); } } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 75, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 75, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["-", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["-", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
8
349
38
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N = GetInt(); var A = GetIntArray(); var ans = 1; var v = 0; for (int i = 0; i < N - 1; i++) { if (v == 0) { v = A[i] < A[i + 1] ? 1 : -1; } else { if ((A[i + 1] - A[i]) * v < 0) { ans++; v = 0; } } } Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N = GetInt(); var A = GetIntArray(); var ans = 1; var v = 0; for (int i = 0; i < N - 1; i++) { if (v == 0) { v = A[i] < A[i + 1] ? 1 : A[i] == A[i + 1] ? 0 : -1; } else { if ((A[i + 1] - A[i]) * v < 0) { ans++; v = 0; } } } Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
[["+", 12, 41, 75, 41, 15, 16, 31, 204, 205, 22], ["+", 75, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 41, 75, 41, 15, 16, 17, 60], ["+", 12, 41, 75, 41, 15, 16, 12, 204, 205, 22], ["+", 75, 41, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 75, 41, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 41, 75, 41, 0, 101], ["+", 0, 1, 0, 11, 12, 41, 75, 41, 64, 203], ["+", 0, 1, 0, 11, 12, 41, 75, 41, 0, 102]]
8
1,593
14
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int cnt = 1; int status = 0; for (int i = 0; i < n - 1; i++) { if (status > 0 && a[i + 1] - a[i] < 0) { cnt++; status = 0; continue; } if (status < 0 && a[i + 1] - a[i] > 0) { cnt++; status = 0; continue; } status = a[i + 1] - a[i]; } Console.WriteLine(cnt); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int cnt = 1; int status = 0; for (int i = 0; i < n - 1; i++) { if (status > 0 && a[i + 1] - a[i] < 0) { cnt++; status = 0; continue; } if (status < 0 && a[i + 1] - a[i] > 0) { cnt++; status = 0; continue; } if (a[i] < a[i + 1]) status = 1; if (a[i] > a[i + 1]) status = -1; } Console.WriteLine(cnt); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 203]]
8
188
29
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using static CS_Contest.Utils; using System.Numerics; using System.Linq.Expressions; using Nakov.IO; using static Nakov.IO.Cin; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { enum dir : int { free, up, down } ; public void Solve() { int N = NextInt(); var list = ReadInts(); Func<dir> getDirection = () => list[0] < list[1] ? dir.up : dir.down; dir current = dir.free; int cnt = 0; while (list.Count > 1) { switch (current) { case dir.free: current = getDirection(); break; case dir.up: if (getDirection() != current) { current = dir.free; cnt++; } break; case dir.down: if (getDirection() != current) { current = dir.free; cnt++; } break; default: break; } list.RemoveAt(0); } (cnt + 1).WL(); return; } } } public static class Utils { public static long ModValue = (long)1e9 + 7; public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li ReadInts() => ReadLine().Split().Select(int.Parse).ToList(); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public struct IndexT<T> { public T Value { get; set; } public int Index { get; set; } public IndexT(T v, int i) { Value = v; Index = i; } public override string ToString() { return Value + " " + Index; } } public static IEnumerable<IndexT<T>> ToIndexEnumerable<T>( this IEnumerable<T> list) => list.Select((x, i) => new IndexT<T>(x, i)); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static IndexT<T> IndexOf<T>(this IEnumerable<T> ie, Func<IndexT<T>, IndexT<T>, IndexT<T>> func) => ie.ToIndexEnumerable().Aggregate(func); public static T[] Range<T>(int range, Func<int, T> func) { var rt = new T[range]; for (var i = 0; i < range; i++) rt[i] = func(i); return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Dictionary<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static int UpperBound<T>(this IEnumerable<T> list, T target) where T : IComparable { var idx = list.ToList().BinarySearch(target); idx = idx < 0 ? ~idx : (idx + 1); return Min(idx, list.Count()); } public static int LowerBound<T>(this IEnumerable<T> list, T target) where T : IComparable { var idx = list.ToList().BinarySearch(target); idx = idx < 0 ? ~idx : idx; return Max(0, idx - 1); } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using static CS_Contest.Utils; using System.Numerics; using System.Linq.Expressions; using Nakov.IO; using static Nakov.IO.Cin; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { enum dir : int { free, up, down } ; public void Solve() { int N = NextInt(); var list = ReadInts(); dir current = dir.free; Func<dir> getDirection = () => list[0] == list[1] ? current : list[0] < list[1] ? dir.up : dir.down; int cnt = 0; while (list.Count > 1) { switch (current) { case dir.free: current = getDirection(); break; case dir.up: if (getDirection() != current) { current = dir.free; cnt++; } break; case dir.down: if (getDirection() != current) { current = dir.free; cnt++; } break; default: break; } list.RemoveAt(0); } (cnt + 1).WL(); return; } } } public static class Utils { public static long ModValue = (long)1e9 + 7; public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li ReadInts() => ReadLine().Split().Select(int.Parse).ToList(); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public struct IndexT<T> { public T Value { get; set; } public int Index { get; set; } public IndexT(T v, int i) { Value = v; Index = i; } public override string ToString() { return Value + " " + Index; } } public static IEnumerable<IndexT<T>> ToIndexEnumerable<T>( this IEnumerable<T> list) => list.Select((x, i) => new IndexT<T>(x, i)); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static IndexT<T> IndexOf<T>(this IEnumerable<T> ie, Func<IndexT<T>, IndexT<T>, IndexT<T>> func) => ie.ToIndexEnumerable().Aggregate(func); public static T[] Range<T>(int range, Func<int, T> func) { var rt = new T[range]; for (var i = 0; i < range; i++) rt[i] = func(i); return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Dictionary<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static int UpperBound<T>(this IEnumerable<T> list, T target) where T : IComparable { var idx = list.ToList().BinarySearch(target); idx = idx < 0 ? ~idx : (idx + 1); return Min(idx, list.Count()); } public static int LowerBound<T>(this IEnumerable<T> list, T target) where T : IComparable { var idx = list.ToList().BinarySearch(target); idx = idx < 0 ? ~idx : idx; return Max(0, idx - 1); } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 218, 8, 41, 15, 16, 31, 204, 205, 22], ["+", 8, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 212, 0, 218, 8, 41, 15, 16, 17, 60], ["+", 0, 218, 8, 41, 15, 16, 12, 204, 205, 22], ["+", 8, 41, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 41, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 218, 8, 41, 0, 101], ["+", 0, 200, 0, 212, 0, 218, 8, 41, 64, 22], ["+", 0, 200, 0, 212, 0, 218, 8, 41, 0, 102], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
1,633
26
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { // C#7.0///////////////////////////////////////////////////// int N; int[] A; void Solve() { N = io.Int; REP(N, i => A[i] = io.Int); int ans = 1; int isAsc = 0; FOR(1, N, i => { if (A[i] > A[i - 1]) { if (isAsc == 0) { isAsc = 1; } else if (isAsc == -1) { ans++; isAsc = 0; } } else if (A[i] < A[i - 1]) { if (isAsc == 0) { isAsc = -1; } else if (isAsc == 1) { ans++; isAsc = 0; } } }); io.o(ans); } //////////////////////////////////////////////////////////// public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // Hack Update // cannot use break,continue,goto void FOR(int a, int b, Action<int> act, int c = 1) { for (int i = a; i < b; i += c) act(i); } void FOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = a; i < b && con(i); i += c) act(i); } void RFOR(int a, int b, Action<int> act, int c = 1) { for (int i = a; i >= b; i -= c) act(i); } void RFOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = a; i >= b && con(i); i -= c) act(i); } void REP(int n, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = 0; i < n && con(i); i += c) act(i); } void REP(int n, Action<int> act, int c = 1) { for (int i = 0; i < n; i += c) act(i); } void RREP(int n, Action<int> act, int c = 1) { for (int i = n - 1; i >= 0; i -= c) act(i); } void RREP(int n, Action<int> act, Func<int, bool> con) { for (int i = n - 1; i >= 0 && con(i); i--) act(i); } #endregion } #region default class IO { TYPE tp; string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); tp = new TYPE(); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return tp.suitType<T>(String); } public void i<T>(out T v) { v = tp.suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; i++) a[i] = tp.suitType<T>(String); } public void ini<T>(out T[] a, out T[] b, int n) { a = new T[n]; b = new T[n]; for (int i = 0; i < n; i++) { a[i] = i<T>(); b[i] = i<T>(); } } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void o<T>(List<T> l) { o(l.ToArray()); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { Array.ForEach(a, n => ol(n)); br(); } public void ol<T>(List<T> l) { ol(l.ToArray()); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } } class Operation<T> { public Operation() { var availableT = new Type[] { typeof(int), typeof(long), typeof(double) }; if (!availableT.Contains(typeof(T))) throw new NotSupportedException(); var p1 = Expression.Parameter(typeof(T)); var p2 = Expression.Parameter(typeof(T)); Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2) .Compile(); Sub = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2) .Compile(); Mul = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2) .Compile(); Div = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2) .Compile(); Mod = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2) .Compile(); EQ = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2) .Compile(); GT = Expression .Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2) .Compile(); GE = Expression .Lambda<Func<T, T, bool>>(Expression.GreaterThanOrEqual(p1, p2), p1, p2) .Compile(); LT = Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2) .Compile(); LE = Expression .Lambda<Func<T, T, bool>>(Expression.LessThanOrEqual(p1, p2), p1, p2) .Compile(); } public Func<T, T, T> Add { get; private set; } public Func<T, T, T> Sub { get; private set; } public Func<T, T, T> Mul { get; private set; } public Func<T, T, T> Div { get; private set; } public Func<T, T, T> Mod { get; private set; } public Func<T, T, bool> EQ { get; private set; } public Func<T, T, bool> GT { get; private set; } public Func<T, T, bool> GE { get; private set; } public Func<T, T, bool> LT { get; private set; } public Func<T, T, bool> LE { get; private set; } } class OP { // Matを簡潔に... public T Add<T>(T a, T b) { var op = new Operation<T>(); return op.Add(a, b); } public T Sub<T>(T a, T b) { var op = new Operation<T>(); return op.Sub(a, b); } public T Mul<T>(T a, T b) { var op = new Operation<T>(); return op.Mul(a, b); } public T Div<T>(T a, T b) { var op = new Operation<T>(); return op.Div(a, b); } public T Mod<T>(T a, T b) { var op = new Operation<T>(); return op.Mod(a, b); } public bool EQ<T>(T a, T b) { var op = new Operation<T>(); return op.EQ(a, b); } public bool GT<T>(T a, T b) { var op = new Operation<T>(); return op.GT(a, b); } public bool GE<T>(T a, T b) { var op = new Operation<T>(); return op.GE(a, b); } public bool LT<T>(T a, T b) { var op = new Operation<T>(); return op.LT(a, b); } public bool LE<T>(T a, T b) { var op = new Operation<T>(); return op.LE(a, b); } } class TYPE { public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } public T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } public T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size = 0; private int type; public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { OP op; public Mat() { op = new OP(); } public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public T Max<T>(params T[] v) { return v.Max(); } public T Min<T>(params T[] v) { return v.Min(); } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public int[] DigValArr(int n) { int[] ret = new int[Digit(n)]; M.REP(ret.Length, i => ret[i] = DigVal(n, i + 1)); return ret; } public int Clamp(int n, int a, int b) { return (n < a) ? a : (b < n) ? b : n; } public long Clamp(long n, long a, long b) { return (n < a) ? a : (b < n) ? b : n; } public double Clamp(double n, double a, double b) { return (n < a) ? a : (b < n) ? b : n; } public long Tousa(long a, long d, int n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, int n) { return n * (2 * a + (n - 1) * d) / 2; } } class AssociativeArray<T> { // hack:配列時要初期化 public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(params T[] a) { M.REP(a.Length, i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { M.REP(a.Length, i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => dic.First(d => d.Value == MaxVal).Key; public T MinKey => dic.First(d => d.Value == MinVal).Key; public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } //:sort->array } class TreeDis { public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; M.REP(g.Length, i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { M.REP(a.Length, i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { M.REP(a.Length, i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class Dijkstra { private int Index = -1; private long INF = (int)1e9; private long[,] m; public Dijkstra() {} public void init(int n) { Index = n + 1; m = new long[Index, Index]; M.REP(Index, i => M.REP(Index, j => m[i, j] = INF)); M.REP(Index, i => m[i, i] = 0); } public void AddPath(long f, long t, long w) { m[f, t] = Math.Min(m[f, t], w); m[t, f] = m[f, t]; } public long GetMinCost(long f, long t) { long[] w = new long[Index]; M.REP(Index, i => w[i] = INF); w[f] = 0; var pq = new PQueue<Tuple<long, long>>(); pq.Enqueue(Tuple.Create(0L, f)); // cost<-from while (pq.Count > 0) { var c = pq.Dequeue(); if (c.Item2 < c.Item1) continue; M.REP(Index, i => { long w2i = m[c.Item2, i] == INF ? INF : c.Item1 + m[c.Item2, i]; if (w2i < w[i]) { w[i] = w2i; pq.Enqueue(Tuple.Create(w2i, (long)i)); } }); } return w[t]; } } class WarshallFloyd { int INF; public WarshallFloyd() { INF = (int)(1e8); } public WarshallFloyd(int INF) { this.INF = INF; } public int[,] Run(int[,] m) { int edgeLength = m.GetLength(0); for (int i = 0; i < edgeLength; i++) for (int j = 0; j < edgeLength; j++) for (int k = 0; k < edgeLength; k++) m[j, k] = Math.Min(m[j, k], m[j, i] + m[i, k]); return m; } public int[,] Init(int n) { int[,] m = new int[n, n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) m[i, j] = INF; for (int i = 0; i < n; i++) m[i, i] = 0; return m; } } class UnionFind { public long[] parent; public long[] depth; public void Init(long n) { parent = new long[n]; depth = new long[n]; M.REP(n, i => parent[i] = i); } public long Find(long x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(long x, long y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(long a, long b) { return Find(a) == Find(b); } } class Time { public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } #endregion #region Ex static class StringEX { //文字 public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { //数値 public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static void Set<T>(this T[] a, T v) { M.REP(a.Length, i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { M.REP(a.GetLength(0), i => M.REP(a.GetLength(1), j => a[i, j] = v)); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class M { public static void REP(int n, Action<int> a) { for (int i = 0; i < n; i++) a(i); } public static void REP(long n, Action<long> a) { for (long i = 0; i < n; i++) a(i); } } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { // C#7.0///////////////////////////////////////////////////// int N; int[] A; void Solve() { N = io.Int; A = new int[N]; for (int i = 0; i < N; i++) A[i] = io.Int; int ans = 1; int isAsc = 0; for (int i = 1; i < N; i++) { if (A[i] > A[i - 1]) { if (isAsc == 0) { isAsc = 1; } else if (isAsc == -1) { ans++; isAsc = 0; } } else if (A[i] < A[i - 1]) { if (isAsc == 0) { isAsc = -1; } else if (isAsc == 1) { ans++; isAsc = 0; } } } io.o(ans); } //////////////////////////////////////////////////////////// public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // Hack Update // cannot use break,continue,goto void FOR(int a, int b, Action<int> act, int c = 1) { for (int i = a; i < b; i += c) act(i); } void FOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = a; i < b && con(i); i += c) act(i); } void RFOR(int a, int b, Action<int> act, int c = 1) { for (int i = a; i >= b; i -= c) act(i); } void RFOR(int a, int b, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = a; i >= b && con(i); i -= c) act(i); } void REP(int n, Action<int> act, Func<int, bool> con, int c = 1) { for (int i = 0; i < n && con(i); i += c) act(i); } void REP(int n, Action<int> act, int c = 1) { for (int i = 0; i < n; i += c) act(i); } void RREP(int n, Action<int> act, int c = 1) { for (int i = n - 1; i >= 0; i -= c) act(i); } void RREP(int n, Action<int> act, Func<int, bool> con) { for (int i = n - 1; i >= 0 && con(i); i--) act(i); } #endregion } #region default class IO { TYPE tp; string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); tp = new TYPE(); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return tp.suitType<T>(String); } public void i<T>(out T v) { v = tp.suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; i++) a[i] = tp.suitType<T>(String); } public void ini<T>(out T[] a, out T[] b, int n) { a = new T[n]; b = new T[n]; for (int i = 0; i < n; i++) { a[i] = i<T>(); b[i] = i<T>(); } } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void o<T>(List<T> l) { o(l.ToArray()); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { Array.ForEach(a, n => ol(n)); br(); } public void ol<T>(List<T> l) { ol(l.ToArray()); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } } class Operation<T> { public Operation() { var availableT = new Type[] { typeof(int), typeof(long), typeof(double) }; if (!availableT.Contains(typeof(T))) throw new NotSupportedException(); var p1 = Expression.Parameter(typeof(T)); var p2 = Expression.Parameter(typeof(T)); Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2) .Compile(); Sub = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2) .Compile(); Mul = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2) .Compile(); Div = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2) .Compile(); Mod = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2) .Compile(); EQ = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2) .Compile(); GT = Expression .Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2) .Compile(); GE = Expression .Lambda<Func<T, T, bool>>(Expression.GreaterThanOrEqual(p1, p2), p1, p2) .Compile(); LT = Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2) .Compile(); LE = Expression .Lambda<Func<T, T, bool>>(Expression.LessThanOrEqual(p1, p2), p1, p2) .Compile(); } public Func<T, T, T> Add { get; private set; } public Func<T, T, T> Sub { get; private set; } public Func<T, T, T> Mul { get; private set; } public Func<T, T, T> Div { get; private set; } public Func<T, T, T> Mod { get; private set; } public Func<T, T, bool> EQ { get; private set; } public Func<T, T, bool> GT { get; private set; } public Func<T, T, bool> GE { get; private set; } public Func<T, T, bool> LT { get; private set; } public Func<T, T, bool> LE { get; private set; } } class OP { // Matを簡潔に... public T Add<T>(T a, T b) { var op = new Operation<T>(); return op.Add(a, b); } public T Sub<T>(T a, T b) { var op = new Operation<T>(); return op.Sub(a, b); } public T Mul<T>(T a, T b) { var op = new Operation<T>(); return op.Mul(a, b); } public T Div<T>(T a, T b) { var op = new Operation<T>(); return op.Div(a, b); } public T Mod<T>(T a, T b) { var op = new Operation<T>(); return op.Mod(a, b); } public bool EQ<T>(T a, T b) { var op = new Operation<T>(); return op.EQ(a, b); } public bool GT<T>(T a, T b) { var op = new Operation<T>(); return op.GT(a, b); } public bool GE<T>(T a, T b) { var op = new Operation<T>(); return op.GE(a, b); } public bool LT<T>(T a, T b) { var op = new Operation<T>(); return op.LT(a, b); } public bool LE<T>(T a, T b) { var op = new Operation<T>(); return op.LE(a, b); } } class TYPE { public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } public T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } public T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size = 0; private int type; public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { OP op; public Mat() { op = new OP(); } public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public T Max<T>(params T[] v) { return v.Max(); } public T Min<T>(params T[] v) { return v.Min(); } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public int[] DigValArr(int n) { int[] ret = new int[Digit(n)]; M.REP(ret.Length, i => ret[i] = DigVal(n, i + 1)); return ret; } public int Clamp(int n, int a, int b) { return (n < a) ? a : (b < n) ? b : n; } public long Clamp(long n, long a, long b) { return (n < a) ? a : (b < n) ? b : n; } public double Clamp(double n, double a, double b) { return (n < a) ? a : (b < n) ? b : n; } public long Tousa(long a, long d, int n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, int n) { return n * (2 * a + (n - 1) * d) / 2; } } class AssociativeArray<T> { // hack:配列時要初期化 public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(params T[] a) { M.REP(a.Length, i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { M.REP(a.Length, i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => dic.First(d => d.Value == MaxVal).Key; public T MinKey => dic.First(d => d.Value == MinVal).Key; public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } //:sort->array } class TreeDis { public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; M.REP(g.Length, i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { M.REP(a.Length, i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { M.REP(a.Length, i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class Dijkstra { private int Index = -1; private long INF = (int)1e9; private long[,] m; public Dijkstra() {} public void init(int n) { Index = n + 1; m = new long[Index, Index]; M.REP(Index, i => M.REP(Index, j => m[i, j] = INF)); M.REP(Index, i => m[i, i] = 0); } public void AddPath(long f, long t, long w) { m[f, t] = Math.Min(m[f, t], w); m[t, f] = m[f, t]; } public long GetMinCost(long f, long t) { long[] w = new long[Index]; M.REP(Index, i => w[i] = INF); w[f] = 0; var pq = new PQueue<Tuple<long, long>>(); pq.Enqueue(Tuple.Create(0L, f)); // cost<-from while (pq.Count > 0) { var c = pq.Dequeue(); if (c.Item2 < c.Item1) continue; M.REP(Index, i => { long w2i = m[c.Item2, i] == INF ? INF : c.Item1 + m[c.Item2, i]; if (w2i < w[i]) { w[i] = w2i; pq.Enqueue(Tuple.Create(w2i, (long)i)); } }); } return w[t]; } } class WarshallFloyd { int INF; public WarshallFloyd() { INF = (int)(1e8); } public WarshallFloyd(int INF) { this.INF = INF; } public int[,] Run(int[,] m) { int edgeLength = m.GetLength(0); for (int i = 0; i < edgeLength; i++) for (int j = 0; j < edgeLength; j++) for (int k = 0; k < edgeLength; k++) m[j, k] = Math.Min(m[j, k], m[j, i] + m[i, k]); return m; } public int[,] Init(int n) { int[,] m = new int[n, n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) m[i, j] = INF; for (int i = 0; i < n; i++) m[i, i] = 0; return m; } } class UnionFind { public long[] parent; public long[] depth; public void Init(long n) { parent = new long[n]; depth = new long[n]; M.REP(n, i => parent[i] = i); } public long Find(long x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(long x, long y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(long a, long b) { return Find(a) == Find(b); } } class Time { public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } #endregion #region Ex static class StringEX { //文字 public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { //数値 public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static void Set<T>(this T[] a, T v) { M.REP(a.Length, i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { M.REP(a.GetLength(0), i => M.REP(a.GetLength(1), j => a[i, j] = v)); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class M { public static void REP(int n, Action<int> a) { for (int i = 0; i < n; i++) a(i); } public static void REP(long n, Action<long> a) { for (long i = 0; i < n; i++) a(i); } } #endregion }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 227, 0, 228], ["+", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
6,339
39
using System; using System.Linq; using System.Numerics; using System.Collections; using System.Collections.Generic; public class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList(); var aa = new List<int>(); aa.Add(a[0]); for (int i = 1; i < n; ++i) { if (a[i - 1] != a[i]) { aa.Add(a[i]); } } if (aa.Count == 1) { Console.WriteLine(1); return; } var cnt = 1; var b = aa[1] - aa[0] < 0 ? -1 : 1; for (int i = 1; i < aa.Count; ++i) { var d = aa[i] - aa[i - 1]; if (!(d == b && Math.Abs(b) == 1)) { cnt += 1; if (i < aa.Count - 1) { b = aa[i + 1] - aa[i] < 0 ? -1 : 1; } } else { b = d < 0 ? -1 : 1; } } Console.WriteLine(cnt); } }
using System; using System.Linq; using System.Numerics; using System.Collections; using System.Collections.Generic; public class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList(); var aa = new List<int>(); aa.Add(a[0]); for (int i = 1; i < n; ++i) { if (a[i - 1] != a[i]) { aa.Add(a[i]); } } if (aa.Count == 1) { Console.WriteLine(1); return; } var cnt = 1; var b = aa[1] - aa[0] < 0 ? -1 : 1; for (int i = 1; i < aa.Count; ++i) { var d = aa[i] - aa[i - 1] < 0 ? -1 : 1; if (!(d == b)) { cnt += 1; if (i < aa.Count - 1) { b = aa[i + 1] - aa[i] < 0 ? -1 : 1; } } else { b = d; } } Console.WriteLine(cnt); } }
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 18], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 200, 0, 212, 0, 41, 64, 241, 0, 33], ["+", 0, 200, 0, 212, 0, 41, 64, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 75, 203], ["-", 0, 57, 15, 241, 0, 23, 0, 16, 17, 98], ["-", 0, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["-", 12, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 15, 241, 0, 23, 0, 16, 12, 16, 17, 60], ["-", 15, 241, 0, 23, 0, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 1, 0, 11, 12, 41, 15, 16, 17, 18], ["-", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203], ["-", 75, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["-", 0, 1, 0, 11, 12, 41, 64, 241, 0, 33], ["-", 0, 1, 0, 11, 12, 41, 64, 241, 0, 203], ["-", 75, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["-", 75, 196, 0, 1, 0, 11, 12, 41, 75, 203]]
8
302
23
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { long a = long.Parse(Console.ReadLine()); long[] s = Console.ReadLine().Split().Select(long.Parse).ToArray(); bool ren = false; long renko = 0; long zoka = 0; long ans = 0; for (long i = 0; i < a - 1; i++) { if (s[i] == s[i + 1]) { ren = true; renko++; } else if (s[i + 1] > s[i] && (zoka == 1 || zoka == 0)) { zoka = 1; ren = true; renko++; } else if (s[i + 1] < s[i] && (zoka == -1 || zoka == 0)) { zoka = -1; ren = true; renko++; } else { ren = false; zoka = 0; } if (!ren) { ans++; } if (i == a - 2) { ans++; } } Console.WriteLine(ans); Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { long a = long.Parse(Console.ReadLine()); long[] s = Console.ReadLine().Split().Select(long.Parse).ToArray(); bool ren = false; long renko = 0; long zoka = 0; long ans = 0; for (long i = 0; i < a - 1; i++) { if (s[i] == s[i + 1]) { ren = true; renko++; } else if (s[i + 1] > s[i] && (zoka == 1 || zoka == 0)) { zoka = 1; ren = true; renko++; } else if (s[i + 1] < s[i] && (zoka == -1 || zoka == 0)) { zoka = -1; ren = true; renko++; } else { ren = false; zoka = 0; } if (!ren) { ans++; } // if (i == a - 2 ) { ans++; } } Console.WriteLine(ans + 1); Console.ReadLine(); } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
268
15
using System; using System.Text; namespace AtCoder { public class ProblemA { public static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int n = int.Parse(line[0]); int l = int.Parse(line[1]); int t = int.Parse(line[2]); int[] ants = new int[n]; long count = 0; for (int i = 0; i < n; i++) { line = Console.ReadLine().Split(' '); int pos = int.Parse(line[0]); bool toClockwise = line[1] == "1"; if (toClockwise) ants[i] = (pos + t) % l; else ants[i] = ((pos - t) % l + l) % l; if (toClockwise) count += (l - pos + t) / l; else count -= (t - pos) / l; } Array.Sort(ants); count = (count % n + n) % n; var sb = new StringBuilder(); for (int i = 0; i < n; i++) { int idx = (int)((i + count) % n); sb.AppendLine(ants[idx].ToString()); } Console.Write(sb.ToString()); } } }
using System; using System.Text; namespace AtCoder { public class ProblemA { public static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int n = int.Parse(line[0]); int l = int.Parse(line[1]); int t = int.Parse(line[2]); int[] ants = new int[n]; long count = 0; for (int i = 0; i < n; i++) { line = Console.ReadLine().Split(' '); int pos = int.Parse(line[0]); bool toClockwise = line[1] == "1"; if (toClockwise) ants[i] = (pos + t) % l; else ants[i] = ((pos - t) % l + l) % l; if (toClockwise) count += (pos + t) / l; else count -= (l - pos - 1 + t) / l; } Array.Sort(ants); count = (count % n + n) % n; var sb = new StringBuilder(); for (int i = 0; i < n; i++) { int idx = (int)((i + count) % n); sb.AppendLine(ants[idx].ToString()); } Console.Write(sb.ToString()); } } }
[["-", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22]]
8
306
8
using System; using System.IO; using System.Linq; namespace AGC013 { class C { static void Main(string[] args) { var NLT = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var N = NLT[0]; var L = NLT[1]; var T = NLT[2]; var AntPos = new int[N]; var StdDir = 1; var XW = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var X = XW[0]; var W = XW[1]; AntPos[0] = X; StdDir = W == 1 ? 1 : -1; var collision = 0; for (int i = 1; i < AntPos.Length; i++) { XW = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); X = XW[0]; W = XW[1] == 1 ? 1 : -1; AntPos[i] = ((W == 1 ? X + T : X - T) % L + L) % L; if (W != StdDir) { var diff = Math.Abs(X - AntPos[0]); diff = StdDir == 1 ? diff : L - diff; collision += (2 * T - diff) >= 0 ? (2 * T - diff) / L + 1 : 0; } } AntPos[0] = ((StdDir == 1 ? AntPos[0] + T : AntPos[0] - T) % L + L) % L; var StdPos = AntPos[0]; Array.Sort(AntPos); var offset = BinarySearch(AntPos, StdPos); if (AntPos[(offset - 1) % N] == StdPos) offset--; var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); for (int i = 0; i < AntPos.Length; i++) { var index = ((i + offset - StdDir * collision) % N + N) % N; Console.WriteLine(AntPos[index]); } Console.Out.Flush(); } public static int BinarySearch<T>(T[] array, T target) where T : IComparable<T> { int min = 0; int max = array.Length - 1; while (true) { if (max < min) return -1; int mid = min + (max - min) / 2; switch (target.CompareTo(array[mid])) { case -1: max = mid - 1; break; case 1: min = mid + 1; break; case 0: return mid; } } } } }
using System; using System.IO; using System.Linq; namespace AGC013 { class C { static void Main(string[] args) { var NLT = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var N = NLT[0]; var L = NLT[1]; var T = NLT[2]; var AntPos = new int[N]; var StdDir = 1; var XW = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var X = XW[0]; var W = XW[1]; AntPos[0] = X; StdDir = W == 1 ? 1 : -1; var collision = 0; for (int i = 1; i < AntPos.Length; i++) { XW = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); X = XW[0]; W = XW[1] == 1 ? 1 : -1; AntPos[i] = ((W == 1 ? X + T : X - T) % L + L) % L; if (W != StdDir) { var diff = Math.Abs(X - AntPos[0]); diff = StdDir == 1 ? diff : L - diff; collision += (2 * T - diff) >= 0 ? (2 * T - diff) / L + 1 : 0; } } AntPos[0] = ((StdDir == 1 ? AntPos[0] + T : AntPos[0] - T) % L + L) % L; var StdPos = AntPos[0]; Array.Sort(AntPos); var offset = BinarySearch(AntPos, StdPos); if (StdDir == -1 && AntPos[(offset - 1 + N) % N] == StdPos) offset--; var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); for (int i = 0; i < AntPos.Length; i++) { var index = ((i + offset - StdDir * collision) % N + N) % N; Console.WriteLine(AntPos[index]); } Console.Out.Flush(); } public static int BinarySearch<T>(T[] array, T target) where T : IComparable<T> { int min = 0; int max = array.Length - 1; while (true) { if (max < min) return -1; int mid = min + (max - min) / 2; switch (target.CompareTo(array[mid])) { case -1: max = mid - 1; break; case 1: min = mid + 1; break; case 0: return mid; } } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 241, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22]]
8
600
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var p = Input().ToInt(); var a = p[0]; var b = p[1]; var c = p[2]; if (Math.Abs(b - a) == Math.Abs(c - b)) { Console.WriteLine("YES"); return; } Console.WriteLine("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 class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var p = Input().ToInt(); var a = p[0]; var b = p[1]; var c = p[2]; if (b - a == c - b) { Console.WriteLine("YES"); return; } Console.WriteLine("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 class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
[["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25]]
8
327
10
using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] dataline = Console.ReadLine().Split(' '); Array.Sort(dataline); int a = int.Parse(dataline[0]); int b = int.Parse(dataline[1]); int c = int.Parse(dataline[2]); if ((b - a) == (c - b)) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] dataline = Console.ReadLine().Split(' '); int a = int.Parse(dataline[0]); int b = int.Parse(dataline[1]); int c = int.Parse(dataline[2]); if ((b - a) == (c - b)) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
130
7
using System; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { var o = Console.ReadLine().ToCharArray(); var e = Console.ReadLine().ToCharArray(); var temp = new List<char>(); for (int i = 0; i < o.Length; i++) { temp.Add(o[i]); temp.Add(e[i]); } var result = String.Join("", temp); Console.WriteLine(result); } } }
using System; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { var o = Console.ReadLine().ToCharArray(); var e = Console.ReadLine().ToCharArray(); var temp = new List<char>(); for (int i = 0; i < o.Length; i++) { if (o.Length > i) temp.Add(o[i]); if (e.Length > i) temp.Add(e[i]); } var result = String.Join("", temp); Console.WriteLine(result); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
8
124
16
using System; namespace ABC058_C { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var mojiCnt = new int[n, 26]; for (var i = 0; i < n; i++) { var s = Console.ReadLine(); for (var j = 0; j < s.Length; j++) { mojiCnt[j, s[j] - 'a']++; } } for (var i = 0; i < 26; i++) { var temp = int.MaxValue; for (var j = 0; j < n; j++) { temp = Math.Min(temp, mojiCnt[j, i]); } for (var j = 0; j < temp; j++) { Console.Write((char)('a' + i)); } } } } }
using System; namespace ABC058_C { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var mojiCnt = new int[n, 26]; for (var i = 0; i < n; i++) { var s = Console.ReadLine(); for (var j = 0; j < s.Length; j++) { mojiCnt[i, s[j] - 'a']++; } } for (var i = 0; i < 26; i++) { var temp = int.MaxValue; for (var j = 0; j < n; j++) { temp = Math.Min(temp, mojiCnt[j, i]); } for (var j = 0; j < temp; j++) { Console.Write((char)('a' + i)); } } Console.WriteLine(); } } }
[["-", 0, 223, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 223, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
192
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { //入力 int xMaxInput = int.Parse(Console.ReadLine()); string[] xInputStrings = new string[xMaxInput]; for (int i = 0; i < xMaxInput; ++i) { xInputStrings[i] = Console.ReadLine(); } //出力 Console.WriteLine( string.Join("", new Output().Calu(xInputStrings).Reverse())); } public class Output { public Output() {} public string Calu(string[] t) { int a = int.MaxValue; char c = 'a'; StringBuilder g = new StringBuilder(); for (int i = 1; i < 27; i++) { foreach (var s in t) { int Count = s.Length - s.Replace(c.ToString(), "").Length; if (Count < a) { a = Count; } } g.Insert(0, c.ToString(), a); c = Convert.ToChar(c + i); a = int.MaxValue; } return g.ToString(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { //入力 int xMaxInput = int.Parse(Console.ReadLine()); string[] xInputStrings = new string[xMaxInput]; for (int i = 0; i < xMaxInput; ++i) { xInputStrings[i] = Console.ReadLine(); } //出力 Console.WriteLine( string.Join("", new Output().Calu(xInputStrings).Reverse())); } public class Output { public Output() {} public string Calu(string[] t) { int a = int.MaxValue; char c = 'a'; int k = (int)c; StringBuilder g = new StringBuilder(); for (int i = 1; i < 27; i++) { foreach (var s in t) { int Count = s.Length - s.Replace(c.ToString(), "").Length; if (Count < a) { a = Count; } } g.Insert(0, c.ToString(), a); c = Convert.ToChar(c); k += 1; c = (char)k; a = int.MaxValue; } return g.ToString(); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 51, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 51, 22]]
8
259
21
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC058D_2 { class Program { static void Main(string[] args) { var n = RInt; var m = RInt; var x = RLongs; var y = RLongs; Mlong sumx = 0; Mlong sumy = 0; for (int i = 0; i < n; i++) { sumx += -x[i] * (Mlong)(n - 1 - 2 * i); } for (int i = 0; i < m; i++) { sumy += -y[i] * (Mlong)(m - 1 - 2 * i); } var ans = sumx * sumy; Console.WriteLine(ans); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m % mod - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m % mod + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a % mod, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { static public void Draw2D<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC058D_2 { class Program { static void Main(string[] args) { var n = RInt; var m = RInt; var x = RLongs; var y = RLongs; Mlong sumx = 0; Mlong sumy = 0; for (int i = 0; i < n; i++) { sumx += -x[i] * (Mlong)(n - 1 - 2 * i); } for (int i = 0; i < m; i++) { sumy += -y[i] * (Mlong)(m - 1 - 2 * i); } var ans = sumx * sumy; Console.WriteLine(ans); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod || n < 0 ? (n % mod + mod) % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a % mod, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { static public void Draw2D<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
[["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 106], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 31, 22], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 17, 18], ["+", 0, 11, 12, 41, 15, 16, 12, 16, 12, 203], ["+", 0, 11, 12, 41, 64, 16, 31, 23, 0, 24], ["+", 64, 16, 31, 23, 0, 16, 31, 16, 17, 109], ["+", 64, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 12, 41, 64, 16, 31, 23, 0, 16, 17, 72], ["+", 12, 41, 64, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 41, 64, 16, 31, 23, 0, 25], ["-", 0, 37, 0, 41, 64, 16, 31, 16, 17, 109], ["-", 0, 37, 0, 41, 64, 16, 31, 16, 12, 22], ["-", 0, 37, 0, 41, 75, 16, 31, 16, 17, 109], ["-", 0, 37, 0, 41, 75, 16, 31, 16, 12, 22]]
8
1,231
14
using System; using System.Collections.Generic; using System.Text; namespace AtTest.D_Challenge { class ABC_058 { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int[] nm = ReadInts(); long[] xs = ReadLongs(); long[] ys = ReadLongs(); long mask = 1000000000 + 7; long ySum = 0; for (int i = 0; i < nm[1] / 2; i++) { ySum += (ys[nm[1] - i - 1] - ys[i]) * (nm[1] - i * 2 - 1); ySum %= mask; } // Console.WriteLine(ySum); long res = 0; for (int i = 0; i < nm[0] / 2; i++) { res += ((xs[nm[0] - i - 1] - xs[i]) * (nm[0] - i * 2 - 1) * ySum) % mask; res %= mask; } Console.WriteLine(res); } private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Text; namespace AtTest.D_Challenge { class ABC_058 { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int[] nm = ReadInts(); long[] xs = ReadLongs(); long[] ys = ReadLongs(); long mask = 1000000000 + 7; long ySum = 0; for (int i = 0; i < nm[1] / 2; i++) { ySum += (ys[nm[1] - i - 1] - ys[i]) * (nm[1] - i * 2 - 1); ySum %= mask; } // Console.WriteLine(ySum); long xSum = 0; for (int i = 0; i < nm[0] / 2; i++) { xSum += (xs[nm[0] - i - 1] - xs[i]) * (nm[0] - i * 2 - 1); xSum %= mask; } Console.WriteLine((xSum * ySum) % mask); } private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 31, 23, 0, 16, 31, 16, 12, 23, 0, 25], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 48], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 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
387
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sikakukei4_30 { class Program { static void Main(string[] args) { string[] nm = Console.ReadLine().Split(' '); string[] xtext = Console.ReadLine().Split(' '); string[] ytext = Console.ReadLine().Split(' '); int n = int.Parse(nm[0]); int m = int.Parse(nm[1]); long[] x = new long[n]; long[] y = new long[m]; for (int i = 0; i < n; i++) { x[i] = Convert.ToInt64(xtext[i]); } for (int j = 0; j < m; j++) { y[j] = Convert.ToInt64(ytext[j]); } long answer = 0; long answerx = 0; for (int k = 0; k < n; k++) { answerx = answerx + (2 * (k + 1) - n - 1) * x[k]; } long answery = 0; for (int l = 0; l < m; l++) { answery = answery + (2 * (l + 1) - m - 1) * y[l]; } answer = (answerx) * (answery); long answer2 = answer % 1000000007; Console.WriteLine(answer2.ToString()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sikakukei4_30 { class Program { static void Main(string[] args) { string[] nm = Console.ReadLine().Split(' '); string[] xtext = Console.ReadLine().Split(' '); string[] ytext = Console.ReadLine().Split(' '); int n = int.Parse(nm[0]); int m = int.Parse(nm[1]); long[] x = new long[n]; long[] y = new long[m]; for (int i = 0; i < n; i++) { x[i] = Convert.ToInt64(xtext[i]); } for (int j = 0; j < m; j++) { y[j] = Convert.ToInt64(ytext[j]); } long answer; long answerx = 0; for (int k = 0; k < n; k++) { answerx = answerx + (2 * (k + 1) - n - 1) * x[k]; } long answery = 0; for (int l = 0; l < m; l++) { answery = answery + (2 * (l + 1) - m - 1) * y[l]; } answer = ((answerx % 1000000007) * (answery % 1000000007)) % (1000000000 + 7); Console.WriteLine(answer.ToString()); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 12, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 17, 109], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22]]
8
331
21
using System; class Program { static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(' '); string[] input2 = Console.ReadLine().Split(' '); string[] input3 = Console.ReadLine().Split(' '); Console.WriteLine(new Output().Calu(input1, input2, input3).ToString()); } public class Output { public Output() {} private long Sum(string[] s, int n) { long Sum = 0; for (int i = 0; i < n; i++) { Sum += long.Parse(s[i]) * (2 * i - n + 1); } return Sum; } public long Calu(string[] input1, string[] input2, string[] input3) { const int MOD = 1000000007; return ((Sum(input2, int.Parse(input1[0])) % MOD) * (Sum(input3, int.Parse(input1[1]) % MOD))) % MOD; } } }
using System; class Program { static void Main(string[] args) { string[] input1 = Console.ReadLine().Split(' '); string[] input2 = Console.ReadLine().Split(' '); string[] input3 = Console.ReadLine().Split(' '); Console.WriteLine(new Output().Calu(input1, input2, input3).ToString()); } public class Output { private const int MOD = 1000000007; private long Sum(string[] s, int n) { long Sum = 0; for (int i = 0; i < n; i++) { Sum += long.Parse(s[i]) * (2 * i - n + 1); } return Sum % MOD; } public long Calu(string[] input1, string[] input2, string[] input3) { return (Sum(input2, int.Parse(input1[0])) * Sum(input3, int.Parse(input1[1]))) % MOD; } } }
[["-", 0, 235, 8, 201, 0, 263, 0, 251, 0, 259], ["-", 8, 201, 0, 235, 8, 201, 0, 263, 141, 22], ["-", 0, 235, 8, 201, 0, 263, 54, 55, 0, 24], ["-", 0, 235, 8, 201, 0, 263, 54, 55, 0, 25], ["-", 0, 235, 8, 201, 0, 263, 8, 196, 0, 45], ["-", 0, 235, 8, 201, 0, 263, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 124, 0, 251, 0, 261], ["+", 0, 235, 8, 201, 0, 124, 0, 251, 0, 154], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 109], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 251, 0, 154], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 37, 0, 16, 31, 23, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 31, 23, 0, 16, 31, 23, 0, 16, 17, 109], ["-", 31, 23, 0, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
236
29
using System; using System.Linq; using System.Collections.Generic; class P { static void Main(string[] _) { _ = Console.ReadLine().Split(' '); int n = int.Parse(_[0]); int m = int.Parse(_[1]); Int64[] x = new Int64[n]; Int64[] y = new Int64[m]; _ = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { x[i] = Int64.Parse(_[i]); } _ = Console.ReadLine().Split(' '); for (int i = 0; i < m; i++) { y[i] = Int64.Parse(_[i]); } Int64 xx = 0; for (int i = 1; i <= n; i++) { xx += ((i - 1) * x[i - 1] - (n - i) * x[i - 1]); } Int64 yy = 0; for (int i = 1; i <= m; i++) { yy += ((i - 1) * y[i - 1] - (m - i) * y[i - 1]); } Console.WriteLine((xx * yy) % 1000000007); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main(string[] _) { _ = Console.ReadLine().Split(' '); int n = int.Parse(_[0]); int m = int.Parse(_[1]); Int64[] x = new Int64[n]; Int64[] y = new Int64[m]; _ = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { x[i] = Int64.Parse(_[i]); } _ = Console.ReadLine().Split(' '); for (int i = 0; i < m; i++) { y[i] = Int64.Parse(_[i]); } Int64 xx = 0; for (int i = 1; i <= n; i++) { xx += ((i - 1) * x[i - 1] - (n - i) * x[i - 1]); } Int64 yy = 0; for (int i = 1; i <= m; i++) { yy += ((i - 1) * y[i - 1] - (m - i) * y[i - 1]); } Console.WriteLine(((xx % 1000000007) * (yy % 1000000007)) % 1000000007); } }
[["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 17, 109], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
300
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace d { class Program { const long MOD = 1000000007; static void Main(string[] args) { var nmstr = Console.ReadLine().Split(' '); var n = int.Parse(nmstr[0]); var m = int.Parse(nmstr[1]); var xstr = Console.ReadLine().Split(' '); var x = new long[n]; for (var i = 0; i < n; i++) { x[i] = long.Parse(xstr[i]); } var ystr = Console.ReadLine().Split(' '); var y = new long[m]; for (var i = 0; i < m; i++) { y[i] = long.Parse(ystr[i]); } var xsum = 0L; for (var i = 0; i < n; i++) { xsum += ((2 * i - n + 1) * x[i]); } var ysum = 0L; for (var i = 0; i < m; i++) { ysum += ((2 * i - m + 1) * y[i]); } var totalArea = (xsum * ysum) % MOD; Console.WriteLine(totalArea); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace d { class Program { const long MOD = 1000000007; static void Main(string[] args) { var nmstr = Console.ReadLine().Split(' '); var n = int.Parse(nmstr[0]); var m = int.Parse(nmstr[1]); var xstr = Console.ReadLine().Split(' '); var x = new long[n]; for (var i = 0; i < n; i++) { x[i] = long.Parse(xstr[i]); } var ystr = Console.ReadLine().Split(' '); var y = new long[m]; for (var i = 0; i < m; i++) { y[i] = long.Parse(ystr[i]); } var xsum = 0L; for (var i = 0; i < n; i++) { xsum += ((2 * i - n + 1) * x[i]); } xsum %= MOD; var ysum = 0L; for (var i = 0; i < m; i++) { ysum += ((2 * i - m + 1) * y[i]); } ysum %= MOD; var totalArea = (xsum * ysum) % MOD; Console.WriteLine(totalArea); } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
304
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 { public void Solve(Scanner sc) { var N = sc.Int; ModInt res = N + (N - 1) * (N - 1L); ModInt S = 1; var dp = new ModInt[N]; dp[0] = 1; dp[1] = 1; for (var i = 2; i < N; i++) { dp[i] = S - dp[i - 2] + 1; S += dp[i]; } WriteLine(res + S * (N - 1) + (S - dp[N - 1]) * (N - 1) * (N - 1)); } } public struct ModInt { public const long MOD = (int)1e9 + 7; // public const long MOD = 998244353; public long Value { get; set; } public ModInt(long n = 0) { Value = n; } private static ModInt[] fac; //階乗 private static ModInt[] inv; //逆数 private static ModInt[] facinv; // 1/(i!) public override string ToString() => Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.Value += r.Value; if (l.Value >= MOD) l.Value -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.Value -= r.Value; if (l.Value < 0) l.Value += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void Build(int n) { fac = new ModInt[n + 1]; facinv = new ModInt[n + 1]; inv = new ModInt[n + 1]; inv[1] = 1; fac[0] = fac[1] = 1; facinv[0] = facinv[1] = 1; for (var i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); facinv[i] = facinv[i - 1] * inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(ModInt n) => fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Inv(ModInt n) => inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacInv(ModInt n) => facinv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(ModInt n, ModInt r) { if (n < r) return 0; if (n == r) return 1; var calc = fac[n]; calc = calc * facinv[r]; calc = calc * facinv[n - r]; return calc; } } #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[] 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; } 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 IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } 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 { public void Solve(Scanner sc) { var N = sc.Int; if (N == 1) Fail(1); ModInt res = N + (N - 1) * (N - 1L); ModInt S = 1; var dp = new ModInt[N]; dp[0] = 1; dp[1] = 1; for (var i = 2; i < N; i++) { dp[i] = S - dp[i - 2] + 1; S += dp[i]; } WriteLine(res + S * (N - 1) + (S - dp[N - 1]) * (N - 1) * (N - 1)); } } public struct ModInt { public const long MOD = (int)1e9 + 7; // public const long MOD = 998244353; public long Value { get; set; } public ModInt(long n = 0) { Value = n; } private static ModInt[] fac; //階乗 private static ModInt[] inv; //逆数 private static ModInt[] facinv; // 1/(i!) public override string ToString() => Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.Value += r.Value; if (l.Value >= MOD) l.Value -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.Value -= r.Value; if (l.Value < 0) l.Value += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void Build(int n) { fac = new ModInt[n + 1]; facinv = new ModInt[n + 1]; inv = new ModInt[n + 1]; inv[1] = 1; fac[0] = fac[1] = 1; facinv[0] = facinv[1] = 1; for (var i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); facinv[i] = facinv[i - 1] * inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(ModInt n) => fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Inv(ModInt n) => inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacInv(ModInt n) => facinv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(ModInt n, ModInt r) { if (n < r) return 0; if (n == r) return 1; var calc = fac[n]; calc = calc * facinv[r]; calc = calc * facinv[n - r]; return calc; } } #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[] 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; } 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 IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } 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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
2,521
11
using System; using System.IO; class Program { static void Main(string[] args) { var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(writer); Console.WriteLine(Solve()); Console.Out.Flush(); } static object Solve() { var N = long.Parse(Console.ReadLine()); var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Array.Sort(a); long sum = 0; for (long i = N; i < N * 2; i++) { sum += a[i]; } return sum; } }
using System; using System.IO; class Program { static void Main(string[] args) { var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(writer); Console.WriteLine(Solve()); Console.Out.Flush(); } static object Solve() { var N = long.Parse(Console.ReadLine()); var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Array.Sort(a); Array.Reverse(a); long sum = 0; for (long i = 1; i < N * 2; i += 2) { sum += a[i]; } return sum; } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203]]
8
148
12
using System; using System.Collections.Generic; namespace AGC012A { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] a = new long[3 * N]; var target = Console.ReadLine().Split(' '); List<long> b = new List<long>(); for (int i = 0; i < 3 * N; i++) { // a[i] = long.Parse(target[i]); b.Insert(i, a[i]); } Array.Sort(a); Array.Reverse(a); b.Sort(); b.Reverse(); // long strength = 0; long st1 = 0; for (int i = 0; i < N; i++) { // strength += a[2*i+1]; st1 += b[2 * i + 1]; } // Console.WriteLine(strength); Console.WriteLine(st1); } } }
using System; using System.Collections.Generic; namespace AGC012A { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] a = new long[3 * N]; var target = Console.ReadLine().Split(' '); List<long> b = new List<long>(); for (int i = 0; i < 3 * N; i++) { // a[i] = long.Parse(target[i]); b.Add(long.Parse(target[i])); } // Array.Sort(a); Array.Reverse(a); b.Sort(); b.Reverse(); // long strength = 0; long st1 = 0; for (int i = 0; i < N; i++) { // strength += a[2*i+1]; st1 += b[2 * i + 1]; } // Console.WriteLine(strength); Console.WriteLine(st1); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
185
25
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class A { public static void Main() { int N = GetInt(); var a = new List<long>(3 * N); for (int i = 0; i < 3 * N; i++) a.Add(GetLong()); a.Sort(); long sum = 0; for (int i = N; i < 2 * N; i++) sum += a[i]; Console.WriteLine(sum); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class A { public static void Main() { int N = GetInt(); var a = new List<long>(3 * N); for (int i = 0; i < 3 * N; i++) a.Add(GetLong()); a.Sort(); long sum = 0; for (int i = 0; i < N; i++) sum += a[N + 2 * i]; Console.WriteLine(sum); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 206, 207, 0, 28, 0, 16, 12, 16, 31, 203], ["+", 206, 207, 0, 28, 0, 16, 12, 16, 17, 48]]
8
275
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int n = cin.nextInt(); long[] a = cin.ArrayLong(3 * n, 0); Array.Sort(a); long ans = 0; for (int i = 0; i < n; i++) { ans += a[i + n]; } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int n = cin.nextInt(); long[] a = cin.ArrayLong(3 * n, 0); Array.Sort(a); Array.Reverse(a); long ans = 0; for (int i = 0; i < n; i++) { ans += a[i * 2 + 1]; } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
755
11
using System; class Program { static void Main(string[] args) { Console.WriteLine(CardGameforThreeABCEdit()); } private static long CardGameforThreeABCEdit() { int N = 0; long[] A = null; readData(ref N, ref A); return playerPower(A); } private static long playerPower(long[] a) { long sum = 0; Array.Sort(a); Array.Reverse(a); for (int i = 1; i < a.Length - 1; i += 2) { sum += a[i]; } return sum; } /// <summary> /// データを読み込む /// </summary> private static void readData(ref int N, ref long[] A) { N = int.Parse(Console.ReadLine()); A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } }
using System; class Program { static void Main(string[] args) { Console.WriteLine(CardGameforThreeABCEdit()); } private static long CardGameforThreeABCEdit() { long N = 0; long[] A = null; readData(ref N, ref A); return playerPower(N, A); } private static long playerPower(long N, long[] a) { long sum = 0; Array.Sort(a); Array.Reverse(a); for (int i = 0; i < N; i++) { sum += a[2 * i + 1]; } return sum; } /// <summary> /// データを読み込む /// </summary> private static void readData(ref long N, ref long[] A) { N = long.Parse(Console.ReadLine()); A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 37, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 37, 0, 213, 3, 4, 0, 21], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 141, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["-", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 31, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
181
26
using System; using System.Collections.Generic; using System.Linq; namespace ABC { class Program { static void Main(string[] args) { AGC012_A(); } static void AGC012_A() { var N = int.Parse(Console.ReadLine()); var an = Console.ReadLine() .Split(' ') .Select(long.Parse) .OrderByDescending(x => x) .ToArray(); var dict = new Dictionary<int, List<long>>(); for (var i = 0; i < N; i++) dict.Add(i, new List<long>()); var k = 0; while (k < an.Length) { for (var i = 0; i < N; i++) { dict[i].Add(an[k]); k++; dict[i].Add(an[k]); k++; if (k == an.Length) break; } } Console.WriteLine(dict.Values.Sum(x => x[1])); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC { class Program { static void Main(string[] args) { AGC012_A(); } static void AGC012_A() { var N = int.Parse(Console.ReadLine()); var an = Console.ReadLine() .Split(' ') .Select(long.Parse) .OrderByDescending(x => x) .ToArray(); var dict = new Dictionary<int, List<long>>(); for (var i = 0; i < N; i++) dict.Add(i, new List<long>()); var k = 0; while (k < an.Length) { for (var i = 0; i < N; i++) { dict[i].Add(an[k]); k++; if (k == an.Length) break; dict[i].Add(an[k]); k++; if (k == an.Length) break; } } Console.WriteLine(dict.Values.Sum(x => x[1])); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35]]
8
230
10
using System; using System.Collections.Generic; using System.Linq; class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int 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; } } class Program { static Scanner cin = new Scanner(); static void Main(string[] args) { int N = cin.Int(); var a = cin.ArrayLong(3 * N); Array.Sort(a); long ans = 0; for (int i = N; i <= 2 * N - 1; i++) { ans += a[i]; } Console.WriteLine(ans); Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Linq; class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int 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; } } class Program { static Scanner cin = new Scanner(); static void Main(string[] args) { int N = cin.Int(); var a = cin.ArrayLong(3 * N); a = a.OrderByDescending(x => x).ToArray(); long ans = 0; for (int i = 1; i <= 2 * N - 1; i += 2) { ans += a[i]; } Console.WriteLine(ans); Console.ReadLine(); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203]]
8
389
19
using System; using System.Linq; class c { static void Main() { int n = int.Parse(Console.ReadLine()); var a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); Console.WriteLine( a.OrderBy(f => f).Where((f, g) => g >= n && g % 2 == 0).Sum()); } }
using System; using System.Linq; class c { static void Main() { int n = int.Parse(Console.ReadLine()); var a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); Console.WriteLine( a.OrderBy(f => f).Where((f, g) => n <= g && g % 2 == n % 2).Sum()); } }
[["-", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22], ["-", 0, 28, 0, 218, 8, 16, 31, 16, 17, 20], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 17, 19], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 12, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 16, 12, 203], ["+", 0, 218, 8, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 218, 8, 16, 12, 16, 12, 16, 17, 109], ["+", 0, 218, 8, 16, 12, 16, 12, 16, 12, 203]]
8
92
8
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // long.Parseはstringをlongに変換。 long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long answer = 0; long memo = 0; while (true) { answer += nums[3 * n - 2 - 2 * memo]; memo++; if (memo == n) break; } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // long.Parseはstringをlongに変換。 long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long answer = 0; long memo = 0; Array.Sort(nums); while (true) { answer += nums[3 * n - 2 - 2 * memo]; memo++; if (memo == n) break; } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
125
7
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class MainClass { // C#7.0//////////////////// int N; long[] a; void Solve() { io.i(out N); io.ini(out a, 3 * N); a.Sort(); long ans = 0; for (int i = N; i < 2 * N; i++) ans += a[i]; io.o(ans); } //////////////////////////////////////////////////////////// public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } //////////////////////////////////////////////////////////// } class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public char nextChar() { return char.Parse(next()); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } public string[] arr() { return Console.ReadLine().Split(' '); } public char[] arrayChar() { return Array.ConvertAll(arr(), char.Parse); } public int[] arrayInt() { return Array.ConvertAll(arr(), int.Parse); } public long[] arrayLong() { return Array.ConvertAll(arr(), long.Parse); } public double[] arrayDouble() { return Array.ConvertAll(arr(), double.Parse); } private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } public void i<T>(out T v) { v = suitType<T>(next()); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void ini(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt(); } public void ini(out long[] a, int size) { a = new long[size]; for (int i = 0; i < size; i++) a[i] = nextInt(); } public void ini(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt(); a2[i] = nextInt(); } } public void ini(out int[,] g, int h, int w) { g = new int[h, w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) g[i, j] = nextInt(); } public void ini(out string[] a, int size) { a = new string[size]; for (int i = 0; i < size; i++) a[i] = next(); } public void inii(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt() - 1; } public void inii(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt() - 1; a2[i] = nextInt() - 1; } } public void inii(out int[,] a, int size) { a = new int[size, size]; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) a[i, j] = nextInt() - 1; } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { foreach (T v in a) Console.WriteLine(v); } public void o<T>(List<T> l) { foreach (T v in l) sw.WriteLine(v); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { foreach (T v in a) { ol(v); } br(); } public void YN(bool f) { Console.WriteLine(f ? "YES" : "NO"); } public void Yn(bool f) { Console.WriteLine(f ? "Yes" : "No"); } public void yn(bool f) { Console.WriteLine(f ? "yes" : "no"); } public void br() { Console.WriteLine(""); } public void writeFlush() { Console.Out.Flush(); } public string pad0<T>(T v, int n) { return v.ToString().PadLeft(n, '0'); } } class Mat { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long Sum(params long[] a) { return a.Aggregate((v, next) => (v % mod + next) % mod); } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public T Max<T>(params T[] v) { return v.Max(); } public T Min<T>(params T[] v) { return v.Min(); } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int Clamp(int n, int a, int b) { return (n < a) ? a : (b < n) ? b : n; } public long Clamp(long n, long a, long b) { return (n < a) ? a : (b < n) ? b : n; } public double Clamp(double n, double a, double b) { return (n < a) ? a : (b < n) ? b : n; } public long Tousa(long a, long d, int n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, int n) { return n * (2 * a + (n - 1) * d) / 2; } } class AssociativeArray<T> { public Dictionary<T, int> dic; public AssociativeArray() {} public AssociativeArray(T[] a) { init(a); } public void init(T[] a) { dic = new Dictionary<T, int>(); for (int i = 0; i < a.Length; i++) { if (!dic.ContainsKey(a[i])) dic[a[i]] = 0; dic[a[i]]++; } } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return dic[k]; } public int ValueSum() { int s = 0; foreach (var i in dic) s += i.Value; return s; } public int KeyNum() { return dic.Keys.Count; } public int Max() { return dic.Values.Max(); } public int Min() { return dic.Values.Min(); } public T MaxKey() { return dic.First(d => d.Value == Max()).Key; } public T MinKey() { return dic.First(d => d.Value == Min()).Key; } public bool isContainsK(T k) { return dic.ContainsKey(k); } public bool anyContainsK(params T[] k) { bool f = false; foreach (T v in k) f |= isContainsK(v); return f; } public bool allContainsK(params T[] k) { bool f = true; foreach (T v in k) f &= isContainsK(v); return f; } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } //:sort->array } class Time { public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } class BucketSort { public int[] bucket; public void Init(int[] a) { bucket = new int[a.Max() + 1]; for (int i = 0; i < a.Length; ++i) ++bucket[a[i]]; for (int i = 0, j = 0; j < bucket.Length; ++j) for (int k = bucket[j]; k != 0; --k, ++i) a[i] = j; } } // Ex//////////////////////////////////////////////////////////// static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } } static class CharEX { public static int toInt(this char c) { return int.Parse(c.ToString()); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static void Set<T>(this T[] a, T v) { for (int i = 0; i < a.Length; i++) { a[i] = v; } } } //////////////////////////////////////////////////////////////// }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class MainClass { // C#7.0//////////////////// int N; long[] a; void Solve() { io.i(out N); io.ini(out a, 3 * N); a.Sort(); Array.Reverse(a); long ans = 0; for (int i = 0; i < N; i++) { ans += a[2 * i + 1]; } io.o(ans); } //////////////////////////////////////////////////////////// public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } //////////////////////////////////////////////////////////// } class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public char nextChar() { return char.Parse(next()); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } public string[] arr() { return Console.ReadLine().Split(' '); } public char[] arrayChar() { return Array.ConvertAll(arr(), char.Parse); } public int[] arrayInt() { return Array.ConvertAll(arr(), int.Parse); } public long[] arrayLong() { return Array.ConvertAll(arr(), long.Parse); } public double[] arrayDouble() { return Array.ConvertAll(arr(), double.Parse); } private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } public void i<T>(out T v) { v = suitType<T>(next()); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void ini(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt(); } public void ini(out long[] a, int size) { a = new long[size]; for (int i = 0; i < size; i++) a[i] = nextInt(); } public void ini(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt(); a2[i] = nextInt(); } } public void ini(out int[,] g, int h, int w) { g = new int[h, w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) g[i, j] = nextInt(); } public void ini(out string[] a, int size) { a = new string[size]; for (int i = 0; i < size; i++) a[i] = next(); } public void inii(out int[] a, int size) { a = new int[size]; for (int i = 0; i < size; i++) a[i] = nextInt() - 1; } public void inii(out int[] a1, out int[] a2, int size) { a1 = new int[size]; a2 = new int[size]; for (int i = 0; i < size; i++) { a1[i] = nextInt() - 1; a2[i] = nextInt() - 1; } } public void inii(out int[,] a, int size) { a = new int[size, size]; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) a[i, j] = nextInt() - 1; } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { foreach (T v in a) Console.WriteLine(v); } public void o<T>(List<T> l) { foreach (T v in l) sw.WriteLine(v); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { foreach (T v in a) { ol(v); } br(); } public void YN(bool f) { Console.WriteLine(f ? "YES" : "NO"); } public void Yn(bool f) { Console.WriteLine(f ? "Yes" : "No"); } public void yn(bool f) { Console.WriteLine(f ? "yes" : "no"); } public void br() { Console.WriteLine(""); } public void writeFlush() { Console.Out.Flush(); } public string pad0<T>(T v, int n) { return v.ToString().PadLeft(n, '0'); } } class Mat { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return (n != 0) ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long Sum(params long[] a) { return a.Aggregate((v, next) => (v % mod + next) % mod); } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public T Max<T>(params T[] v) { return v.Max(); } public T Min<T>(params T[] v) { return v.Min(); } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int Clamp(int n, int a, int b) { return (n < a) ? a : (b < n) ? b : n; } public long Clamp(long n, long a, long b) { return (n < a) ? a : (b < n) ? b : n; } public double Clamp(double n, double a, double b) { return (n < a) ? a : (b < n) ? b : n; } public long Tousa(long a, long d, int n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, int n) { return n * (2 * a + (n - 1) * d) / 2; } } class AssociativeArray<T> { public Dictionary<T, int> dic; public AssociativeArray() {} public AssociativeArray(T[] a) { init(a); } public void init(T[] a) { dic = new Dictionary<T, int>(); for (int i = 0; i < a.Length; i++) { if (!dic.ContainsKey(a[i])) dic[a[i]] = 0; dic[a[i]]++; } } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return dic[k]; } public int ValueSum() { int s = 0; foreach (var i in dic) s += i.Value; return s; } public int KeyNum() { return dic.Keys.Count; } public int Max() { return dic.Values.Max(); } public int Min() { return dic.Values.Min(); } public T MaxKey() { return dic.First(d => d.Value == Max()).Key; } public T MinKey() { return dic.First(d => d.Value == Min()).Key; } public bool isContainsK(T k) { return dic.ContainsKey(k); } public bool anyContainsK(params T[] k) { bool f = false; foreach (T v in k) f |= isContainsK(v); return f; } public bool allContainsK(params T[] k) { bool f = true; foreach (T v in k) f &= isContainsK(v); return f; } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } //:sort->array } class Time { public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } class BucketSort { public int[] bucket; public void Init(int[] a) { bucket = new int[a.Max() + 1]; for (int i = 0; i < a.Length; ++i) ++bucket[a[i]]; for (int i = 0, j = 0; j < bucket.Length; ++j) for (int k = bucket[j]; k != 0; --k, ++i) a[i] = j; } } // Ex//////////////////////////////////////////////////////////// static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } } static class CharEX { public static int toInt(this char c) { return int.Parse(c.ToString()); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static void Set<T>(this T[] a, T v) { for (int i = 0; i < a.Length; i++) { a[i] = v; } } } //////////////////////////////////////////////////////////////// }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 31, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
2,942
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.IO; class _Class { void _Do() { int N = _int()[0]; int[] a = _int(); Array.Sort(a); int c = a.Length / 3; int d = a.Length / 3 * 2; long l = 0; for (int i = c; i < d; i++) { l += a[i]; } Console.WriteLine(l); } static void Main(string[] args) { new _Class()._Do(); } #region string _string() { return Console.ReadLine(); } // string[] _strings() { return Console.ReadLine().Split(); } int[] _int(int n) { var x = new int[n]; for (var i = 0; i < n; i++) { x[i] = int.Parse(Console.ReadLine()); } return x; } // int[] _int() { var ss = Console.ReadLine().Split(); var x = new int[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = int.Parse(ss[i]); return x; } long[] _long() { var ss = Console.ReadLine().Split(); var x = new long[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = long.Parse(ss[i]); return x; } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.IO; class _Class { void _Do() { int N = _int()[0]; int[] a = _int(); Array.Sort(a); Array.Reverse(a); int m = a.Length / 3 * 2; long l = 0; for (int i = 0; i < m; i++) { if (i % 2 == 0) continue; l += a[i]; } Console.WriteLine(l); } static void Main(string[] args) { new _Class()._Do(); } #region string _string() { return Console.ReadLine(); } // string[] _strings() { return Console.ReadLine().Split(); } int[] _int(int n) { var x = new int[n]; for (var i = 0; i < n; i++) { x[i] = int.Parse(Console.ReadLine()); } return x; } // int[] _int() { var ss = Console.ReadLine().Split(); var x = new int[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = int.Parse(ss[i]); return x; } long[] _long() { var ss = Console.ReadLine().Split(); var x = new long[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = long.Parse(ss[i]); return x; } #endregion }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
365
28
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); // static Scan sc = new ScanCHK(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n = sc.Int; var a = sc.IntArr; Array.Sort(a); long sum = 0; for (int i = n; i < n * 2; i++) { sum += a[i]; } Prt(sum); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { Console.WriteLine(string.Join(" ", a)); } static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); } static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); // static Scan sc = new ScanCHK(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n = sc.Int; var a = sc.IntArr; Array.Sort(a); long sum = 0; for (int i = n * 3 - 2, c = 0; c < n; i -= 2, ++c) { sum += a[i]; } Prt(sum); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { Console.WriteLine(string.Join(" ", a)); } static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); } static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
[["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 0, 21], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 110], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 26, 21], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 22]]
8
2,966
16
using System; using System.Collections.Generic; using System.Linq; class P { static void Main(string[] _) { decimal r = 0; int n = int.Parse(Console.ReadLine()); int[] a = new int[3 * n]; _ = Console.ReadLine().Split(' '); for (int i = 0; i < 3 * n; i++) { a[i] = int.Parse(_[i]); } Array.Sort(a); for (int i = n; i < 2 * n; i++) { r = decimal.Add(r, a[i]); } Console.WriteLine(r); } }
using System; using System.Collections.Generic; using System.Linq; class P { static void Main(string[] _) { decimal r = 0; int n = int.Parse(Console.ReadLine()); int[] a = new int[3 * n]; _ = Console.ReadLine().Split(' '); for (int i = 0; i < 3 * n; i++) { a[i] = int.Parse(_[i]); } Array.Sort(a); for (int i = 3 * n - 2; i >= n; i -= 2) { r = decimal.Add(r, a[i]); } Console.WriteLine(r); } }
[["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 110], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203]]
8
156
11
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Globalization; using System.Diagnostics; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().Solve(); Out.Flush(); } Scanner cin = new Scanner(); Random rnd = new Random(); Stopwatch sw = new Stopwatch(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; void Solve() { int N = cin.Nextint; var A = cin.Scanlong; Array.Sort(A); long ans = 0; for (int i = N; i < 2 * N; i++) { ans += A[i]; } WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] Scan { get { return ReadLine().Split(); } } public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } } public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } } public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } } public string Next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next; } } public int Nextint { get { return int.Parse(Next); } } public long Nextlong { get { return long.Parse(Next); } } public double Nextdouble { get { return double.Parse(Next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Globalization; using System.Diagnostics; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().Solve(); Out.Flush(); } Scanner cin = new Scanner(); Random rnd = new Random(); Stopwatch sw = new Stopwatch(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; void Solve() { int N = cin.Nextint; var A = cin.Scanlong; Array.Sort(A); Array.Reverse(A); long ans = 0; int cnt = 0; for (int i = 1; i < 3 * N; i += 2) { ans += A[i]; cnt++; if (cnt == N) break; } WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] Scan { get { return ReadLine().Split(); } } public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } } public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } } public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } } public string Next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next; } } public int Nextint { get { return int.Parse(Next); } } public long Nextlong { get { return long.Parse(Next); } } public double Nextdouble { get { return double.Parse(Next); } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94]]
8
454
30
using System; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { int N = Reader.Int(); var A = Reader.IntArray(N * 3); Array.Sort(A); long ans = A.Skip(N).Take(N).Sum(a => (long)a); Console.WriteLine(ans); } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
using System; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { int N = Reader.Int(); var A = Reader.IntArray(N * 3); Array.Sort(A); long ans = A.Skip(N).Where((v, i) => i % 2 == 0).Sum(a => (long)a); Console.WriteLine(ans); } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["+", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 17, 109], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203]]
8
610
14
using System; namespace abc057 { public class Program { public static void Main(string[] args) { string str = Console.ReadLine(); string[] arr = str.Split(' '); int a = Convert.ToInt32(arr[0]); int b = Convert.ToInt32(arr[1]); if ((a + b) > 24) { Console.WriteLine((a + b) - 24); } else { Console.WriteLine(a + b); } } } }
using System; namespace abc057 { public class Program { public static void Main(string[] args) { string str = Console.ReadLine(); string[] arr = str.Split(' '); int a = Convert.ToInt32(arr[0]); int b = Convert.ToInt32(arr[1]); if ((a + b) == 24) { Console.WriteLine(0); } else if ((a + b) > 24) { Console.WriteLine((a + b) - 24); } else { Console.WriteLine(a + b); } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 23, 0, 24], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 17, 72], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 23, 0, 25]]
8
110
20
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class Program { public static void Main() { var nm = Console.ReadLine().Split(); int n = int.Parse(nm[0]); int m = int.Parse(nm[1]); int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[m]; int[] d = new int[m]; for (int i = 0; i < n; i++) { var ab = Console.ReadLine().Split(); a[i] = int.Parse(ab[0]); b[i] = int.Parse(ab[1]); } for (int i = 0; i < m; i++) { var cd = Console.ReadLine().Split(); c[i] = int.Parse(cd[0]); d[i] = int.Parse(cd[1]); } for (int i = 0; i < n; i++) { int min = 100000000; int ans = 0; for (int j = 0; j < m; j++) { int l = Math.Abs(a[i] - c[j]) + Math.Abs(b[i] - d[j]); if (l < min) { min = l; ans = j; } } Console.WriteLine(ans + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class Program { public static void Main() { var nm = Console.ReadLine().Split(); int n = int.Parse(nm[0]); int m = int.Parse(nm[1]); int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[m]; int[] d = new int[m]; for (int i = 0; i < n; i++) { var ab = Console.ReadLine().Split(); a[i] = int.Parse(ab[0]); b[i] = int.Parse(ab[1]); } for (int i = 0; i < m; i++) { var cd = Console.ReadLine().Split(); c[i] = int.Parse(cd[0]); d[i] = int.Parse(cd[1]); } for (int i = 0; i < n; i++) { int min = Math.Abs(a[i] - c[0]) + Math.Abs(b[i] - d[0]); ; int ans = 0; for (int j = 1; j < m; j++) { int l = Math.Abs(a[i] - c[j]) + Math.Abs(b[i] - d[j]); if (l < min) { min = l; ans = j; } } Console.WriteLine(ans + 1); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 212, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 260, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
334
33
using System; using System.Linq; namespace ABC057 { class B { static void Main(string[] args) { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ab = Enumerable.Repeat(0, nm[0]) .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); var cd = Enumerable.Repeat(0, nm[1]) .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); var dist = int.MaxValue; for (int i = 0; i < nm[0]; i++) { var res = 0; for (int j = nm[1] - 1; j >= 0; j--) { if (Math.Abs(ab[i][0] - cd[j][0]) + Math.Abs(ab[i][1] - cd[j][1]) <= dist) { dist = Math.Abs(ab[i][0] - cd[j][0]) + Math.Abs(ab[i][1] - cd[j][1]); res = j; } } Console.WriteLine(res + 1); } } } }
using System; using System.Linq; namespace ABC057 { class B { static void Main(string[] args) { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ab = Enumerable.Repeat(0, nm[0]) .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); var cd = Enumerable.Repeat(0, nm[1]) .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); for (int i = 0; i < nm[0]; i++) { var dist = int.MaxValue; var res = 0; for (int j = nm[1] - 1; j >= 0; j--) { if (Math.Abs(ab[i][0] - cd[j][0]) + Math.Abs(ab[i][1] - cd[j][1]) <= dist) { dist = Math.Abs(ab[i][0] - cd[j][0]) + Math.Abs(ab[i][1] - cd[j][1]); res = j + 1; } } Console.WriteLine(res); } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
298
18
// shakyo using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = input[0]; var M = input[1]; var A = new int[N]; var B = new int[N]; var C = new int[M]; var D = new int[M]; for (var i = 0; i < N; i++) { var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); A[i] = a[0]; B[i] = a[1]; } for (var j = 0; j < M; j++) { var b = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); C[j] = b[0]; D[j] = b[1]; } for (var n = 0; n < N; n++) { var cp = 1; var minDist = Math.Abs(A[n] - C[0]) + Math.Abs(B[n] - D[0]); for (var m = 1; m < M; m++) { var curdist = Math.Abs(A[n] - C[m]) + Math.Abs(B[n] - C[m]); if (curdist < minDist) { minDist = curdist; cp = m + 1; } } Console.WriteLine(cp); } } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var N = input[0]; var M = input[1]; var A = new long[N]; var B = new long[N]; var C = new long[M]; var D = new long[M]; for (var i = 0; i < N; i++) { var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); A[i] = a[0]; B[i] = a[1]; } for (var j = 0; j < M; j++) { var b = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); C[j] = b[0]; D[j] = b[1]; } for (var n = 0; n < N; n++) { var cp = 1; var minDist = Math.Abs(A[n] - C[0]) + Math.Abs(B[n] - D[0]); for (var m = 1; m < M; m++) { var curdist = Math.Abs(A[n] - C[m]) + Math.Abs(B[n] - D[m]); if (curdist < minDist) { minDist = curdist; cp = m + 1; } } Console.WriteLine(cp); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22]]
8
362
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int N = x[0]; int M = x[1]; var out1 = new int[N]; var A = new int [N][]; for (var i = 0; i < N; i++) A[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var C = new int [M][]; for (var i = 0; i < M; i++) C[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); for (int i = 0; i < N; i++) { int l = 99999999; for (int j = 0; j < M; j++) { if (D(A[i], C[j]) < l) { l = D(A[i], C[j]); out1[i] = j + 1; } } Console.WriteLine(out1[i]); } } static int D(int[] a, int[] b) { return Math.Abs(a[0] - b[0]) + Math.Abs(a[1] - b[1]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int N = x[0]; int M = x[1]; var out1 = new int[N]; var A = new int [N][]; for (var i = 0; i < N; i++) A[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var C = new int [M][]; for (var i = 0; i < M; i++) C[i] = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); for (int i = 0; i < N; i++) { int l = D(A[i], C[0]); out1[i] = 1; for (int j = 0; j < M; j++) { if (D(A[i], C[j]) < l) { l = D(A[i], C[j]); out1[i] = j + 1; } } Console.WriteLine(out1[i]); } } static int D(int[] a, int[] b) { return Math.Abs(a[0] - b[0]) + Math.Abs(a[1] - b[1]); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203]]
8
343
20
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace AtCoder { internal class Program { static void Main(string[] args) { var sr = new InputReader(Console.In); // var sr = new InputReader(new StreamReader(new // MemoryStream(Encoding.Unicode.GetBytes("input.txt")))); using (var sw = Console.Out) // using (var sw = new StreamWriter("output.txt")) { Solve(sr, sw); } } internal static void Solve(InputReader sr, TextWriter sw) { var param = sr.NextSplitLongs(); var studentCount = param[0]; var checkPointCount = param[1]; var studentPoints = new List<Tuple<int, int>>(); var checkPoints = new List<Tuple<int, int>>(); //学生の座標を取得 for (var i = 0; i < studentCount; ++i) { var position = sr.NextSplitInts(); studentPoints.Add(Tuple.Create(position[0], position[1])); } //チェックポイントの座標を取得 for (var i = 0; i < checkPointCount; ++i) { var position = sr.NextSplitInts(); checkPoints.Add(Tuple.Create(position[0], position[1])); } //マンハッタン座標の出力 for (var i = 0; i < studentCount; ++i) { var stdudentXPos = studentPoints[i].Item1; var stdudentYPos = studentPoints[i].Item2; var ans = int.MaxValue; for (var j = 0; j < checkPointCount; ++j) { var checkXPos = checkPoints[j].Item1; var checkYPos = checkPoints[j].Item2; var manhattan = Math.Abs(stdudentXPos - checkXPos) + Math.Abs(stdudentYPos - checkYPos); if (manhattan < ans) { ans = j + 1; } } sw.WriteLine(ans); } } internal class InputReader : IDisposable { private bool isDispose; private readonly TextReader sr; public InputReader(TextReader stream) { sr = stream; } public void Dispose() { // Dispose(true); GC.SuppressFinalize(this); } public string NextString() { var result = sr.ReadLine(); return result; } public int NextInt32() { return int.Parse(NextString()); } public long NextInt64() { return long.Parse(NextString()); } public string[] NextSplitStrings() { return NextString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } public int[] NextSplitInts() { return NextString() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); } public long[] NextSplitLongs() { return NextString() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(long.Parse) .ToArray(); } public T[] ReadArray<T>(Func<string, CultureInfo, T> func) { return NextSplitStrings() .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } // protected void Dispose(bool dispose) //{ // if (isDispose) return; // if (dispose) // { // sr.Close(); // } // isDispose = true; //} //~InputReader() //{ // Dispose(false); //} } } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace AtCoder { internal class Program { static void Main(string[] args) { var sr = new InputReader(Console.In); // var sr = new InputReader(new StreamReader(new // MemoryStream(Encoding.Unicode.GetBytes("input.txt")))); using (var sw = Console.Out) // using (var sw = new StreamWriter("output.txt")) { Solve(sr, sw); } } internal static void Solve(InputReader sr, TextWriter sw) { var param = sr.NextSplitLongs(); var studentCount = param[0]; var checkPointCount = param[1]; var studentPoints = new List<Tuple<int, int>>(); var checkPoints = new List<Tuple<int, int>>(); //学生の座標を取得 for (var i = 0; i < studentCount; ++i) { var position = sr.NextSplitInts(); studentPoints.Add(Tuple.Create(position[0], position[1])); } //チェックポイントの座標を取得 for (var i = 0; i < checkPointCount; ++i) { var position = sr.NextSplitInts(); checkPoints.Add(Tuple.Create(position[0], position[1])); } //マンハッタン座標の出力 for (var i = 0; i < studentCount; ++i) { var stdudentXPos = studentPoints[i].Item1; var stdudentYPos = studentPoints[i].Item2; var ans = 0; var minManhattan = int.MaxValue; for (var j = 0; j < checkPointCount; ++j) { var checkXPos = checkPoints[j].Item1; var checkYPos = checkPoints[j].Item2; var manhattan = Math.Abs(stdudentXPos - checkXPos) + Math.Abs(stdudentYPos - checkYPos); if (manhattan < minManhattan) { minManhattan = manhattan; ans = j + 1; } } sw.WriteLine(ans); } } internal class InputReader : IDisposable { private bool isDispose; private readonly TextReader sr; public InputReader(TextReader stream) { sr = stream; } public void Dispose() { // Dispose(true); GC.SuppressFinalize(this); } public string NextString() { var result = sr.ReadLine(); return result; } public int NextInt32() { return int.Parse(NextString()); } public long NextInt64() { return long.Parse(NextString()); } public string[] NextSplitStrings() { return NextString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } public int[] NextSplitInts() { return NextString() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); } public long[] NextSplitLongs() { return NextString() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(long.Parse) .ToArray(); } public T[] ReadArray<T>(Func<string, CultureInfo, T> func) { return NextSplitStrings() .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } // protected void Dispose(bool dispose) //{ // if (isDispose) return; // if (dispose) // { // sr.Close(); // } // isDispose = true; //} //~InputReader() //{ // Dispose(false); //} } } }
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
692
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { Question.Exec(); } } public static class Question { public static void Exec() { long n = long.Parse(Console.ReadLine()); long min = long.MaxValue; var ans = n.ToString().Length; if (ans < min) { min = ans; } if (n % 2 == 0) { for (long i = 2; i * i <= n; ++i) { if (n % i != 0) { continue; } var a = n / i; ans = Math.Max(i.ToString().Length, a.ToString().Length); if (ans < min) { min = ans; } } } Console.WriteLine($"{min}"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { Question.Exec(); } } public static class Question { public static void Exec() { long n = long.Parse(Console.ReadLine()); long min = n.ToString().Length; for (long i = 1; i * i <= n; ++i) { if (n % i != 0) { continue; } var a = n / i; var ans = Math.Max(i.ToString().Length, a.ToString().Length); if (ans < min) { min = ans; } } Console.WriteLine($"{min}"); Console.ReadKey(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
202
32
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class Program { public static void Main() { //入力 int n = int.Parse(Console.ReadLine()); //処理 int a = 0, b = 0; // 1/2乗を整数値で求める int m = (int)Pow(n, 0.5); // mから割り切れる数を探して、F(a,b)が最小となる組み合わせを探す for (int i = m; i > 0; i--) { if (n % i == 0) { a = i; b = n / a; break; } } //桁数を求める int ans = 0; while (b > 0) { b /= 10; ans++; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class Program { public static void Main() { //入力 long n = long.Parse(Console.ReadLine()); //処理 long a = 0, b = 0; // nの平方根を求める long m = (long)Sqrt(n); // mから割り切れる数を探して、F(a,b)が最小となる組み合わせを探す for (long i = m; i > 0; i--) { if (n % i == 0) { a = i; b = n / a; break; } } //桁数を求める int ans = 0; while (b > 0) { b /= 10; ans++; } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 200, 0, 212, 0, 74, 51, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 74, 51, 213, 63, 22], ["-", 0, 212, 0, 74, 51, 213, 3, 4, 0, 21], ["-", 0, 74, 51, 213, 3, 4, 0, 28, 0, 250], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
8
139
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_C.Lib_IO; using static Contest_C.Lib_Minifunc; public static class Contest_C { public static void Main() { checked{ long n; Lib_IO.rm(out n); int d = (int)Math.Sqrt(n); for (int i = d; i <= n; i++) { if(n%i==0){ wm(i.ToString().Length); return; } } } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public 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 を更新 [MethodImpl(256)] public 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 を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_C.Lib_IO; using static Contest_C.Lib_Minifunc; public static class Contest_C { public static void Main() { checked{ long n; Lib_IO.rm(out n); int d = Convert.ToInt32(Math.Sqrt(n)); for (int i = d; 1<=i; i--) { if(n%i==0){ wm((n/i).ToString().Length); return; } } } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public 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 を更新 [MethodImpl(256)] public 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 を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 287, 0, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 287, 0, 196, 0, 7, 15, 16, 31, 203], ["-", 0, 287, 0, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 287, 0, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 287, 0, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 287, 0, 196, 0, 7, 26, 223, 0, 68], ["+", 0, 214, 205, 213, 63, 214, 205, 23, 0, 24], ["+", 205, 213, 63, 214, 205, 23, 0, 16, 31, 22], ["+", 205, 213, 63, 214, 205, 23, 0, 16, 17, 85], ["+", 0, 214, 205, 213, 63, 214, 205, 23, 0, 25]]
8
2,936
16
using System; using System.Linq; using System.Collections.Generic; using static System.Math; namespace C { class Program { static void Main(string[] args) { Func<long, long, int> f = (x, y) => Max(x.ToString().Count(), y.ToString().Count()); var n = long.Parse(Console.ReadLine()); var sqrtN = Sqrt(n); var minF = int.MaxValue; // nが素数の場合、処理を中断 if (isPrime(n)) { Console.WriteLine(f(1, n.ToString().Count())); } else { for (int i = 1; i <= sqrtN; i++) { var a = i; if (n % a == 0) { var b = n / a; minF = Min(minF, f(a, b)); } } Console.WriteLine(minF); } } static bool isPrime(long x) { if (x < 2) return false; else if (x == 2) return true; else if (x % 2 == 0) return false; double sqrtX = Math.Sqrt(x); for (int i = 3; i < sqrtX; i += 2) { if (x % i == 0) { return false; } } return true; } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Math; namespace C { class Program { static void Main(string[] args) { Func<long, long, int> f = (x, y) => Max(x.ToString().Count(), y.ToString().Count()); var n = long.Parse(Console.ReadLine()); var sqrtN = Sqrt(n); var minF = int.MaxValue; // nが素数の場合、処理を中断 // if (isPrime(n)) // { // var a = n.ToString().Count(); // Console.WriteLine(f(1, n)); // } // else // { for (int i = 1; i <= sqrtN; i++) { var a = i; if (n % a == 0) { var b = n / a; minF = Min(minF, f(a, b)); } } Console.WriteLine(minF); // } } static bool isPrime(long x) { if (x < 2) return false; else if (x == 2) return true; else if (x % 2 == 0) return false; double sqrtX = Math.Sqrt(x); for (int i = 3; i < sqrtX; i += 2) { if (x % i == 0) { return false; } } return true; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 213, 63, 22], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
283
32
using System; using System.Collections.Generic; using System.Linq; namespace abc057 { class Program { static void Main(string[] args) { // var line1 = Console.ReadLine().Split(' ').Select(x => // int.Parse(x)).ToArray(); var N = long.Parse(Console.ReadLine()); var M = (int)Math.Sqrt(N); int ans = int.MaxValue; for (int i = 1; i < M; i++) { if (N % i != 0) continue; long temp = N / i; if (ans > F(temp, i)) { ans = F(temp, i); } } Console.WriteLine(ans); // Console.ReadKey(); } static int F(long a, long b) { var ans = Math.Max(a, b); return ans.ToString().Length; } } }
using System; using System.Collections.Generic; using System.Linq; namespace abc057 { class Program { static void Main(string[] args) { // var line1 = Console.ReadLine().Split(' ').Select(x => // int.Parse(x)).ToArray(); var N = long.Parse(Console.ReadLine()); int ans = int.MaxValue; for (int i = 1; i <= Math.Sqrt(N); i++) { if (N % i != 0) continue; long temp = N / i; if (ans > F(temp, i)) { ans = F(temp, i); } } Console.WriteLine(ans); // Console.ReadKey(); } static int F(long a, long b) { var ans = Math.Max(a, b); return ans.ToString().Length; } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 0, 131], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 74, 51, 213, 3, 4, 0, 24], ["-", 0, 74, 51, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 212, 0, 74, 51, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25]]
8
166
22
using System.Collections.Generic; using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var a = int.Parse(line[1]); var b = int.Parse(line[2]); line = Console.ReadLine().Trim().Split(' '); var w = Array.ConvertAll(line, long.Parse); var ret1 = (decimal)w.OrderByDescending(x => x).Take(a).Average(); Console.WriteLine("{0:0.000000}", ret1); var d = new Dictionary<long, int>(); for (int i = 0; i < n; i++) if (d.ContainsKey(w[i])) d[w[i]]++; else d[w[i]] = 1; var w2 = d.OrderByDescending(x => x.Key).Select(x => x.Value).ToArray(); var ret2 = getAns2(w2, a, b); Console.WriteLine(ret2); } public static long getAns2(int[] w, int a, int b) { var ret = 0L; var w0 = w[0]; if (a < w0) { var imax = Math.Max(b, w0); for (int i = a; i <= imax; i++) ret += Combi(w0, i); return ret; } else { var p = 0; while (true) { if (a - w[p] > 0) { a -= w[p]; p++; } else if (a - w[p] < 0) return Combi(w[p], a); else return 1; } } } public static long Combi(int n, int r) { if (n < 2 * r) r = n - r; var dp = new long[n + 1, r + 1]; for (int i = 0; i <= n; i++) for (int j = 0; j <= r; j++) if (i == j | j == 0) dp[i, j] = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= r; j++) dp[i, j] = dp[i - 1, j] + dp[i - 1, j - 1]; return dp[n, r]; } }
using System.Collections.Generic; using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var a = int.Parse(line[1]); var b = int.Parse(line[2]); line = Console.ReadLine().Trim().Split(' '); var w = Array.ConvertAll(line, long.Parse); var ret1 = (decimal)w.OrderByDescending(x => x).Take(a).Average(); Console.WriteLine("{0:0.000000}", ret1); var d = new Dictionary<long, int>(); for (int i = 0; i < n; i++) if (d.ContainsKey(w[i])) d[w[i]]++; else d[w[i]] = 1; var w2 = d.OrderByDescending(x => x.Key).Select(x => x.Value).ToArray(); var ret2 = getAns2(w2, a, b); Console.WriteLine(ret2); } public static long getAns2(int[] w, int a, int b) { var ret = 0L; var w0 = w[0]; if (a == w0) return 1; if (a < w0) { var imax = Math.Min(b, w0); for (int i = a; i <= imax; i++) ret += Combi(w0, i); return ret; } else { var aa = a; var p = 0; while (true) { if (aa - w[p] > 0) { aa -= w[p]; p++; } else if (aa - w[p] < 0) return Combi(w[p], aa); else return 1; } } } public static long Combi(int n, int r) { if (n < 2 * r) r = n - r; var dp = new long[n + 1, r + 1]; for (int i = 0; i <= n; i++) for (int j = 0; j <= r; j++) if (i == j | j == 0) dp[i, j] = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= r; j++) dp[i, j] = dp[i - 1, j] + dp[i - 1, j - 1]; return dp[n, r]; } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["-", 64, 37, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 37, 0, 213, 3, 4, 0, 28, 0, 22]]
8
555
24
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int itemCount = inpt[0]; int selMin = inpt[1]; int selMax = inpt[2]; decimal[] items = Reader.ReadLine() .Split(' ') .Select(a => decimal.Parse(a)) .OrderByDescending(a => a) .ToArray(); decimal avg = items.Take(selMin).Average(); decimal target = items[selMin - 1]; int selTargetMin = items.Take(selMin).Count(a => a == target); int targetCount = items.Count(a => a == target); int selTargetMax = Math.Min(selTargetMin + (selMax - selMin), targetCount); decimal ans = 0; for (int i = selTargetMin; i <= selTargetMax; i++) { ans += GetSelCount(0, targetCount, i); } Console.WriteLine(avg); Console.WriteLine(ans); } private long GetSelCount(int idx, int lastIndex, int remain) { if (remain == 0) { return 1; } if (idx >= lastIndex) { return 0; } if (!dic.ContainsKey(idx)) { dic.Add(idx, new Dictionary<int, long>()); } if (dic[idx].ContainsKey(remain)) { return dic[idx][remain]; } long ans = GetSelCount(idx + 1, lastIndex, remain - 1); ans += GetSelCount(idx + 1, lastIndex, remain); dic[idx].Add(remain, ans); return ans; } private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int, Dictionary<int, long>>(); public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 50 1 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int itemCount = inpt[0]; int selMin = inpt[1]; int selMax = inpt[2]; decimal[] items = Reader.ReadLine() .Split(' ') .Select(a => decimal.Parse(a)) .OrderByDescending(a => a) .ToArray(); decimal avg = items.Take(selMin).Average(); decimal target = items[selMin - 1]; int selTargetMin = items.Take(selMin).Count(a => a == target); int targetCount = items.Count(a => a == target); int selTargetMax = Math.Min(selTargetMin + (selMax - selMin), targetCount); if (avg != target) { selTargetMax = selTargetMin; } decimal ans = 0; for (int i = selTargetMin; i <= selTargetMax; i++) { ans += GetSelCount(0, targetCount, i); } Console.WriteLine(avg); Console.WriteLine(ans); } private long GetSelCount(int idx, int lastIndex, int remain) { if (remain == 0) { return 1; } if (idx >= lastIndex) { return 0; } if (!dic.ContainsKey(idx)) { dic.Add(idx, new Dictionary<int, long>()); } if (dic[idx].ContainsKey(remain)) { return dic[idx][remain]; } long ans = GetSelCount(idx + 1, lastIndex, remain - 1); ans += GetSelCount(idx + 1, lastIndex, remain); dic[idx].Add(remain, ans); return ans; } private Dictionary<int, Dictionary<int, long>> dic = new Dictionary<int, Dictionary<int, long>>(); public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 4 2 3 10 20 10 10 "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
8
536
14
using System; using System.Text; using System.Linq; using System.Collections; using System.Threading.Tasks; using System.Collections.Generic; using System.Runtime.InteropServices; using static System.Console; using static System.Math; namespace NotFounds { public class Program { public static void Main(string[] args) { new Program().Solve(); } public void Solve() { var cin = new MyInputStream(); var N = cin.ReadInt(); var A = cin.ReadInt(); var B = cin.ReadInt(); var v = new List<long>(); for (int i = 0; i < N; ++i) v.Add(cin.ReadLong()); var sorted = v.OrderBy(val => val).Reverse().ToList(); var maxAve = 0.0; var maxSum = 0.0; for (int i = 0; i < A; ++i) maxSum += sorted[i]; maxAve = maxSum / A; WriteLine(maxAve.ToString("F8")); var cnt = 0; var idx = 0; for (int i = 0; i < N; ++i) { if (sorted[i] == sorted[A - 1]) cnt++; else if (sorted[i] > sorted[A - 1]) idx++; } if (cnt >= A) { ulong sum = 0; for (int i = A; i <= B; ++i) sum += nCm((ulong)cnt, (ulong)i); WriteLine(sum.ToString("D")); } else WriteLine(nCm((ulong)cnt, (ulong)(A - idx)).ToString("D")); } public ulong nCm(ulong n, ulong m) { ulong r = 1; for (ulong d = 1; d <= m; ++d) { r *= n--; r /= d; } return r; } } public class MyInputStream { private char separator = ' '; private Queue<string> inputStream; public MyInputStream(char separator = ' ') { this.separator = separator; inputStream = new Queue<string>(); } public string Read() { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = Console.ReadLine().Split(separator); for (int i = 0; i < tmp.Length; i++) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } public string ReadLine() => Console.ReadLine(); public int ReadInt() => int.Parse(Read()); public long ReadLong() => long.Parse(Read()); public double ReadDouble() => double.Parse(Read()); } public class Pair<T1, T2> { public T1 First; public T2 Second; public Pair() { First = default(T1); Second = default(T2); } public Pair(T1 f, T2 s) { First = f; Second = s; } public override string ToString() { return "(" + First + ", " + Second + ")"; } public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); } public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) return true; else if (obj == null) return false; var tmp = obj as Pair<T1, T2>; return (object)tmp != null && First.Equals(tmp.First) && Second.Equals(tmp.Second); } } #region HashMap public class HashMap<K, V> : Dictionary<K, V> { public HashMap() : base() {} public HashMap(int cap) : base(cap) {} public HashMap(IDictionary<K, V> dictionary) : base(dictionary) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = default(V); } set { base[i] = value; } } } #endregion }
using System; using System.Text; using System.Linq; using System.Collections; using System.Threading.Tasks; using System.Collections.Generic; using System.Runtime.InteropServices; using static System.Console; using static System.Math; namespace NotFounds { public class Program { public static void Main(string[] args) { new Program().Solve(); } public void Solve() { var cin = new MyInputStream(); var N = cin.ReadInt(); var A = cin.ReadInt(); var B = cin.ReadInt(); var v = new List<long>(); for (int i = 0; i < N; ++i) v.Add(cin.ReadLong()); var sorted = v.OrderBy(val => val).Reverse().ToList(); var maxAve = 0.0; var maxSum = 0.0; for (int i = 0; i < A; ++i) maxSum += sorted[i]; maxAve = maxSum / A; WriteLine(maxAve.ToString("F8")); var cnt = 0; var idx = 0; for (int i = 0; i < N; ++i) { if (sorted[i] == sorted[A - 1]) cnt++; else if (sorted[i] > sorted[A - 1]) idx++; } if (sorted[0] == sorted[A - 1]) { ulong sum = 0; for (int i = A; i <= B; ++i) sum += nCm((ulong)cnt, (ulong)i); WriteLine(sum.ToString("D")); } else WriteLine(nCm((ulong)cnt, (ulong)(A - idx)).ToString("D")); } public ulong nCm(ulong n, ulong m) { ulong r = 1; for (ulong d = 1; d <= m; ++d) { r *= n--; r /= d; } return r; } } public class MyInputStream { private char separator = ' '; private Queue<string> inputStream; public MyInputStream(char separator = ' ') { this.separator = separator; inputStream = new Queue<string>(); } public string Read() { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = Console.ReadLine().Split(separator); for (int i = 0; i < tmp.Length; i++) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } public string ReadLine() => Console.ReadLine(); public int ReadInt() => int.Parse(Read()); public long ReadLong() => long.Parse(Read()); public double ReadDouble() => double.Parse(Read()); } public class Pair<T1, T2> { public T1 First; public T2 Second; public Pair() { First = default(T1); Second = default(T2); } public Pair(T1 f, T2 s) { First = f; Second = s; } public override string ToString() { return "(" + First + ", " + Second + ")"; } public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); } public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) return true; else if (obj == null) return false; var tmp = obj as Pair<T1, T2>; return (object)tmp != null && First.Equals(tmp.First) && Second.Equals(tmp.Second); } } #region HashMap public class HashMap<K, V> : Dictionary<K, V> { public HashMap() : base() {} public HashMap(int cap) : base(cap) {} public HashMap(IDictionary<K, V> dictionary) : base(dictionary) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = default(V); } set { base[i] = value; } } } #endregion }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73]]
8
877
12
using System; namespace ABC_056_A_Csharp_ver { class Program { static void Main(string[] args) { var word = Console.ReadLine().Split(' '); string a = Console.ReadLine(); string b = Console.ReadLine(); if (a == "H" && b == "H" || a == "D" && b == "D") { Console.WriteLine("H"); } else if (a == "D" || b == "D") { Console.WriteLine("D"); } Console.ReadKey(); } } }
using System; namespace ABC_056_A_Csharp_ver { class Program { static void Main(string[] args) { var word = Console.ReadLine().Split(' '); string a = (word[0]); string b = (word[1]); if (a == "H" && b == "H" || a == "D" && b == "D") { Console.WriteLine("H"); } else if (a == "D" || b == "D") { Console.WriteLine("D"); } Console.ReadKey(); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 23, 0, 204, 205, 22], ["+", 0, 212, 0, 23, 0, 204, 206, 207, 0, 70], ["+", 0, 23, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 23, 0, 204, 206, 207, 0, 73]]
8
125
14
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class MainClass { public static void Main(string[] args) { new MainClass().stream(); } IO io = new IO(); void stream() { solve(); io.writeFlush(); } int W, a, b; void solve() { W = io.nextInt(); a = io.nextInt(); b = io.nextInt(); int ans = Math.Max(0, b - (a + W)); io.write(ans); } class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public char nextChar() { return char.Parse(next()); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } public string[] array() { return Console.ReadLine().Split(' '); } public char[] arrayChar() { return Array.ConvertAll(array(), char.Parse); } public int[] arrayInt() { return Array.ConvertAll(array(), int.Parse); } public long[] arrayLong() { return Array.ConvertAll(array(), long.Parse); } public double[] arrayDouble() { return Array.ConvertAll(array(), double.Parse); } public void write<T>(T v) { Console.WriteLine(v); } public void write<T>(T[] v) { foreach (T n in v) Console.WriteLine(n); } public void writeFlush() { Console.Out.Flush(); } } class Mathf { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace AtCoder { class MainClass { public static void Main(string[] args) { new MainClass().stream(); } IO io = new IO(); void stream() { solve(); io.writeFlush(); } int W, a, b; void solve() { W = io.nextInt(); a = io.nextInt(); b = io.nextInt(); if (a > b) { int tmp = a; a = b; b = tmp; } int ans = Math.Max(0, b - (a + W)); io.write(ans); } class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public char nextChar() { return char.Parse(next()); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } public string[] array() { return Console.ReadLine().Split(' '); } public char[] arrayChar() { return Array.ConvertAll(array(), char.Parse); } public int[] arrayInt() { return Array.ConvertAll(array(), int.Parse); } public long[] arrayLong() { return Array.ConvertAll(array(), long.Parse); } public double[] arrayDouble() { return Array.ConvertAll(array(), double.Parse); } public void write<T>(T v) { Console.WriteLine(v); } public void write<T>(T[] v) { foreach (T n in v) Console.WriteLine(n); } public void writeFlush() { Console.Out.Flush(); } } class Mathf { public int mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; } public long C(long n, long r) { if (r == 0 || n == r) return 1; else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
819
21
using System; class myclass { public static void Main() { string str = Console.ReadLine(); string[] stArr = str.Split(' '); int w = int.Parse(stArr[0]), a = int.Parse(stArr[1]), b = int.Parse(stArr[2]); int ans; if (a + w >= b) ans = 0; else ans = b - (a + w); Console.WriteLine(ans); } }
using System; class myclass { public static void Main() { string str = Console.ReadLine(); string[] stArr = str.Split(' '); int w = int.Parse(stArr[0]), a = int.Parse(stArr[1]), b = int.Parse(stArr[2]); int ans; // Console.WriteLine("{0},{1},{2}", w, a, b); if (b + w < a) ans = a - (b + w); else if (a + w >= b) ans = 0; else ans = b - (a + w); Console.WriteLine(ans); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 64, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22]]
8
108
19
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; class Hello { public Hello() {} public static int Main() { new Hello().calc(); return 0; } Scanner cin; void calc() { int W = cin.nextInt(), a = cin.nextInt(), b = cin.nextInt(); Console.WriteLine(Math.Max(Math.Abs(a - b), 0)); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; class Program { public Program() {} public static int Main() { new Program().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int W = cin.nextInt(), a = cin.nextInt(), b = cin.nextInt(); Console.WriteLine(Math.Max(Math.Abs(a - b) - W, 0)); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); 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()); } }
[["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["-", 0, 208, 0, 235, 8, 201, 0, 263, 141, 22], ["+", 0, 208, 0, 235, 8, 201, 0, 263, 141, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 230, 39, 22], ["+", 0, 1, 0, 213, 63, 214, 205, 230, 39, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 230, 0, 228], ["+", 8, 196, 0, 1, 0, 11, 12, 230, 39, 22], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
274
15
using System; class P { static void Main(string[] _) { _ = Console.ReadLine().Split(' '); int w = int.Parse(_[0]); int a = int.Parse(_[1]); int b = int.Parse(_[2]); Console.WriteLine((Math.Max(a, b) - Math.Min(a, b)) - w); } }
using System; class P { static void Main(string[] _) { _ = Console.ReadLine().Split(' '); int w = int.Parse(_[0]); int a = int.Parse(_[1]); int b = int.Parse(_[2]); int result = (Math.Max(a, b) - Math.Min(a, b)) - w; Console.WriteLine(result > 0 ? result : 0); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
99
19
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCorder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var x = cin.ReadLong; var n = Ceiling(Sqrt(2 * x)); var step = n * (n + 1) / 2; if (x <= step) { WriteLine(n); } else { WriteLine(n + 1); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCorder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var x = cin.ReadLong; var n = (int)(Sqrt(2 * x) - 1); var step = n * (n + 1) / 2; if (x <= step) { WriteLine(n); return; } var IncStep = step; while (IncStep < x) { n++; IncStep = n * (n + 1) / 2; } WriteLine(n); } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["-", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
480
35
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int ans = 0; long jmp = 1; while (X > 0) { ans++; X -= jmp; jmp += ans; } Console.WriteLine(ans); } long X; public Sol() { X = rl(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { int i = 0; for (i = 1; X > 0; i++) { X -= i; } Console.WriteLine(i - 1); } long X; public Sol() { X = rl(); } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 11, 31, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
333
25
using System; class E { static void Main() => new J(); } class J { int F() => int.Parse(Console.ReadLine()); public J() { var X = F(); var t = (int)((Math.Sqrt(8.0 * X + 1) - 1) / 2) - 3; var s = t * (t + 1L) / 2; while (s < X) { t++; s += t; } Console.WriteLine(t); } }
using System; class E { static void Main() => new J(); } class J { int F() => int.Parse(Console.ReadLine()); public J() { var X = F(); var t = Math.Max(0, (int)((Math.Sqrt(8.0 * X + 1) - 1) / 2) - 3); var s = t * (t + 1L) / 2; while (s < X) { t++; s += t; } Console.WriteLine(t); } }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
113
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_A.Lib_IO; using static Contest_A.Lib_Minifunc; public static class Contest_A { public static void Main() { checked{ long n, c,k; Lib_IO.rm(out n, out c,out k); ll[] t; rl(n,out t); Array.Sort(t); long ans = 0; int bi = 0; for (int i = 0; i < n; i++) { if(i-bi+1==c){ ans++; bi = i+1; } if(bi<n&&t[bi]+k<t[i]){ ans++; bi = i; } } if(bi<n) ans++; Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public 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 を更新 [MethodImpl(256)] public 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 を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_A.Lib_IO; using static Contest_A.Lib_Minifunc; public static class Contest_A { public static void Main() { checked{ long n, c,k; Lib_IO.rm(out n, out c,out k); ll[] t; rl(n,out t); Array.Sort(t); long ans = 0; int bi = 0; for (int i = 0; i < n; i++) { if(i-bi+1==c){ if(bi<n&&t[bi]+k<t[i]){ ans++; bi = i; }else{ ans++; bi = i+1; } } if(bi<n&&t[bi]+k<t[i]){ ans++; bi = i; } } if(bi<n) ans++; Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public 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 を更新 [MethodImpl(256)] public 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 を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
3,004
30
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = l[0], C = l[1], K = l[2]; var T = new int[N]; for (var i = 0; i < N; i++) T[i] = int.Parse(Console.ReadLine()); Array.Sort(T); var humansCount = 0; var ridesCount = 0; var longest = T[0]; var current = 0; for (var i = 0; i < N; i++) { if (humansCount == C) { ridesCount++; humansCount = 0; } else if (T[i] - longest > K) { ridesCount++; humansCount = Math.Max(0, humansCount - C); longest = T[current + (C - humansCount)]; } humansCount++; } Console.WriteLine(humansCount > 0 ? ridesCount + 1 : ridesCount); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = l[0], C = l[1], K = l[2]; var T = new int[N]; for (var i = 0; i < N; i++) T[i] = int.Parse(Console.ReadLine()); Array.Sort(T); var humansCount = 0; var ridesCount = 0; var longest = 0; for (var i = 0; i < N; i++) { if (humansCount == C) { ridesCount++; longest += C; humansCount = 0; } else if (T[i] - T[longest] > K) { ridesCount++; longest += humansCount; humansCount = Math.Max(0, humansCount - C); } humansCount++; } Console.WriteLine(humansCount > 0 ? ridesCount + 1 : ridesCount); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 75, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 206, 207, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 22], ["-", 206, 207, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
8
241
32
using System; namespace AGC011 { class A { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int N = int.Parse(input[0]); int C = int.Parse(input[1]); int K = int.Parse(input[2]); int[] T = new int[N]; for (int i = 0; i < T.Length; i++) { T[i] = int.Parse(Console.ReadLine()); } Array.Sort(T); int busCount = 0; int passengerCount = 0; for (int i = 0; i < N; i++) { passengerCount++; if (i == N - 1 || T[i] + K < T[i + 1]) { while (0 < passengerCount) { passengerCount -= C; busCount++; } passengerCount = 0; } } Console.WriteLine(busCount); } } }
using System; namespace AGC011 { class A { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int N = int.Parse(input[0]); int C = int.Parse(input[1]); int K = int.Parse(input[2]); int[] T = new int[N]; for (int i = 0; i < T.Length; i++) { T[i] = int.Parse(Console.ReadLine()); } Array.Sort(T); int busCount = 0; int passengerCount = 0; int index = 0; for (int i = 0; i < N; i++) { passengerCount++; if (i == N - 1 || passengerCount == C || T[index] + K < T[i + 1]) { busCount++; index = i + 1; passengerCount = 0; } } Console.WriteLine(busCount); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 52, 0, 89], ["-", 8, 196, 0, 57, 64, 196, 0, 52, 0, 24], ["-", 0, 57, 64, 196, 0, 52, 15, 16, 31, 203], ["-", 0, 57, 64, 196, 0, 52, 15, 16, 17, 18], ["-", 0, 57, 64, 196, 0, 52, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 52, 0, 25], ["-", 0, 57, 64, 196, 0, 52, 8, 196, 0, 45], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 64, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 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, 52, 8, 196, 0, 46]]
8
207
29
using System; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var arr = ReadLib.ReadAsIntArray(); var n = arr[0]; var c = arr[1]; var k = arr[2]; var ts = ReadLib.ReadNTimesAsInt(n).OrderByDescending(i => i); var nBus = 0; var nCurrentCustomers = 0; var maxT = ts.First(); foreach (var t in ts) { var allowCurrentSubmit = t + k; if (maxT > allowCurrentSubmit || nCurrentCustomers > c) { nBus++; nCurrentCustomers = 0; maxT = t; } nCurrentCustomers++; } if (nCurrentCustomers > 0) { nBus += nCurrentCustomers / c + 1; } Console.WriteLine(nBus); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray() { return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine())) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray(); } }
using System; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var arr = ReadLib.ReadAsIntArray(); var n = arr[0]; var c = arr[1]; var k = arr[2]; var ts = ReadLib.ReadNTimesAsInt(n).OrderBy(i => i); var nBus = 0; var nCurrentCustomers = 0; var upLimitT = ts.First() + k; foreach (var t in ts) { if (t > upLimitT || nCurrentCustomers >= c) { nBus++; upLimitT = t + k; nCurrentCustomers = 0; } nCurrentCustomers++; } if (nCurrentCustomers > 0) { nBus++; } Console.WriteLine(nBus); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray() { return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine())) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray(); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 8, 196, 0, 210, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 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, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 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, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 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
415
9
using System; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var arr = ReadLib.ReadAsIntArray(); var n = arr[0]; var c = arr[1]; var k = arr[2]; var ts = ReadLib.ReadNTimesAsInt(n).OrderByDescending(i => i); var nBus = 0; var nCurrentCustomers = 0; var maxT = ts.First(); foreach (var t in ts) { var allowCurrentSubmit = t + k; if (maxT > allowCurrentSubmit || nCurrentCustomers > c) { nBus++; nCurrentCustomers = 0; maxT = t; } nCurrentCustomers++; } if (nCurrentCustomers > 0) { nBus += nCurrentCustomers / c + 1; } Console.WriteLine(nBus); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray() { return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine())) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray(); } }
using System; using System.Linq; #if !DEBUG using System.IO; #endif public class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var arr = ReadLib.ReadAsIntArray(); var n = arr[0]; var c = arr[1]; var k = arr[2]; var ts = ReadLib.ReadNTimesAsInt(n).OrderByDescending(i => i); var nBus = 0; var nCurrentCustomers = 0; var maxT = ts.First(); foreach (var t in ts) { var allowCurrentSubmit = t + k; if (maxT > allowCurrentSubmit || nCurrentCustomers >= c) { nBus++; nCurrentCustomers = 0; maxT = t; } nCurrentCustomers++; } if (nCurrentCustomers > 0) { nBus++; } Console.WriteLine(nBus); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray() { return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine())) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray(); } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 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
415
9
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { private const int INF = 1000000007; public static void Main() { long[] NCK = LongLine(); long N = NCK[0], C = NCK[1], K = NCK[2]; long[] Tn = new long[N]; for (int i = 0; i < N; i++) Tn[i] = LongRead(); Array.Sort(Tn); long limit = Tn[0] + K; int count = 1; int ans = 1; for (int i = 0; i < N; i++) { if (Tn[i] < limit) { if (count > C) { ans++; count = 1; limit = Tn[i] + K; } } else { ans++; count = 1; limit = Tn[i] + K; } // Console.WriteLine(Tn[i] + " " + ans); } Console.WriteLine(ans); } } public class Factorization { private static long N; public Factorization(long n) { N = n; } //最大公約数を返す public static long GCD(long a, long b) { if (a < b) return GCD(b, a); long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } //素数判定 public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; double root = Math.Sqrt(n); for (int i = 3; i <= root; i += 2) { if (n % i == 0) return false; } return true; } //試し割り private static int[] TryPrimes = new int[] { 2, 3, 5, 7, 11 }; public long TryAllocation(long p) { long count = 0; while (N % p == 0) { count++; N /= p; } return count; } private int[] xi = new int[] { 13, 17, 19, 23, 29 }; private long f(long x, int suffix) { return (xi[suffix % xi.Count()] * x + suffix) % N; } // nを分解 public long PollardsRho(long n, int suffix = 0) { //素数を渡すと失敗するらしい if (IsPrime(n)) return n; //もう素数 long x = 2, y = 2, d = 1; while (d == 1) { x = f(x, suffix); y = f(f(y, suffix), suffix); d = GCD(Math.Abs(x - y), n); } if (d == n) { // f(x)を変えて試す return PollardsRho(n, suffix + 1); } return d; } public IEnumerable<long> Calc() { //小さな素因数の計算 foreach (var prime in TryPrimes) { var box = TryAllocation(prime); for (int i = 0; i < box; i++) yield return prime; } //残りをRhoで解く while (true) { if (N == 1) break; var ret = PollardsRho(N); yield return ret; N /= ret; } } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string StrReverce(string s) { return new string(s.Reverse().ToArray()); } public static int IntRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } public static long[] LSRead() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static long Combination(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r + 1), r) .ToList() .Aggregate((now, next) => now * next) / Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next); } public static long Permutation(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r), r) .ToList() .Aggregate((now, next) => now * next); } public static long LongRead() { return long.Parse(Console.ReadLine()); } public static long[] LongLine() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { private const int INF = 1000000007; public static void Main() { long[] NCK = LongLine(); long N = NCK[0], C = NCK[1], K = NCK[2]; long[] Tn = new long[N]; for (int i = 0; i < N; i++) Tn[i] = LongRead(); Array.Sort(Tn); long limit = Tn[0] + K; int count = 1; int ans = 1; for (int i = 1; i < N; i++) { count++; if (Tn[i] > limit || count > C) { ans++; limit = Tn[i] + K; count = 1; } } Console.WriteLine(ans); } } public class Factorization { private static long N; public Factorization(long n) { N = n; } //最大公約数を返す public static long GCD(long a, long b) { if (a < b) return GCD(b, a); long r; while (b != 0) { r = a % b; a = b; b = r; } return a; } //素数判定 public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; double root = Math.Sqrt(n); for (int i = 3; i <= root; i += 2) { if (n % i == 0) return false; } return true; } //試し割り private static int[] TryPrimes = new int[] { 2, 3, 5, 7, 11 }; public long TryAllocation(long p) { long count = 0; while (N % p == 0) { count++; N /= p; } return count; } private int[] xi = new int[] { 13, 17, 19, 23, 29 }; private long f(long x, int suffix) { return (xi[suffix % xi.Count()] * x + suffix) % N; } // nを分解 public long PollardsRho(long n, int suffix = 0) { //素数を渡すと失敗するらしい if (IsPrime(n)) return n; //もう素数 long x = 2, y = 2, d = 1; while (d == 1) { x = f(x, suffix); y = f(f(y, suffix), suffix); d = GCD(Math.Abs(x - y), n); } if (d == n) { // f(x)を変えて試す return PollardsRho(n, suffix + 1); } return d; } public IEnumerable<long> Calc() { //小さな素因数の計算 foreach (var prime in TryPrimes) { var box = TryAllocation(prime); for (int i = 0; i < box; i++) yield return prime; } //残りをRhoで解く while (true) { if (N == 1) break; var ret = PollardsRho(N); yield return ret; N /= ret; } } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string StrReverce(string s) { return new string(s.Reverse().ToArray()); } public static int IntRead() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } public static long[] LSRead() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static long Combination(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r + 1), r) .ToList() .Aggregate((now, next) => now * next) / Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next); } public static long Permutation(int n, int r) { if (n == r) return 1; return Enumerable.Range((n - r), r) .ToList() .Aggregate((now, next) => now * next); } public static long LongRead() { return long.Parse(Console.ReadLine()); } public static long[] LongLine() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
1,146
32
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var c = int.Parse(line[1]); var k = int.Parse(line[2]); var a = new int[n]; for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim()); Array.Sort(a); var tcount = 0; var bcount = 1; var startmax = a[0] + k; for (int i = 1; i < n; i++) { if (bcount == 0) { bcount++; startmax = a[i] + k; } else { if (a[i] <= startmax && bcount + 1 == c) { tcount++; bcount = 0; } else if (a[i] <= startmax && bcount + 1 < c) bcount++; else if (a[i] > startmax) { tcount++; bcount = 1; startmax = a[i] + k; } } } if (bcount > 0) tcount++; Console.WriteLine(tcount); } }
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = long.Parse(line[0]); var c = long.Parse(line[1]); var k = long.Parse(line[2]); var a = new int[n]; for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim()); Array.Sort(a); var tcount = 0; var bcount = 1; var startmax = a[0] + k; for (int i = 1; i < n; i++) { if (bcount == 0) { bcount++; startmax = a[i] + k; } else { if (a[i] <= startmax && bcount + 1 == c) { tcount++; bcount = 0; } else if (a[i] <= startmax && bcount + 1 < c) bcount++; else { tcount++; bcount = 1; startmax = a[i] + k; } } } if (bcount > 0) tcount++; Console.WriteLine(tcount); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 75, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["-", 75, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["-", 75, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["-", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 17, 47], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["-", 75, 196, 0, 57, 75, 57, 75, 57, 0, 25]]
8
273
15