buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; int count = 0; int min = 0; var p = cin.ReadIntArray(n); for (int k = 0; k < n; k++) { if (min > p[k]) { min = p[k]; count++; } } WriteLine(count); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; int count = 0; int min = n + 1; var p = cin.ReadIntArray(n); for (int k = 0; k < n; k++) { if (min > p[k]) { min = p[k]; count++; } } WriteLine(count); } } 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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, 203]]
8
493
4
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var totalnum = cin.ReadInt; int min = cin.ReadInt; int cnt = 1; for (int i = 1; i < totalnum; i++) { int next = cin.ReadInt; if (next < min) cnt++; else min = next; } WriteLine(cnt.ToString()); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var totalnum = cin.ReadInt; int min = cin.ReadInt; int cnt = 1; for (int i = 1; i < totalnum; i++) { int next = cin.ReadInt; if (next < min) { cnt++; min = next; } } WriteLine(cnt.ToString()); } } 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, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
490
3
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Collections; using System.Linq.Expressions; using Pair = System.Tuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using static _20200213.Cin; using static _20200213.Util; namespace _20200213 { public class Program { public static void Main(string[] args) { // ABC085_D(); 45m // ARC066_C(); 17m // ABC003_C(); 15m // ABC016_C(); 18m // AGC034_B(); 50m ABC152_D(); } /// <summary> /// D - Handstand 2 /// </summary> public static void ABC152_D() { long N = rl; long[,] table = new long[10, 10]; for (int i = 0; i < N; i++) { int r = i % 10; int l = i; while (l >= 10) { l /= 10; } table[l, r]++; } long ans = 0; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { ans += table[i, j] * table[j, i]; } } Console.WriteLine(ans); } /// <summary> /// B - ABC /// </summary> public static void AGC034_B() { string S = rs; int N = S.Length; int r = 0; int bc = 0; long ans = 0; for (int l = 0; l < N - 2; l++) { if (S[l] == 'A') { if (r <= l) { bc = 0; r = l + 1; while (r < N - 1) { if (S[r] == 'A') { r++; } else if (S[r] == 'B' && S[r + 1] == 'C') { bc++; r += 2; } else { break; } } } ans += bc; } else if (S[l] == 'B' && S[l + 1] == 'C') { bc--; } } Console.WriteLine(ans); } /// <summary> /// C - 友達の友達 /// </summary> public static void ABC016_C() { long N = rl; long M = rl; Graph G = new Graph(); for (int i = 0; i < N; i++) { G.Add(new List<long>()); } for (int i = 0; i < M; i++) { long a = rl - 1; long b = rl - 1; G[(int)a].Add(b); G[(int)b].Add(a); G[(int)a].Add(a); G[(int)b].Add(b); } for (int i = 0; i < N; i++) { HashSet<long> hs = new HashSet<long>(); foreach (var friend in G[i]) { foreach (var ffriend in G[(int)friend]) { if (G[i].Contains(ffriend)) continue; hs.Add(ffriend); } } Console.WriteLine(hs.Count); } } /// <summary> /// C - AtCoderプログラミング講座 /// </summary> public static void ABC003_C() { long N = rl; long K = rl; long[] A = rla; Sort(A); double ans = 0; for (int i = (int)(N - K); i < N; i++) { ans = (ans + A[i]) / 2; } Console.WriteLine(ans); } /// <summary> /// C - Lining Up /// </summary> public static void ARC066_C() { long N = rl; long[] A = rla; bool even = N % 2 == 0; HashMap<long, long> hm = new HashMap<long, long>(); for (int i = 0; i < N / 2; i++) { hm[i * 2 + (even ? 1 : 2)] = 2; } if (N % 2 == 1) hm[0] = 1; for (int i = 0; i < N; i++) { if (!hm.ContainsKey(A[i])) { Console.WriteLine(0); return; } hm[A[i]]--; if (hm[A[i]] < 0) { Console.WriteLine(0); return; } } long ans = 1; for (int i = 0; i < N / 2; i++) { ChModMul(ref ans, 2); } Console.WriteLine(ans); } /// <summary> /// D - Katana Thrower /// </summary> public static void ABC085_D() { long N = rl; long H = rl; long[] A, B; ReadCols(out A, out B, N); SortDecend(B); long max = A.Max(); long count = 0; for (int i = 0; i < N; i++) { if (B[i] > max) { H -= B[i]; count++; if (H <= 0) { Console.WriteLine(count); return; } } else { break; } } count += (H + max - 1) / max; Console.WriteLine(count); } } public class HashMap<K, V> : Dictionary<K, V> { V i; static Func<V> j = Expression.Lambda<Func<V>>(Expression.New(typeof(V))).Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public static void DontAutoFlush() { var a = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static int ReadInt() { return int.Parse(k()); } public static long ReadLong() { return long.Parse(k()); } public static double ReadDouble() { return double.Parse(k()); } public static string ReadString() { return k(); } public static int[] ReadIntArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[][] ReadIntTable(int a) { i = null; int[][] b = new int [a][]; for (int c = 0; c < a; c++) b[c] = ReadIntArray(); return b; } public static long[][] ReadLongTable(long a) { i = null; long[][] b = new long [a][]; for (long c = 0; c < a; c++) b[c] = ReadLongArray(); return b; } static string[] i { get; set; } static int j { get; set; } static string k() { if (i == null || i.Length <= j) { i = Console.ReadLine().Split(' '); j = 0; } return i[j++]; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Collections; using System.Linq.Expressions; using Pair = System.Tuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using static _20200213.Cin; using static _20200213.Util; namespace _20200213 { public class Program { public static void Main(string[] args) { // ABC085_D(); 45m // ARC066_C(); 17m // ABC003_C(); 15m // ABC016_C(); 18m // AGC034_B(); 50m ABC152_D(); } /// <summary> /// D - Handstand 2 /// </summary> public static void ABC152_D() { long N = rl; long[,] table = new long[10, 10]; for (int i = 0; i <= N; i++) { int r = i % 10; int l = i; while (l >= 10) { l /= 10; } table[l, r]++; } long ans = 0; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { ans += table[i, j] * table[j, i]; } } Console.WriteLine(ans); } /// <summary> /// B - ABC /// </summary> public static void AGC034_B() { string S = rs; int N = S.Length; int r = 0; int bc = 0; long ans = 0; for (int l = 0; l < N - 2; l++) { if (S[l] == 'A') { if (r <= l) { bc = 0; r = l + 1; while (r < N - 1) { if (S[r] == 'A') { r++; } else if (S[r] == 'B' && S[r + 1] == 'C') { bc++; r += 2; } else { break; } } } ans += bc; } else if (S[l] == 'B' && S[l + 1] == 'C') { bc--; } } Console.WriteLine(ans); } /// <summary> /// C - 友達の友達 /// </summary> public static void ABC016_C() { long N = rl; long M = rl; Graph G = new Graph(); for (int i = 0; i < N; i++) { G.Add(new List<long>()); } for (int i = 0; i < M; i++) { long a = rl - 1; long b = rl - 1; G[(int)a].Add(b); G[(int)b].Add(a); G[(int)a].Add(a); G[(int)b].Add(b); } for (int i = 0; i < N; i++) { HashSet<long> hs = new HashSet<long>(); foreach (var friend in G[i]) { foreach (var ffriend in G[(int)friend]) { if (G[i].Contains(ffriend)) continue; hs.Add(ffriend); } } Console.WriteLine(hs.Count); } } /// <summary> /// C - AtCoderプログラミング講座 /// </summary> public static void ABC003_C() { long N = rl; long K = rl; long[] A = rla; Sort(A); double ans = 0; for (int i = (int)(N - K); i < N; i++) { ans = (ans + A[i]) / 2; } Console.WriteLine(ans); } /// <summary> /// C - Lining Up /// </summary> public static void ARC066_C() { long N = rl; long[] A = rla; bool even = N % 2 == 0; HashMap<long, long> hm = new HashMap<long, long>(); for (int i = 0; i < N / 2; i++) { hm[i * 2 + (even ? 1 : 2)] = 2; } if (N % 2 == 1) hm[0] = 1; for (int i = 0; i < N; i++) { if (!hm.ContainsKey(A[i])) { Console.WriteLine(0); return; } hm[A[i]]--; if (hm[A[i]] < 0) { Console.WriteLine(0); return; } } long ans = 1; for (int i = 0; i < N / 2; i++) { ChModMul(ref ans, 2); } Console.WriteLine(ans); } /// <summary> /// D - Katana Thrower /// </summary> public static void ABC085_D() { long N = rl; long H = rl; long[] A, B; ReadCols(out A, out B, N); SortDecend(B); long max = A.Max(); long count = 0; for (int i = 0; i < N; i++) { if (B[i] > max) { H -= B[i]; count++; if (H <= 0) { Console.WriteLine(count); return; } } else { break; } } count += (H + max - 1) / max; Console.WriteLine(count); } } public class HashMap<K, V> : Dictionary<K, V> { V i; static Func<V> j = Expression.Lambda<Func<V>>(Expression.New(typeof(V))).Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public static void DontAutoFlush() { var a = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static int ReadInt() { return int.Parse(k()); } public static long ReadLong() { return long.Parse(k()); } public static double ReadDouble() { return double.Parse(k()); } public static string ReadString() { return k(); } public static int[] ReadIntArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[][] ReadIntTable(int a) { i = null; int[][] b = new int [a][]; for (int c = 0; c < a; c++) b[c] = ReadIntArray(); return b; } public static long[][] ReadLongTable(long a) { i = null; long[][] b = new long [a][]; for (long c = 0; c < a; c++) b[c] = ReadLongArray(); return b; } static string[] i { get; set; } static int j { get; set; } static string k() { if (i == null || i.Length <= j) { i = Console.ReadLine().Split(' '); j = 0; } return i[j++]; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
2,572
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; namespace ABC152 { class Program { static void Main(string[] args) { START: // A(); 4m // B(); 8m(4m) // C(); 29m(21m) // D(); 98m(77m) D2(); #if DEBUG goto START; #endif } private static void D2() { long N = ReadInt(); int[,] table = new int[10, 10]; for (int i = 0; i < N; i++) { int top = i; while (top / 10 != 0) { top /= 10; } int bottom = i % 10; table[top, bottom]++; } long ans = 0; for (int a = 1; a <= 9; a++) { for (int b = 1; b <= 9; b++) { ans += table[a, b] * table[b, a]; } } WriteLine(ans); } private static void D() { int N = ReadInt(); long ans = 0; for (int i = 1; i <= N; i++) { if (i % 10 == 0) continue; int top = i; while (true) { if (top / 10 == 0) { break; } top /= 10; } int bottom = i % 10; int count = 1; int j = top; if (top != bottom) { count = 2; j = (i % 10) * 10 + top; } while (j <= N) { if (count <= 2) { ans++; } else { int tmp = (int)Pow(10, count - 2); ans += Math.Min(((N - j) / 10) + 1, tmp); } j = (int)Pow(10, count) * (i % 10) + top; count++; } } WriteLine(ans); } private static void C() { int N = ReadInt(); int[] P = ReadIntArray(); int ans = 1; int min = P[0]; for (int i = 1; i < N; i++) { if (P[i] < min) { ans++; min = P[i]; } } WriteLine(ans); } private static void B() { int A = ReadInt(); int B = ReadInt(); if (A <= B) { WriteLine(new String(A.ToString()[0], B)); } else { WriteLine(new String(B.ToString()[0], A)); } } private static void A() { int A = ReadInt(); int B = ReadInt(); if (A <= B) { WriteLine("Yes"); } else { WriteLine("No"); } } } } namespace Ha2ne2Util { public static class Cin { static string[] Tokens { get; set; } static int Ptr { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Ptr) { Tokens = Console.ReadLine().Split(' '); Ptr = 0; } return Tokens[Ptr++]; } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 逆順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] ReverseSort<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static void ModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static Ha2ne2Util.Cin; using static Ha2ne2Util.Util; using static System.Console; using static System.Math; using System.Collections; namespace ABC152 { class Program { static void Main(string[] args) { START: // A(); 4m // B(); 8m(4m) // C(); 29m(21m) // D(); 98m(77m) D2(); #if DEBUG goto START; #endif } private static void D2() { int N = ReadInt(); int[,] table = new int[10, 10]; for (int i = 0; i <= N; i++) { int top = i; while (top / 10 != 0) { top /= 10; } int bottom = i % 10; table[top, bottom]++; } long ans = 0; for (int a = 1; a <= 9; a++) { for (int b = 1; b <= 9; b++) { ans += table[a, b] * table[b, a]; } } WriteLine(ans); } private static void D() { int N = ReadInt(); long ans = 0; for (int i = 1; i <= N; i++) { if (i % 10 == 0) continue; int top = i; while (true) { if (top / 10 == 0) { break; } top /= 10; } int bottom = i % 10; int count = 1; int j = top; if (top != bottom) { count = 2; j = (i % 10) * 10 + top; } while (j <= N) { if (count <= 2) { ans++; } else { int tmp = (int)Pow(10, count - 2); ans += Math.Min(((N - j) / 10) + 1, tmp); } j = (int)Pow(10, count) * (i % 10) + top; count++; } } WriteLine(ans); } private static void C() { int N = ReadInt(); int[] P = ReadIntArray(); int ans = 1; int min = P[0]; for (int i = 1; i < N; i++) { if (P[i] < min) { ans++; min = P[i]; } } WriteLine(ans); } private static void B() { int A = ReadInt(); int B = ReadInt(); if (A <= B) { WriteLine(new String(A.ToString()[0], B)); } else { WriteLine(new String(B.ToString()[0], A)); } } private static void A() { int A = ReadInt(); int B = ReadInt(); if (A <= B) { WriteLine("Yes"); } else { WriteLine("No"); } } } } namespace Ha2ne2Util { public static class Cin { static string[] Tokens { get; set; } static int Ptr { get; set; } public static string Next() { if (Tokens == null || Tokens.Length <= Ptr) { Tokens = Console.ReadLine().Split(' '); Ptr = 0; } return Tokens[Ptr++]; } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static int[][] ReadIntTable(int n) { Tokens = null; int[][] ret = new int [n][]; for (int i = 0; i < n; i++) { ret[i] = ReadIntArray(); } return ret; } public static long[][] ReadLongTable(long n) { Tokens = null; long[][] ret = new long [n][]; for (long i = 0; i < n; i++) { ret[i] = ReadLongArray(); } return ret; } public static string ReadString() { return Next(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { Tokens = null; return Array.ConvertAll(Console.ReadLine().ToArray(), c => int.Parse(c.ToString())); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { Tokens = null; return Console.ReadLine().Select(c => c == '1').ToArray(); } } /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static IEnumerable<int> Range(int end) { for (int i = 0; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end) { for (int i = from; i < end; i++) { yield return i; } } public static IEnumerable<int> Range(int from, int end, int step) { for (int i = from; i < end; i += step) { yield return i; } } /// <summary> /// ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } /// <summary> /// 逆順ソートをして結果を返します。 /// 破壊的関数です。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] ReverseSort<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } /// <summary> /// Rubyにあるようなやつ /// ex) 5.Times(i => Console.WriteLine(i)); /// </summary> /// <param name="times"></param> /// <param name="action"></param> public static void Times(this int times, Action<int> action) { for (int i = 0; i < times; i++) { action(i); } } /// <summary> /// 引数aと引数bの値を入れ替えます /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } /// <summary> /// Console.WriteLineの自動フラッシュをしないようにする /// </summary> public static void DontAutoFlush() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } /// <summary> /// 先頭と末尾に要素を増やした新しい配列を返します。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="array"></param> /// <returns></returns> public static T[] AddHeadAndTail<T>(T[] array) { int len = array.Length; T[] res = new T[len + 2]; Array.Copy(array, 0, res, 1, len); return res; } /// <summary> /// 昇順ソート済みの配列を2分探索します。 /// 要素が見つからなかった場合はnより大きい数値の中で最小の数値のインデックスを返す。 /// </summary> /// <param name="array"></param> /// <param name="n"></param> /// <returns></returns> public static int BinarySearch(long[] array, long n) { int left = 0; int right = array.Length - 1; while (left <= right) { int mid = (right - left) / 2 + left; if (array[mid] == n) { return mid; } else if (n < array[mid]) { right = mid - 1; } else { left = mid + 1; } } return left; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static int[] GetDivisor(int n) { double sqrt = Math.Sqrt(n); List<int> divisor = new List<int>(); for (int i = 1; i <= sqrt; i++) { if (n % i == 0) { divisor.Add(i); int tmp = n / i; if (tmp != i) { divisor.Add(tmp); } } } return Sort(divisor.ToArray()); } public static int[] LongToBinaryArray(long n) { List<int> lst = new List<int>(); while (n > 0) { int amari = (int)(n % 2); lst.Add(amari); n /= 2; } return lst.ToArray(); } public static long BinaryArrayToLong(int[] binaryArray) { long result = 0; long b = 1; int len = binaryArray.Length; for (int i = 0; i < len; i++) { result += binaryArray[i] * b; b *= 2; } return result; } public static void Deconstruct<T>(this T[] items, out T t0) { t0 = items.Length > 0 ? items[0] : default(T); } public static void Deconstruct<T>(this T[] items, out T t0, out T t1) { if (items.Length < 2) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2) { if (items.Length < 3) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; } public static void Deconstruct<T>(this T[] items, out T t0, out T t1, out T t2, out T t3) { if (items.Length < 4) throw new ArgumentException(); t0 = items[0]; t1 = items[1]; t2 = items[2]; t3 = items[3]; } public static void ArrayInitialize<T>(T[,] array, T value) { int len0 = array.GetLength(0); int len1 = array.GetLength(1); for (int i = 0; i < len0; i++) { for (int j = 0; j < len1; j++) { array[i, j] = value; } } } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public readonly static int MOD = 1000000007; public static void ModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long minValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (n < minValue) { min = x; } } return min; } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> conv) { T min = source.First(); long maxValue = conv(min); foreach (T x in source.Skip(1)) { long n = conv(x); if (maxValue < n) { min = x; } } return min; } } /// <summary> /// HashSetにTupleを入れた時の、等値性判定方法の指定に使います。 /// HashSetのコンストラクタに渡して使います。 /// EqualsとGetHashCodeを提供します。 /// </summary> /// <typeparam name="T"></typeparam> public class EqualityComparer<T> : IEqualityComparer<T> { private Func<T, T, bool> _equals; private Func<T, int> _getHashCode; public EqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode) { _equals = equals; _getHashCode = getHashCode; } public bool Equals(T x, T y) { return _equals(x, y); } public int GetHashCode(T obj) { return _getHashCode(obj); } } /// <summary> /// UnionFindTree /// </summary> public class UnionFindTree { int[] Node; public UnionFindTree(int N) { Node = new int[N]; for (int i = 0; i < N; i++) { Node[i] = -1; } } public bool IsSameGroup(int x, int y) { return GetRoot(x) == GetRoot(y); } public bool Merge(int x, int y) { int xr = GetRoot(x); int yr = GetRoot(y); if (xr == yr) return false; // xが、大きなグループを示すようにSwapする(値が小さい方が大きなグループ) if (Node[xr] > Node[yr]) Swap(ref xr, ref yr); // グループの数を合算する Node[xr] += Node[yr]; // 根を張り替える Node[yr] = xr; return true; } public int Size(int x) { return -Node[GetRoot(x)]; } public int GetRoot(int n) { if (Node[n] < 0) { return n; } else { // 根を張りなおす。 Node[n] = GetRoot(Node[n]); return Node[n]; } } } /// <summary> /// PriorityQueue /// </summary> /// <typeparam name="T"></typeparam> public class PriorityQueue<T> { private Comparison<T> _comparison = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } public PriorityQueue(int maxSize, Comparison<T> comparison) { _heap = new T[maxSize]; _comparison = comparison; } private int Compare(T x, T y) { return _comparison(x, y); // if (_comparison != null) return _comparison(x, y); // return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
3,202
4
using System; using System.Collections; using System.Collections.Generic; using System.IO; namespace AtCoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[,] tmp = new int[10, 10]; for (int i = 1; i < N; i++) { int first, last; if (i > 99999) first = i / 100000; else if (i > 9999) first = i / 10000; else if (i > 999) first = i / 1000; else if (i > 99) first = i / 100; else if (i > 9) first = i / 10; else first = i; last = i % 10; tmp[first, last]++; } long ans = 0; for (int i = 1; i < N; i++) { int first, last; if (i > 99999) first = i / 100000; else if (i > 9999) first = i / 10000; else if (i > 999) first = i / 1000; else if (i > 99) first = i / 100; else if (i > 9) first = i / 10; else first = i; last = i % 10; ans += tmp[last, first]; } Console.WriteLine(ans); Console.ReadLine(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; namespace AtCoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[,] tmp = new int[10, 10]; for (int i = 1; i <= N; i++) { int first, last; if (i > 99999) first = i / 100000; else if (i > 9999) first = i / 10000; else if (i > 999) first = i / 1000; else if (i > 99) first = i / 100; else if (i > 9) first = i / 10; else first = i; last = i % 10; tmp[first, last]++; } long ans = 0; for (int i = 1; i <= N; i++) { int first, last; if (i > 99999) first = i / 100000; else if (i > 9999) first = i / 10000; else if (i > 999) first = i / 1000; else if (i > 99) first = i / 100; else if (i > 9) first = i / 10; else first = i; last = i % 10; ans += tmp[last, first]; } Console.WriteLine(ans); Console.ReadLine(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
294
4
using System; using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; using static program.Input; using static program.MyMath; using static System.Console; namespace program { class Program { static string alp = "abcdefghijklmnopqrstuvwxyz"; static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static long MOD = 1000000007; static void Main() { var n = ScanInt(); int res = 0; int[,] c = new int[10, 10]; for (int i = 1; i < n; i++) { c[i.Top(), i % 10]++; } for (int h = 1; h < 10; h++) for (int l = 1; l < 10; l++) res += c[l, h] * c[h, l]; WriteLine(res); } static int count(int l, int h, int n) { int r = 0; for (int i = 1; i <= n; i++) { WriteLine($"{i.Top()} {i}"); if (i.Top() == h && i % 10 == l) r++; } return r; } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(); } static public string RegaxReplace(this string arg1, string pattern, string replacement) { return Regex.Replace(arg1, pattern, replacement); } static public int Digit(this int n, int d) { if (d < 0) return 0; return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d); } static public int Length(this int n) { if (n < 0) return 0; return (int)Math.Log10(n) + 1; } static public int Top(this int n) { return n.Digit(n.Length() - 1); } } static class MyMath { public static bool isPrime(this int p) { if (p <= 1) return false; for (int i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static bool isPrime(this long p) { if (p <= 1) return false; for (long i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static long GCD(long a, long b) { Func<long, long, long> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) { if (b == 0) { x = 1; y = 0; return a; } var d = extGCD(b, a % b, ref y, ref x); y -= a / b * x; return d; } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long Inv(this long a, long m = 1000000007) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } private static void swap(ref long a, ref long b) { var t = a; a = b; b = t; } } }
using System; using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; using static program.Input; using static program.MyMath; using static System.Console; namespace program { class Program { static string alp = "abcdefghijklmnopqrstuvwxyz"; static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static long MOD = 1000000007; static void Main() { var n = ScanInt(); int res = 0; int[,] c = new int[10, 10]; for (int i = 1; i <= n; i++) { c[i.Top(), i % 10]++; } for (int h = 1; h < 10; h++) for (int l = 1; l < 10; l++) res += c[l, h] * c[h, l]; WriteLine(res); } static int count(int l, int h, int n) { int r = 0; for (int i = 1; i <= n; i++) { WriteLine($"{i.Top()} {i}"); if (i.Top() == h && i % 10 == l) r++; } return r; } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(); } static public string RegaxReplace(this string arg1, string pattern, string replacement) { return Regex.Replace(arg1, pattern, replacement); } static public int Digit(this int n, int d) { if (d < 0) return 0; return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d); } static public int Length(this int n) { if (n < 0) return 0; return (int)Math.Log10(n) + 1; } static public int Top(this int n) { return n.Digit(n.Length() - 1); } } static class MyMath { public static bool isPrime(this int p) { if (p <= 1) return false; for (int i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static bool isPrime(this long p) { if (p <= 1) return false; for (long i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static long GCD(long a, long b) { Func<long, long, long> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) { if (b == 0) { x = 1; y = 0; return a; } var d = extGCD(b, a % b, ref y, ref x); y -= a / b * x; return d; } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long Inv(this long a, long m = 1000000007) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } private static void swap(ref long a, ref long b) { var t = a; a = b; b = t; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
1,199
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionD { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long n = long.Parse(Console.ReadLine()); long result = 0; if (n < 10) { result = n; } else { for (long i = 0; i < n; i++) { result += Count(i); } } Console.WriteLine(result); Console.Out.Flush(); } public static long Count(long n) { string str = n.ToString(); if (str.EndsWith("0")) { return 0; // 0で終わっている数は、解がゼロ } long result = 0; // 左側がn (a...z) の場合、右側は(z...a)になる if (str[0] == str[str.Length - 1]) { //最初と最後が同じ場合、その数字1桁のものがOKになる result = 1; } for (int i = 2; i < str.Length; i++) // nと桁数と同じ場合、途中からnを超える場合があるので、別で計算 { // i桁の場合を数える (10^桁数-2) result += (long)Math.Pow(10, i - 2); } //右側の個数は、10^桁数-2 //ただし、nを超えてしまうとアウトなので、その検出 long max = long.Parse( str[str.Length - 1].ToString().PadRight(str.Length - 1, '9') + str[0]); //最大の値 long min = long.Parse( str[str.Length - 1].ToString().PadRight(str.Length - 1, '0') + str[0]); //最大の値 if (n < min) { } else if (max <= n) { result += (long)Math.Pow(10, str.Length - 2); } else { long diff = long.Parse(str.Substring(1, str.Length - 2)); result += diff + 1; } //左右入れ替えたパターンを含めるので、二倍にする result *= 2; //入れ替えられないパターンを除外 if (str[0] == str[str.Length - 1]) { result--; } // Console.WriteLine(n + " : " + result); return result; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionD { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数の入力 long n = long.Parse(Console.ReadLine()); long result = 0; if (n < 10) { result = n; } else { for (long i = 0; i <= n; i++) { result += Count(i); } } Console.WriteLine(result); Console.Out.Flush(); } public static long Count(long n) { string str = n.ToString(); if (str.EndsWith("0")) { return 0; // 0で終わっている数は、解がゼロ } long result = 0; // 左側がn (a...z) の場合、右側は(z...a)になる if (str[0] == str[str.Length - 1]) { //最初と最後が同じ場合、その数字1桁のものがOKになる result = 1; } for (int i = 2; i < str.Length; i++) // nと桁数と同じ場合、途中からnを超える場合があるので、別で計算 { // i桁の場合を数える (10^桁数-2) result += (long)Math.Pow(10, i - 2); } //右側の個数は、10^桁数-2 //ただし、nを超えてしまうとアウトなので、その検出 long max = long.Parse( str[str.Length - 1].ToString().PadRight(str.Length - 1, '9') + str[0]); //最大の値 long min = long.Parse( str[str.Length - 1].ToString().PadRight(str.Length - 1, '0') + str[0]); //最大の値 if (n < min) { } else if (max <= n) { result += (long)Math.Pow(10, str.Length - 2); } else { long diff = long.Parse(str.Substring(1, str.Length - 2)); result += diff + 1; } //左右入れ替えたパターンを含めるので、二倍にする result *= 2; //入れ替えられないパターンを除外 if (str[0] == str[str.Length - 1]) { result--; } // Console.WriteLine(n + " : " + result); return result; } } }
[["-", 0, 57, 75, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 17, 19]]
8
430
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] res = new int[100]; for (int i = 0; i < N; i++) { int A = i.ToString()[0] - '0'; int B = i % 10; res[A * 10 + B]++; } long ans = 0; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { ans += res[i * 10 + j] * res[j * 10 + i]; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] res = new int[100]; for (int i = 0; i <= N; i++) { int A = i.ToString()[0] - '0'; int B = i % 10; res[A * 10 + B]++; } long ans = 0; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { ans += res[i * 10 + j] * res[j * 10 + i]; } } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
184
2
using System; using System.Collections.Generic; public class Program { private int N; private List<E>[] Edges; private int M; private int[] U, V; private long[] F; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); Edges = new List<E>[N]; for (int i = 0; i < N; i++) { Edges[i] = new List<E>(); } for (int i = 0; i < N - 1; i++) { int a = sc.NextInt() - 1; int b = sc.NextInt() - 1; Edges[a].Add(new E(a, b, i)); Edges[b].Add(new E(b, a, i)); } M = sc.NextInt(); U = new int[M]; V = new int[M]; for (int i = 0; i < M; i++) { U[i] = sc.NextInt() - 1; V[i] = sc.NextInt() - 1; } // U-Vのパス 辺 jが含まれるならtrue F = new long[M]; for (int i = 0; i < M; i++) { Search(U[i], -1, i); } int l = 1 << M; long ans = 0; for (int i = 0; i < l; i++) { // 1 条件を満たさない // 0 条件を満たしても良い long f = 0; int cnt = 0; for (int j = 0; j < M; j++) { if (C(i, j)) { f |= F[j]; cnt++; } } // どっちもつかっていいやつの個数 int c = 0; for (int j = 0; j < N - 1; j++) { if (!C(f, j)) { c++; } } if (cnt % 2 == 0) { ans += 1L << c; } else { ans -= 1L << c; } } Console.WriteLine(ans); } private bool C(long mask, int i) { return (mask & (1L << i)) > 0; } private bool Search(int i, int parent, int index) { if (i == V[index]) return true; foreach (E e in Edges[i]) { if (e.B == parent) continue; if (Search(e.B, i, index)) { F[index] |= 1 << e.Index; return true; } } return false; } public static void Main(string[] args) { new Program().Solve(); } } struct E { public int A, B, Index; public E(int a, int b, int i) { A = a; B = b; Index = i; } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; using System.Collections.Generic; public class Program { private int N; private List<E>[] Edges; private int M; private int[] U, V; private long[] F; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); Edges = new List<E>[N]; for (int i = 0; i < N; i++) { Edges[i] = new List<E>(); } for (int i = 0; i < N - 1; i++) { int a = sc.NextInt() - 1; int b = sc.NextInt() - 1; Edges[a].Add(new E(a, b, i)); Edges[b].Add(new E(b, a, i)); } M = sc.NextInt(); U = new int[M]; V = new int[M]; for (int i = 0; i < M; i++) { U[i] = sc.NextInt() - 1; V[i] = sc.NextInt() - 1; } // U-Vのパス 辺 jが含まれるならtrue F = new long[M]; for (int i = 0; i < M; i++) { Search(U[i], -1, i); } int l = 1 << M; long ans = 0; for (long i = 0; i < l; i++) { // 1 条件を満たさない (パスの辺は全部白) // 0 条件を満たしても良い long f = 0; int cnt = 0; for (int j = 0; j < M; j++) { if (C(i, j)) { f |= F[j]; cnt++; } } // どっちもつかっていいやつの個数 int c = 0; for (int j = 0; j < N - 1; j++) { if (!C(f, j)) { c++; } } if (cnt % 2 == 0) { ans += 1L << c; } else { ans -= 1L << c; } } Console.WriteLine(ans); } private bool C(long mask, int i) { return (mask & (1L << i)) > 0; } private bool Search(int i, int parent, int index) { if (i == V[index]) return true; foreach (E e in Edges[i]) { if (e.B == parent) continue; if (Search(e.B, i, index)) { F[index] |= 1L << e.Index; return true; } } return false; } public static void Main(string[] args) { new Program().Solve(); } } struct E { public int A, B, Index; public E(int a, int b, int i) { A = a; B = b; Index = i; } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 203]]
8
1,019
4
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static List<Tuple<int, int>>[] li; static bool[] b; static int[] hn; static void Main() { Sc sc = new Sc(); var s = sc.Ia; int n = s[0], m = n - 1; li = new List<Tuple<int, int>>[n + 1]; var c = new long[n + 1]; hn = new int[n]; for (int i = 1; i <= n; i++) { li[i] = new List<Tuple<int, int>>(); c[i] = long.MaxValue; } for (int i = 0; i < m; i++) { var e = sc.Ia; li[e[0]].Add(Tuple.Create(e[1], i)); li[e[1]].Add(Tuple.Create(e[0], i)); } int q = sc.I; for (int i = 0; i < q; i++) { var e = sc.Ia; b = new bool[n + 1]; Fu(e[0], e[1], i); } long ans = 1 << (n - 1); int r = 1 << q; for (int i = 1; i < r; i++) { int d = bits(i) & 1, p = 0; for (int j = 0; j < m; j++) { if ((hn[j] & i) != 0) { p++; } } if (d == 0) { ans += 1 << (n - p - 1); } else { ans -= 1 << (n - p - 1); } } Console.WriteLine("{0}", ans); } static int bits(long bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (int)((bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff)); } static bool Fu(int a, int g, int m) { b[a] = true; var bo = false; if (a == g) { bo = true; } for (int i = 0; i < li[a].Count && !bo; i++) { if (!b[li[a][i].Item1]) { bo = Fu(li[a][i].Item1, g, m); if (bo) { hn[li[a][i].Item2] |= 1 << m; } } } return bo; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static List<Tuple<int, int>>[] li; static bool[] b; static int[] hn; static void Main() { Sc sc = new Sc(); var s = sc.Ia; int n = s[0], m = n - 1; li = new List<Tuple<int, int>>[n + 1]; var c = new long[n + 1]; hn = new int[n]; for (int i = 1; i <= n; i++) { li[i] = new List<Tuple<int, int>>(); c[i] = long.MaxValue; } for (int i = 0; i < m; i++) { var e = sc.Ia; li[e[0]].Add(Tuple.Create(e[1], i)); li[e[1]].Add(Tuple.Create(e[0], i)); } int q = sc.I; for (int i = 0; i < q; i++) { var e = sc.Ia; b = new bool[n + 1]; Fu(e[0], e[1], i); } long ans = 1L << (n - 1); int r = 1 << q; for (int i = 1; i < r; i++) { int d = bits(i) & 1, p = 0; for (int j = 0; j < m; j++) { if ((hn[j] & i) != 0) { p++; } } if (d == 0) { ans += 1L << (n - p - 1); } else { ans -= 1L << (n - p - 1); } } Console.WriteLine("{0}", ans); } static int bits(long bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (int)((bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff)); } static bool Fu(int a, int g, int m) { b[a] = true; var bo = false; if (a == g) { bo = true; } for (int i = 0; i < li[a].Count && !bo; i++) { if (!b[li[a][i].Item1]) { bo = Fu(li[a][i].Item1, g, m); if (bo) { hn[li[a][i].Item2] |= 1 << m; } } } return bo; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 203]]
8
1,473
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long h = sc.NextLong(); long w = sc.NextLong(); long n = sc.NextLong(); long answer = (n + (Math.Max(h, w) - 1) / (Math.Max(h, w) - 1)); Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long h = sc.NextLong(); long w = sc.NextLong(); long n = sc.NextLong(); long answer = (n + Math.Max(h, w) - 1) / Math.Max(h, w); Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 23, 0, 16, 12, 16, 31, 23, 0, 24], ["-", 0, 23, 0, 16, 12, 16, 12, 23, 0, 24], ["-", 12, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 16, 12, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 23, 0, 16, 12, 16, 12, 23, 0, 25]]
8
401
6
using static System.Math; using System; public class Hello { public static void Main() { var h = int.Parse(Console.ReadLine().Trim()); var w = int.Parse(Console.ReadLine().Trim()); var n = int.Parse(Console.ReadLine().Trim()); var a = Max(h, w); Console.WriteLine((n + a - 1) / n); } }
using static System.Math; using System; public class Hello { public static void Main() { var h = int.Parse(Console.ReadLine().Trim()); var w = int.Parse(Console.ReadLine().Trim()); var n = int.Parse(Console.ReadLine().Trim()); var a = Max(h, w); Console.WriteLine((n + a - 1) / a); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
101
2
using System; class Painting { static void Main(string[] args) { int h = int.Parse(System.Console.ReadLine()); int w = int.Parse(System.Console.ReadLine()); int n = int.Parse(System.Console.ReadLine()); int rtn = 0; int wk = 0; while (wk < n) { if (h < w) { wk = wk + w; h--; } else { wk = wk + h; w--; } } System.Console.WriteLine(rtn.ToString()); } }
using System; class Painting { static void Main(string[] args) { int h = int.Parse(System.Console.ReadLine()); int w = int.Parse(System.Console.ReadLine()); int n = int.Parse(System.Console.ReadLine()); int rtn = 0; int wk = 0; while (wk < n) { if (h < w) { wk = wk + w; h--; } else { wk = wk + h; w--; } rtn++; } System.Console.WriteLine(rtn.ToString()); } }
[["+", 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]]
8
126
3
using System; class Program { static void Main() { int h = int.Parse(Console.ReadLine()); int w = int.Parse(Console.ReadLine()); int p = int.Parse(Console.ReadLine()); Console.WriteLine(Math.Round(p / (double)Math.Max(h, w))); } }
using System; class Program { static void Main() { int h = int.Parse(Console.ReadLine()); int w = int.Parse(Console.ReadLine()); int p = int.Parse(Console.ReadLine()); Console.WriteLine(Math.Ceiling(p / (double)Math.Max(h, w))); } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
8
80
2
using System; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); foreach (var a in A) { if (a % 2 == 0) { if (a % 3 != 0 && a % 5 != 0) { Console.WriteLine("DINIED"); return; } } } Console.WriteLine("APPROVED"); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); foreach (var a in A) { if (a % 2 == 0) { if (a % 3 != 0 && a % 5 != 0) { Console.WriteLine("DENIED"); return; } } } Console.WriteLine("APPROVED"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
121
2
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { bool flag = true; int N = int.Parse(Console.ReadLine()); string[] temp = Console.ReadLine().Split(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(temp[i]); if (A[i] % 2 == 0) { if (A[i] % 3 != 0 || A[i] % 5 != 0) { flag = false; } } } Array.Sort(A); if (flag) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { bool flag = true; int N = int.Parse(Console.ReadLine()); string[] temp = Console.ReadLine().Split(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(temp[i]); if (A[i] % 2 == 0) { if (A[i] % 3 == 0 || A[i] % 5 == 0) { } else { flag = false; } } } Array.Sort(A); if (flag) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } }
[["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95]]
8
176
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp13 { class Program { static void Main(string[] args) { int ass = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); bool iuu = true; for (int i = 0; i < ass; i++) { if (int.Parse(str[i]) % 2 == 0) { if (int.Parse(str[i]) % 3 == 0 || int.Parse(str[i]) % 5 == 0) { iuu = true; } else { iuu = false; break; } } if (iuu) { break; } } if (iuu) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp13 { class Program { static void Main(string[] args) { int ass = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); bool iuu = true; for (int i = 0; i < ass; i++) { if (int.Parse(str[i]) % 2 == 0) { if (int.Parse(str[i]) % 3 == 0 || int.Parse(str[i]) % 5 == 0) { iuu = true; } else { iuu = false; break; } } if (!iuu) { break; } } if (iuu) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 111]]
8
197
1
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Sample { class Sample { static void Main() { var list = new List<int>(); int number = int.Parse(Console.ReadLine()); var p = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int count = 0; int count1 = 0; foreach (int n in p) { if (n % 2 == 0) { list.Add(n); } } foreach (int z in list) { count1++; if (z % 3 == 0 || z % 5 == 0) count++; } if (count == count1) { Console.Write("APPRPVED"); } else { Console.Write("DENIED"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Sample { class Sample { static void Main() { var list = new List<int>(); int number = int.Parse(Console.ReadLine()); var p = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int count = 0; int count1 = 0; foreach (int n in p) { if (n % 2 == 0) { list.Add(n); } } foreach (int z in list) { count1++; if (z % 3 == 0 || z % 5 == 0) count++; } if (count == count1) { Console.Write("APPROVED"); } else { Console.Write("DENIED"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
179
2
using System; using System.Linq; class Program { public static void Main() { int n = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); bool flag = false; for (int i = 0; i < n; i++) { if (input[i] % 2 == 0) { if (input[i] % 3 != 0 && n % 5 != 0) { flag = true; } } } if (!flag) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } }
using System; using System.Linq; class Program { public static void Main() { int n = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); bool flag = false; for (int i = 0; i < n; i++) { if (input[i] % 2 == 0) { if (input[i] % 3 != 0 && input[i] % 5 != 0) { flag = true; } } } if (!flag) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } }
[["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 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]]
8
153
5
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Numerics; namespace abc155 { class Program { static void Main(string[] args) { if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc155B(); } public static void solve_abc155B() { int n = Convert.ToInt32(Console.ReadLine()); int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); bool ok = true; for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) { if (a[i] % 3 != 0 && a[i] % 5 != 0) { ok = false; } break; } } if (ok) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } public static void solve_abc155A() { int[] abc = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); if ((abc[0] == abc[1] && abc[2] != abc[0]) || (abc[0] == abc[2] && abc[1] != abc[0]) || (abc[1] == abc[2] && abc[0] != abc[1])) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Numerics; namespace abc155 { class Program { static void Main(string[] args) { if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc155B(); } public static void solve_abc155B() { int n = Convert.ToInt32(Console.ReadLine()); int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); bool ok = true; for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) { if (a[i] % 3 != 0 && a[i] % 5 != 0) { ok = false; break; } } } if (ok) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } public static void solve_abc155A() { int[] abc = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); if ((abc[0] == abc[1] && abc[2] != abc[0]) || (abc[0] == abc[2] && abc[1] != abc[0]) || (abc[1] == abc[2] && abc[0] != abc[1])) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
332
2
using System; using System.Linq; namespace ConsoleApp1111 { class Program { static void Main(string[] args) { var n = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var a = n.Where(_ => _ % 2 == 0).All(_ => _ % 3 == 0 || _ % 5 == 0); if (a) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } } }
using System; using System.Linq; namespace ConsoleApp1111 { class Program { static void Main(string[] args) { Console.ReadLine(); var n = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var a = n.Where(_ => _ % 2 == 0).All(_ => _ % 3 == 0 || _ % 5 == 0); if (a) { Console.WriteLine("APPROVED"); } else { Console.WriteLine("DENIED"); } } } }
[["+", 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
118
6
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); string[] s; rl(n,out s); var e = ElementCount(s,-4); ll cnt = e[0].Value; var ans = new List<string>(); foreach(var w in e){ if(w.Value==cnt){ ans.Add(w.Key); }else{ break; } } Lib_IO.wl(ans); } } public static int StrCmp(string a,string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } public static KeyValuePair<T,long>[] ElementCount<T>(IEnumerable<T> a, long order=0) where T : IComparable<T> { var d = new Dictionary<T, long>(); foreach (var e in a) { if(!d.ContainsKey(e)) d[e] = 0; d[e]++; } var r = d.ToArray(); switch(order) { case 1: Array.Sort(r,(x,y)=>(x.Key.CompareTo(y.Key))); break; case -1: Array.Sort(r,(x,y)=>(y.Key.CompareTo(x.Key))); break; case 2: Array.Sort(r,(x,y)=>(x.Value.CompareTo(y.Value))); break; case -2: Array.Sort(r,(x,y)=>(y.Value.CompareTo(x.Value))); break; case 3: Array.Sort(r,(x,y)=>(x.Value!=y.Value?x.Value.CompareTo(y.Value):x.Key.CompareTo(y.Key))); break; case 4: Array.Sort(r,(x,y)=>(x.Value!=y.Value?x.Value.CompareTo(y.Value):y.Key.CompareTo(x.Key))); break; case -3: Array.Sort(r,(x,y)=>(x.Value!=y.Value?y.Value.CompareTo(x.Value):x.Key.CompareTo(y.Key))); break; case -4: Array.Sort(r,(x,y)=>(x.Value!=y.Value?y.Value.CompareTo(x.Value):y.Key.CompareTo(x.Key))); break; default: break; } return r; } // string用 (デフォルトの文字列比較関数が遅いため) public static KeyValuePair<string,long>[] ElementCount(IEnumerable<string> a, long order=0) { var sc = StringComparer.Ordinal; var d = new Dictionary<string, long>(sc); foreach (var e in a) { if(!d.ContainsKey(e)) d[e] = 0; d[e]++; } var r = d.ToArray(); switch(order) { case 1: Array.Sort(r,(x,y)=>(sc.Compare(x.Key,y.Key))); break; case -1: Array.Sort(r,(x,y)=>(sc.Compare(y.Key,x.Key))); break; case 2: Array.Sort(r,(x,y)=>(x.Value.CompareTo(y.Value))); break; case -2: Array.Sort(r,(x,y)=>(y.Value.CompareTo(x.Value))); break; case 3: Array.Sort(r,(x,y)=>(x.Value!=y.Value?x.Value.CompareTo(y.Value):sc.Compare(x.Key,y.Key))); break; case 4: Array.Sort(r,(x,y)=>(x.Value!=y.Value?x.Value.CompareTo(y.Value):sc.Compare(y.Key,x.Key))); break; case -3: Array.Sort(r,(x,y)=>(x.Value!=y.Value?y.Value.CompareTo(x.Value):sc.Compare(x.Key,y.Key))); break; case -4: Array.Sort(r,(x,y)=>(x.Value!=y.Value?y.Value.CompareTo(x.Value):sc.Compare(y.Key,x.Key))); break; default: break; } return r; } #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); string[] s; rl(n,out s); var e = ElementCount(s,-3); ll cnt = e[0].Value; var ans = new List<string>(); foreach(var w in e){ if(w.Value==cnt){ ans.Add(w.Key); }else{ break; } } Lib_IO.wl(ans); } } public static int StrCmp(string a,string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } public static KeyValuePair<T,long>[] ElementCount<T>(IEnumerable<T> a, long order=0) where T : IComparable<T> { var d = new Dictionary<T, long>(); foreach (var e in a) { if(!d.ContainsKey(e)) d[e] = 0; d[e]++; } var r = d.ToArray(); switch(order) { case 1: Array.Sort(r,(x,y)=>(x.Key.CompareTo(y.Key))); break; case -1: Array.Sort(r,(x,y)=>(y.Key.CompareTo(x.Key))); break; case 2: Array.Sort(r,(x,y)=>(x.Value.CompareTo(y.Value))); break; case -2: Array.Sort(r,(x,y)=>(y.Value.CompareTo(x.Value))); break; case 3: Array.Sort(r,(x,y)=>(x.Value!=y.Value?x.Value.CompareTo(y.Value):x.Key.CompareTo(y.Key))); break; case 4: Array.Sort(r,(x,y)=>(x.Value!=y.Value?x.Value.CompareTo(y.Value):y.Key.CompareTo(x.Key))); break; case -3: Array.Sort(r,(x,y)=>(x.Value!=y.Value?y.Value.CompareTo(x.Value):x.Key.CompareTo(y.Key))); break; case -4: Array.Sort(r,(x,y)=>(x.Value!=y.Value?y.Value.CompareTo(x.Value):y.Key.CompareTo(x.Key))); break; default: break; } return r; } // string用 (デフォルトの文字列比較関数が遅いため) public static KeyValuePair<string,long>[] ElementCount(IEnumerable<string> a, long order=0) { var sc = StringComparer.Ordinal; var d = new Dictionary<string, long>(sc); foreach (var e in a) { if(!d.ContainsKey(e)) d[e] = 0; d[e]++; } var r = d.ToArray(); switch(order) { case 1: Array.Sort(r,(x,y)=>(sc.Compare(x.Key,y.Key))); break; case -1: Array.Sort(r,(x,y)=>(sc.Compare(y.Key,x.Key))); break; case 2: Array.Sort(r,(x,y)=>(x.Value.CompareTo(y.Value))); break; case -2: Array.Sort(r,(x,y)=>(y.Value.CompareTo(x.Value))); break; case 3: Array.Sort(r,(x,y)=>(x.Value!=y.Value?x.Value.CompareTo(y.Value):sc.Compare(x.Key,y.Key))); break; case 4: Array.Sort(r,(x,y)=>(x.Value!=y.Value?x.Value.CompareTo(y.Value):sc.Compare(y.Key,x.Key))); break; case -3: Array.Sort(r,(x,y)=>(x.Value!=y.Value?y.Value.CompareTo(x.Value):sc.Compare(x.Key,y.Key))); break; case -4: Array.Sort(r,(x,y)=>(x.Value!=y.Value?y.Value.CompareTo(x.Value):sc.Compare(y.Key,x.Key))); break; default: break; } return r; } #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, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203]]
8
3,941
2
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var n = sc.I; var hs = new Dictionary<string, int>(); int p = 1, o = 0; for (int i = 0; i < n; i++) { var e = sc.S; if (hs.ContainsKey(e)) { hs[e]++; int z = hs[e]; if (p < z) { p = z; o = 1; } else if (p == z) { o++; } } else { hs.Add(e, 1); } } var a = new string[o]; int j = 0; foreach (var e in hs) { if (e.Value == p) { a[j] = e.Key; j++; } } a = a.OrderBy(x => x, StringComparer.Ordinal).ToArray(); Console.WriteLine(String.Join("\n", a)); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var n = sc.I; var hs = new Dictionary<string, int>(); int p = 1, o = n; for (int i = 0; i < n; i++) { var e = sc.S; if (hs.ContainsKey(e)) { hs[e]++; int z = hs[e]; if (p < z) { p = z; o = 1; } else if (p == z) { o++; } } else { hs.Add(e, 1); } } var a = new string[o]; int j = 0; foreach (var e in hs) { if (e.Value == p) { a[j] = e.Key; j++; } } a = a.OrderBy(x => x, StringComparer.Ordinal).ToArray(); Console.WriteLine(String.Join("\n", a)); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), double.Parse); } public double[] Da3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
1,231
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var S = sc.ReadStrArray(N); var dic = new Dictionary<string, int>(); var max = 0; for (int i = 0; i < N; i++) { var j = 0; dic[S[i]] = dic.TryGetValue(S[i], out j) ? j + 1 : 1; max = Math.Max(max, dic[S[i]]); } var list = new List<string>(); foreach (var p in dic) { if (p.Value == max) list.Add(p.Key); } var array = list.ToArray(); Array.Sort(S, StringComparer.Ordinal); foreach (var a in array) { Console.WriteLine(a); } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var S = sc.ReadStrArray(N); var dic = new Dictionary<string, int>(); var max = 0; for (int i = 0; i < N; i++) { var j = 0; dic[S[i]] = dic.TryGetValue(S[i], out j) ? j + 1 : 1; max = Math.Max(max, dic[S[i]]); } var list = new List<string>(); foreach (var p in dic) { if (p.Value == max) list.Add(p.Key); } var array = list.ToArray(); Array.Sort(array, StringComparer.Ordinal); foreach (var a in array) { Console.WriteLine(a); } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
1,181
2
using System; // k番目の値->「x未満がk未満」であるxの最大値 //-INF=ok,INF=ngを条件に(今回はINF=10^18 +1)二分探索でO(log INF) //「x未満が何個?」 class Program { static public readonly long INF = (long)Math.Pow(10, 18) + 1; static void Main(string[] args) { string[] In = Console.ReadLine().Split(' '); int n = int.Parse(In[0]); long k = int.Parse(In[1]); string[] In1 = Console.ReadLine().Split(' '); long[] A = new long[n]; for (int i = 0; i < n; i++) { A[i] = int.Parse(In1[i]); } // A[i]のソートを行う Array.Sort(A); //二分探索 lとrが隣あったら終わり long l = -INF, r = INF; // left right while (l + 1 < r) { long x = (l + r) / 2; bool ok = BinarySerach(A, n, x, k); if (ok) l = x; else r = x; } Console.WriteLine(l); } static public bool BinarySerach(long[] A, int n, long x, long k) { long tot = 0; for (int i = 0; i < n; i++) { if (A[i] < 0) { int L = -1, R = n; while (L + 1 < R) { int c = (L + R) / 2; if (A[c] * A[i] < x) R = c; else L = c; } tot += n - R; } else { int L = -1, R = n; while (L + 1 < R) { int c = (L + R) / 2; if (A[c] * A[i] < x) L = c; else R = c; } tot += R; } if (A[i] * A[i] < x) tot--; } tot /= 2; return tot < k; } } // class Program // { // static void Main(string[] args) // { // string[] In = Console.ReadLine().Split(' '); // int n = int.Parse(In[0]); // int k = int.Parse(In[1]); // string[] In1 = Console.ReadLine().Split(' '); // int[] A = new int[n]; // int m = 0, z = 0, p = 0;//minus,zero,plus // for(int i=0; i < n; i++) // { // A[i] = int.Parse(In1[i]); // if (A[i] < 0) m++; // else if (A[i] == 0) z++; // else if (A[i] > 0) p++; // } // long rm =m*p; // long rp =p*(p-1)/2; // long rz = n * (n - 1) / 2 - rm - rp; // } //}
using System; // k番目の値->「x未満がk未満」であるxの最大値 //-INF=ok,INF=ngを条件に(今回はINF=10^18 +1)二分探索でO(log INF) //「x未満が何個?」 class Program { static public readonly long INF = (long)Math.Pow(10, 18) + 1; static void Main(string[] args) { string[] In = Console.ReadLine().Split(' '); int n = int.Parse(In[0]); long k = long.Parse(In[1]); string[] In1 = Console.ReadLine().Split(' '); long[] A = new long[n]; for (int i = 0; i < n; i++) { A[i] = long.Parse(In1[i]); } // A[i]のソートを行う Array.Sort(A); //二分探索 lとrが隣あったら終わり long l = -INF, r = INF; // left right while (l + 1 < r) { long x = (l + r) / 2; bool ok = BinarySerach(A, n, x, k); if (ok) l = x; else r = x; } Console.WriteLine(l); } static public bool BinarySerach(long[] A, int n, long x, long k) { long tot = 0; for (int i = 0; i < n; i++) { if (A[i] < 0) { int L = -1, R = n; while (L + 1 < R) { int c = (L + R) / 2; if (A[c] * A[i] < x) R = c; else L = c; } tot += n - R; } else { int L = -1, R = n; while (L + 1 < R) { int c = (L + R) / 2; if (A[c] * A[i] < x) L = c; else R = c; } tot += R; } if (A[i] * A[i] < x) tot--; } tot /= 2; return tot < k; } } // class Program // { // static void Main(string[] args) // { // string[] In = Console.ReadLine().Split(' '); // int n = int.Parse(In[0]); // int k = int.Parse(In[1]); // string[] In1 = Console.ReadLine().Split(' '); // int[] A = new int[n]; // int m = 0, z = 0, p = 0;//minus,zero,plus // for(int i=0; i < n; i++) // { // A[i] = int.Parse(In1[i]); // if (A[i] < 0) m++; // else if (A[i] == 0) z++; // else if (A[i] > 0) p++; // } // long rm =m*p; // long rp =p*(p-1)/2; // long rz = n * (n - 1) / 2 - rm - rp; // } //}
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
442
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { long n = Read; long k = Read - 1; var a = Arr(n).OrderBy(x => x).ToArray(); var aMinus = a.Where(x => x < 0).Select(x => -x).Reverse().ToArray(); var aZero = a.Where(x => x == 0).ToArray(); var aPlus = a.Where(x => x > 0).ToArray(); var cMinus = aMinus.LongLength * aPlus.LongLength; var cPlus = aMinus.LongLength * (aMinus.LongLength - 1) / 2 + aPlus.LongLength * (aPlus.LongLength - 1) / 2; var cZero = a.LongLength * (a.LongLength - 1) / 2 - cMinus - cPlus; if (cMinus > k) { var order = cMinus - k; var min = 0L; var max = aMinus.Last() * aPlus.Last(); while (min < max) { var mid = (min + max) / 2; var midCount = GetCountInAll(aMinus, aPlus, mid); if (midCount >= order) { max = mid; } else if (midCount < order) { min = mid + 1; } } return -min; } else if (cMinus + cZero > k) { return 0; } else { var order = k - cMinus - cZero + 1; var min = 0L; var max = Math.Max(aMinus.Last() * aMinus.Last(), aPlus.Last() * aPlus.Last()); while (min < max) { var mid = (min + max) / 2; var midCount = GetCountInHalf(aMinus, aPlus, mid); if (midCount >= order) { max = mid; } else if (midCount < order) { min = mid + 1; } } return min; } } long GetCountInAll(long[] a, long[] b, long max) { var res = 0L; foreach (var aa in a) { var th = max / aa; var r = C.BinarySearch.GetFirstIndexGreater(th, b); res += r; } return res; } long GetCountInHalf(long[] a, long[] b, long max) { return GetCountInHalf(a, max) + GetCountInHalf(b, max); } long GetCountInHalf(long[] a, long max) { var res = 0L; for (long i = 0; i < a.LongLength; i++) { var th = max / a[i]; var r = C.BinarySearch.GetFirstIndexGreater(th, a) - 1 - i; if (r > 0) res += r; } return res; } public bool SolveBool() { long n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); } class C { public class Tree { public Tree() { to = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); to = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> to; public long[] To(long from) { long[] res = null; if (to.TryGetValue(from, out res)) return res; else return empty; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetFirstIndexGreater(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } public static long GetLastIndexLess(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { long n = Read; long k = Read - 1; var a = Arr(n).OrderBy(x => x).ToArray(); var aMinus = a.Where(x => x < 0).Select(x => -x).Reverse().ToArray(); var aZero = a.Where(x => x == 0).ToArray(); var aPlus = a.Where(x => x > 0).ToArray(); var cMinus = aMinus.LongLength * aPlus.LongLength; var cPlus = aMinus.LongLength * (aMinus.LongLength - 1) / 2 + aPlus.LongLength * (aPlus.LongLength - 1) / 2; var cZero = a.LongLength * (a.LongLength - 1) / 2 - cMinus - cPlus; if (cMinus > k) { var order = cMinus - k; var min = 0L; var max = aMinus.LastOrDefault() * aPlus.LastOrDefault(); while (min < max) { var mid = (min + max) / 2; var midCount = GetCountInAll(aMinus, aPlus, mid); if (midCount >= order) { max = mid; } else if (midCount < order) { min = mid + 1; } } return -min; } else if (cMinus + cZero > k) { return 0; } else { var order = k - cMinus - cZero + 1; var min = 0L; var max = Math.Max(aMinus.LastOrDefault() * aMinus.LastOrDefault(), aPlus.LastOrDefault() * aPlus.LastOrDefault()); while (min < max) { var mid = (min + max) / 2; var midCount = GetCountInHalf(aMinus, aPlus, mid); if (midCount >= order) { max = mid; } else if (midCount < order) { min = mid + 1; } } return min; } } long GetCountInAll(long[] a, long[] b, long max) { var res = 0L; foreach (var aa in a) { var th = max / aa; var r = C.BinarySearch.GetFirstIndexGreater(th, b); res += r; } return res; } long GetCountInHalf(long[] a, long[] b, long max) { return GetCountInHalf(a, max) + GetCountInHalf(b, max); } long GetCountInHalf(long[] a, long max) { var res = 0L; for (long i = 0; i < a.LongLength; i++) { var th = max / a[i]; var r = C.BinarySearch.GetFirstIndexGreater(th, a) - 1 - i; if (r > 0) res += r; } return res; } public bool SolveBool() { long n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); } class C { public class Tree { public Tree() { to = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); to = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> to; public long[] To(long from) { long[] res = null; if (to.TryGetValue(from, out res)) return res; else return empty; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetFirstIndexGreater(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } public static long GetLastIndexLess(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } public static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
[["-", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22]]
8
7,214
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { var N = GetString().Select(x => (int)(x - '0')).ToList(); N.Reverse(); int L = N.Count; int INF = int.MaxValue / L; var dp = new int[L + 1, 2]; for (int i = 0; i <= L; i++) { for (int j = 0; j < 2; j++) dp[i, j] = INF; } dp[0, 0] = 0; for (int i = 0; i < L; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 10; k++) { int a = (j == 0) ? k : (k + 9) % 10; int b = (a < N[i]) ? 10 + a - N[i] : a - N[i]; int c = ((j == 1 && k == 0) || a < N[i]) ? 1 : 0; chmin(ref dp[i + 1, c], dp[i, j] + k + b); } } } WriteLine(Min(dp[L, 0], dp[L, 1] + 1)); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray(); public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray(); public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { var N = GetString().Select(x => (int)(x - '0')).ToList(); N.Reverse(); int L = N.Count; int INF = int.MaxValue / 2; var dp = new int[L + 1, 2]; for (int i = 0; i <= L; i++) { for (int j = 0; j < 2; j++) dp[i, j] = INF; } dp[0, 0] = 0; for (int i = 0; i < L; i++) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 10; k++) { int a = (j == 0) ? k : (k + 9) % 10; int b = (a < N[i]) ? 10 + a - N[i] : a - N[i]; int c = ((j == 1 && k == 0) || a < N[i]) ? 1 : 0; chmin(ref dp[i + 1, c], dp[i, j] + k + b); } } } WriteLine(Min(dp[L, 0], dp[L, 1] + 1)); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray(); public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray(); public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
822
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace A { class StartingPoint { static void Main(string[] args) { if (args?.Any() == true) { var assembly = Assembly.GetEntryAssembly(); var resourceName = "AtCoderCSharp.In.txt"; var stream = assembly.GetManifestResourceStream(resourceName); var streamReader = new StreamReader(stream, Encoding.UTF8); var str = streamReader.ReadToEnd(); var textReader = new StringReader(str); Console.SetIn(textReader); } try { foreach (var s in new Program().Solve()) { Console.WriteLine(s); } } catch (Exception e) { Console.WriteLine(e); if (args?.Any() != true) throw e; } if (args?.Any() == true) Console.ReadKey(); } } class Program { public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList(); public List<int> ScanInts(long count) => ScanInts((int)count); public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList(); public List<long> ScanLongs(long count) => ScanLongs((int)count); public int ScanInt => int.Parse(Str); public long Scan => long.Parse(Str); public double ScanDouble => (double)Scan; StringBuilder sb = new StringBuilder(); public string Str => ScanStr(); public string ScanStr() { sb.Clear(); int r = 0; bool? b = null; do { r = Console.Read(); b = IsBreak(r); } while (b == true); if (b == null) throw new Exception("input error: unexpected end of stream"); do { sb.Append((char)r); r = Console.Read(); b = IsBreak(r); } while (b == false); return sb.ToString(); } bool? IsBreak(int c) { switch (c) { case -1: return null; case (int)' ': case (int)'\n': case (int)'\r': return true; default: return false; } } public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count); public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1); public IEnumerable<long> Loop(long count) => Loop(0, count - 1); public IEnumerable<long> Loop(long from, long to) { for (long i = from; i <= to; i++) yield return i; } public string YesNo(bool isYes) => isYes ? "Yes" : "No"; public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts); public long Slv(string n) { var res = 0L; var cri = 0; for (int i = n.Length - 1; i >= 0; i--) { var d = (n[i] - '0'); if (cri == 1) d++; else if (cri == -1) { if (d >= 5) d++; } if (d >= 6) { res += (10 - d); cri = 1; } else if (d == 5) { res += 5; cri = -1; } else { res += d; cri = 0; } } if (cri != 0) res++; return res; } public IEnumerable<string> Solve() { // for (int i = 10; i < 100; i++) //{ // yield return i.ToString() + " " + Slv(i.ToString()); //} var res = Slv(ScanStr()); yield return res.ToString(); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace A { class StartingPoint { static void Main(string[] args) { if (args?.Any() == true) { var assembly = Assembly.GetEntryAssembly(); var resourceName = "AtCoderCSharp.In.txt"; var stream = assembly.GetManifestResourceStream(resourceName); var streamReader = new StreamReader(stream, Encoding.UTF8); var str = streamReader.ReadToEnd(); var textReader = new StringReader(str); Console.SetIn(textReader); } try { foreach (var s in new Program().Solve()) { Console.WriteLine(s); } } catch (Exception e) { Console.WriteLine(e); if (args?.Any() != true) throw e; } if (args?.Any() == true) Console.ReadKey(); } } class Program { public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList(); public List<int> ScanInts(long count) => ScanInts((int)count); public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList(); public List<long> ScanLongs(long count) => ScanLongs((int)count); public int ScanInt => int.Parse(Str); public long Scan => long.Parse(Str); public double ScanDouble => (double)Scan; StringBuilder sb = new StringBuilder(); public string Str => ScanStr(); public string ScanStr() { sb.Clear(); int r = 0; bool? b = null; do { r = Console.Read(); b = IsBreak(r); } while (b == true); if (b == null) throw new Exception("input error: unexpected end of stream"); do { sb.Append((char)r); r = Console.Read(); b = IsBreak(r); } while (b == false); return sb.ToString(); } bool? IsBreak(int c) { switch (c) { case -1: return null; case (int)' ': case (int)'\n': case (int)'\r': return true; default: return false; } } public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count); public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1); public IEnumerable<long> Loop(long count) => Loop(0, count - 1); public IEnumerable<long> Loop(long from, long to) { for (long i = from; i <= to; i++) yield return i; } public string YesNo(bool isYes) => isYes ? "Yes" : "No"; public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts); public long Slv(string n) { var res = 0L; var cri = 0; for (int i = n.Length - 1; i >= 0; i--) { var d = (n[i] - '0'); if (cri == 1) d++; else if (cri == -1) { if (d >= 5) d++; } if (d >= 6) { res += (10 - d); cri = 1; } else if (d == 5) { res += 5; cri = -1; } else { res += d; cri = 0; } } if (cri == 1) res++; return res; } public IEnumerable<string> Solve() { // for (int i = 10; i < 100; i++) //{ // yield return i.ToString() + " " + Slv(i.ToString()); //} var res = Slv(ScanStr()); yield return res.ToString(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
826
4
using System; using static System.Console; using System.Linq; namespace Main { class Program { static void Main(string[] args) { string[] tmp = ReadLine().Split(' ').ToArray(); string S = tmp[0]; string T = tmp[1]; int[] nums = ReadLine().Split(' ').Select(int.Parse).ToArray(); int A = nums[0]; int B = nums[1]; string U = ReadLine(); if (U == "red") { A = A - 1; } else { B = B - 1; } WriteLine("{0} {1}", A, B); } } }
using System; using static System.Console; using System.Linq; namespace Main { class Program { static void Main(string[] args) { string[] tmp = ReadLine().Split(' ').ToArray(); string S = tmp[0]; string T = tmp[1]; int[] nums = ReadLine().Split(' ').Select(int.Parse).ToArray(); int A = nums[0]; int B = nums[1]; string U = ReadLine(); if (U == S) { A = A - 1; } else { B = B - 1; } WriteLine("{0} {1}", A, B); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 62], ["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
155
4
using System; using System.Collections.Generic; using System.Linq; namespace Hayadoki20200309A { 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 { static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { private Input input = new Input(); public Solver() { string s; input.String(out s); string[] t = s.Split(' '); S = t[0]; T = t[1]; input.Long(out A, out B); input.String(out U); } private string S; private string T; private long A; private long B; private string U; public void Solve() { if (U == "red") { Console.WriteLine("" + (A - 1) + " " + B); } else { Console.WriteLine("" + A + " " + (B - 1)); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace Hayadoki20200309A { 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 { static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { private Input input = new Input(); public Solver() { string s; input.String(out s); string[] t = s.Split(' '); S = t[0]; T = t[1]; input.Long(out A, out B); input.String(out U); } private string S; private string T; private long A; private long B; private string U; public void Solve() { if (U == S) { Console.WriteLine("" + (A - 1) + " " + B); } else { Console.WriteLine("" + A + " " + (B - 1)); } } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 62], ["-", 8, 196, 0, 57, 15, 16, 12, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
971
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); Tuple<long, long>[] robots = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { long x = sc.NextLong(); long l = sc.NextLong(); robots[i] = Tuple.Create(x - l, x + l); } robots = robots.OrderBy(t => t.Item2).ToArray(); long answer = 0; long right = int.MinValue; foreach (var robot in robots) { if (robot.Item1 < right) { answer++; } else { right = robot.Item2; } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); Tuple<long, long>[] robots = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { long x = sc.NextLong(); long l = sc.NextLong(); robots[i] = Tuple.Create(x - l, x + l); } robots = robots.OrderBy(t => t.Item2).ToArray(); long answer = n; long right = int.MinValue; foreach (var robot in robots) { if (robot.Item1 < right) { answer--; } else { right = robot.Item2; } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68]]
8
483
4
using System; using System.IO; class Solve { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var robos = new(int left, int right)[N]; for (int i = 0; i < N; i++) { var arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); robos[i] = (arr[0] - arr[1], arr[0] + arr[1]); } Array.Sort(robos); var answer = N; var x = int.MinValue; for (int i = N - 1; i >= 0; i--) { if (x > robos[i].right) continue; answer--; x = robos[i].left; } var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(writer); Console.WriteLine(answer); Console.Out.Flush(); } }
using System; using System.IO; class Solve { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var robos = new(int left, int right)[N]; for (int i = 0; i < N; i++) { var arr = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); robos[i] = (arr[0] - arr[1], arr[0] + arr[1]); } Array.Sort(robos); var answer = 0; var x = int.MaxValue; for (int i = N - 1; i >= 0; i--) { if (x < robos[i].right) continue; answer++; x = robos[i].left; } var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(writer); Console.WriteLine(answer); Console.Out.Flush(); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29]]
8
219
8
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); var n = long.Parse(Console.ReadLine()); long[] x = new long[n]; long[] l = new long[n]; for (int i = 0; i < n; i++) { int[] t = Console.ReadLine().Split().Select(int.Parse).ToArray(); x[i] = t[0]; l[i] = t[1]; } long[] s = new long[n]; long[] e = new long[n]; for (int i = 0; i < n; i++) { s[i] = x[i] - l[i]; e[i] = x[i] + l[i]; } Array.Sort(e, s); //区間スケジューリング var ans = 0; var num = long.MinValue; for (int i = 0; i < n; i++) { if (num <= s[i]) { num = s[i]; ans++; } } // 出力 Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); var n = long.Parse(Console.ReadLine()); long[] x = new long[n]; long[] l = new long[n]; for (int i = 0; i < n; i++) { int[] t = Console.ReadLine().Split().Select(int.Parse).ToArray(); x[i] = t[0]; l[i] = t[1]; } long[] s = new long[n]; long[] e = new long[n]; for (int i = 0; i < n; i++) { s[i] = x[i] - l[i]; e[i] = x[i] + l[i]; } Array.Sort(e, s); //区間スケジューリング var ans = 0; var num = long.MinValue; for (int i = 0; i < n; i++) { if (num <= s[i]) { num = e[i]; ans++; } } // 出力 Console.WriteLine(ans); } }
[["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22]]
8
275
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; using static AtCoder.CalcL; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1 }; static readonly int[] dJ = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int N = int.Parse(Console.ReadLine()); var R = new List<Tuple<long, long>>(); for (var i = 0; i < N; i++) { var p = cin.ReadSplitInt(); long X = p[0]; long L = p[1]; R.Add(new Tuple<long, long>(X + L, X - L + 1)); } R.Sort(); long ans = 0; long prev = -SINF; for (var i = 0; i < N; i++) { if (prev <= R[i].Item2) { ans++; prev = R[i].Item1; } } Console.WriteLine(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Scanner { public int[] ReadSplitInt() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitLong() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplit_Double() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) { return (long)Pow(a, b); } } static public class CalcI { public static int Gcd(int a, int b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static int Lcm(int a, int b) { int g = Gcd(a, b); return a / g * b; } public static int Ceil(int n, int div) { return (n + div - 1) / div; } } static public class CalcL { public static long Gcd(long a, long b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static long Lcm(long a, long b) { long g = Gcd(a, b); return a / g * b; } public static long Ceil(long n, long div) { return (n + div - 1) / div; } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } public Modulo() {} } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; using static AtCoder.CalcL; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1 }; static readonly int[] dJ = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int N = int.Parse(Console.ReadLine()); var R = new List<Tuple<long, long>>(); for (var i = 0; i < N; i++) { var p = cin.ReadSplitInt(); long X = p[0]; long L = p[1]; R.Add(new Tuple<long, long>(X + L, X - L + 1)); } R.Sort(); long ans = 0; long prev = -SINF; for (var i = 0; i < N; i++) { if (prev < R[i].Item2) { ans++; prev = R[i].Item1; } } Console.WriteLine(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Scanner { public int[] ReadSplitInt() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitLong() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplit_Double() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) { return (long)Pow(a, b); } } static public class CalcI { public static int Gcd(int a, int b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static int Lcm(int a, int b) { int g = Gcd(a, b); return a / g * b; } public static int Ceil(int n, int div) { return (n + div - 1) / div; } } static public class CalcL { public static long Gcd(long a, long b) { if (a * b == 0) { return Max(a, b); } return a % b == 0 ? b : Gcd(b, a % b); } public static long Lcm(long a, long b) { long g = Gcd(a, b); return a / g * b; } public static long Ceil(long n, long div) { return (n + div - 1) / div; } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } public Modulo() {} } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18]]
8
1,160
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200313.Keyence2020_B.Cin; using static _20200313.Keyence2020_B.Util; using Pair = _20200313.Keyence2020_B.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200313 { public class Keyence2020_B { public static void Main(string[] args) { long n = rl; Pair[] ps = new Pair[n]; for (int i = 0; i < n; i++) { long p = rl; long r = rl; ps[i] = new Pair(p - r, p + r); } Sort(ps); long right = long.MinValue; long ans = 0; for (int i = 0; i < n; i++) { if (right <= ps[i].First) { ans++; right = ps[i].Second; } } Console.WriteLine(ans); } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200313.Keyence2020_B.Cin; using static _20200313.Keyence2020_B.Util; using Pair = _20200313.Keyence2020_B.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200313 { public class Keyence2020_B { public static void Main(string[] args) { long n = rl; Pair[] ps = new Pair[n]; for (int i = 0; i < n; i++) { long p = rl; long r = rl; ps[i] = new Pair(p + r, p - r); } Sort(ps); long right = long.MinValue; long ans = 0; for (int i = 0; i < n; i++) { if (right <= ps[i].Second) { ans++; right = ps[i].First; } } Console.WriteLine(ans); } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
[["-", 12, 230, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 12, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 230, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22]]
8
2,281
8
using System; using System.Linq; using System.Collections.Generic; class ProgramB { static void Main(string[] args) { //入力 int n = int.Parse(Console.ReadLine()); int[] pos = new int[n]; int[] l = new int[n]; List<Task> task = new List<Task>(); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); pos[i] = int.Parse(input[0]); l[i] = int.Parse(input[1]); task.Add(new Task(pos[i], l[i])); } IOrderedEnumerable<Task> sorted = task.OrderBy(x => x.a); int z = 0; foreach (Task s in sorted) { pos[z] = s.a; l[z] = s.order; z++; } int temp = 0; int temp2 = pos[0] + l[0]; int k = 0; int count = 0; for (int i = 1; i < n; i++) { temp = pos[i] - l[i]; if (temp < temp2) { count++; if (temp2 >= pos[i] + l[i]) { temp2 = pos[i] + l[i]; } } else { temp2 = pos[i] + l[i]; } } Console.WriteLine(count); } } public class Task { public int order; public int a; public Task(int a, int order) { this.a = a; this.order = order; } }
using System; using System.Linq; using System.Collections.Generic; class ProgramB { static void Main(string[] args) { //入力 int n = int.Parse(Console.ReadLine()); int[] pos = new int[n]; int[] l = new int[n]; List<Task> task = new List<Task>(); for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); pos[i] = int.Parse(input[0]); l[i] = int.Parse(input[1]); task.Add(new Task(pos[i], l[i])); } IOrderedEnumerable<Task> sorted = task.OrderBy(x => x.a); int z = 0; foreach (Task s in sorted) { pos[z] = s.a; l[z] = s.order; z++; } int temp = 0; int temp2 = pos[0] + l[0]; int k = 0; int count = 0; for (int i = 1; i < n; i++) { temp = pos[i] - l[i]; if (temp < temp2) { count++; if (temp2 >= pos[i] + l[i]) { temp2 = pos[i] + l[i]; } } else { temp2 = pos[i] + l[i]; } } Console.WriteLine(n - count); } } public class Task { public int order; public int a; public Task(int a, int order) { this.a = a; this.order = order; } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
369
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { var N = sc.Int; var XL = Create(N, () => new int[3]); for (var i = 0; i < N; i++) { for (var j = 0; j < 2; j++) XL[i][j] = sc.Next<int>(); XL[i][2] = i; } Array.Sort(XL, (a, b) => (a[0] + a[1]).CompareTo(b[0] + b[1])); var cp = Create(N, id => XL[id].Copy()); Array.Sort(cp, (a, b) => (a[0] - a[1]).CompareTo(b[0] - b[1])); var res = 0; var idx = 0; var use = new bool[N]; for (var i = 0; i < N; i++) { if (use[XL[i][2]]) continue; while (idx != N && XL[i][0] + XL[i][1] - 1 >= cp[idx][0] - cp[idx][1] + 1) { use[cp[idx][2]] = true; idx++; } res++; } WriteLine(res); } } #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 T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static T[] Copy<T>(this T[] A) => Create(A.Length, i => A[i]); 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); public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>()); public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>()); 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 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 Tie(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 Tie(out T1 a, out T2 b, out T3 c) { Tie(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 static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { var N = sc.Int; var XL = Create(N, () => new int[3]); for (var i = 0; i < N; i++) { for (var j = 0; j < 2; j++) XL[i][j] = sc.Next<int>(); XL[i][2] = i; } Array.Sort(XL, (a, b) => (a[0] + a[1]).CompareTo(b[0] + b[1])); var cp = Create(N, id => XL[id].Copy()); Array.Sort(cp, (a, b) => (a[0] - a[1]).CompareTo(b[0] - b[1])); var res = 0; var idx = 0; var use = new bool[N]; for (var i = 0; i < N; i++) { if (use[XL[i][2]]) continue; while (idx != N && XL[i][0] + XL[i][1] - 1 >= cp[idx][0] - cp[idx][1]) { use[cp[idx][2]] = true; idx++; } res++; } WriteLine(res); } } #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 T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static T[] Copy<T>(this T[] A) => Create(A.Length, i => A[i]); 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); public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>()); public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>()); 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 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 Tie(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 Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; } } #endregion
[["-", 0, 52, 15, 16, 12, 16, 12, 16, 17, 72], ["-", 0, 52, 15, 16, 12, 16, 12, 16, 12, 203]]
8
1,817
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using System.IO; class readint { public readint(out int i) { i = int.Parse(Console.ReadLine()); } public readint(out int a, out int b) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readint(out int a, out int b, out int c) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readint(out int a, out int b, out int c, out int d) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class readlong { public readlong(out long i) { i = long.Parse(Console.ReadLine()); } public readlong(out long a, out long b) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readlong(out long a, out long b, out long c) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readlong(out long a, out long b, out long c, out long d) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class Util { public static int[] readintarr() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static long[] readlongarr() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } /// <summary> /// 2引数の最大公約数を返します。longです。 /// </summary> /// <param name="a">long 引数1</param> /// <param name="b">long 引数2</param> /// <returns></returns> public static long GCD(long a, long b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2引数の最大公約数を返します。intです。 /// </summary> /// <param name="a">int 引数1</param> /// <param name="b">int 引数2</param> /// <returns></returns> public static int GCD(int a, int b) { // if (a < b) // swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2つの変数の中身を交換する。型はなんでもいい /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void swap<T>(ref T a, ref T b) { T temp = b; b = a; a = temp; } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(long a, long b) { return a * b / GCD(a, b); } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); } public static int M = (int)(Math.Pow(10, 9)) + 7; private static int[] factorial_modM; /// <summary> /// 2引数の積 mod Mを求める。Mは10億7。 /// 変えられるよ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Multiple_modM(int a, int b) { return (int)(Math.BigMul(a, b) % M); } /// <summary> /// n! modMを求めるための準備を行う。引数は最大値。 /// </summary> /// <param name="n"></param> public static void factorial_modM_Prepare(int n) { factorial_modM = new int[n + 1]; factorial_modM[0] = 1; for (int i = 1; i <= n; ++i) { factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i); } } /// <summary> /// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int Factorial(int n) { return factorial_modM[n]; } public static int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiple_modM(p1, p1); return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a); } } /// <summary> /// a / m Mod M を求める。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Div(int a, int b) { return Multiple_modM(a, Pow(b, M - 2)); } /// <summary> /// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <param name="r"></param> /// <returns></returns> public static int nCr_modM(int n, int r) { if (r < 0) return 0; if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Div(res, Factorial(r)); res = Div(res, Factorial(n - r)); return res; } } /// <summary> /// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。 /// おすすめとしては、UnionFind<T>[] で宣言してしまう。 /// </summary> /// <typeparam name="T">int固定でいいよね。</typeparam> class UnionFind<T> { public int tree_height; public UnionFind<T> parent; public T item { get; private set; } public UnionFind(T item) { tree_height = 0; parent = this; } /// <summary> /// 一番上の親を探す。 /// 探しながら繋がり方を最適化している。 /// UnionFindの頂点そのものを返すので、==での比較が可能。 /// </summary> /// <returns></returns> public UnionFind<T> FindAdam() { if (parent == this) return this; else { UnionFind<T> ParentOfParent = parent.FindAdam(); parent = ParentOfParent; //縦長な構成をつなぎ直している return ParentOfParent; } } /// <summary> /// unionfind2つを一つにつなぐ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void Unite(UnionFind<T> a, UnionFind<T> b) { UnionFind<T> ParentOfA = a.FindAdam(); UnionFind<T> ParentOfB = b.FindAdam(); if (ParentOfA.tree_height < ParentOfB.tree_height) { ParentOfA.parent = ParentOfB; ParentOfB.tree_height = Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height); } else { ParentOfB.parent = ParentOfA; ParentOfA.tree_height = Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height); } } } // Treap 平衡二分木 class Treap<T> where T : IComparable { private class Node { private static Random g_rand = new Random(); private readonly int m_rank = g_rand.Next(); private readonly T m_value; private Node m_lch; private Node m_rch; private int m_count; public Node(T value) { m_value = value; m_count = 1; } private static int Count(Node node) { return (node != null) ? node.m_count : 0; } private Node Update() { m_count = Count(m_lch) + Count(m_rch) + 1; return this; } public static Node Merge(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } if (a.m_rank < b.m_rank) { a.m_rch = Merge(a.m_rch, b); return a.Update(); } else { b.m_lch = Merge(a, b.m_lch); return b.Update(); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) { return new Tuple<Node, Node>(null, null); } if (k <= Count(t.m_lch)) { var pair = Split(t.m_lch, k); t.m_lch = pair.Item2; return new Tuple<Node, Node>(pair.Item1, t.Update()); } else { var pair = Split(t.m_rch, k - Count(t.m_lch) - 1); t.m_rch = pair.Item1; return new Tuple<Node, Node>(t.Update(), pair.Item2); } } public int FindIndex(T value) { int L = Count(m_lch); if (value.CompareTo(m_value) < 0) { return (m_lch != null) ? m_lch.FindIndex(value) : 0; } else if (value.CompareTo(m_value) > 0) { return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1; } else { return L; } } public T this[int i] { get { int L = Count(m_lch); if (i < L) { return m_lch[i]; } else if (i > L) { return m_rch[i - L - 1]; } else { return m_value; } } } } private Node node; public void Insert(T value) { if (node != null) { int k = node.FindIndex(value); var pair = Node.Split(node, k); node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2); } else { node = new Node(value); } } public int FindIndex(T value) { return node.FindIndex(value); } public T this[int i] { get { return node[i]; } } } static class Permutation<T> { private static void Search(List<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) { perms.Add(stack.Reverse().ToArray()); } else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) { b[i] = a[i]; } stack.Pop(); } } } public static IEnumerable<T[]> All(IEnumerable<T> src) { var perms = new List<T[]>(); Search(perms, new Stack<T>(), src.ToArray()); return perms; } } namespace CompLib.Collections { #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } /// <summary> /// SEGTREEは1-BASE運用でございます /// よろしくおねがいします /// </summary> /// <typeparam name="T"></typeparam> class Segtree<T> { int n; //高さ T[] tree; //本体 Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか T exnum; //初期値 int count; /// <summary> /// !!!WARNING!!! 1-BASEです。 /// </summary> /// <param name="m">最大値。200001とか入れておくとよい</param> /// <param name="f">2引数の関数</param> /// <param /// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param> public Segtree(int m, Func<T, T, T> f, T ex) { this.count = 0; this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { this.count = 0; for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } /// <summary> /// j番目の値をxにする。計算し直さないので、 /// 入れ替えた後はall_update();を使おう /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } /// <summary> /// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void update(int j, T x) // j番目をxにする { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } this.count++; } /// <summary> /// 木を全部計算し直す。多分NlogN。違うかも知れないから /// よかったら教えて /// </summary> public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } /// <summary> /// j番目を消す。 /// </summary> /// <param name="j"></param> public void delete (int j) { int i = j + n - 1; tree[i] = exnum; int moved = 0; while (true) { tree[i + 1] = tree[i]; T check = tree[i]; moved++; if (moved + j + 2 > count) { break; } } all_update(); } // [s, t) /// <summary> /// s番目からt番目までの結果を返す。 /// これも当然のように1-BASE. /// </summary> /// <param name="s"></param> /// <param name="t"></param> /// <returns></returns> public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); // CompLib.Collections.PriorityQueue<?> public static void Main() { int N, K, S; new readint(out N, out K, out S); int Max = (int)Math.Pow(10, 9); int[] answer = new int[N]; if (S == Max) { for (int i = 0; i < N; i++) { int insert = 1; if (i >= K) { } else { insert = S; } answer[i] = insert; } } else { for (int i = 0; i < N; i++) { int insert = Max; if (i >= K) { } else { insert = K; } answer[i] = insert; } } Console.WriteLine(String.Join(" ", answer)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using System.IO; class readint { public readint(out int i) { i = int.Parse(Console.ReadLine()); } public readint(out int a, out int b) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readint(out int a, out int b, out int c) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readint(out int a, out int b, out int c, out int d) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class readlong { public readlong(out long i) { i = long.Parse(Console.ReadLine()); } public readlong(out long a, out long b) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readlong(out long a, out long b, out long c) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readlong(out long a, out long b, out long c, out long d) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class Util { public static int[] readintarr() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static long[] readlongarr() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } /// <summary> /// 2引数の最大公約数を返します。longです。 /// </summary> /// <param name="a">long 引数1</param> /// <param name="b">long 引数2</param> /// <returns></returns> public static long GCD(long a, long b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2引数の最大公約数を返します。intです。 /// </summary> /// <param name="a">int 引数1</param> /// <param name="b">int 引数2</param> /// <returns></returns> public static int GCD(int a, int b) { // if (a < b) // swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2つの変数の中身を交換する。型はなんでもいい /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void swap<T>(ref T a, ref T b) { T temp = b; b = a; a = temp; } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(long a, long b) { return a * b / GCD(a, b); } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); } public static int M = (int)(Math.Pow(10, 9)) + 7; private static int[] factorial_modM; /// <summary> /// 2引数の積 mod Mを求める。Mは10億7。 /// 変えられるよ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Multiple_modM(int a, int b) { return (int)(Math.BigMul(a, b) % M); } /// <summary> /// n! modMを求めるための準備を行う。引数は最大値。 /// </summary> /// <param name="n"></param> public static void factorial_modM_Prepare(int n) { factorial_modM = new int[n + 1]; factorial_modM[0] = 1; for (int i = 1; i <= n; ++i) { factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i); } } /// <summary> /// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int Factorial(int n) { return factorial_modM[n]; } public static int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiple_modM(p1, p1); return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a); } } /// <summary> /// a / m Mod M を求める。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Div(int a, int b) { return Multiple_modM(a, Pow(b, M - 2)); } /// <summary> /// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <param name="r"></param> /// <returns></returns> public static int nCr_modM(int n, int r) { if (r < 0) return 0; if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Div(res, Factorial(r)); res = Div(res, Factorial(n - r)); return res; } } /// <summary> /// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。 /// おすすめとしては、UnionFind<T>[] で宣言してしまう。 /// </summary> /// <typeparam name="T">int固定でいいよね。</typeparam> class UnionFind<T> { public int tree_height; public UnionFind<T> parent; public T item { get; private set; } public UnionFind(T item) { tree_height = 0; parent = this; } /// <summary> /// 一番上の親を探す。 /// 探しながら繋がり方を最適化している。 /// UnionFindの頂点そのものを返すので、==での比較が可能。 /// </summary> /// <returns></returns> public UnionFind<T> FindAdam() { if (parent == this) return this; else { UnionFind<T> ParentOfParent = parent.FindAdam(); parent = ParentOfParent; //縦長な構成をつなぎ直している return ParentOfParent; } } /// <summary> /// unionfind2つを一つにつなぐ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void Unite(UnionFind<T> a, UnionFind<T> b) { UnionFind<T> ParentOfA = a.FindAdam(); UnionFind<T> ParentOfB = b.FindAdam(); if (ParentOfA.tree_height < ParentOfB.tree_height) { ParentOfA.parent = ParentOfB; ParentOfB.tree_height = Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height); } else { ParentOfB.parent = ParentOfA; ParentOfA.tree_height = Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height); } } } // Treap 平衡二分木 class Treap<T> where T : IComparable { private class Node { private static Random g_rand = new Random(); private readonly int m_rank = g_rand.Next(); private readonly T m_value; private Node m_lch; private Node m_rch; private int m_count; public Node(T value) { m_value = value; m_count = 1; } private static int Count(Node node) { return (node != null) ? node.m_count : 0; } private Node Update() { m_count = Count(m_lch) + Count(m_rch) + 1; return this; } public static Node Merge(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } if (a.m_rank < b.m_rank) { a.m_rch = Merge(a.m_rch, b); return a.Update(); } else { b.m_lch = Merge(a, b.m_lch); return b.Update(); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) { return new Tuple<Node, Node>(null, null); } if (k <= Count(t.m_lch)) { var pair = Split(t.m_lch, k); t.m_lch = pair.Item2; return new Tuple<Node, Node>(pair.Item1, t.Update()); } else { var pair = Split(t.m_rch, k - Count(t.m_lch) - 1); t.m_rch = pair.Item1; return new Tuple<Node, Node>(t.Update(), pair.Item2); } } public int FindIndex(T value) { int L = Count(m_lch); if (value.CompareTo(m_value) < 0) { return (m_lch != null) ? m_lch.FindIndex(value) : 0; } else if (value.CompareTo(m_value) > 0) { return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1; } else { return L; } } public T this[int i] { get { int L = Count(m_lch); if (i < L) { return m_lch[i]; } else if (i > L) { return m_rch[i - L - 1]; } else { return m_value; } } } } private Node node; public void Insert(T value) { if (node != null) { int k = node.FindIndex(value); var pair = Node.Split(node, k); node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2); } else { node = new Node(value); } } public int FindIndex(T value) { return node.FindIndex(value); } public T this[int i] { get { return node[i]; } } } static class Permutation<T> { private static void Search(List<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) { perms.Add(stack.Reverse().ToArray()); } else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) { b[i] = a[i]; } stack.Pop(); } } } public static IEnumerable<T[]> All(IEnumerable<T> src) { var perms = new List<T[]>(); Search(perms, new Stack<T>(), src.ToArray()); return perms; } } namespace CompLib.Collections { #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } /// <summary> /// SEGTREEは1-BASE運用でございます /// よろしくおねがいします /// </summary> /// <typeparam name="T"></typeparam> class Segtree<T> { int n; //高さ T[] tree; //本体 Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか T exnum; //初期値 int count; /// <summary> /// !!!WARNING!!! 1-BASEです。 /// </summary> /// <param name="m">最大値。200001とか入れておくとよい</param> /// <param name="f">2引数の関数</param> /// <param /// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param> public Segtree(int m, Func<T, T, T> f, T ex) { this.count = 0; this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { this.count = 0; for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } /// <summary> /// j番目の値をxにする。計算し直さないので、 /// 入れ替えた後はall_update();を使おう /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } /// <summary> /// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void update(int j, T x) // j番目をxにする { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } this.count++; } /// <summary> /// 木を全部計算し直す。多分NlogN。違うかも知れないから /// よかったら教えて /// </summary> public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } /// <summary> /// j番目を消す。 /// </summary> /// <param name="j"></param> public void delete (int j) { int i = j + n - 1; tree[i] = exnum; int moved = 0; while (true) { tree[i + 1] = tree[i]; T check = tree[i]; moved++; if (moved + j + 2 > count) { break; } } all_update(); } // [s, t) /// <summary> /// s番目からt番目までの結果を返す。 /// これも当然のように1-BASE. /// </summary> /// <param name="s"></param> /// <param name="t"></param> /// <returns></returns> public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); // CompLib.Collections.PriorityQueue<?> public static void Main() { int N, K, S; new readint(out N, out K, out S); int Max = (int)Math.Pow(10, 9); int[] answer = new int[N]; if (S == Max) { for (int i = 0; i < N; i++) { int insert = 1; if (i >= K) { } else { insert = S; } answer[i] = insert; } } else { for (int i = 0; i < N; i++) { int insert = Max; if (i >= K) { } else { insert = S; } answer[i] = insert; } } Console.WriteLine(String.Join(" ", answer)); } }
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22]]
8
3,353
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var array = "abcdefghijklmnopqrstuvwxy"; var r = Console.ReadLine(); var nowPos = array.IndexOf(r); Console.WriteLine(array[nowPos + 1]); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var array = "abcdefghijklmnopqrstuvwxyz"; var r = Console.ReadLine(); var nowPos = array.IndexOf(r); Console.WriteLine(array[nowPos + 1]); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
8
91
2
using System; namespace ABC151 { class Program { static void Main(string[] args) { // int a = int.Parse(Console.ReadLine()); // string[] input = Console.ReadLine().Split(' '); // int b = int.Parse(input[0]); // int c = int.Parse(input[1]); // string s = Console.ReadLine(); // Console.WriteLine(a + b + c + " " + s); // Console.ReadLine(); string[] words = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u,", "w", "x", "y", "z" }; string input = Console.ReadLine(); var i = Array.IndexOf(words, input); if (i != 25) { Console.WriteLine(words[i + 1]); } Console.ReadLine(); } } }
using System; namespace ABC151 { class Program { static void Main(string[] args) { // int a = int.Parse(Console.ReadLine()); // string[] input = Console.ReadLine().Split(' '); // int b = int.Parse(input[0]); // int c = int.Parse(input[1]); // string s = Console.ReadLine(); // Console.WriteLine(a + b + c + " " + s); // Console.ReadLine(); string[] words = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; string input = Console.ReadLine(); var i = Array.IndexOf(words, input); // for(int j =0;j <words.Length;j++) //{ if (i != 25) { Console.WriteLine(words[i + 1]); } //} // if (i != 25) //{ // Console.WriteLine(words[i + 1]); //} Console.ReadLine(); } } }
[["-", 0, 200, 0, 212, 0, 229, 0, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 229, 0, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 229, 0, 5, 0, 62], ["+", 0, 198, 0, 200, 0, 212, 0, 229, 0, 21]]
8
183
6
using System; using System.Diagnostics; namespace atcode { class Program { static void Main(string[] args) { string charString = "abcdefghijklmnopqrstuvwxy"; string inputS = Console.ReadLine().Trim(); if (inputS == "z") { return; } int inputindex = charString.IndexOf(inputS); if (inputindex < 0) { return; } int nextIndex = inputindex + 1; string nextShar = charString.Substring(nextIndex, 1); Console.WriteLine(nextShar); // Debug.WriteLine(nextShar); } } }
using System; using System.Diagnostics; namespace atcode { class Program { static void Main(string[] args) { string charString = "abcdefghijklmnopqrstuvwxyz"; string inputS = Console.ReadLine().Trim(); if (inputS == "z") { return; } int inputindex = charString.IndexOf(inputS); if (inputindex < 0) { return; } int nextIndex = inputindex + 1; string nextShar = charString.Substring(nextIndex, 1); Console.WriteLine(nextShar); // Debug.WriteLine(nextShar); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
8
106
2
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp15 { class Class102 { static void Main() { var NM = Console.ReadLine().Split(); int N = int.Parse(NM[0]); int M = int.Parse(NM[1]); bool[] Table = new bool[N]; int[] wa = new int[N]; int WA = 0; for (int i = 0; i < M; i++) { var r = Console.ReadLine().Split(); int p = int.Parse(r[0]); string S = r[1]; if (!Table[p - 1]) { if (S == "WA") wa[p - 1]++; else { Table[p - 1] = true; WA += wa[p - 1]; } } } int ac = Table.Count(x => x == true); Console.WriteLine($"{ac} {wa}"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp15 { class Class102 { static void Main() { var NM = Console.ReadLine().Split(); int N = int.Parse(NM[0]); int M = int.Parse(NM[1]); bool[] Table = new bool[N]; int[] wa = new int[N]; int WA = 0; for (int i = 0; i < M; i++) { var r = Console.ReadLine().Split(); int p = int.Parse(r[0]); string S = r[1]; if (!Table[p - 1]) { if (S == "WA") wa[p - 1]++; else { Table[p - 1] = true; WA += wa[p - 1]; } } } int ac = Table.Count(x => x == true); Console.WriteLine($"{ac} {WA}"); } } }
[["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22]]
8
224
2
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] NK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int N = NK[0]; int K = NK[1]; if (K == 0) { Console.WriteLine("0 0"); } int[] A = new int[N]; Boolean[] B = new Boolean[N]; for (int i = 0; i < K; i++) { string[] vs = Console.ReadLine().Split(' '); int P = int.Parse(vs[0]) - 1; string S = vs[1]; if (!B[P]) { if ("AC" == S) { B[P] = true; } else { A[P] += 1; } } } int okcnt = 0; int ngcnt = 0; for (int i = 0; i < N; i++) { if (B[i]) { okcnt++; ngcnt += A[i]; } } Console.WriteLine(okcnt + " " + ngcnt); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] NK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int N = NK[0]; int K = NK[1]; if (K == 0) { Console.WriteLine("0 0"); return; } int[] A = new int[N]; Boolean[] B = new Boolean[N]; for (int i = 0; i < K; i++) { string[] vs = Console.ReadLine().Split(' '); int P = int.Parse(vs[0]) - 1; string S = vs[1]; if (!B[P]) { if ("AC" == S) { B[P] = true; } else { A[P] += 1; } } } int okcnt = 0; int ngcnt = 0; for (int i = 0; i < N; i++) { if (B[i]) { okcnt++; ngcnt += A[i]; } } Console.WriteLine(okcnt + " " + ngcnt); } } } // long n = long.Parse(Console.ReadLine()); // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(cnt); // Console.ReadKey();
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
8
275
2
using System; using System.Linq; using System.Collections.Generic; namespace lineAralgebra { class Program { public static void Main(String[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = input[0]; var m = input[1]; var correctSet = new HashSet<int>(); // var wrongSet = new HashSet<int>(); var wrongCount = 0; var p_count = new int[n]; for (var i = 0; i < m; i++) { var a = Console.ReadLine().Split(); var p = int.Parse(a[0]); var s = a[1]; if (s == "AC" && !correctSet.Contains(p)) { correctSet.Add(p); } else if (s == "WA" && !correctSet.Contains(p)) { p_count[p]++; } } foreach (var set in correctSet) { wrongCount += p_count[set]; } System.Console.WriteLine(correctSet.Count + " " + wrongCount); } } }
using System; using System.Linq; using System.Collections.Generic; namespace lineAralgebra { class Program { public static void Main(String[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int n = input[0]; var m = input[1]; var correctSet = new HashSet<int>(); // var wrongSet = new HashSet<int>(); var wrongCount = 0; var p_count = new int[n + 1]; for (var i = 0; i < m; i++) { var a = Console.ReadLine().Split(); var p = int.Parse(a[0]); var s = a[1]; if (s == "AC" && !correctSet.Contains(p)) { correctSet.Add(p); } else if (s == "WA" && !correctSet.Contains(p)) { p_count[p]++; } } foreach (var set in correctSet) { wrongCount += p_count[set]; } System.Console.WriteLine(correctSet.Count + " " + wrongCount); } } }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
8
234
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class C { static void Main() { int[] intRecord = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var N = intRecord[0]; var M = intRecord[1]; int p_i = 0; var S_i = string.Empty; var ac = new int[N]; var temp = new int[N]; int ACCount = 0; int WACount = 0; for (int i = 0; i < M; i++) { string[] lineRecord = Console.ReadLine().Trim().Split(' '); p_i = int.Parse(lineRecord[0]) - 1; S_i = lineRecord[1]; if (ac[p_i] == p_i) continue; if (S_i == "WA" && temp[p_i] != null) temp[p_i]++; else if (S_i == "WA" && temp[p_i] == null) temp[p_i] = 1; else if (S_i == "AC") { WACount += temp[p_i]; ACCount++; ac[p_i] = p_i; } } Console.WriteLine(ACCount.ToString() + " " + WACount.ToString()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class C { static void Main() { int[] intRecord = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var N = intRecord[0]; var M = intRecord[1]; int p_i = 0; var S_i = string.Empty; var ac = new int[N]; var temp = new int[N]; int ACCount = 0; int WACount = 0; for (int i = 0; i < M; i++) { string[] lineRecord = Console.ReadLine().Trim().Split(' '); p_i = int.Parse(lineRecord[0]) - 1; S_i = lineRecord[1]; if (ac[p_i] == 1) continue; if (S_i == "WA" && temp[p_i] != null) temp[p_i]++; else if (S_i == "WA" && temp[p_i] == null) temp[p_i] = 1; else if (S_i == "AC") { WACount += temp[p_i]; ACCount++; ac[p_i] = 1; } } Console.WriteLine(ACCount.ToString() + " " + WACount.ToString()); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
284
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { var str = IO.ReadLineToIntList(); var N = str[0]; var M = str[1]; Dictionary<int, int> q = new Dictionary<int, int>(); for (int i = 0; i < N; i++) { q[i] = 0; } int ac = 0; int wa = 0; for (int i = 0; i < M; i++) { var s = IO.ReadLineToStringList(); var p = int.Parse(s[0]); var S = s[1]; if (S == "WA" && q[p - 1] > 0) { q[p - 1]++; } else if (S == "AC" && q[p - 1] != -1) { ac++; wa += q[p - 1]; q[p - 1] = -1; } } Console.WriteLine(ac + " " + wa); Console.ReadKey(); } } static class Func { static public long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { var str = IO.ReadLineToIntList(); var N = str[0]; var M = str[1]; Dictionary<int, int> q = new Dictionary<int, int>(); for (int i = 0; i < N; i++) { q[i] = 0; } int ac = 0; int wa = 0; for (int i = 0; i < M; i++) { var s = IO.ReadLineToStringList(); var p = int.Parse(s[0]); var S = s[1]; if (S == "WA" && q[p - 1] != -1) { q[p - 1]++; } else if (S == "AC" && q[p - 1] != -1) { ac++; wa += q[p - 1]; q[p - 1] = -1; } } Console.WriteLine(ac + " " + wa); Console.ReadKey(); } } static class Func { static public long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 203]]
8
794
5
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] arr = Console.ReadLine().Split(' '); int N = int.Parse(arr[0]); int M = int.Parse(arr[1]); int ac = 0; int wa = 0; bool[] arrAC = new bool[N]; int[] arrWA = Enumerable.Repeat(0, M).ToArray(); for (int i = 0; i < M; i++) { string[] ps = Console.ReadLine().Split(' '); int qNo = int.Parse(ps[0]); if (N < qNo || qNo < 1) { continue; } if (arrAC[qNo - 1]) { continue; } if (ps[1] == "AC") { arrAC[qNo - 1] = true; wa += arrWA[qNo - 1]; ac++; } else { arrWA[qNo - 1]++; } } Console.WriteLine(ac.ToString() + " " + wa.ToString()); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] arr = Console.ReadLine().Split(' '); int N = int.Parse(arr[0]); int M = int.Parse(arr[1]); int ac = 0; int wa = 0; bool[] arrAC = new bool[N]; int[] arrWA = Enumerable.Repeat(0, N).ToArray(); for (int i = 0; i < M; i++) { string[] ps = Console.ReadLine().Split(' '); int qNo = int.Parse(ps[0]); if (N < qNo || qNo < 1) { continue; } if (arrAC[qNo - 1]) { continue; } if (ps[1] == "AC") { arrAC[qNo - 1] = true; wa += arrWA[qNo - 1]; ac++; } else { arrWA[qNo - 1]++; } } Console.WriteLine(ac.ToString() + " " + wa.ToString()); } }
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22]]
8
249
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string Input; int N, M; int ac = 0; int wa = 0; Input = Console.ReadLine(); N = int.Parse(Input.Split(' ')[0]); M = int.Parse(Input.Split(' ')[1]); int[] ac_flag = new int[105000]; int[] wa_count = new int[105000]; for (int i = 0; i < M; i++) { int No; string S; Input = Console.ReadLine(); No = int.Parse(Input.Split(' ')[0]); S = Input.Split(' ')[1]; if (S == "AC") { if (ac_flag[No - 1] == 0) { ac_flag[No - 1] = 1; ac++; wa = wa_count[No - 1]; } } if (S == "WA") { if (ac_flag[No - 1] == 0) { wa_count[No - 1]++; } } } Console.WriteLine("{0} {1}", ac, wa); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string Input; int N, M; int ac = 0; int wa = 0; Input = Console.ReadLine(); N = int.Parse(Input.Split(' ')[0]); M = int.Parse(Input.Split(' ')[1]); int[] ac_flag = new int[105000]; int[] wa_count = new int[105000]; for (int i = 0; i < M; i++) { int No; string S; Input = Console.ReadLine(); No = int.Parse(Input.Split(' ')[0]); S = Input.Split(' ')[1]; if (S == "AC") { if (ac_flag[No - 1] == 0) { ac_flag[No - 1] = 1; ac++; wa += wa_count[No - 1]; } } if (S == "WA") { if (ac_flag[No - 1] == 0) { wa_count[No - 1]++; } } } Console.WriteLine("{0} {1}", ac, wa); } } }
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
8
283
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(' '); string N = a[0]; string M = a[1]; Dictionary<int, List<string>> l = new Dictionary<int, List<string>>(); for (int i = 0; i < int.Parse(M); i++) { string[] b = Console.ReadLine().Split(' '); if (!l.ContainsKey(int.Parse(b[0]))) { l[int.Parse(b[0])] = new List<string>(); } l[int.Parse(b[0])].Add(b[1]); } int ans1 = 0; int ans2 = 0; foreach (var p in l) { if (p.Value.Contains("AC")) { ans1++; ans2 = ans2 - p.Value.TakeWhile(s => s == "WA").Count(); } } Console.Write(ans1.ToString() + " " + ans2.ToString()); // Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(' '); string N = a[0]; string M = a[1]; Dictionary<int, List<string>> l = new Dictionary<int, List<string>>(); for (int i = 0; i < int.Parse(M); i++) { string[] b = Console.ReadLine().Split(' '); if (!l.ContainsKey(int.Parse(b[0]))) { l[int.Parse(b[0])] = new List<string>(); } l[int.Parse(b[0])].Add(b[1]); } int ans1 = 0; int ans2 = 0; foreach (var p in l) { if (p.Value.Contains("AC")) { ans1++; ans2 = ans2 + p.Value.TakeWhile(s => s == "WA").Count(); } } Console.Write(ans1.ToString() + " " + ans2.ToString()); // Console.ReadKey(); } } }
[["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
8
287
2
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int correctNum = 0; int penaltyNum = 0; bool[] probB = new bool[N]; int[] wai = new int[N]; for (int i = 0; i < M; i++) { string[] input1 = Console.ReadLine().Split(' '); int probNum = int.Parse(input1[0]); if (!probB[probNum]) { if (input1[1] == "WA") { wai[probNum]++; } else { correctNum++; penaltyNum += wai[probNum]; probB[probNum] = true; } } } Console.WriteLine(correctNum + " " + penaltyNum); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int correctNum = 0; int penaltyNum = 0; bool[] probB = new bool[N]; int[] wai = new int[N]; for (int i = 0; i < M; i++) { string[] input1 = Console.ReadLine().Split(' '); int probNum = int.Parse(input1[0]) - 1; if (!probB[probNum]) { if (input1[1] == "WA") { wai[probNum]++; } else { correctNum++; penaltyNum += wai[probNum]; probB[probNum] = true; } } } Console.WriteLine(correctNum + " " + penaltyNum); } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
203
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; namespace Atcoder { class Program { public static int h; public static int w; static void Main(string[] args) { StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); h = scan.Integer(); w = scan.Integer(); char[,] map = new char[h, w]; int max = 0; for (int i = 0; i < h; i++) { var read = Console.ReadLine().ToCharArray(); for (int k = 0; k < w; k++) { map[i, k] = read[k]; } } for (int i = 0; i < h; i++) { for (int k = 0; k < w; k++) { if (map[i, k] == '#') continue; max = Math.Max(max, BFS(i, k, map)); } } Console.WriteLine(max); } public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading.Tasks; using System.Globalization; namespace Atcoder { class Program { public static int h; public static int w; static void Main(string[] args) { StreamScanner scan = new StreamScanner(System.Console.OpenStandardInput()); h = scan.Integer(); w = scan.Integer(); char[,] map = new char[h, w]; int max = 0; for (int i = 0; i < h; i++) { var read = scan.Scan().ToCharArray(); for (int k = 0; k < w; k++) { map[i, k] = read[k]; } } for (int i = 0; i < h; i++) { for (int k = 0; k < w; k++) { if (map[i, k] == '#') continue; max = Math.Max(max, BFS(i, k, map)); } } Console.WriteLine(max); } public static int BFS(int height, int width, char[,] map) { int[] dx = new int[] { -1, 0, 0, 1 }; int[] dy = new int[] { 0, 1, -1, 0 }; bool[,] visited = new bool[h, w]; int[,] len = new int[h, w]; var queue = new Queue<Tuple<int, int>>(); queue.Enqueue(new Tuple<int, int>(height, width)); int max = 0; visited[height, width] = true; while (queue.Count > 0) { var now = queue.Dequeue(); for (int i = 0; i < 4; i++) { int ny = now.Item1 + dy[i]; int nx = now.Item2 + dx[i]; if (ny >= h || ny < 0 || nx >= w || nx < 0) continue; if (visited[ny, nx] || map[ny, nx] == '#') continue; visited[ny, nx] = true; len[ny, nx] = len[now.Item1, now.Item2] + 1; max = Math.Max(max, len[ny, nx]); queue.Enqueue(new Tuple<int, int>(ny, nx)); } } return max; } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } public class UnionFind { public int[] data; public UnionFind(int size) { data = new int[size]; for (int i = 0; i < size; i++) data[i] = -1; } public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x != y) { if (data[y] < data[x]) { var tmp = y; y = x; x = tmp; } data[x] += data[y]; data[y] = x; } return x != y; } public bool IsSameGroup(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return data[x] < 0 ? x : data[x] = Root(data[x]); } } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
8
1,103
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>(); static long mod = 1000000007; static long[] factorial = new long[100001]; static long[] invFactorial = new long[100001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } static void Main(string[] args) { var AA = ReadLongArr(); var N = AA[0]; var K = AA[1]; calcFanctorial(N); var ll = ReadLongArr(); Array.Sort(ll); long res = 0; for (int i = 0; i < N; i++) { res += ll[N - 1 - i] * nCm(N - 1 - i, K - 1); res %= mod; res -= ll[i] * nCm(N - 1 - i, K - 1); res %= mod; } res = (res % mod + mod) % mod; Console.WriteLine(res); } private static long nCm(long n, long m) { if (n < m) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>(); static long mod = 1000000007; static long[] factorial = new long[100001]; static long[] invFactorial = new long[100001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } static void Main(string[] args) { var AA = ReadLongArr(); var N = AA[0]; var K = AA[1]; calcFanctorial(N); var ll = ReadLongArr(); Array.Sort(ll); long res = 0; for (int i = 0; i < N; i++) { res += ll[N - 1 - i] * nCm(N - 1 - i, K - 1); res %= mod; res -= ll[i] * nCm(N - 1 - i, K - 1); res %= mod; } res = (res % mod + mod) % mod; Console.WriteLine(res); } private static long nCm(long n, long m) { if (n < m) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
650
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC151F { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} class EncloseCircle { public EncloseCircle() { pointList = new List<Point>(); } public struct Point { public double x; public double y; static public Point operator +(Point a, Point b) => new Point() { x = a.x + b.x, y = a.y + b.y }; static public Point operator -(Point a, Point b) => new Point() { x = a.x - b.x, y = a.y - b.y }; static public Point operator *(Point p, double v) => new Point() { x = p.x * v, y = p.y * v }; static public Point operator *(double v, Point p) => p * v; static public Point operator /(Point p, double v) => new Point() { x = p.x / v, y = p.y / v }; static public Point operator /(double v, Point p) => p / v; } static double EPS = 1e-10; public struct Circle { public Point p; public double r; } List<Point> pointList; public void AddPoint(double x, double y) { pointList.Add(new Point() { x = x, y = y }); } double Norm(Point p) => Sqrt(p.x * p.x + p.y * p.y); double Cross(Point p1, Point p2) => p1.x * p2.y - p1.y * p2.x; public Circle GetEncloseCircle() { if (pointList.Count < 2) throw new Exception(); var list = pointList.OrderByRand().ToList(); Func<Point, Point, Point, Circle> mc3 = null; mc3 = (a, b, c) => { var A = Norm(b - c); var B = Norm(c - a); var C = Norm(a - b); var S = Abs(Cross(b - a, c - a)); var p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S); var r = Norm(p - a); return new Circle() { p = p, r = r }; }; Func<Point, Point, Circle> mc2 = null; mc2 = (a, b) => { var c = (a + b) / 2; var r = Norm(a - c); return new Circle() { p = c, r = r }; }; Func<Point, Circle, bool> inCircle = null; inCircle = (p, c) => Norm(p - c.p) <= c.r + EPS; { var c = mc2(list[0], list[1]); for (var i = 2; i < list.Count; i++) { if (!inCircle(list[i], c)) { c = mc2(list[0], list[i]); for (var j = 1; j < i; j++) { if (!inCircle(list[j], c)) { c = mc2(list[i], list[j]); for (var k = 0; k < j; k++) { if (!inCircle(list[k], c)) { c = mc3(list[i], list[j], list[k]); } } } } } } return c; } } } static public void Solve() { var N = NN; var xy = Repeat(0, N).Select(_ => new { x = NN, y = NN }).ToArray(); var c = new EncloseCircle(); foreach (var item in xy) { c.AddPoint(item.x, item.y); } Console.WriteLine(c.GetEncloseCircle().r); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library {}
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC151F { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} class EncloseCircle { public EncloseCircle() { pointList = new List<Point>(); } public struct Point { public double x; public double y; static public Point operator +(Point a, Point b) => new Point() { x = a.x + b.x, y = a.y + b.y }; static public Point operator -(Point a, Point b) => new Point() { x = a.x - b.x, y = a.y - b.y }; static public Point operator *(Point p, double v) => new Point() { x = p.x * v, y = p.y * v }; static public Point operator *(double v, Point p) => p * v; static public Point operator /(Point p, double v) => new Point() { x = p.x / v, y = p.y / v }; static public Point operator /(double v, Point p) => p / v; } static double EPS = 1e-10; public struct Circle { public Point p; public double r; } List<Point> pointList; public void AddPoint(double x, double y) { pointList.Add(new Point() { x = x, y = y }); } double Norm(Point p) => p.x * p.x + p.y * p.y; double Cross(Point p1, Point p2) => p1.x * p2.y - p1.y * p2.x; public Circle GetEncloseCircle() { if (pointList.Count < 2) throw new Exception(); var list = pointList.OrderByRand().ToList(); Func<Point, Point, Point, Circle> mc3 = null; mc3 = (a, b, c) => { var A = Norm(b - c); var B = Norm(c - a); var C = Norm(a - b); var S = Abs(Cross(b - a, c - a)); var p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S); var r = Norm(p - a); return new Circle() { p = p, r = r }; }; Func<Point, Point, Circle> mc2 = null; mc2 = (a, b) => { var c = (a + b) / 2; var r = Norm(a - c); return new Circle() { p = c, r = r }; }; Func<Point, Circle, bool> inCircle = null; inCircle = (p, c) => Norm(p - c.p) <= c.r + EPS; { var c = mc2(list[0], list[1]); for (var i = 2; i < list.Count; i++) { if (!inCircle(list[i], c)) { c = mc2(list[0], list[i]); for (var j = 1; j < i; j++) { if (!inCircle(list[j], c)) { c = mc2(list[i], list[j]); for (var k = 0; k < j; k++) { if (!inCircle(list[k], c)) { c = mc3(list[i], list[j], list[k]); } } } } } } return c; } } } static public void Solve() { var N = NN; var xy = Repeat(0, N).Select(_ => new { x = NN, y = NN }).ToArray(); var c = new EncloseCircle(); foreach (var item in xy) { c.AddPoint(item.x, item.y); } Console.WriteLine(Sqrt(c.GetEncloseCircle().r)); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library {}
[["-", 8, 201, 0, 195, 8, 306, 0, 213, 63, 22], ["-", 0, 195, 8, 306, 0, 213, 3, 4, 0, 24], ["-", 0, 195, 8, 306, 0, 213, 3, 4, 0, 25], ["+", 8, 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, 25]]
8
1,527
6
using System; using System.Linq; using System.Collections.Generic; namespace Contest { partial class Program { static void Main(string[] args) { ABC151F(); } static void ABC151A() { var s = ReadStr(); Console.WriteLine((char)(s[0] + 1)); } static void ABC151B() { var nkm = ReadIntN(); var A = ReadIntN(); var N = nkm[0]; var K = nkm[1]; var M = nkm[2]; var goal = N * M - A.Sum(); Console.WriteLine(goal > K ? -1 : (goal < 0 ? 0 : goal)); } static void ABC151C() { var nm = ReadIntN(); var PS = ReadTupleStr(nm[1]); var N = nm[0]; int[] ac = new int[N + 1]; int[] wa = new int[N + 1]; foreach (var ps in PS) { var n = Convert.ToInt32(ps.Item1); if (ps.Item2 == "AC") { ac[n] = 1; } else { if (ac[n] == 0) { wa[n]++; } } } long countAC = ac.Sum(); long countWA = Enumerable.Range(0, ac.Length).Select(i => ac[i] > 0 ? wa[i] : 0).Sum(); Console.WriteLine("{0} {1}", countAC, countWA); } static void ABC151D() { var hw = ReadIntN(); var H = hw[0]; var W = hw[1]; bool[,] road = new bool[H + 2, W + 2]; for (int h = 0; h < H; ++h) { var str = ReadStr(); for (int w = 0; w < W; ++w) { road[h + 1, w + 1] = str[w] == '.'; } } Tuple<int, int>[] moves = new Tuple<int, int>[] { new Tuple<int, int>(-1, 0), new Tuple<int, int>(1, 0), new Tuple<int, int>(0, -1), new Tuple<int, int>(0, 1) }; int max = 0; for (int startH = 1; startH <= H; ++startH) { for (int startW = 1; startW <= W; ++startW) { if (!road[startH, startW]) { continue; } bool[,] done = new bool[H + 2, W + 2]; List<Tuple<int, int>> list = new List<Tuple<int, int>>(); done[startH, startW] = true; list.Add(new Tuple<int, int>(startH, startW)); int counter = -1; while (list.Count > 0) { List<Tuple<int, int>> next = new List<Tuple<int, int>>(); foreach (var t in list) { foreach (var move in moves) { var h = t.Item1 + move.Item1; var w = t.Item2 + move.Item2; if (!done[h, w] && road[h, w]) { done[h, w] = true; next.Add(new Tuple<int, int>(h, w)); } } } list = next; counter++; } max = Math.Max(max, counter); } } Console.WriteLine(max); } static void ABC151E() { var nk = ReadIntN(); var A = ReadLongN(); var N = nk[0]; var K = nk[1]; A = A.OrderBy(x => x).ToArray(); var combFunc = Util.Combin(N, Util.P); long sumMax = 0; long sumMin = 0; for (int i = 0; i < N; ++i) { sumMax = (sumMax + combFunc(i, K - 1) * A[i]) % Util.P; sumMin = (sumMin + combFunc(N - i - 1, K - 1) * A[i]) % Util.P; } Console.WriteLine((sumMax - sumMin + Util.P * 10) % Util.P); } static void ABC151F() { var N = ReadInt(); var XY = ReadTupleDouble(N); double eps = 1e-8; double min = Double.MaxValue; /// 2点間の距離 Func<Tuple<double, double>, Tuple<double, double>, double> distance = (a, b) => { var diff1 = a.Item1 - b.Item1; var diff2 = a.Item2 - b.Item2; return Math.Sqrt(diff1 * diff1 + diff2 * diff2); }; /// 最小の半径を与える円は以下のいずれか /// (1) ある2点を直径とする /// (2) ある3点を通る /// ある2点を直径とする for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { var p = XY[i]; var q = XY[j]; ///中心o 半径r var o = new Tuple<double, double>((p.Item1 + q.Item1) / 2, (p.Item2 + q.Item2) / 2); var r = distance(p, o); /// 全点がoからr以内にあればOK bool ok = true; for (int k = 0; k < N; ++k) { if (distance(XY[k], o) > r + eps) { ok = false; break; } } if (ok) { min = Math.Min(min, r); } } } /// ある3点を通る for (int i = 0; i < N; ++i) { var I = XY[i]; for (int j = i + 1; j < N; ++j) { var J = XY[j]; /// 線分(I,J)の垂直二等分線 a1 x + b1 y + c1 =0 var a1 = J.Item1 - I.Item1; var b1 = J.Item2 - I.Item2; var c1 = -a1 * (I.Item1 + J.Item1) / 2 - b1 * (I.Item2 + J.Item2) / 2; for (int k = j + 1; k < N; ++k) { var K = XY[k]; /// 線分(I,K)の垂直二等分線 a2 x + b2 y + c2 =0 var a2 = K.Item1 - I.Item1; var b2 = K.Item2 - I.Item2; var c2 = -a2 * (I.Item1 + K.Item1) / 2 - b2 * (I.Item2 + K.Item2) / 2; /// 垂直二等分線が平行=3点が同一直線上にあるので円は存在しない var a1b2a2b1 = a1 * b2 - a2 * b1; if (Math.Abs(a1b2a2b1) < eps) { continue; } /// 垂直二等分線の交点が円の中心 var ox = (c2 * b1 - c1 * b2) / a1b2a2b1; var oy = -(c2 * a1 - c1 * a1) / a1b2a2b1; var o = new Tuple<double, double>(ox, oy); var r = distance(o, I); /// 全点がoからr以内にあればOK bool ok = true; for (int l = 0; l < N; ++l) { if (distance(XY[l], o) > r + eps) { ok = false; break; } } if (ok) { min = Math.Min(min, r); } } } } Console.WriteLine(min); } class Util { public static readonly long P = 1000000007; public static Dictionary<long, int> Factorize(long x) { var dict = new Dictionary<long, int>(); long minp = 2; while (x > 1) { bool ok = false; for (long p = minp; p * p <= x; ++p) { if (x % p == 0) { if (!dict.ContainsKey(p)) { dict.Add(p, 0); } dict[p]++; minp = p; x /= p; ok = true; break; } } if (!ok) { if (!dict.ContainsKey(x)) { dict.Add(x, 0); } dict[x]++; break; } } return dict; } public static long Inverse(long a, long p) { long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public static long[] Facts(int n, long p) { var facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; ++i) { facts[i] = (i * facts[i - 1]) % p; } return facts; } public static Func<int, int, long> Combin(int n, long P) { var fact = Facts(n, P); var inv = fact.Select(x => Inverse(x, P)).ToArray(); return (N, M) => { if (N < 0 || N < M || M < 0) { return 0; } return (((fact[N] * inv[M]) % P) * inv[N - M]) % P; }; } } static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrN() { return Console.ReadLine().Split(' '); } static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } static int[] ReadIntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } static long[] ReadLongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } static Tuple<string, string>[] ReadTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReadTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReadTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { partial class Program { static void Main(string[] args) { ABC151F(); } static void ABC151A() { var s = ReadStr(); Console.WriteLine((char)(s[0] + 1)); } static void ABC151B() { var nkm = ReadIntN(); var A = ReadIntN(); var N = nkm[0]; var K = nkm[1]; var M = nkm[2]; var goal = N * M - A.Sum(); Console.WriteLine(goal > K ? -1 : (goal < 0 ? 0 : goal)); } static void ABC151C() { var nm = ReadIntN(); var PS = ReadTupleStr(nm[1]); var N = nm[0]; int[] ac = new int[N + 1]; int[] wa = new int[N + 1]; foreach (var ps in PS) { var n = Convert.ToInt32(ps.Item1); if (ps.Item2 == "AC") { ac[n] = 1; } else { if (ac[n] == 0) { wa[n]++; } } } long countAC = ac.Sum(); long countWA = Enumerable.Range(0, ac.Length).Select(i => ac[i] > 0 ? wa[i] : 0).Sum(); Console.WriteLine("{0} {1}", countAC, countWA); } static void ABC151D() { var hw = ReadIntN(); var H = hw[0]; var W = hw[1]; bool[,] road = new bool[H + 2, W + 2]; for (int h = 0; h < H; ++h) { var str = ReadStr(); for (int w = 0; w < W; ++w) { road[h + 1, w + 1] = str[w] == '.'; } } Tuple<int, int>[] moves = new Tuple<int, int>[] { new Tuple<int, int>(-1, 0), new Tuple<int, int>(1, 0), new Tuple<int, int>(0, -1), new Tuple<int, int>(0, 1) }; int max = 0; for (int startH = 1; startH <= H; ++startH) { for (int startW = 1; startW <= W; ++startW) { if (!road[startH, startW]) { continue; } bool[,] done = new bool[H + 2, W + 2]; List<Tuple<int, int>> list = new List<Tuple<int, int>>(); done[startH, startW] = true; list.Add(new Tuple<int, int>(startH, startW)); int counter = -1; while (list.Count > 0) { List<Tuple<int, int>> next = new List<Tuple<int, int>>(); foreach (var t in list) { foreach (var move in moves) { var h = t.Item1 + move.Item1; var w = t.Item2 + move.Item2; if (!done[h, w] && road[h, w]) { done[h, w] = true; next.Add(new Tuple<int, int>(h, w)); } } } list = next; counter++; } max = Math.Max(max, counter); } } Console.WriteLine(max); } static void ABC151E() { var nk = ReadIntN(); var A = ReadLongN(); var N = nk[0]; var K = nk[1]; A = A.OrderBy(x => x).ToArray(); var combFunc = Util.Combin(N, Util.P); long sumMax = 0; long sumMin = 0; for (int i = 0; i < N; ++i) { sumMax = (sumMax + combFunc(i, K - 1) * A[i]) % Util.P; sumMin = (sumMin + combFunc(N - i - 1, K - 1) * A[i]) % Util.P; } Console.WriteLine((sumMax - sumMin + Util.P * 10) % Util.P); } static void ABC151F() { var N = ReadInt(); var XY = ReadTupleDouble(N); double eps = 1e-8; double min = Double.MaxValue; /// 2点間の距離 Func<Tuple<double, double>, Tuple<double, double>, double> distance = (a, b) => { var diff1 = a.Item1 - b.Item1; var diff2 = a.Item2 - b.Item2; return Math.Sqrt(diff1 * diff1 + diff2 * diff2); }; /// 最小の半径を与える円は以下のいずれか /// (1) ある2点を直径とする /// (2) ある3点を通る /// ある2点を直径とする for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { var p = XY[i]; var q = XY[j]; ///中心o 半径r var o = new Tuple<double, double>((p.Item1 + q.Item1) / 2, (p.Item2 + q.Item2) / 2); var r = distance(p, o); /// 全点がoからr以内にあればOK bool ok = true; for (int k = 0; k < N; ++k) { if (distance(XY[k], o) > r + eps) { ok = false; break; } } if (ok) { min = Math.Min(min, r); } } } /// ある3点を通る for (int i = 0; i < N; ++i) { var I = XY[i]; for (int j = i + 1; j < N; ++j) { var J = XY[j]; /// 線分(I,J)の垂直二等分線 a1 x + b1 y + c1 =0 var a1 = J.Item1 - I.Item1; var b1 = J.Item2 - I.Item2; var c1 = -a1 * (I.Item1 + J.Item1) / 2 - b1 * (I.Item2 + J.Item2) / 2; for (int k = j + 1; k < N; ++k) { var K = XY[k]; /// 線分(I,K)の垂直二等分線 a2 x + b2 y + c2 =0 var a2 = K.Item1 - I.Item1; var b2 = K.Item2 - I.Item2; var c2 = -a2 * (I.Item1 + K.Item1) / 2 - b2 * (I.Item2 + K.Item2) / 2; /// 垂直二等分線が平行=3点が同一直線上にあるので円は存在しない var a1b2a2b1 = a1 * b2 - a2 * b1; if (Math.Abs(a1b2a2b1) < eps) { continue; } /// 垂直二等分線の交点が円の中心 var ox = (c2 * b1 - c1 * b2) / a1b2a2b1; var oy = -(c2 * a1 - c1 * a2) / a1b2a2b1; var o = new Tuple<double, double>(ox, oy); var r = distance(o, I); /// 全点がoからr以内にあればOK bool ok = true; for (int l = 0; l < N; ++l) { if (distance(XY[l], o) > r + eps) { ok = false; break; } } if (ok) { min = Math.Min(min, r); } } } } Console.WriteLine(min); } class Util { public static readonly long P = 1000000007; public static Dictionary<long, int> Factorize(long x) { var dict = new Dictionary<long, int>(); long minp = 2; while (x > 1) { bool ok = false; for (long p = minp; p * p <= x; ++p) { if (x % p == 0) { if (!dict.ContainsKey(p)) { dict.Add(p, 0); } dict[p]++; minp = p; x /= p; ok = true; break; } } if (!ok) { if (!dict.ContainsKey(x)) { dict.Add(x, 0); } dict[x]++; break; } } return dict; } public static long Inverse(long a, long p) { long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public static long[] Facts(int n, long p) { var facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; ++i) { facts[i] = (i * facts[i - 1]) % p; } return facts; } public static Func<int, int, long> Combin(int n, long P) { var fact = Facts(n, P); var inv = fact.Select(x => Inverse(x, P)).ToArray(); return (N, M) => { if (N < 0 || N < M || M < 0) { return 0; } return (((fact[N] * inv[M]) % P) * inv[N - M]) % P; }; } } static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrN() { return Console.ReadLine().Split(' '); } static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } static int[] ReadIntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } static long[] ReadLongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } static Tuple<string, string>[] ReadTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReadTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReadTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } } }
[["-", 31, 241, 0, 23, 0, 16, 12, 16, 12, 22], ["+", 31, 241, 0, 23, 0, 16, 12, 16, 12, 22]]
8
2,428
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_151 { class F { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int n = ReadInt(); double[][] xys = new double [n][]; for (int i = 0; i < n; i++) { xys[i] = ReadDoubles(); } double res = long.MaxValue; double thres = 0.0000001; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { double x = (xys[i][0] + xys[j][0]) / 2; double y = (xys[i][1] + xys[j][1]) / 2; double r2 = (x - xys[i][0]) * (x - xys[i][0]) + (y - xys[i][1]) * (y - xys[i][1]); bool ok = true; for (int k = 0; k < n; k++) { double tmpR2 = (x - xys[k][0]) * (x - xys[k][0]) + (y - xys[k][1]) * (y - xys[k][1]); if (tmpR2 < r2 + thres) continue; else { ok = false; break; } } if (ok) res = Min(res, r2); } } if (n == 2) { WriteLine(Sqrt(res)); return; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { double[] a = new double[2] { xys[j][0] - xys[i][0], xys[j][1] - xys[i][1] }; double[] b = new double[2] { xys[k][0] - xys[i][0], xys[k][1] - xys[i][1] }; double a2 = a[0] * a[0] * a[1] * a[1]; double b2 = b[0] * b[0] * b[1] * b[1]; double ab = a[0] * b[0] + a[1] * b[1]; double s = 0.5 * (1 - ab * (ab - b2) / (ab * ab - a2 * b2)); double t = 0.5 * a2 * (ab - b2) / (ab * ab - a2 * b2); double x = xys[i][0] + a[0] * s + b[0] * t; double y = xys[i][1] + a[1] * s + b[1] * t; double r2 = (x - xys[i][0]) * (x - xys[i][0]) + (y - xys[i][1]) * (y - xys[i][1]); bool ok = true; for (int l = 0; l < n; l++) { double tmpR2 = (x - xys[l][0]) * (x - xys[l][0]) + (y - xys[l][1]) * (y - xys[l][1]); if (tmpR2 < r2 + thres) continue; else { ok = false; break; } } if (ok) res = Min(res, r2); } } } WriteLine(Sqrt(res)); } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_151 { class F { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int n = ReadInt(); double[][] xys = new double [n][]; for (int i = 0; i < n; i++) { xys[i] = ReadDoubles(); } double res = long.MaxValue; double thres = 0.0000001; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { double x = (xys[i][0] + xys[j][0]) / 2; double y = (xys[i][1] + xys[j][1]) / 2; double r2 = (x - xys[i][0]) * (x - xys[i][0]) + (y - xys[i][1]) * (y - xys[i][1]); bool ok = true; for (int k = 0; k < n; k++) { double tmpR2 = (x - xys[k][0]) * (x - xys[k][0]) + (y - xys[k][1]) * (y - xys[k][1]); if (tmpR2 < r2 + thres) continue; else { ok = false; break; } } if (ok) res = Min(res, r2); } } if (n == 2) { WriteLine(Sqrt(res)); return; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { double[] a = new double[2] { xys[j][0] - xys[i][0], xys[j][1] - xys[i][1] }; double[] b = new double[2] { xys[k][0] - xys[i][0], xys[k][1] - xys[i][1] }; double a2 = a[0] * a[0] + a[1] * a[1]; double b2 = b[0] * b[0] + b[1] * b[1]; double ab = a[0] * b[0] + a[1] * b[1]; double s = 0.5 * (1 - ab * (ab - b2) / (ab * ab - a2 * b2)); double t = 0.5 * a2 * (ab - b2) / (ab * ab - a2 * b2); double x = xys[i][0] + a[0] * s + b[0] * t; double y = xys[i][1] + a[1] * s + b[1] * t; double r2 = (x - xys[i][0]) * (x - xys[i][0]) + (y - xys[i][1]) * (y - xys[i][1]); bool ok = true; for (int l = 0; l < n; l++) { double tmpR2 = (x - xys[l][0]) * (x - xys[l][0]) + (y - xys[l][1]) * (y - xys[l][1]); if (tmpR2 < r2 + thres) continue; else { ok = false; break; } } if (ok) res = Min(res, r2); } } } WriteLine(Sqrt(res)); } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72]]
8
1,066
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Program { private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } class Point { public readonly double x; public readonly double y; public Point(double[] args) { x = args[0]; y = args[1]; } public Point(double x, double y) { this.x = x; this.y = y; } } static bool Online(Point p1, Point p2, Point p3) { return p1.y * (p2.x - p3.x) + p2.y * (p3.x - p1.x) + p3.y * (p1.x - p2.x) == 0; } static Point Center(Point p1, Point p2, Point p3) { double a = p2.x - p1.x; double b = p2.y - p1.y; double c = p3.x - p1.x; double d = p3.y - p1.y; double x = p1.x + (d * (a * a + b * b) - b * (c * c + d * d)) / (a * d - b * c) / 2; double y = (b != 0) ? (a * (p1.x + p2.x - x - x) + b * (p1.y + p2.y)) / b / 2 : (c * (p1.x + p3.x - x - x) + d * (p1.y + p3.y)) / d / 2; return new Point(x, y); } static double Distance(Point p1, Point p2) { double x = p1.x - p2.x; double y = p1.y - p2.y; return Math.Sqrt(x * x + y * y); } static double Solve(int N, Point[] P) { double min = double.MaxValue; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { { var o = new Point((P[i].x + P[j].x) * 0.5, (P[i].y + P[j].y) * 0.5); double r = Distance(P[i], P[j]) * 0.5; if (P.All(p => Distance(o, p) <= r)) { min = Math.Min(r, min); } } for (int k = j + 1; k < N; ++k) { if (!Online(P[i], P[j], P[k])) { var o = Center(P[i], P[j], P[k]); double r = Distance(P[i], o); if (P.All(p => Distance(o, p) <= r)) { min = Math.Min(r, min); } } } } } return min; } static void Main(string[] args) { int N = ReadInt(); var P = new Point[N]; for (int i = 0; i < N; ++i) { P[i] = new Point(ReadDoubles()); } Console.WriteLine(Solve(N, P)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Program { private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } class Point { public readonly double x; public readonly double y; public Point(double[] args) { x = args[0]; y = args[1]; } public Point(double x, double y) { this.x = x; this.y = y; } } static bool Online(Point p1, Point p2, Point p3) { return p1.y * (p2.x - p3.x) + p2.y * (p3.x - p1.x) + p3.y * (p1.x - p2.x) == 0; } static Point Center(Point p1, Point p2, Point p3) { double a = p2.x - p1.x; double b = p2.y - p1.y; double c = p3.x - p1.x; double d = p3.y - p1.y; double x = p1.x + (d * (a * a + b * b) - b * (c * c + d * d)) / (a * d - b * c) / 2; double y = (b != 0) ? (a * (p1.x + p2.x - x - x) + b * (p1.y + p2.y)) / b / 2 : (c * (p1.x + p3.x - x - x) + d * (p1.y + p3.y)) / d / 2; return new Point(x, y); } static double Distance(Point p1, Point p2) { double x = p1.x - p2.x; double y = p1.y - p2.y; return Math.Sqrt(x * x + y * y); } static double Solve(int N, Point[] P) { double min = double.MaxValue; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { { var o = new Point((P[i].x + P[j].x) * 0.5, (P[i].y + P[j].y) * 0.5); double r = Distance(P[i], P[j]) * 0.5; if (P.All(p => Distance(o, p) <= r + 1e-6)) { min = Math.Min(r, min); } } for (int k = j + 1; k < N; ++k) { if (!Online(P[i], P[j], P[k])) { var o = Center(P[i], P[j], P[k]); double r = Distance(P[i], o); if (P.All(p => Distance(o, p) <= r + 1e-6)) { min = Math.Min(r, min); } } } } } return min; } static void Main(string[] args) { int N = ReadInt(); var P = new Point[N]; for (int i = 0; i < N; ++i) { P[i] = new Point(ReadDoubles()); } Console.WriteLine(Solve(N, P)); } } }
[["+", 0, 28, 0, 218, 8, 16, 12, 16, 17, 72], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 12, 250]]
8
871
4
using System; namespace dowa6_A { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] s = new string[n]; int[] t = new int[n]; for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); s[i] = input[0]; t[i] = int.Parse(input[1]); } string x = Console.ReadLine(); int count = 0; int target = 0; for (int j = 0; j < n; j++) { if (x == s[j]) { target = j; } } for (int k = target + 1; k < n; k++) { count = +t[k]; } Console.WriteLine(count); } } }
using System; namespace dowa6_A { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] s = new string[n]; int[] t = new int[n]; for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); s[i] = input[0]; t[i] = int.Parse(input[1]); } string x = Console.ReadLine(); int count = 0; int target = 0; for (int j = 0; j < n; j++) { if (x == s[j]) { target = j; } } for (int k = target + 1; k < n; k++) { count += t[k]; } Console.WriteLine(count); } } }
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 241, 0, 72], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
8
200
3
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var K = cin.ReadInt; var X = cin.ReadInt; if (K * 500 <= X) { WriteLine("Yes"); } else { WriteLine("No"); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var K = cin.ReadInt; var X = cin.ReadInt; if (K * 500 >= X) { WriteLine("Yes"); } else { WriteLine("No"); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
465
2
using System; namespace abc150_a { class Program { static void Main(string[] args) { string[] KX = Console.ReadLine().Split(" "); int K = int.Parse(KX[0]); int X = int.Parse(KX[1]); int sum = K * 500; if (X >= sum) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; namespace abc150_a { class Program { static void Main(string[] args) { string[] KX = Console.ReadLine().Split(" "); int K = int.Parse(KX[0]); int X = int.Parse(KX[1]); int sum = K * 500; if (X <= sum) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
102
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { string[] KX = Console.ReadLine().Split(' '); int K = int.Parse(KX[0]); int X = int.Parse(KX[1]); int a = K * X; if (a >= X) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { string[] KX = Console.ReadLine().Split(' '); int K = int.Parse(KX[0]); int X = int.Parse(KX[1]); int a = 500 * K; if (a >= X) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
126
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_150a { class Program { static void Main(string[] args) { int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); if (input[0] >= input[1]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_150a { class Program { static void Main(string[] args) { int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); if (input[0] * 500 >= input[1]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
108
2
using System; using System.Linq; using static System.Console; using System.Collections.Generic; class Program { public static void Main() { var input = ReadLine().Split(' ').Select(int.Parse).ToArray(); if (input[0] * 500 >= input[0]) { Write("Yes"); } else { Write("No"); } } }
using System; using System.Linq; using static System.Console; using System.Collections.Generic; class Program { public static void Main() { var input = ReadLine().Split(' ').Select(int.Parse).ToArray(); if (input[0] * 500 >= input[1]) { Write("Yes"); } else { Write("No"); } } }
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
91
2
using System; public class Hello { public static void Main() { int result; int M = 500; var str = Console.ReadLine().Split(' '); int K = int.Parse(str[0]); int X = int.Parse(str[1]); if (K * M > X) { Console.Write("Yes"); } else { Console.Write("No"); } } }
using System; public class Hello { public static void Main() { int result; int M = 500; var str = Console.ReadLine().Split(' '); int K = int.Parse(str[0]); int X = int.Parse(str[1]); if (K * M >= X) { Console.Write("Yes"); } else { Console.Write("No"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
97
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { int a, b; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); if ((a * 500) < b) Console.WriteLine("NO"); else Console.WriteLine("YES"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { int a, b; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); if ((a * 500) < b) Console.WriteLine("No"); else Console.WriteLine("Yes"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
126
4
using System; class MainClass { public static void Main(string[] args) { var kx = Console.ReadLine().Split(); var k = int.Parse(kx[0]); var x = int.Parse(kx[1]); Console.WriteLine(x < 500 * k ? "No" : "Yes"); } }
using System; class MainClass { public static void Main(string[] args) { var kx = Console.ReadLine().Split(); var k = int.Parse(kx[0]); var x = int.Parse(kx[1]); Console.WriteLine(500 * k < x ? "No" : "Yes"); } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 22]]
8
77
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { int x, k, n; string d; var word = Console.ReadLine().Split(' '); x = int.Parse(word[0]); k = int.Parse(word[1]); n = 500 * x; if (n >= x) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { int x, k, n; string d; var word = Console.ReadLine().Split(' '); x = int.Parse(word[0]); k = int.Parse(word[1]); n = 500 * x; if (k <= n) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
133
4
using System; namespace MyProgram { class AtCoder { public static void Main(string[] args) { int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int K = input[0]; int X = input[1]; Console.WriteLine(K * 500 >= X ? "Yes" : "NO"); } } }
using System; namespace MyProgram { class AtCoder { public static void Main(string[] args) { int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int K = input[0]; int X = input[1]; Console.WriteLine(K * 500 >= X ? "Yes" : "No"); } } }
[["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
85
2
using System; using System.Linq; public class Hello { public static void Main() { var lines = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int coin_count = lines[0]; int border = lines[1]; int value = coin_count * 5; if (value >= border) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; using System.Linq; public class Hello { public static void Main() { var lines = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int coin_count = lines[0]; int border = lines[1]; int value = coin_count * 500; if (value >= border) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
100
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { int K, X; var word = Console.ReadLine().Split(' '); //全体をSpace区切りで文字列として認識 K = int.Parse(word[0]); //文字列から数字を取り出す X = int.Parse(word[1]); //上意 if (500 * K > X) Console.WriteLine("Yes"); //文字列XXXを表示する else Console.WriteLine("No"); //文字列XXXを表示する Console.ReadKey(); //プログラムの最後に書こう } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { int K, X; var word = Console.ReadLine().Split(' '); //全体をSpace区切りで文字列として認識 K = int.Parse(word[0]); //文字列から数字を取り出す X = int.Parse(word[1]); //上意 if (500 * K >= X) Console.WriteLine("Yes"); //文字列XXXを表示する else Console.WriteLine("No"); //文字列XXXを表示する Console.ReadKey(); //プログラムの最後に書こう } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
130
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { int k, x; var word = Console.ReadLine().Split(' '); k = int.Parse(word[0]); x = int.Parse(word[1]); if (500 * k > x) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150A { class Program { static void Main(string[] args) { int k, x; var word = Console.ReadLine().Split(' '); k = int.Parse(word[0]); x = int.Parse(word[1]); if (500 * k >= x) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.ReadKey(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
128
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp12 { class Program { static void Main(string[] args) { var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Console.WriteLine(arr[0] * 500 >= arr[1] ? "Yse" : "No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp12 { class Program { static void Main(string[] args) { var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Console.WriteLine(arr[0] * 500 >= arr[1] ? "Yes" : "No"); } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222]]
8
103
2
using System; class Program { static void Main(string[] args) { int K, X; string[] str = Console.ReadLine().Split(' '); K = int.Parse(str[0]); X = int.Parse(str[1]); if (500 * K > X) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; class Program { static void Main(string[] args) { int K, X; string[] str = Console.ReadLine().Split(' '); K = int.Parse(str[0]); X = int.Parse(str[1]); if (500 * K >= X) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
96
2
using System; class Program { static void Main(string[] args) { // get a integer var input = Console.ReadLine().Split(' '); var K = int.Parse(input[0]); var X = int.Parse(input[1]); if (K * 500 <= X || X == 0) { Console.Write("Yes"); } else { Console.Write("No"); } } }
using System; class Program { static void Main(string[] args) { // get a integer var input = Console.ReadLine().Split(' '); var K = int.Parse(input[0]); var X = int.Parse(input[1]); if (K * 500 >= X || X == 0) { Console.Write("Yes"); } else { Console.Write("No"); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20]]
8
96
2
using System; namespace tst { class Program { public static void Main() { string[] In = Console.ReadLine().Split(' '); int k = int.Parse(In[0]); int x = int.Parse(In[1]); int have = k * 500; if (have >= x) { Console.WriteLine("YES"); } else { Console.WriteLine("No"); } } } }
using System; namespace tst { class Program { public static void Main() { string[] In = Console.ReadLine().Split(' '); int k = int.Parse(In[0]); int x = int.Parse(In[1]); int have = k * 500; if (have >= x) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
99
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC150_A { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var k = cin.ReadInt; var x = cin.ReadInt; var coin = 500; Console.Write(coin * k >= x ? "yes" : "No"); } } 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 ABC150_A { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var k = cin.ReadInt; var x = cin.ReadInt; var coin = 500; Console.Write(coin * k >= x ? "Yes" : "No"); } } 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; } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222]]
8
463
2
using System; using System.Linq; class Program { static void Main(string[] args) { int[] KX = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray(); int K = KX[0], X = KX[1]; string O = 500 * K >= X ? "YES" : "NO"; Console.WriteLine(O); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int[] KX = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray(); int K = KX[0], X = KX[1]; string O = 500 * K >= X ? "Yes" : "No"; Console.WriteLine(O); } }
[["-", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 64, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
96
4
using System; namespace ABC150A { public class MainClass { public static void Main(string[] args) { int[] inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); Console.WriteLine(500 * inp[0] >= inp[1] ? "YES" : "NO"); } } }
using System; namespace ABC150A { public class MainClass { public static void Main(string[] args) { int[] inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); Console.WriteLine(500 * inp[0] >= inp[1] ? "Yes" : "No"); } } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
76
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150_A { class Program { static void Main(string[] args) { var kx = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(kx[0] * 500 > kx[1] ? "Yes" : "No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC150_A { class Program { static void Main(string[] args) { var kx = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(kx[0] * 500 >= kx[1] ? "Yes" : "No"); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
8
95
2
using System; class ProgramA { static void Main(string[] args) { //日付を入力する string[] input = Console.ReadLine().Split(' '); int x = int.Parse(input[0]); int k = int.Parse(input[1]); //月が同じなら月末、それ以外は別 if (x * 2 >= k) Console.WriteLine("Yes"); else { Console.WriteLine("No"); } } }
using System; class ProgramA { static void Main(string[] args) { //日付を入力する string[] input = Console.ReadLine().Split(' '); int x = int.Parse(input[0]); int k = int.Parse(input[1]); //月が同じなら月末、それ以外は別 if (x * 500 >= k) Console.WriteLine("Yes"); else { Console.WriteLine("No"); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
93
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); // CompLib.Collections.PriorityQueue<?> public static void Main() { int K, X; new readint(out K, out X); string output = "No"; if (K * 200 >= X) output = "Yes"; Console.WriteLine(output); } } class readint { public readint(out int i) { i = int.Parse(Console.ReadLine()); } public readint(out int a, out int b) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readint(out int a, out int b, out int c) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readint(out int a, out int b, out int c, out int d) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class readlong { public readlong(out long i) { i = long.Parse(Console.ReadLine()); } public readlong(out long a, out long b) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readlong(out long a, out long b, out long c) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readlong(out long a, out long b, out long c, out long d) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class Util { /// <summary> /// 2引数の最大公約数を返します。longです。 /// </summary> /// <param name="a">long 引数1</param> /// <param name="b">long 引数2</param> /// <returns></returns> public static long GCD(long a, long b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2引数の最大公約数を返します。intです。 /// </summary> /// <param name="a">int 引数1</param> /// <param name="b">int 引数2</param> /// <returns></returns> public static int GCD(int a, int b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2つの変数の中身を交換する。型はなんでもいい /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void swap<T>(ref T a, ref T b) { T temp = b; b = a; a = temp; } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(long a, long b) { return a * b / GCD(a, b); } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); } public static int M = (int)(Math.Pow(10, 9)) + 7; private static int[] factorial_modM; /// <summary> /// 2引数の積 mod Mを求める。Mは10億7。 /// 変えられるよ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Multiple_modM(int a, int b) { return (int)(Math.BigMul(a, b) % M); } /// <summary> /// n! modMを求めるための準備を行う。引数は最大値。 /// </summary> /// <param name="n"></param> public static void factorial_modM_Prepare(int n) { factorial_modM = new int[n + 1]; factorial_modM[0] = 1; for (int i = 1; i <= n; ++i) { factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i); } } /// <summary> /// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int Factorial(int n) { return factorial_modM[n]; } public static int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiple_modM(p1, p1); return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a); } } /// <summary> /// a / m Mod M を求める。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Div(int a, int b) { return Multiple_modM(a, Pow(b, M - 2)); } /// <summary> /// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <param name="r"></param> /// <returns></returns> public static int nCr_modM(int n, int r) { if (r < 0) return 0; if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Div(res, Factorial(r)); res = Div(res, Factorial(n - r)); return res; } } /// <summary> /// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。 /// おすすめとしては、UnionFind<T>[] で宣言してしまう。 /// </summary> /// <typeparam name="T">int固定でいいよね。</typeparam> class UnionFind<T> { public int tree_height; public UnionFind<T> parent; public T item { get; private set; } public UnionFind(T item) { tree_height = 0; parent = this; } /// <summary> /// 一番上の親を探す。 /// 探しながら繋がり方を最適化している。 /// UnionFindの頂点そのものを返すので、==での比較が可能。 /// </summary> /// <returns></returns> public UnionFind<T> FindAdam() { if (parent == this) return this; else { UnionFind<T> ParentOfParent = parent.FindAdam(); parent = ParentOfParent; //縦長な構成をつなぎ直している return ParentOfParent; } } /// <summary> /// unionfind2つを一つにつなぐ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void Unite(UnionFind<T> a, UnionFind<T> b) { UnionFind<T> ParentOfA = a.FindAdam(); UnionFind<T> ParentOfB = b.FindAdam(); if (ParentOfA.tree_height < ParentOfB.tree_height) { ParentOfA.parent = ParentOfB; ParentOfB.tree_height = Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height); } else { ParentOfB.parent = ParentOfA; ParentOfA.tree_height = Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height); } } } // Treap 平衡二分木 class Treap<T> where T : IComparable { private class Node { private static Random g_rand = new Random(); private readonly int m_rank = g_rand.Next(); private readonly T m_value; private Node m_lch; private Node m_rch; private int m_count; public Node(T value) { m_value = value; m_count = 1; } private static int Count(Node node) { return (node != null) ? node.m_count : 0; } private Node Update() { m_count = Count(m_lch) + Count(m_rch) + 1; return this; } public static Node Merge(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } if (a.m_rank < b.m_rank) { a.m_rch = Merge(a.m_rch, b); return a.Update(); } else { b.m_lch = Merge(a, b.m_lch); return b.Update(); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) { return new Tuple<Node, Node>(null, null); } if (k <= Count(t.m_lch)) { var pair = Split(t.m_lch, k); t.m_lch = pair.Item2; return new Tuple<Node, Node>(pair.Item1, t.Update()); } else { var pair = Split(t.m_rch, k - Count(t.m_lch) - 1); t.m_rch = pair.Item1; return new Tuple<Node, Node>(t.Update(), pair.Item2); } } public int FindIndex(T value) { int L = Count(m_lch); if (value.CompareTo(m_value) < 0) { return (m_lch != null) ? m_lch.FindIndex(value) : 0; } else if (value.CompareTo(m_value) > 0) { return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1; } else { return L; } } public T this[int i] { get { int L = Count(m_lch); if (i < L) { return m_lch[i]; } else if (i > L) { return m_rch[i - L - 1]; } else { return m_value; } } } } private Node node; public void Insert(T value) { if (node != null) { int k = node.FindIndex(value); var pair = Node.Split(node, k); node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2); } else { node = new Node(value); } } public int FindIndex(T value) { return node.FindIndex(value); } public T this[int i] { get { return node[i]; } } } static class Permutation<T> { private static void Search(List<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) { perms.Add(stack.Reverse().ToArray()); } else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) { b[i] = a[i]; } stack.Pop(); } } } public static IEnumerable<T[]> All(IEnumerable<T> src) { var perms = new List<T[]>(); Search(perms, new Stack<T>(), src.ToArray()); return perms; } } namespace CompLib.Collections { #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } /// <summary> /// SEGTREEは1-BASE運用でございます /// よろしくおねがいします /// </summary> /// <typeparam name="T"></typeparam> class Segtree<T> { int n; //高さ T[] tree; //本体 Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか T exnum; //初期値 int count; /// <summary> /// !!!WARNING!!! 1-BASEです。 /// </summary> /// <param name="m">最大値。200001とか入れておくとよい</param> /// <param name="f">2引数の関数</param> /// <param /// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param> public Segtree(int m, Func<T, T, T> f, T ex) { this.count = 0; this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { this.count = 0; for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } /// <summary> /// j番目の値をxにする。計算し直さないので、 /// 入れ替えた後はall_update();を使おう /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } /// <summary> /// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void update(int j, T x) // j番目をxにする { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } this.count++; } /// <summary> /// 木を全部計算し直す。多分NlogN。違うかも知れないから /// よかったら教えて /// </summary> public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } /// <summary> /// j番目を消す。 /// </summary> /// <param name="j"></param> public void delete (int j) { int i = j + n - 1; tree[i] = exnum; int moved = 0; while (true) { tree[i + 1] = tree[i]; T check = tree[i]; moved++; if (moved + j + 2 > count) { break; } } all_update(); } // [s, t) /// <summary> /// s番目からt番目までの結果を返す。 /// これも当然のように1-BASE. /// </summary> /// <param name="s"></param> /// <param name="t"></param> /// <returns></returns> public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); // CompLib.Collections.PriorityQueue<?> public static void Main() { int K, X; new readint(out K, out X); string output = "No"; if (K * 500 >= X) output = "Yes"; Console.WriteLine(output); } } class readint { public readint(out int i) { i = int.Parse(Console.ReadLine()); } public readint(out int a, out int b) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readint(out int a, out int b, out int c) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readint(out int a, out int b, out int c, out int d) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class readlong { public readlong(out long i) { i = long.Parse(Console.ReadLine()); } public readlong(out long a, out long b) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readlong(out long a, out long b, out long c) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readlong(out long a, out long b, out long c, out long d) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class Util { /// <summary> /// 2引数の最大公約数を返します。longです。 /// </summary> /// <param name="a">long 引数1</param> /// <param name="b">long 引数2</param> /// <returns></returns> public static long GCD(long a, long b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2引数の最大公約数を返します。intです。 /// </summary> /// <param name="a">int 引数1</param> /// <param name="b">int 引数2</param> /// <returns></returns> public static int GCD(int a, int b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2つの変数の中身を交換する。型はなんでもいい /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void swap<T>(ref T a, ref T b) { T temp = b; b = a; a = temp; } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(long a, long b) { return a * b / GCD(a, b); } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); } public static int M = (int)(Math.Pow(10, 9)) + 7; private static int[] factorial_modM; /// <summary> /// 2引数の積 mod Mを求める。Mは10億7。 /// 変えられるよ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Multiple_modM(int a, int b) { return (int)(Math.BigMul(a, b) % M); } /// <summary> /// n! modMを求めるための準備を行う。引数は最大値。 /// </summary> /// <param name="n"></param> public static void factorial_modM_Prepare(int n) { factorial_modM = new int[n + 1]; factorial_modM[0] = 1; for (int i = 1; i <= n; ++i) { factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i); } } /// <summary> /// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int Factorial(int n) { return factorial_modM[n]; } public static int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiple_modM(p1, p1); return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a); } } /// <summary> /// a / m Mod M を求める。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Div(int a, int b) { return Multiple_modM(a, Pow(b, M - 2)); } /// <summary> /// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <param name="r"></param> /// <returns></returns> public static int nCr_modM(int n, int r) { if (r < 0) return 0; if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Div(res, Factorial(r)); res = Div(res, Factorial(n - r)); return res; } } /// <summary> /// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。 /// おすすめとしては、UnionFind<T>[] で宣言してしまう。 /// </summary> /// <typeparam name="T">int固定でいいよね。</typeparam> class UnionFind<T> { public int tree_height; public UnionFind<T> parent; public T item { get; private set; } public UnionFind(T item) { tree_height = 0; parent = this; } /// <summary> /// 一番上の親を探す。 /// 探しながら繋がり方を最適化している。 /// UnionFindの頂点そのものを返すので、==での比較が可能。 /// </summary> /// <returns></returns> public UnionFind<T> FindAdam() { if (parent == this) return this; else { UnionFind<T> ParentOfParent = parent.FindAdam(); parent = ParentOfParent; //縦長な構成をつなぎ直している return ParentOfParent; } } /// <summary> /// unionfind2つを一つにつなぐ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void Unite(UnionFind<T> a, UnionFind<T> b) { UnionFind<T> ParentOfA = a.FindAdam(); UnionFind<T> ParentOfB = b.FindAdam(); if (ParentOfA.tree_height < ParentOfB.tree_height) { ParentOfA.parent = ParentOfB; ParentOfB.tree_height = Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height); } else { ParentOfB.parent = ParentOfA; ParentOfA.tree_height = Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height); } } } // Treap 平衡二分木 class Treap<T> where T : IComparable { private class Node { private static Random g_rand = new Random(); private readonly int m_rank = g_rand.Next(); private readonly T m_value; private Node m_lch; private Node m_rch; private int m_count; public Node(T value) { m_value = value; m_count = 1; } private static int Count(Node node) { return (node != null) ? node.m_count : 0; } private Node Update() { m_count = Count(m_lch) + Count(m_rch) + 1; return this; } public static Node Merge(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } if (a.m_rank < b.m_rank) { a.m_rch = Merge(a.m_rch, b); return a.Update(); } else { b.m_lch = Merge(a, b.m_lch); return b.Update(); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) { return new Tuple<Node, Node>(null, null); } if (k <= Count(t.m_lch)) { var pair = Split(t.m_lch, k); t.m_lch = pair.Item2; return new Tuple<Node, Node>(pair.Item1, t.Update()); } else { var pair = Split(t.m_rch, k - Count(t.m_lch) - 1); t.m_rch = pair.Item1; return new Tuple<Node, Node>(t.Update(), pair.Item2); } } public int FindIndex(T value) { int L = Count(m_lch); if (value.CompareTo(m_value) < 0) { return (m_lch != null) ? m_lch.FindIndex(value) : 0; } else if (value.CompareTo(m_value) > 0) { return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1; } else { return L; } } public T this[int i] { get { int L = Count(m_lch); if (i < L) { return m_lch[i]; } else if (i > L) { return m_rch[i - L - 1]; } else { return m_value; } } } } private Node node; public void Insert(T value) { if (node != null) { int k = node.FindIndex(value); var pair = Node.Split(node, k); node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2); } else { node = new Node(value); } } public int FindIndex(T value) { return node.FindIndex(value); } public T this[int i] { get { return node[i]; } } } static class Permutation<T> { private static void Search(List<T[]> perms, Stack<T> stack, T[] a) { int N = a.Length; if (N == 0) { perms.Add(stack.Reverse().ToArray()); } else { var b = new T[N - 1]; Array.Copy(a, 1, b, 0, N - 1); for (int i = 0; i < a.Length; ++i) { stack.Push(a[i]); Search(perms, stack, b); if (i < b.Length) { b[i] = a[i]; } stack.Pop(); } } } public static IEnumerable<T[]> All(IEnumerable<T> src) { var perms = new List<T[]>(); Search(perms, new Stack<T>(), src.ToArray()); return perms; } } namespace CompLib.Collections { #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } /// <summary> /// SEGTREEは1-BASE運用でございます /// よろしくおねがいします /// </summary> /// <typeparam name="T"></typeparam> class Segtree<T> { int n; //高さ T[] tree; //本体 Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか T exnum; //初期値 int count; /// <summary> /// !!!WARNING!!! 1-BASEです。 /// </summary> /// <param name="m">最大値。200001とか入れておくとよい</param> /// <param name="f">2引数の関数</param> /// <param /// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param> public Segtree(int m, Func<T, T, T> f, T ex) { this.count = 0; this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { this.count = 0; for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } /// <summary> /// j番目の値をxにする。計算し直さないので、 /// 入れ替えた後はall_update();を使おう /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } /// <summary> /// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void update(int j, T x) // j番目をxにする { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } this.count++; } /// <summary> /// 木を全部計算し直す。多分NlogN。違うかも知れないから /// よかったら教えて /// </summary> public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } /// <summary> /// j番目を消す。 /// </summary> /// <param name="j"></param> public void delete (int j) { int i = j + n - 1; tree[i] = exnum; int moved = 0; while (true) { tree[i + 1] = tree[i]; T check = tree[i]; moved++; if (moved + j + 2 > count) { break; } } all_update(); } // [s, t) /// <summary> /// s番目からt番目までの結果を返す。 /// これも当然のように1-BASE. /// </summary> /// <param name="s"></param> /// <param name="t"></param> /// <returns></returns> public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
3,181
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { //ここから var str = IO.ReadLineToIntList(); var ans = str[1] / str[0] <= 500 ? "Yes" : "No"; //ここまで Console.WriteLine(ans); Console.ReadKey(); } } static class Func { static public long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { //ここから var str = IO.ReadLineToIntList(); var ans = str[1] <= 500 * str[0] ? "Yes" : "No"; //ここまで Console.WriteLine(ans); Console.ReadKey(); } } static class Func { static public long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
[["-", 0, 212, 0, 41, 15, 16, 31, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 19], ["+", 0, 212, 0, 41, 15, 16, 12, 16, 31, 203], ["+", 0, 212, 0, 41, 15, 16, 12, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 41, 15, 16, 17, 19], ["-", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203]]
8
630
6
using System; using System.Linq; namespace ABC150A { class Program { static void Main(string[] args) { var KX = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (KX[0] * 500 > KX[1]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.ReadLine(); } } }
using System; using System.Linq; namespace ABC150A { class Program { static void Main(string[] args) { var KX = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (KX[0] * 500 >= KX[1]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.ReadLine(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
97
2
using System; using System.Linq; public class AtCoder_150_A { public static void Main() { // var exStdIn = new System.IO.StreamReader( "input.txt" ); // System.Console.SetIn( exStdIn ); int[] nums = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int count = nums[0]; int threshold = nums[1]; Console.WriteLine(count * 500 >= threshold ? "YES" : "NO"); } }
using System; using System.Linq; public class AtCoder_150_A { public static void Main() { // var exStdIn = new System.IO.StreamReader( "input.txt" ); // System.Console.SetIn( exStdIn ); int[] nums = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int count = nums[0]; int threshold = nums[1]; Console.WriteLine(count * 500 >= threshold ? "Yes" : "No"); } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
92
4
using System; using System.Linq; namespace CSharp { class Program { static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var K = input[0]; var X = input[1]; Console.WriteLine(K * 500 > X ? "Yes" : "No"); } } }
using System; using System.Linq; namespace CSharp { class Program { static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var K = input[0]; var X = input[1]; Console.WriteLine(K * 500 >= X ? "Yes" : "No"); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20]]
8
82
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); int cnt = 0; for (int i = 0; i < N - 3; i++) { if ("ABC" == S.Substring(i, 3)) cnt++; } Console.WriteLine(cnt); } } // string s = Console.ReadLine(); // int[] intArray = Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray(); int H = intArray[0]; int W = intArray[1]; int N = // int.Parse(Console.ReadLine()); List<int> A = new // List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray()); // Boolean ok = false; // Console.WriteLine(ans); // Console.WriteLine("Yes"); // Console.WriteLine("No"); // Console.ReadKey(); // Console.WriteLine(cnt); // string[] strArray = Console.ReadLine().Split(' ').ToArray(); // string S = strArray[0]; // string T = strArray[1];
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); int cnt = 0; for (int i = 0; i < N - 2; i++) { if ("ABC" == S.Substring(i, 3)) cnt++; } Console.WriteLine(cnt); } } // string s = Console.ReadLine(); // int[] intArray = Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray(); int H = intArray[0]; int W = intArray[1]; int N = // int.Parse(Console.ReadLine()); List<int> A = new // List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray()); // Boolean ok = false; // Console.WriteLine(ans); // Console.WriteLine("Yes"); // Console.WriteLine("No"); // Console.ReadKey(); // Console.WriteLine(cnt); // string[] strArray = Console.ReadLine().Split(' ').ToArray(); // string S = strArray[0]; // string T = strArray[1];
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
115
2
using System; class Program { static void Main(string[] args) { Console.ReadLine(); char[] s = Console.ReadLine().ToCharArray(); int count = 0; for (int i = 0; i < s.Length; i++) { if (s[i] != 'A') continue; if (s[i + 1] != 'B') continue; if (s[i + 2] == 'C') count++; } Console.WriteLine(count); } }
using System; class Program { static void Main(string[] args) { Console.ReadLine(); char[] s = Console.ReadLine().ToCharArray(); int count = 0; for (int i = 0; i < s.Length - 2; i++) { if (s[i] != 'A') continue; if (s[i + 1] != 'B') continue; if (s[i + 2] == 'C') count++; } Console.WriteLine(count); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
113
2
using System; using System.Linq; using System.Collections.Generic; namespace ForAtcoder { class Program { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); var s = Console.ReadLine(); var count = 0; for (var i = 1; i <= n; i++) { if (s.Substring(i - 1, 3) == "ABC") count++; } Console.WriteLine(count); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ForAtcoder { class Program { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); var s = Console.ReadLine(); var count = 0; for (var i = 1; i <= n - 2; i++) { if (s.Substring(i - 1, 3) == "ABC") count++; } Console.WriteLine(count); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
105
2
using System; using System.Collections.Generic; using static Assistant.Input; using System.Linq; using Assistant; namespace ABC150B { class Program { static void Main(string[] args) { int N = ReadInt; var S = Console.ReadLine(); string match = "ABC"; int count = 0; for (int i = 0; i < S.Length - 3; i++) { string a = S.Substring(i, 3); if (match == a) count++; } Console.WriteLine(count); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String ReadNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int ReadInt => int.Parse(ReadNext()); public static long ReadLong => long.Parse(ReadNext()); public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); } static class Debug { // drawmap // drawarray } }
using System; using System.Collections.Generic; using static Assistant.Input; using System.Linq; using Assistant; namespace ABC150B { class Program { static void Main(string[] args) { int N = ReadInt; var S = Console.ReadLine(); string match = "ABC"; int count = 0; for (int i = 0; i <= S.Length - 3; i++) { string a = S.Substring(i, 3); if (match == a) count++; } Console.WriteLine(count); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String ReadNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int ReadInt => int.Parse(ReadNext()); public static long ReadLong => long.Parse(ReadNext()); public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); } static class Debug { // drawmap // drawarray } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
275
2
using System; using System.Linq; public class Test { public static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int counter = 0; for (int i = 0; i != n - 3; i++) { if (s.Substring(i, 3) == "ABC") { counter++; } } Console.WriteLine(counter); } }
using System; using System.Linq; public class Test { public static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int counter = 0; for (int i = 0; i != n - 2; i++) { if (s.Substring(i, 3) == "ABC") { counter++; } } Console.WriteLine(counter); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
94
2
using System; using System.Linq; namespace AtCoder { class Program { static void Main() { int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = input[0], a = input[1], b = input[2]; int[] d = new int[3]; d[0] = b - a; d[1] = (a - 1) + 1 + (b - 1); d[2] = (n - a) + 1 + (n - b); Console.WriteLine(d.Where(x => x % 2 == 0).Min() / 2); } } }
using System; using System.Linq; namespace AtCoder { class Program { static void Main() { long[] input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long n = input[0], a = input[1], b = input[2]; long[] d = new long[3]; d[0] = b - a; d[1] = (a - 1) + 1 + (b - 1); d[2] = (n - a) + 1 + (n - b); Console.WriteLine(d.Where(x => x % 2 == 0).Min() / 2); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
156
10
using System; namespace agc041a { class Program { static void Main(string[] args) { double[] read = Array.ConvertAll(Console.ReadLine().Split(), double.Parse); double N = read[0]; double A = read[1]; double B = read[2]; double roundNum = 0; if (Math.Abs(A - B) % 2 == 0) { roundNum = (B - A) / 2; } else { roundNum = Math.Min(A - 1, N - B) + 1 + (B - A - 1) / 2; } Console.WriteLine(roundNum); } } }
using System; namespace agc041a { class Program { static void Main(string[] args) { long[] read = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long N = read[0]; long A = read[1]; long B = read[2]; long roundNum = 0; if (Math.Abs(A - B) % 2 == 0) { roundNum = (B - A) / 2; } else { roundNum = Math.Min(A - 1, N - B) + 1 + (B - A - 1) / 2; } Console.WriteLine(roundNum); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
139
12
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int a = int.Parse(input[1]); int b = int.Parse(input[2]); if ((b - a) % 2 == 0) { Console.WriteLine((b - a) / 2); } else { if (a + b < n + 1) { Console.WriteLine((b - a - 1) / 2 + a); } else { Console.WriteLine((b - a - 1) / 2 + n - b + 1); } } } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); long n = long.Parse(input[0]); long a = long.Parse(input[1]); long b = long.Parse(input[2]); if ((b - a) % 2 == 0) { Console.WriteLine((b - a) / 2); } else { if (a + b < n + 1) { Console.WriteLine((b - a - 1) / 2 + a); } else { Console.WriteLine((b - a - 1) / 2 + n - b + 1); } } } }
[["-", 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]]
8
158
12
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Myon { public Myon() {} public static int Main() { cin = new Scanner(); new Myon().calc(); return 0; } static Scanner cin; void calc() { long N, A, B; N = cin.nextLong(); A = cin.nextLong() - 1; B = cin.nextLong() - 1; long ans = 0; if ((B - A) % 2 == 0) ans = (B - A) / 2; else { ans = Math.Min(A + A + B + 1, (N - 1 - B) * 2 + 1 + (B - A)) / 2; } 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 XRand { uint x, y, z, w; public XRand() { init(); } public XRand(uint s) { init(); init_xor128(s); } void init() { x = 314159265; y = 358979323; z = 846264338; w = 327950288; } public void init_xor128(uint s) { z ^= s; z ^= z >> 21; z ^= z << 35; z ^= z >> 4; z *= 736338717; } uint next() { uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; } public long nextLong(long m) { return (long)((((ulong)next() << 32) + next()) % (ulong)m); } public int nextInt(int m) { return (int)(next() % m); } public int nextIntP(int a) { return (int)Math.Pow(a, nextDouble()); } public int nextInt(int min, int max) { return min + nextInt(max - min + 1); } public double nextDouble() { return (double)next() / uint.MaxValue; } public double nextDoubleP(double a) { return Math.Pow(a, nextDouble()); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Myon { public Myon() {} public static int Main() { cin = new Scanner(); new Myon().calc(); return 0; } static Scanner cin; void calc() { long N, A, B; N = cin.nextLong(); A = cin.nextLong() - 1; B = cin.nextLong() - 1; long ans = 0; if ((B - A) % 2 == 0) ans = (B - A) / 2; else { ans = Math.Min(A + B + 1, (N - 1 - B) * 2 + 1 + (B - A)) / 2; } 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 XRand { uint x, y, z, w; public XRand() { init(); } public XRand(uint s) { init(); init_xor128(s); } void init() { x = 314159265; y = 358979323; z = 846264338; w = 327950288; } public void init_xor128(uint s) { z ^= s; z ^= z >> 21; z ^= z << 35; z ^= z >> 4; z *= 736338717; } uint next() { uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; } public long nextLong(long m) { return (long)((((ulong)next() << 32) + next()) % (ulong)m); } public int nextInt(int m) { return (int)(next() % m); } public int nextIntP(int a) { return (int)Math.Pow(a, nextDouble()); } public int nextInt(int min, int max) { return min + nextInt(max - min + 1); } public double nextDouble() { return (double)next() / uint.MaxValue; } public double nextDoubleP(double a) { return Math.Pow(a, nextDouble()); } }
[["-", 0, 28, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72]]
8
819
2
using System; class Program { static void Main(string[] args) {   long n, a, b; // a = int.Parse(Console.ReadLine()); //標準入力 string[] str = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得 n = long.Parse(str[0]); //数値で受け取りたい場合は変換する a = long.Parse(str[1]); b = long.Parse(str[2]); if ((b - a) % 2 == 0) { Console.Write((b - a)); } else { Console.Write(((b - a) / 2 + 1 + Math.Min((a - 1), (n - b)))); } } }
using System; class Program { static void Main(string[] args) {   long n, a, b; string[] str = Console.ReadLine().Split(' '); n = long.Parse(str[0]); a = long.Parse(str[1]); b = long.Parse(str[2]); if (((b - a) % 2) == 0) { Console.Write((b - a) / 2); } else { Console.Write((b - a) / 2 + 1 + Math.Min((a - 1), (n - b))); } } }
[["+", 15, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 23, 0, 25]]
8
145
6
using System; class Program { static void Main(string[] args) {   long n, a, b; // a = int.Parse(Console.ReadLine()); //標準入力 string[] str = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得 n = long.Parse(str[0]); //数値で受け取りたい場合は変換する a = long.Parse(str[1]); b = long.Parse(str[2]); if ((b - a) % 2 == 0) { Console.Write((b - a)); } else { Console.Write( (((b - a) / 2) + 1 + Math.Min((a - 1), (n - b))).ToString()); } } }
using System; class Program { static void Main(string[] args) {   long n, a, b; // a = int.Parse(Console.ReadLine()); //標準入力 string[] str = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得 n = long.Parse(str[0]); //数値で受け取りたい場合は変換する a = long.Parse(str[1]); b = long.Parse(str[2]); if (((b - a) % 2) == 0) { Console.Write((b - a) / 2); } else { Console.Write( (((b - a) / 2) + 1 + Math.Min((a - 1), (n - b))).ToString()); } } }
[["+", 15, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
151
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class AC { public void Do() { var N = Split.Int(); var A = Split.Int(); var B = Split.Int(); if ((Math.Abs(A - B) % 2) == 0) { Console.WriteLine(Math.Abs(A - B) / 2); return; } var a = Math.Min(A - 1, N - A); var b = Math.Min(B - 1, N - B); if (a > b) { var tmp = B; B = A; A = tmp; } if (A - 1 > N - A) { A = N - A + 1; B = N - B + 1; } Console.WriteLine(A + (B - A) / 2); } #if !piyo static void Main(string[] args) { new AC().Do(); } #endif } static class Split { public static string String() { if (_ss.Count == 0) { var s = Console.ReadLine(); if (s == null) return null; _ss = s.Split(_delim).ToList(); } var ret = _ss[0]; _ss.RemoveAt(0); return ret; } public static int Int() { var str = String(); return int.Parse(str); } public static long Long() { var str = String(); return long.Parse(str); } static List<string> _ss = new List<string>(); static char[] _delim = new[] { '\t', ' ' }; }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class AC { public void Do() { var N = Split.Long(); var A = Split.Long(); var B = Split.Long(); if ((Math.Abs(A - B) % 2) == 0) { Console.WriteLine(Math.Abs(A - B) / 2); return; } var a = Math.Min(A - 1, N - A); var b = Math.Min(B - 1, N - B); if (a > b) { var tmp = B; B = A; A = tmp; } if (A - 1 > N - A) { A = N - A + 1; B = N - B + 1; } Console.WriteLine(A + (B - A) / 2); } #if !piyo static void Main(string[] args) { new AC().Do(); } #endif } static class Split { public static string String() { if (_ss.Count == 0) { var s = Console.ReadLine(); if (s == null) return null; _ss = s.Split(_delim).ToList(); } var ret = _ss[0]; _ss.RemoveAt(0); return ret; } public static int Int() { var str = String(); return int.Parse(str); } public static long Long() { var str = String(); return long.Parse(str); } static List<string> _ss = new List<string>(); static char[] _delim = new[] { '\t', ' ' }; }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
376
6
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var nab = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nab[0]; var a = nab[1]; var b = nab[2]; var diff = Abs(a - b); if (diff % 2 == 0) { Console.WriteLine(diff / 2); return; } Console.WriteLine(Min(Solve(a - 1, b - 1), Min(n - a, n - b))); } static long Solve(long a, long b) { if (a > b) { var tmp = a; a = b; b = tmp; } var min = a; a -= min; b -= min; b -= 1; return min + 1 + b / 2; } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var nab = Console.ReadLine().Split().Select(long.Parse).ToArray(); var n = nab[0]; var a = nab[1]; var b = nab[2]; var diff = Abs(a - b); if (diff % 2 == 0) { Console.WriteLine(diff / 2); return; } Console.WriteLine(Min(Solve(a - 1, b - 1), Solve(n - a, n - b))); } static long Solve(long a, long b) { if (a > b) { var tmp = a; a = b; b = tmp; } var min = a; a -= min; b -= min; b -= 1; return min + 1 + b / 2; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22]]
8
264
2
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif //#define TOPCODER using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; using static UtakaApp.Util; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "agc041"; public const string ProblemName = "B"; private int NOrig; private long M; private int VOrig; private int POrig; private int[] AOrig; private int N; private long V; private long[] A; private const int P = 1; private int TargetIndex; private long TargetValue; public void Solve() { NOrig = cin.ReadInt; M = cin.ReadLong; VOrig = cin.ReadInt; POrig = cin.ReadInt; AOrig = cin.ReadIntArray(NOrig); Array.Sort(AOrig); N = NOrig - POrig + 1; V = VOrig - POrig + 1; A = new long[N]; for (int i = 0; i < N; i++) { A[i] = AOrig[i]; } TargetIndex = N - P; TargetValue = A[TargetIndex]; // まず、最初に外した分を入れておく long ans = POrig - 1; int left = 0; int right = N; while (right - left > 1) { int mid = left + (right - left) / 2; if (!Check(mid)) { left = mid; } else { right = mid; } } ans += (N - left - 1); cou.WriteLine(ans); } public bool Check(int i) { if (TargetIndex <= i) { return true; } if (V <= i + 1) { long diff = TargetValue - A[i]; return diff <= M; } long self = A[i]; // ここ、ループ回さなくできる long sum = 0; long maxNum = 0; for (int j = i + 1; j < N; j++) { long tmpVal = A[j] - self; sum += tmpVal; maxNum = Math.Max(maxNum, tmpVal); } long num = N - V; long canDelete = num * M; if (canDelete < sum) { return false; } if (M < maxNum) { return false; } return true; } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } #if !TOPCODER public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } #endif public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") { if (!A.Any()) { return; } var sb = new StringBuilder(); foreach (T v in A) { sb.Append(v); sb.Append(delimiter); } if (sb.Length > 0) { sb.Length--; } cou.WriteLine(sb.ToString()); } } public static class Util { public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(List<T> list, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(list[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(List<T> list, T value) { return UpperBound(list, 0, list.Count, value, Comparer<T>.Default); } public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// IList<T>をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } /// <summary> /// 2次元ジャグ配列をコピーして返す。 /// </summary> public static T[][] Copy<T>(this T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public class IntLargeComparer : IComparer<int> { public static IntLargeComparer Instance = new IntLargeComparer(); public int Compare(int x, int y) { return y - x; } } public class LongLargeComparer : IComparer<long> { public static LongLargeComparer Instance = new LongLargeComparer(); public int Compare(long x, long y) { if (x > y) return -1; if (x < y) return 1; return 0; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public int[] ReadIntArrayMinus1(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt - 1; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif //#define TOPCODER using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; using static UtakaApp.Util; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "agc041"; public const string ProblemName = "B"; // private int N; // private long M; // private int V; // private int P; // // private long[] A; // // public void Solve() // { // N = cin.ReadInt; // M = cin.ReadLong; // V = cin.ReadInt; // P = cin.ReadInt; // // A = cin.ReadLongArray(N); // // Array.Sort(A); // // int left = -1; // int right = N - 1; // // while (right - left > 1) // { // int mid = left + (right - left) / 2; // // if (IsOk(mid)) // { // right = mid; // } // else // { // left = mid; // } // } // // cou.WriteLine(N - right); // } // // public bool IsOk(int i) // { // long rem = Math.Max((V - (i + 1) - (P - 1)) * M, 0); // // int rc = Math.Max(N - (i + 1) - (P - 1), 0); // // long s = A[i] + M; // long sum = 0; // // bool f = true; // // for (int j = 0; j < rc; j++) // { // int k = i + 1 + j; // // if (k < N) // { // if (A[k] > s) f = false; // // sum += Math.Min(Math.Max(s - A[k], 0), M); // } // } // // if (f && sum >= rem) // { // return true; // } // // return false; // } private int NOrig; private long M; private int VOrig; private int POrig; private int[] AOrig; private int N; private long V; private long[] A; private const int P = 1; private int TargetIndex; private long TargetValue; public void Solve() { NOrig = cin.ReadInt; M = cin.ReadLong; VOrig = cin.ReadInt; POrig = cin.ReadInt; AOrig = cin.ReadIntArray(NOrig); Array.Sort(AOrig); N = NOrig - POrig + 1; V = VOrig - POrig + 1; A = new long[N]; for (int i = 0; i < N; i++) { A[i] = AOrig[i]; } TargetIndex = N - P; TargetValue = A[TargetIndex]; // まず、最初に外した分を入れておく long ans = POrig - 1; int left = -1; int right = N - 1; while (right - left > 1) { int mid = left + (right - left) / 2; if (!Check(mid)) { left = mid; } else { right = mid; } } ans += (N - left - 1); cou.WriteLine(ans); } public bool Check(int i) { if (TargetIndex <= i) { return true; } if (V <= i + 1) { long diff = TargetValue - A[i]; return diff <= M; } long self = A[i]; // ここ、ループ回さなくできる long sum = 0; long maxNum = 0; for (int j = i + 1; j < N; j++) { long tmpVal = A[j] - self; sum += tmpVal; maxNum = Math.Max(maxNum, tmpVal); } long num = N - V; long canDelete = num * M; if (canDelete < sum) { return false; } if (M < maxNum) { return false; } return true; } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } #if !TOPCODER public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } #endif public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") { if (!A.Any()) { return; } var sb = new StringBuilder(); foreach (T v in A) { sb.Append(v); sb.Append(delimiter); } if (sb.Length > 0) { sb.Length--; } cou.WriteLine(sb.ToString()); } } public static class Util { public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(List<T> list, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(list[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(List<T> list, T value) { return UpperBound(list, 0, list.Count, value, Comparer<T>.Default); } public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// IList<T>をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } /// <summary> /// 2次元ジャグ配列をコピーして返す。 /// </summary> public static T[][] Copy<T>(this T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public class IntLargeComparer : IComparer<int> { public static IntLargeComparer Instance = new IntLargeComparer(); public int Compare(int x, int y) { return y - x; } } public class LongLargeComparer : IComparer<long> { public static LongLargeComparer Instance = new LongLargeComparer(); public int Compare(long x, long y) { if (x > y) return -1; if (x < y) return 1; return 0; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public int[] ReadIntArrayMinus1(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt - 1; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
4,234
5
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif //#define TOPCODER using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; using static UtakaApp.Util; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "agc041"; public const string ProblemName = "B"; private int N; private long M; private int V; private int P; private long[] A; public void Solve() { N = cin.ReadInt; M = cin.ReadLong; V = cin.ReadInt; P = cin.ReadInt; A = cin.ReadLongArray(N); Array.Sort(A); int left = 0; int right = N; while (right - left > 1) { int mid = left + (right - left) / 2; if (IsOk(mid)) { right = mid; } else { left = mid; } } cou.WriteLine(N - right); } public bool IsOk(int i) { long rem = Math.Max((V - (i + 1) - (P - 1)) * M, 0); int rc = Math.Max(N - (i + 1) - (P - 1), 0); long s = A[i] + M; long sum = 0; bool f = true; for (int j = 0; j < rc; j++) { int k = i + 1 + j; if (k < N) { if (A[k] > s) f = false; sum += Math.Min(Math.Max(s - A[k], 0), M); } } if (f && sum >= rem) { return true; } return false; } } // private int NOrig; // private long M; // private int VOrig; // private int POrig; // private int[] AOrig; // // private int N; // private long V; // private long[] A; // // private const int P = 1; // // private int TargetIndex; // private long TargetValue; // // public void Solve() // { // // NOrig = cin.ReadInt; // // M = cin.ReadLong; // // VOrig = cin.ReadInt; // // POrig = cin.ReadInt; // // AOrig = cin.ReadIntArray(NOrig); // // // // Array.Sort(AOrig); // // // // N = NOrig - POrig + 1; // // V = VOrig - POrig + 1; // // // // A = new long[N]; // // // // for (int i = 0; i < N; i++) // // { // // A[i] = AOrig[i]; // // } // // // // TargetIndex = N - P; // // TargetValue = A[TargetIndex]; // // // // // まず、最初に外した分を入れておく // // long ans = POrig - 1; // // // // int left = 0; // // int right = N; // // // // while (right - left > 1) // // { // // int mid = left + (right - left) / 2; // // // // if (!Check(mid)) // // { // // left = mid; // // } // // else // // { // // right = mid; // // } // // } // // // // ans += (N - left - 1); // // // // cou.WriteLine(ans); // } // // public bool Check(int i) // { // if (TargetIndex <= i) // { // return true; // } // // if (V <= i + 1) // { // long diff = TargetValue - A[i]; // return diff <= M; // } // // long self = A[i]; // // // ここ、ループ回さなくできる // // long sum = 0; // long maxNum = 0; // for (int j = i + 1; j < N; j++) // { // long tmpVal = A[j] - self; // sum += tmpVal; // maxNum = Math.Max(maxNum, tmpVal); // } // // long num = N - V; // // long canDelete = num * M; // // if (canDelete < sum) // { // return false; // } // // if (M < maxNum) // { // return false; // } // // return true; // } // } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } #if !TOPCODER public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } #endif public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") { if (!A.Any()) { return; } var sb = new StringBuilder(); foreach (T v in A) { sb.Append(v); sb.Append(delimiter); } if (sb.Length > 0) { sb.Length--; } cou.WriteLine(sb.ToString()); } } public static class Util { public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(List<T> list, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(list[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(List<T> list, T value) { return UpperBound(list, 0, list.Count, value, Comparer<T>.Default); } public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// IList<T>をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } /// <summary> /// 2次元ジャグ配列をコピーして返す。 /// </summary> public static T[][] Copy<T>(this T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public class IntLargeComparer : IComparer<int> { public static IntLargeComparer Instance = new IntLargeComparer(); public int Compare(int x, int y) { return y - x; } } public class LongLargeComparer : IComparer<long> { public static LongLargeComparer Instance = new LongLargeComparer(); public int Compare(long x, long y) { if (x > y) return -1; if (x < y) return 1; return 0; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public int[] ReadIntArrayMinus1(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt - 1; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif //#define TOPCODER using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; using static UtakaApp.Util; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "agc041"; public const string ProblemName = "B"; private int N; private long M; private int V; private int P; private long[] A; public void Solve() { N = cin.ReadInt; M = cin.ReadLong; V = cin.ReadInt; P = cin.ReadInt; A = cin.ReadLongArray(N); Array.Sort(A); int left = -1; int right = N - 1; while (right - left > 1) { int mid = left + (right - left) / 2; if (IsOk(mid)) { right = mid; } else { left = mid; } } cou.WriteLine(N - right); } public bool IsOk(int i) { long rem = Math.Max((V - (i + 1) - (P - 1)) * M, 0); int rc = Math.Max(N - (i + 1) - (P - 1), 0); long s = A[i] + M; long sum = 0; bool f = true; for (int j = 0; j < rc; j++) { int k = i + 1 + j; if (k < N) { if (A[k] > s) f = false; sum += Math.Min(Math.Max(s - A[k], 0), M); } } if (f && sum >= rem) { return true; } return false; } } // private int NOrig; // private long M; // private int VOrig; // private int POrig; // private int[] AOrig; // // private int N; // private long V; // private long[] A; // // private const int P = 1; // // private int TargetIndex; // private long TargetValue; // // public void Solve() // { // // NOrig = cin.ReadInt; // // M = cin.ReadLong; // // VOrig = cin.ReadInt; // // POrig = cin.ReadInt; // // AOrig = cin.ReadIntArray(NOrig); // // // // Array.Sort(AOrig); // // // // N = NOrig - POrig + 1; // // V = VOrig - POrig + 1; // // // // A = new long[N]; // // // // for (int i = 0; i < N; i++) // // { // // A[i] = AOrig[i]; // // } // // // // TargetIndex = N - P; // // TargetValue = A[TargetIndex]; // // // // // まず、最初に外した分を入れておく // // long ans = POrig - 1; // // // // int left = 0; // // int right = N; // // // // while (right - left > 1) // // { // // int mid = left + (right - left) / 2; // // // // if (!Check(mid)) // // { // // left = mid; // // } // // else // // { // // right = mid; // // } // // } // // // // ans += (N - left - 1); // // // // cou.WriteLine(ans); // } // // public bool Check(int i) // { // if (TargetIndex <= i) // { // return true; // } // // if (V <= i + 1) // { // long diff = TargetValue - A[i]; // return diff <= M; // } // // long self = A[i]; // // // ここ、ループ回さなくできる // // long sum = 0; // long maxNum = 0; // for (int j = i + 1; j < N; j++) // { // long tmpVal = A[j] - self; // sum += tmpVal; // maxNum = Math.Max(maxNum, tmpVal); // } // // long num = N - V; // // long canDelete = num * M; // // if (canDelete < sum) // { // return false; // } // // if (M < maxNum) // { // return false; // } // // return true; // } // } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } #if !TOPCODER public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } #endif public void WriteEnumerable<T>(IEnumerable<T> A, string delimiter = " ") { if (!A.Any()) { return; } var sb = new StringBuilder(); foreach (T v in A) { sb.Append(v); sb.Append(delimiter); } if (sb.Length > 0) { sb.Length--; } cou.WriteLine(sb.ToString()); } } public static class Util { public static int LowerBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(T[] arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(T[] arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(T[] arr, T value) { return UpperBound(arr, 0, arr.Length, value, Comparer<T>.Default); } public static int UpperBound<T>(List<T> list, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; while (low < high) { var mid = ((high - low) >> 1) + low; if (comparer.Compare(list[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(List<T> list, T value) { return UpperBound(list, 0, list.Count, value, Comparer<T>.Default); } public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// IList<T>をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } /// <summary> /// 2次元ジャグ配列をコピーして返す。 /// </summary> public static T[][] Copy<T>(this T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public class IntLargeComparer : IComparer<int> { public static IntLargeComparer Instance = new IntLargeComparer(); public int Compare(int x, int y) { return y - x; } } public class LongLargeComparer : IComparer<long> { public static LongLargeComparer Instance = new LongLargeComparer(); public int Compare(long x, long y) { if (x > y) return -1; if (x < y) return 1; return 0; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public int[] ReadIntArrayMinus1(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt - 1; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
4,251
5
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); long m = cin.Long(); long v = cin.Long(); long p = cin.Long(); long[] a = cin.ArrayLong(n); Array.Sort(a); long[] rui = new long[n]; rui[0] = a[0]; for (int i = 1; i < n; i++) { rui[i] = a[i] + rui[i - 1]; } int pp = n - (int)p; long ans = 0; for (int i = 0; i < n; i++) { long self = a[i] + m; if (self < a[pp]) { continue; } long pre = i * m; long post = ((pp - i) * self) - (rui[pp] - rui[i]); long all = (long)m * v; long remain = all - (p * m); if (remain <= pre + post) { ++ans; } } Console.WriteLine(ans); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); long m = cin.Long(); long v = cin.Long(); long p = cin.Long(); long[] a = cin.ArrayLong(n); Array.Sort(a); long[] rui = new long[n]; rui[0] = a[0]; for (int i = 1; i < n; i++) { rui[i] = a[i] + rui[i - 1]; } int pp = n - (int)p; long ans = p - 1; for (int i = 0; i <= pp; i++) { long self = a[i] + m; if (self < a[pp]) { continue; } long pre = i * m; long post = ((pp - i) * self) - (rui[pp] - rui[i]); long all = (long)m * v; long remain = all - (p * m); if (remain <= pre + post) { ++ans; } } Console.WriteLine(ans); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
747
8