buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0033 { class Program { static void Main(string[] args) { var s = Console.ReadLine(); int result = int.MaxValue; for (int i = 0; i < s.Length - 3; i++) { var t = s.Substring(i, 3); var sa = Math.Abs(753 - int.Parse(t)); if (sa <= result) { result = sa; } } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0033 { class Program { static void Main(string[] args) { var s = Console.ReadLine(); int result = int.MaxValue; for (int i = 0; i < s.Length - 2; i++) { var t = s.Substring(i, 3); var sa = Math.Abs(753 - int.Parse(t)); if (sa <= result) { result = sa; } } Console.WriteLine(result); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
130
2
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder.Contest.B { static class Program { public static void Solve(Scanner cin) { var s = cin.ReadString(); var ans = int.MaxValue; for (int i = 0; i < s.Length - 3; i++) { var x = int.Parse(s.Substring(i, 3)); ans = Math.Min(ans, Math.Abs(x - 753)); } Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = " ") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder.Contest.B { static class Program { public static void Solve(Scanner cin) { var s = cin.ReadString(); var ans = int.MaxValue; for (int i = 0; i < s.Length - 2; i++) { var x = int.Parse(s.Substring(i, 3)); ans = Math.Min(ans, Math.Abs(x - 753)); } Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = " ") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
2,607
2
// A Dynamic Programming based // C# program to find minimum // number operations to // convert str1 to str2 using System; using System.Collections.Generic; using System.Linq; class GFG { static Dictionary<int, int> ans = new Dictionary<int, int>(); public static void Main() { var intput = Console.ReadLine(); Sachi(intput); } public static void Sachi(string s) { var min = int.MaxValue; for (int i = 0; i < s.Length - 3; i++) { var temp = s.Substring(i, 3); var diff = Math.Abs(Convert.ToInt32(temp) - 753); min = Math.Min(diff, min); } Console.Write(min); } }
// A Dynamic Programming based // C# program to find minimum // number operations to // convert str1 to str2 using System; using System.Collections.Generic; using System.Linq; class GFG { static Dictionary<int, int> ans = new Dictionary<int, int>(); public static void Main() { var intput = Console.ReadLine(); Sachi(intput); } public static void Sachi(string s) { var min = int.MaxValue; for (int i = 0; i < s.Length - 2; i++) { var temp = s.Substring(i, 3); var diff = Math.Abs(Convert.ToInt32(temp) - 753); min = Math.Min(diff, min); } Console.Write(min); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
148
2
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var s = cin.next(); var ans = int.MaxValue; for (int i = 0; i < s.Length - 1; i++) { var ss = ""; for (int j = i; j < i + 3; j++) { ss += s[i]; } ans = Math.Min(ans, Math.Abs(753 - int.Parse(ss))); ; } 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 int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var s = cin.next(); var ans = int.MaxValue; for (int i = 0; i < s.Length - 2; i++) { var ss = ""; for (int j = i; j < i + 3; j++) { ss += s[j]; } ans = Math.Min(ans, Math.Abs(int.Parse(ss) - 753)); ; } 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 int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
637
8
namespace AtCoder { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Util; class AtCoder { /*------------------------------------------------------------------*/ private int N; private int[] A; void Solve() { io.String.ToCharArray() .Select(c => int.Parse(c.ToString())) .Windowed(3) .Select(xs => int.Parse(xs.Join(""))) .Min(x => Abs(x - 753)) .Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] _) => new AtCoder().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Util { public static T Id<T>(T x) => x; public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static IEnumerable<TResult> ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, Func<T1, T2, TResult> f = null) { using (var e1 = xs.GetEnumerator()) using ( var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext()) yield return f(e1.Current, e2.Current); } public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs, IEnumerable<T2> ys) => ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y)); public static IEnumerable<TResult> ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) { using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using ( var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) yield return f(e1.Current, e2.Current, e3.Current); } public static IEnumerable<Tuple<T1, T2, T3>> ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z)); public static bool ODD(int x) => x % 2 != 0; public static bool ODD(long x) => x % 2L != 0L; public static bool EVE(int x) => !ODD(x); public static bool EVE(long x) => !ODD(x); public static T MAX<T>(params T[] xs) => xs.Max(); public static T MIN<T>(params T[] xs) => xs.Min(); public static int SUM(params int[] xs) => xs.Sum(); public static long SUM(params long[] xs) => xs.Sum(); public static IEnumerable<int> RANGE(int start, int step = 1) { var v = start; while (true) { yield return v; v += step; } } public struct IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } } static class Ex { public static Tuple<IEnumerable<T>, IEnumerable<T>> Split<T>(this IEnumerable<T> xs, Func<T, bool> f) { var ys = xs.Where(f); var zs = xs.Where(x => !f(x)); return Tuple.Create(ys, zs); } public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static void Log<T>(this T x) { #if DEBUG WriteLine($"LOG [{nameof(x)}] : {x}"); #endif } public static IEnumerable<IndexedItem<T>> Indexed<T>(this IEnumerable<T> xs) => xs.Select((x, idx) => new IndexedItem<T>(idx, x)); public static IEnumerable<T> UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val); public static IEnumerable<Tuple<T, T>> Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1)); public static IEnumerable<T[]> Windowed<T>(this IEnumerable<T> xs, int size) { if (size <= 0) throw new ArgumentException(); var w = new T[size]; var r = size - 1; var i = 0; var e = xs.GetEnumerator(); while (e.MoveNext()) { w[i] = e.Current; i = (i + 1) % size; if (i == 0) { var ret = new T[size]; Array.Copy(w, i, ret, 0, size - i); Array.Copy(w, 0, ret, size - i, i); yield return ret; } else { r--; } } } public static IEnumerable<int> ToZeroIndexed(this IEnumerable<int> xs) => xs.Select(x => x - 1); public static string Join<T>(this IEnumerable<T> xs, string str = " ") => String.Join(str, xs); public static string Sort(this string s) { var arr = s.ToCharArray(); Array.Sort(arr); return new string(arr); } public static string Yn(this bool f, string y = "Yes", string n = "No") => f ? y : n; public static bool Is<T>(this T x, Func<T, bool> f) => f(x); public static TU Fun<T, TU>(this T x, Func<T, TU> f) => f(x); } }
namespace AtCoder { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Util; class AtCoder { /*------------------------------------------------------------------*/ private int N; private int[] A; void Solve() { io.String.ToCharArray() .Select(c => int.Parse(c.ToString())) .Windowed(3) .Select(xs => int.Parse(xs.Join(""))) .Min(x => Abs(x - 753)) .Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] _) => new AtCoder().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Util { public static T Id<T>(T x) => x; public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static IEnumerable<TResult> ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, Func<T1, T2, TResult> f = null) { using (var e1 = xs.GetEnumerator()) using ( var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext()) yield return f(e1.Current, e2.Current); } public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs, IEnumerable<T2> ys) => ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y)); public static IEnumerable<TResult> ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) { using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using ( var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) yield return f(e1.Current, e2.Current, e3.Current); } public static IEnumerable<Tuple<T1, T2, T3>> ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z)); public static bool ODD(int x) => x % 2 != 0; public static bool ODD(long x) => x % 2L != 0L; public static bool EVE(int x) => !ODD(x); public static bool EVE(long x) => !ODD(x); public static T MAX<T>(params T[] xs) => xs.Max(); public static T MIN<T>(params T[] xs) => xs.Min(); public static int SUM(params int[] xs) => xs.Sum(); public static long SUM(params long[] xs) => xs.Sum(); public static IEnumerable<int> RANGE(int start, int step = 1) { var v = start; while (true) { yield return v; v += step; } } public struct IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } } static class Ex { public static Tuple<IEnumerable<T>, IEnumerable<T>> Split<T>(this IEnumerable<T> xs, Func<T, bool> f) { var ys = xs.Where(f); var zs = xs.Where(x => !f(x)); return Tuple.Create(ys, zs); } public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static void Log<T>(this T x) { #if DEBUG WriteLine($"LOG [{nameof(x)}] : {x}"); #endif } public static IEnumerable<IndexedItem<T>> Indexed<T>(this IEnumerable<T> xs) => xs.Select((x, idx) => new IndexedItem<T>(idx, x)); public static IEnumerable<T> UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val); public static IEnumerable<Tuple<T, T>> Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1)); public static IEnumerable<T[]> Windowed<T>(this IEnumerable<T> xs, int size) { if (size <= 0) throw new ArgumentException(); var w = new T[size]; var r = size - 1; var i = 0; var e = xs.GetEnumerator(); while (e.MoveNext()) { w[i] = e.Current; i = (i + 1) % size; if (r == 0) { var ret = new T[size]; Array.Copy(w, i, ret, 0, size - i); Array.Copy(w, 0, ret, size - i, i); yield return ret; } else r--; } } public static IEnumerable<int> ToZeroIndexed(this IEnumerable<int> xs) => xs.Select(x => x - 1); public static string Join<T>(this IEnumerable<T> xs, string str = " ") => String.Join(str, xs); public static string Sort(this string s) { var arr = s.ToCharArray(); Array.Sort(arr); return new string(arr); } public static string Yn(this bool f, string y = "Yes", string n = "No") => f ? y : n; public static bool Is<T>(this T x, Func<T, bool> f) => f(x); public static TU Fun<T, TU>(this T x, Func<T, TU> f) => f(x); } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46]]
8
2,693
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<long, long>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var S = cin.next; int min = int.MaxValue; for (int i = 0; i < S.Length - 3; i++) { chmin(ref min, Abs(753 - int.Parse(S.Substring(i, 3)))); } WriteLine(min); } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) { return f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); } public override string ToString() { return $"{f} {s}"; } } static class Ex { public static void join<T>(this IEnumerable<T> values) { WriteLine(string.Join(" ", values)); } public static string join<T>(this IEnumerable<T> values, string sep) { return string.Join(sep, values); } public static string concat<T>(this IEnumerable<T> values) { return string.Concat(values); } public static string reverse(this string s) { return s.Reverse().concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count(); int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count(); int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<long, long>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var S = cin.next; int min = int.MaxValue; for (int i = 0; i < S.Length - 2; i++) { chmin(ref min, Abs(753 - int.Parse(S.Substring(i, 3)))); } WriteLine(min); } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) { return f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); } public override string ToString() { return $"{f} {s}"; } } static class Ex { public static void join<T>(this IEnumerable<T> values) { WriteLine(string.Join(" ", values)); } public static string join<T>(this IEnumerable<T> values, string sep) { return string.Join(sep, values); } public static string concat<T>(this IEnumerable<T> values) { return string.Concat(values); } public static string reverse(this string s) { return s.Reverse().concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count(); int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count(); int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
955
2
using System; 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 str = cin.ReadLine.Replace("\n", ""); var len = str.Length; var min = 10000000; for (int index = 0; index < len - 3; index++) { min = Min(Abs(753 - int.Parse(str.Substring(index, 3))), min); } Console.WriteLine(min); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } } }
using System; using System.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 str = cin.ReadLine.Replace("\n", ""); var len = str.Length; var min = int.MaxValue; for (int index = 0; index < len - 2; index++) { min = Min(Abs(753 - int.Parse(str.Substring(index, 3))), min); } Console.WriteLine(min); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
538
6
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace AtCoderABC114 { class Program { public static void Main(string[] args) { string S = Console.ReadLine(); List<int> l = new List<int>(); for (int i = 0; i < S.Length - 3; i++) { l.Add(Math.Abs(int.Parse(S.Substring(i, 3)) - 753)); } l = l.OrderBy(x => x).ToList(); Console.WriteLine(l[0]); } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace AtCoderABC114 { class Program { public static void Main(string[] args) { string S = Console.ReadLine(); List<int> l = new List<int>(); for (int i = 0; i < S.Length - 2; i++) { l.Add(Math.Abs(int.Parse(S.Substring(i, 3)) - 753)); } l = l.OrderBy(x => x).ToList(); Console.WriteLine(l[0]); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
134
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BC114 { class Program { static void Main(string[] args) { var obj = new Q1(); obj.Solver(); } } class Q1 { public void Solver() { long amswer = 753; var s = Console.ReadLine().Select(x => long.Parse(x.ToString())).ToArray(); long diff = 1000; for (int i = 0; i < s.Count() - 3; i++) { long temp = s[i] * 100 + s[i + 1] * 10 + s[i + 2]; diff = Math.Min(diff, Math.Abs(amswer - temp)); } Console.WriteLine(diff); } } // class Q1 //{ // public void Solver() // { // var age = int.Parse(Console.ReadLine()); // Console.WriteLine((age == 3 || age == 5 || age == 7) ? "YES" : "NO"); // } //} }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BC114 { class Program { static void Main(string[] args) { var obj = new Q1(); obj.Solver(); } } class Q1 { public void Solver() { long amswer = 753; var s = Console.ReadLine().Select(x => long.Parse(x.ToString())).ToArray(); long diff = 1000; for (int i = 0; i < s.Count() - 2; i++) { long temp = s[i] * 100 + s[i + 1] * 10 + s[i + 2]; diff = Math.Min(diff, Math.Abs(amswer - temp)); } Console.WriteLine(diff); } } // class Q1 //{ // public void Solver() // { // var age = int.Parse(Console.ReadLine()); // Console.WriteLine((age == 3 || age == 5 || age == 7) ? "YES" : "NO"); // } //} }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
191
2
// Undone using System; using System.Linq; using System.Collections.Generic; using System.Collections; public class Program { public static void Main() { string S = Console.ReadLine(); int min = int.MaxValue; for (int i = 0; i < S.Length - 3; i++) { min = Math.Min(min, Math.Abs(753 - int.Parse(S.Substring(i, 3)))); } Console.WriteLine(min); } private static int ReadInt() { return int.Parse(Console.ReadLine()); } private static double ReadDouble() { return double.Parse(Console.ReadLine()); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static char ReadChar() { return Console.ReadLine()[0]; } private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); } private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); } }
// Undone using System; using System.Linq; using System.Collections.Generic; using System.Collections; public class Program { public static void Main() { string S = Console.ReadLine(); int min = int.MaxValue; for (int i = 0; i < S.Length - 2; i++) { min = Math.Min(min, Math.Abs(753 - int.Parse(S.Substring(i, 3)))); } Console.WriteLine(min); } private static int ReadInt() { return int.Parse(Console.ReadLine()); } private static double ReadDouble() { return double.Parse(Console.ReadLine()); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static char ReadChar() { return Console.ReadLine()[0]; } private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); } private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
335
2
using System; using System.Linq; class A { static void Main() { string str = Console.ReadLine(); int min = 34753; for (int i = 0; i < str.Length - 3; i++) { int u = int.Parse(str.Substring(i, 3)); min = Math.Min(min, Math.Abs(u - 753)); } Console.WriteLine(min); } }
using System; using System.Linq; class A { static void Main() { string str = Console.ReadLine(); int min = 34753; for (int i = 0; i < str.Length - 3 + 1; i++) { int u = int.Parse(str.Substring(i, 3)); min = Math.Min(min, Math.Abs(u - 753)); } Console.WriteLine(min); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
95
2
using System; using System.Collections; namespace Bcs { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var min_ = 1000; for (int i = 0; i < s.Length - 2; ++i) { var x = int.Parse(s.Substring(i - 2, 3)); min_ = Math.Min(min_, Math.Abs(x - 753)); } Console.WriteLine(min_); } } }
using System; using System.Collections; namespace Bcs { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var min_ = 1000; for (int i = 0; i < s.Length - 2; ++i) { var x = int.Parse(s.Substring(i, 3)); min_ = Math.Min(min_, Math.Abs(x - 753)); } Console.WriteLine(min_); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
105
2
using System; class Program { static void Main() { string s = Console.ReadLine(); int ans = int.Parse(s.Substring(0, 2)); for (int i = 1; i < s.Length - 2; i++) { int tmp = int.Parse(s.Substring(i, 3)); if (Math.Abs(753 - tmp) < Math.Abs(753 - ans)) ans = tmp; } Console.WriteLine(Math.Abs(753 - ans)); } }
using System; class Program { static void Main() { string s = Console.ReadLine(); int ans = int.Parse(s.Substring(0, 3)); for (int i = 1; i < s.Length - 2; i++) { int tmp = int.Parse(s.Substring(i, 3)); if (Math.Abs(753 - tmp) < Math.Abs(753 - ans)) ans = tmp; } Console.WriteLine(Math.Abs(753 - ans)); } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203]]
8
115
2
using static System.Math; using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); var ans = int.MaxValue; for (int i = 0; i < s.Length - 3; i++) ans = Min(ans, Abs(753 - int.Parse(s.Substring(i, 3)))); Console.WriteLine(ans); } }
using static System.Math; using System; public class Hello { public static void Main() { var s = Console.ReadLine().Trim(); var ans = int.MaxValue; for (int i = 0; i <= s.Length - 3; i++) ans = Min(ans, Abs(753 - int.Parse(s.Substring(i, 3)))); Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
93
2
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { long a = long.Parse(Console.ReadLine()); var b = new List<long>(); for (int i = 0; i < a.ToString().Length - 2; i++) { b.Add(a / (int)Math.Pow(10, i) - (a / (int)Math.Pow(10, i + 3) * 1000)); } Console.WriteLine(b.Min(x => Math.Abs(753 - x))); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { long a = long.Parse(Console.ReadLine()); var b = new List<long>(); for (int i = 0; i < a.ToString().Length - 2; i++) { b.Add(a / (long)Math.Pow(10, i) - (a / (long)Math.Pow(10, i + 3) * 1000)); } Console.WriteLine(b.Min(x => Math.Abs(753 - x))); } }
[["-", 0, 28, 0, 16, 31, 16, 12, 74, 39, 199], ["+", 0, 28, 0, 16, 31, 16, 12, 74, 39, 199], ["-", 12, 23, 0, 16, 31, 16, 12, 74, 39, 199], ["+", 12, 23, 0, 16, 31, 16, 12, 74, 39, 199]]
8
135
4
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int num = input.Length - 3; List<int> data = new List<int>(); for (int i = 0; i < num; i++) { int n = int.Parse(input[i].ToString() + input[i + 1].ToString() + input[i + 2].ToString()); data.Add(n); } int min = data.Min(x => Math.Abs(753 - x)); Console.WriteLine(min); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int num = input.Length - 3; List<int> data = new List<int>(); for (int i = 0; i <= num; i++) { int n = int.Parse(input[i].ToString() + input[i + 1].ToString() + input[i + 2].ToString()); data.Add(n); } int min = data.Min(x => Math.Abs(753 - x)); Console.WriteLine(min); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
154
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static ABC114.Util; using static System.Console; #if DEBUG using System.Diagnostics; #endif namespace ABC114 { class Program { static void Main(string[] args) { START: // Shitigosan(); // 3m // NanaGoYon(); // 9m NanaGoGo(); #if DEBUG goto START; #endif } private static long[] f(int n) { if (n == 0) return new long[] { 0 }; List<long> ans = new List<long>(); foreach (var l in f(n - 1)) { ans.Add(l * 10 + 7); ans.Add(l * 10 + 5); ans.Add(l * 10 + 3); } return ans.ToArray(); } private static bool Contains753(long n) { bool flag7 = false; bool flag5 = false; bool flag3 = false; while (n != 0) { long tmp = n % 10; if (tmp == 7) flag7 = true; if (tmp == 5) flag5 = true; if (tmp == 3) flag3 = true; n /= 10; } return flag7 && flag5 && flag3; } private static void NanaGoGo() { int N = ReadInt(); int n = N; int keta = 0; while (n != 0) { n /= 10; keta++; } long ans = 0; for (int i = 3; i <= keta; i++) { long[] numList = f(i); foreach (var num in numList) { if (num < N && Contains753(num)) ans++; } } WriteLine(ans); } private static void NanaGoYon() { string S = ReadString(); int len = S.Length; long min = INF; for (int i = 0; i < len - 2; i++) { ChMin(ref min, Math.Abs(long.Parse(S.Substring(i, 3)) - 753)); } WriteLine(min); } private static void Shitigosan() { int X = ReadInt(); if (X == 7 || X == 5 || X == 3) { WriteLine("YES"); } else { WriteLine("NO"); } } } #region ToolBox /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadIntArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static string ReadString() { return Console.ReadLine(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { return Console.ReadLine().Select(c => int.Parse(c.ToString())).ToArray(); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { return Console.ReadLine().Select(c => c == '1').ToArray(); } /// <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; } #if DEBUG static void SampleGenerator() { int A = 1000; int B = 1000; int Q = 1000; Random r = new Random(); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("{0} {1} {2}", A, B, Q)); A.Times(a => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); B.Times(b => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Q.Times(q => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Debug.WriteLine(sb.ToString()); } #endif } /// <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; } } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static ABC114.Util; using static System.Console; #if DEBUG using System.Diagnostics; #endif namespace ABC114 { class Program { static void Main(string[] args) { START: // Shitigosan(); // 3m // NanaGoYon(); // 9m NanaGoGo(); #if DEBUG goto START; #endif } private static long[] f(int n) { if (n == 0) return new long[] { 0 }; List<long> ans = new List<long>(); foreach (var l in f(n - 1)) { ans.Add(l * 10 + 7); ans.Add(l * 10 + 5); ans.Add(l * 10 + 3); } return ans.ToArray(); } private static bool Contains753(long n) { bool flag7 = false; bool flag5 = false; bool flag3 = false; while (n != 0) { long tmp = n % 10; if (tmp == 7) flag7 = true; if (tmp == 5) flag5 = true; if (tmp == 3) flag3 = true; n /= 10; } return flag7 && flag5 && flag3; } private static void NanaGoGo() { int N = ReadInt(); int n = N; int keta = 0; while (n != 0) { n /= 10; keta++; } long ans = 0; for (int i = 3; i <= keta; i++) { long[] numList = f(i); foreach (var num in numList) { if (num <= N && Contains753(num)) ans++; } } WriteLine(ans); } private static void NanaGoYon() { string S = ReadString(); int len = S.Length; long min = INF; for (int i = 0; i < len - 2; i++) { ChMin(ref min, Math.Abs(long.Parse(S.Substring(i, 3)) - 753)); } WriteLine(min); } private static void Shitigosan() { int X = ReadInt(); if (X == 7 || X == 5 || X == 3) { WriteLine("YES"); } else { WriteLine("NO"); } } } #region ToolBox /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadIntArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static string ReadString() { return Console.ReadLine(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { return Console.ReadLine().Select(c => int.Parse(c.ToString())).ToArray(); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { return Console.ReadLine().Select(c => c == '1').ToArray(); } /// <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; } #if DEBUG static void SampleGenerator() { int A = 1000; int B = 1000; int Q = 1000; Random r = new Random(); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("{0} {1} {2}", A, B, Q)); A.Times(a => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); B.Times(b => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Q.Times(q => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Debug.WriteLine(sb.ToString()); } #endif } /// <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; } } #endregion }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19]]
8
2,724
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace algorithm { class Program { public static void Main() { int n = int.Parse(Console.ReadLine()); Queue<string> num = new Queue<string>(); List<long> List = new List<long>(); while (num.Count > 0) { } num.Enqueue("3"); num.Enqueue("5"); num.Enqueue("7"); while (num.Count > 0) { string tmp = num.Dequeue(); if (tmp.Contains("3")) if (tmp.Contains("5")) if (tmp.Contains("7")) List.Add(long.Parse(tmp)); if (tmp.Length < 11) { num.Enqueue(tmp + "3"); num.Enqueue(tmp + "5"); num.Enqueue(tmp + "7"); } } Console.WriteLine(List.Count(x => x < n && x >= 357)); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace algorithm { class Program { public static void Main() { int n = int.Parse(Console.ReadLine()); Queue<string> num = new Queue<string>(); List<long> List = new List<long>(); while (num.Count > 0) { } num.Enqueue("3"); num.Enqueue("5"); num.Enqueue("7"); while (num.Count > 0) { string tmp = num.Dequeue(); if (tmp.Contains("3")) if (tmp.Contains("5")) if (tmp.Contains("7")) List.Add(long.Parse(tmp)); if (tmp.Length < 11) { num.Enqueue(tmp + "3"); num.Enqueue(tmp + "5"); num.Enqueue(tmp + "7"); } } Console.WriteLine(List.Count(x => x <= n && x >= 357)); } } }
[["-", 0, 28, 0, 218, 8, 16, 31, 16, 17, 18], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 17, 19]]
8
252
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace AtCoderABC114 { class Program { public static List<long> GetL(long x) { if (x > 100000000) return new List<long>(); List<long> l1 = new List<long>(); List<long> l2 = new List<long>(); List<long> l3 = new List<long>(); l1.Add(10 * x + 3); l1 = l1.Concat(GetL(10 * x + 3)).ToList(); l2.Add(10 * x + 5); l2 = l2.Concat(GetL(10 * x + 5)).ToList(); l3.Add(10 * x + 7); l3 = l3.Concat(GetL(10 * x + 7)).ToList(); return l1.Concat(l2).Concat(l3).ToList(); } public static bool Judge(long x) { string s = Convert.ToString(x, 10); return s.Contains("7") && s.Contains("5") && s.Contains("3"); } public static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); List<long> l = GetL(0).OrderBy(x => x).ToList(); long res = 0; for (int i = 0; l[i] <= N; i++) { if (Judge(l[i])) res++; } Console.WriteLine(res); } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace AtCoderABC114 { class Program { public static List<long> GetL(long x) { if (x > 100000000) return new List<long>(); List<long> l1 = new List<long>(); List<long> l2 = new List<long>(); List<long> l3 = new List<long>(); l1.Add(10 * x + 3); l1 = l1.Concat(GetL(10 * x + 3)).ToList(); l2.Add(10 * x + 5); l2 = l2.Concat(GetL(10 * x + 5)).ToList(); l3.Add(10 * x + 7); l3 = l3.Concat(GetL(10 * x + 7)).ToList(); return l1.Concat(l2).Concat(l3).ToList(); } public static bool Judge(long x) { string s = Convert.ToString(x, 10); return s.Contains("7") && s.Contains("5") && s.Contains("3"); } public static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); List<long> l = GetL(0).OrderBy(x => x).ToList(); long res = 0; for (int i = 0; i < l.Count && l[i] <= N; i++) { if (Judge(l[i])) res++; } Console.WriteLine(res); } } }
[["+", 8, 196, 0, 7, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 18], ["+", 0, 7, 15, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 7, 15, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 7, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 98]]
8
350
6
using System; namespace _755 { class Program { static float N; static void Main(string[] args) { N = int.Parse(Console.ReadLine()); Console.WriteLine(Dfs("0")); } public static int Dfs(string s) { if (float.Parse(s) > N) { return 0; } int result = 0; if (s.Contains("7") && s.Contains("5") && s.Contains("3")) { result++; } foreach (var item in "753") { result += Dfs(s + item); } return result; } } }
using System; namespace _755 { class Program { static double N; static void Main(string[] args) { N = double.Parse(Console.ReadLine()); Console.WriteLine(Dfs("0")); } public static int Dfs(string s) { if (double.Parse(s) > N) { return 0; } int result = 0; if (s.Contains("7") && s.Contains("5") && s.Contains("3")) { result++; } foreach (var item in "753") { result += Dfs(s + item); } return result; } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 199]]
8
139
6
using System; using System.Linq; namespace ABC144_C { class Program { static long N; static void Main(string[] args) { N = long.Parse(Console.ReadLine()); Console.WriteLine(Dfs("0")); } static long Dfs(string s) { long ret = 0; if (long.Parse(s) > N) { return 0L; } if (s.Contains("3") && s.Contains("5") && s.Contains("7")) { return 1L; } foreach (var i in new char[] { '3', '5', '7' }) { ret += Dfs(s + i); } return ret; } } }
using System; using System.Linq; namespace ABC144_C { class Program { static long N; static void Main(string[] args) { N = long.Parse(Console.ReadLine()); Console.WriteLine(Dfs("0")); } static long Dfs(string s) { long ret = 0; if (long.Parse(s) > N) { return 0L; } if (s.Contains("3") && s.Contains("5") && s.Contains("7")) { ret = 1; } foreach (var i in new char[] { '3', '5', '7' }) { ret += Dfs(s + i); } return ret; } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
157
5
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var n = Int32.Parse(Console.ReadLine()); var shichigosanNums = new List<Int64>(); for (var digit = 3; digit <= 10; digit++) { for (var i = 0; i < Math.Pow(3, digit); i++) { var s = ""; for (var d = 0; d < digit; d++) { var di = 0; if (d == 0) { di = i % 3; } else { di = i % (int)Math.Pow(3, d + 1) / (int)Math.Pow(3, d); } if (di == 0) { s += 3; } else if (di == 1) { s += 5; } else if (di == 2) { s += 7; } } if (s.Contains('7') && s.Contains('5') && s.Contains('3')) { shichigosanNums.Add(Int64.Parse(string.Concat(s.Reverse()))); } } } var c = 0; foreach (var shichigosanNum in shichigosanNums) { if (shichigosanNum < n) { c++; } else { break; } } Console.WriteLine(c); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var n = Int32.Parse(Console.ReadLine()); var shichigosanNums = new List<Int64>(); for (var digit = 3; digit <= 10; digit++) { for (var i = 0; i < Math.Pow(3, digit); i++) { var s = ""; for (var d = 0; d < digit; d++) { var di = 0; if (d == 0) { di = i % 3; } else { di = i % (int)Math.Pow(3, d + 1) / (int)Math.Pow(3, d); } if (di == 0) { s += 3; } else if (di == 1) { s += 5; } else if (di == 2) { s += 7; } } if (s.Contains('7') && s.Contains('5') && s.Contains('3')) { shichigosanNums.Add(Int64.Parse(string.Concat(s.Reverse()))); } } } var c = 0; foreach (var shichigosanNum in shichigosanNums) { if (shichigosanNum <= n) { c++; } else { break; } } Console.WriteLine(c); } }
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 19]]
8
295
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static List<long> list = new List<long>(); static long N = long.Parse(Console.ReadLine()); static void Main(string[] args) { Scanner cin = new Scanner(); foreach (var x in "357") { hoge(long.Parse(x.ToString())); } Console.WriteLine( list.Count(x => x.ToString().ToCharArray().Distinct().Count() == 3)); Console.ReadLine(); } static void hoge(long x) { if (x < N) { list.Add(x); hoge(10 * x + 3); hoge(10 * x + 5); hoge(10 * x + 7); } } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static List<long> list = new List<long>(); static long N = long.Parse(Console.ReadLine()); static void Main(string[] args) { Scanner cin = new Scanner(); foreach (var x in "357") { hoge(long.Parse(x.ToString())); } Console.WriteLine( list.Count(x => x.ToString().ToCharArray().Distinct().Count() == 3)); Console.ReadLine(); } static void hoge(long x) { if (x <= N) { list.Add(x); hoge(10 * x + 3); hoge(10 * x + 5); hoge(10 * x + 7); } } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
545
2
using System; using System.IO; class Program { public static void Main() { long N = int.Parse(Console.ReadLine()); //たくさん確保 long[] a = new long[100000]; a[0] = 3; a[1] = 5; a[2] = 7; for (int i = 0; a[3 * (i - 1) + 5] < N; i++) { a[3 * i + 3] = a[i] * 10 + 3; a[3 * i + 4] = a[i] * 10 + 5; a[3 * i + 5] = a[i] * 10 + 7; // (a[3 * i + 3], // a[3 * i + 4], // a[3 * i + 5]) = sgs(a[i]); } int count = 0; //全てのa[i]に対して、条件を満たすか調べる for (int i = 0; a[i] <= N; i++) { // Console.WriteLine(a[i]); int check3 = 0; int check5 = 0; int check7 = 0; long tmp; tmp = a[i]; //全ての桁に対して、数値を調べる for (int j = 0; j < 10; j++) { // Console.WriteLine(tmp); if (tmp % 10 == 3) { check3++; tmp /= 10; } else if (tmp % 10 == 5) { check5++; tmp /= 10; } else if (tmp % 10 == 7) { check7++; tmp /= 10; } } /* Console.WriteLine("{0} {1} {2} {3}", check3, check5, check7, N); */ if (check3 > 0 && check5 > 0 && check7 > 0 && a[i] <= N) { count++; } } Console.WriteLine(count); // (a[3], a[4], a[5]) = sgs(a[0]); // (a[6], a[7], a[8]) = sgs(a[1]); // (a[9], a[10], a[11]) = sgs(a[2]); } /* static public (long a, long b, long c) sgs(long d) { long a = d * 10 + 3; long b = d * 10 + 5; long c = d * 10 + 7; return (a, b, c); } */ }
using System; using System.IO; class Program { public static void Main() { long N = int.Parse(Console.ReadLine()); //たくさん確保 long[] a = new long[1000000]; a[0] = 3; a[1] = 5; a[2] = 7; for (int i = 0; a[3 * (i - 1) + 5] <= N; i++) { a[3 * i + 3] = a[i] * 10 + 3; a[3 * i + 4] = a[i] * 10 + 5; a[3 * i + 5] = a[i] * 10 + 7; // (a[3 * i + 3], // a[3 * i + 4], // a[3 * i + 5]) = sgs(a[i]); } int count = 0; //全てのa[i]に対して、条件を満たすか調べる for (int i = 0; a[i] <= N; i++) { // Console.WriteLine(a[i]); int check3 = 0; int check5 = 0; int check7 = 0; long tmp; tmp = a[i]; //全ての桁に対して、数値を調べる for (int j = 0; j < 10; j++) { // Console.WriteLine(tmp); if (tmp % 10 == 3) { check3++; tmp /= 10; } else if (tmp % 10 == 5) { check5++; tmp /= 10; } else if (tmp % 10 == 7) { check7++; tmp /= 10; } } /* Console.WriteLine("{0} {1} {2} {3}", check3, check5, check7, N); */ if (check3 > 0 && check5 > 0 && check7 > 0 && a[i] <= N) { count++; } } Console.WriteLine(count); // (a[3], a[4], a[5]) = sgs(a[0]); // (a[6], a[7], a[8]) = sgs(a[1]); // (a[9], a[10], a[11]) = sgs(a[2]); } /* static public (long a, long b, long c) sgs(long d) { long a = d * 10 + 3; long b = d * 10 + 5; long c = d * 10 + 7; return (a, b, c); } */ }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
311
4
using System; using System.Collections.Generic; using System.Linq; class P { static void Main() { long n = long.Parse(Console.ReadLine()); List<long> p = new List<long>(); p.Add(7); p.Add(5); p.Add(3); int ist = 0; int ien = 2; for (int i = 0; i < 7; i++) { for (int j = ist; j <= ien; j++) { p.Add(p[j] * 10 + 7); p.Add(p[j] * 10 + 5); p.Add(p[j] * 10 + 3); } int r = ien - ist + 1; ist = ien + 1; ien += r * 3 + 1; } int ans = 0; p.Sort(); foreach (var i in p) { if (i > n) break; // Console.WriteLine(i); ans += Judge(i) ? 1 : 0; } Console.WriteLine(ans); } static bool Judge(long n) { // nが七五三数か判定 int c7 = 0; int c5 = 0; int c3 = 0; while (n > 0) { long m = n % 10; if (m == 7) c7++; else if (m == 5) c5++; else if (m == 3) c3++; else return false; n /= 10; } if (c7 == 0 || c5 == 0 || c3 == 0) return false; return true; } }
using System; using System.Collections.Generic; using System.Linq; class P { static void Main() { long n = long.Parse(Console.ReadLine()); List<long> p = new List<long>(); p.Add(7); p.Add(5); p.Add(3); int ist = 0; int ien = 2; for (int i = 0; i < 8; i++) { for (int j = ist; j <= ien; j++) { p.Add(p[j] * 10 + 7); p.Add(p[j] * 10 + 5); p.Add(p[j] * 10 + 3); } int r = ien - ist + 1; ist = ien + 1; ien += r * 3 + 1; } int ans = 0; p.Sort(); foreach (var i in p) { if (i > n) break; // Console.WriteLine(i); ans += Judge(i) ? 1 : 0; } Console.WriteLine(ans); } static bool Judge(long n) { // nが七五三数か判定 int c7 = 0; int c5 = 0; int c3 = 0; while (n > 0) { long m = n % 10; if (m == 7) c7++; else if (m == 5) c5++; else if (m == 3) c3++; else return false; n /= 10; } if (c7 == 0 || c5 == 0 || c3 == 0) return false; return true; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
326
2
using System; using System.Text; using static System.Console; namespace a755 { class a755 { static void Main(string[] args) { long x = long.Parse(ReadLine()); long op = 0; long c = 357; while (c <= x) { bool hit3 = false; bool hit5 = false; bool hit7 = false; bool hitX = false; for (int i = 1; (long)Math.Pow(10, i) <= x; i++) { IsNumber357((c - c / (long)Math.Pow(10, i) * (long)Math.Pow(10, i)) / (long)Math.Pow(10, i - 1), ref hit3, ref hit5, ref hit7, ref hitX); if (hitX) { if (i == 1) { c = c + 2; break; } else { c = c + (long)Math.Pow(10, i - 1); break; } } } if (!hitX) { if (hit3 && hit5 && hit7) { op = ++op; } c = c + 2; } } WriteLine(op); } static void IsNumber357(long c, ref bool hit3, ref bool hit5, ref bool hit7, ref bool hitX) { switch (c) { case 3: hit3 = true; break; case 5: hit5 = true; break; case 7: hit7 = true; break; default: hitX = true; break; } } } }
using System; using System.Text; using static System.Console; namespace a755 { class a755 { static void Main(string[] args) { long x = long.Parse(ReadLine()); long op = 0; long c = 357; while (c <= x) { bool hit3 = false; bool hit5 = false; bool hit7 = false; bool hitX = false; for (int i = 1; (long)Math.Pow(10, i - 1) <= c; i++) { IsNumber357((c - c / (long)Math.Pow(10, i) * (long)Math.Pow(10, i)) / (long)Math.Pow(10, i - 1), ref hit3, ref hit5, ref hit7, ref hitX); if (hitX) { if (i == 1) { c = c + 2; break; } else { c = c + (long)Math.Pow(10, i - 1); break; } } } if (!hitX) { if (hit3 && hit5 && hit7) { op = ++op; } c = c + 2; } } WriteLine(op); } static void IsNumber357(long c, ref bool hit3, ref bool hit5, ref bool hit7, ref bool hitX) { switch (c) { case 3: hit3 = true; break; case 5: hit5 = true; break; case 7: hit7 = true; break; default: hitX = true; break; } } } }
[["+", 51, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 51, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 52, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 12, 22]]
8
312
4
using System; using System.Collections.Generic; namespace abc114_c { class Program { static void Main(string[] args) { List<string>[] list = new List<string>[10]; list[0] = new List<string> { "" }; for (int i = 1; i < 10; i++) { list[i] = new List<string>(); foreach (var item in list[i - 1]) { list[i].Add(item + "3"); list[i].Add(item + "5"); list[i].Add(item + "7"); } } int n = int.Parse(Console.ReadLine()); int ret = 0; for (int i = 3; i < 10; i++) { foreach (var item in list[i]) { int a = 0; int b = 0; int c = 0; for (int j = 0; j < item.Length; j++) { switch (item[j]) { case '3': { a++; break; } case '5': { b++; break; } case '7': { c++; break; } } } if (int.Parse(item) < n && a > 0 && b > 0 && c > 0) ret++; } } Console.WriteLine(ret); } } }
using System; using System.Collections.Generic; namespace abc114_c { class Program { static void Main(string[] args) { List<string>[] list = new List<string>[10]; list[0] = new List<string> { "" }; for (int i = 1; i < 10; i++) { list[i] = new List<string>(); foreach (var item in list[i - 1]) { list[i].Add(item + "3"); list[i].Add(item + "5"); list[i].Add(item + "7"); } } int n = int.Parse(Console.ReadLine()); int ret = 0; for (int i = 3; i < 10; i++) { foreach (var item in list[i]) { int a = 0; int b = 0; int c = 0; for (int j = 0; j < item.Length; j++) { switch (item[j]) { case '3': { a++; break; } case '5': { b++; break; } case '7': { c++; break; } } } if (int.Parse(item) <= n && a > 0 && b > 0 && c > 0) ret++; } } Console.WriteLine(ret); } } }
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 19]]
8
304
2
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder { class Program { static List<int> primeNumbers; static int count = 0; static void Main(string[] args) { //[summary]D - 756 primeNumbers = new List<int> { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; int n = int.Parse(Console.ReadLine()); //素因数分解した要素を入れるためのDictionary var divisors = new Dictionary<int, int>(); foreach (var num in primeNumbers) { divisors.Add(num, 0); } // N!を素因数分解 for (int i = 2; i <= n; i++) { Divide(i, divisors); } // 74x1 で七五数になるパターンを取得 CountCombisByOneNum(divisors); // 14x4 で七五数になるパターンを取得 CountCombisByTwoNums(divisors, 14, 4); // 24x3 で七五数になるパターンを取得 CountCombisByTwoNums(divisors, 24, 3); // 4x4x2 で七五数になるパターンを取得 CountCombisByThreeNums(divisors); Console.WriteLine(count); } static void CountCombisByThreeNums(Dictionary<int, int> divisors) { var combis = new List<List<int>>(); foreach (var p in divisors) { if (p.Value >= 4) { foreach (var q in divisors) { if (q.Key != p.Key && q.Value >= 4) { if (!IsSameCombiExists(combis, p.Key, q.Key)) { foreach (var r in divisors) { if (r.Key != p.Key && r.Key != q.Key && r.Value >= 2) { count++; } } } } } } } } static bool IsSameCombiExists(List<List<int>> combis, int p, int q) { foreach (var c in combis) { if (c.Contains(p) && c.Contains(q)) { return true; } } combis.Add(new List<int> { p, q }); return false; } static void CountCombisByTwoNums(Dictionary<int, int> divisors, int a, int b) { foreach (var p in divisors) { if (p.Value >= a) { foreach (var q in divisors) { if (p.Key != q.Key && q.Value >= b) { count++; } } } } } static void CountCombisByOneNum(Dictionary<int, int> divisors) { foreach (var divisor in divisors) { if (divisor.Value >= 74) { count++; } } } static void Divide(int num, Dictionary<int, int> divisors) { if (IsPrimeNumber(num)) { divisors[num]++; return; } else { for (int i = 2; i < num; i++) { if (num % i == 0) { divisors[i]++; Divide(num / i, divisors); return; } } } } static bool IsPrimeNumber(int num) { if (primeNumbers.Contains(num)) { return true; } else { return false; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder { class Program { static List<int> primeNumbers; static int count = 0; static void Main(string[] args) { //[summary]D - 756 primeNumbers = new List<int> { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 }; int n = int.Parse(Console.ReadLine()); //素因数分解した要素を入れるためのDictionary var divisors = new Dictionary<int, int>(); foreach (var num in primeNumbers) { divisors.Add(num, 0); } // N!を素因数分解 for (int i = 2; i <= n; i++) { Divide(i, divisors); } // 74x1 で七五数になるパターンを取得 CountCombisByOneNum(divisors); // 14x4 で七五数になるパターンを取得 CountCombisByTwoNums(divisors, 14, 4); // 24x3 で七五数になるパターンを取得 CountCombisByTwoNums(divisors, 24, 2); // 4x4x2 で七五数になるパターンを取得 CountCombisByThreeNums(divisors); Console.WriteLine(count); } static void CountCombisByThreeNums(Dictionary<int, int> divisors) { var combis = new List<List<int>>(); foreach (var p in divisors) { if (p.Value >= 4) { foreach (var q in divisors) { if (q.Key != p.Key && q.Value >= 4) { if (!IsSameCombiExists(combis, p.Key, q.Key)) { foreach (var r in divisors) { if (r.Key != p.Key && r.Key != q.Key && r.Value >= 2) { count++; } } } } } } } } static bool IsSameCombiExists(List<List<int>> combis, int p, int q) { foreach (var c in combis) { if (c.Contains(p) && c.Contains(q)) { return true; } } combis.Add(new List<int> { p, q }); return false; } static void CountCombisByTwoNums(Dictionary<int, int> divisors, int a, int b) { foreach (var p in divisors) { if (p.Value >= a) { foreach (var q in divisors) { if (p.Key != q.Key && q.Value >= b) { count++; } } } } } static void CountCombisByOneNum(Dictionary<int, int> divisors) { foreach (var divisor in divisors) { if (divisor.Value >= 74) { count++; } } } static void Divide(int num, Dictionary<int, int> divisors) { if (IsPrimeNumber(num)) { divisors[num]++; return; } else { for (int i = 2; i < num; i++) { if (num % i == 0) { divisors[i]++; Divide(num / i, divisors); return; } } } } static bool IsPrimeNumber(int num) { if (primeNumbers.Contains(num)) { return true; } else { return false; } } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
635
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long[] aa = sc.LongArray(); long sum = aa.Sum(); long answer = 0; long min = long.MaxValue; for (int i = 0; i < n; i++) { long diff = Math.Abs(sum - min * n); if (diff < min) { min = diff; answer = i + 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 n = sc.NextLong(); long[] aa = sc.LongArray(); long sum = aa.Sum(); long answer = 0; long min = long.MaxValue; for (int i = 0; i < n; i++) { long diff = Math.Abs(sum - aa[i] * n); if (diff < min) { min = diff; answer = i; } } 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(); } }
[["-", 3, 4, 0, 28, 0, 16, 12, 16, 31, 22], ["+", 0, 28, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
430
7
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { //入力 int N = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); string[] t = s.Split(' '); int[] a = new int[N]; //数値を当てはめていく for (int i = 0; i < N; i++) { a[i] = int.Parse(t[i]); } float sum = 0; //全体の合計 float ave = 0; //全体の平均 //合計及び平均を求める for (int i = 0; i < N; i++) { sum += a[i]; } //平均値との差をとっていき、最小の値及びその時のiの値を保存する float diff = sum - a[0] * N; //暫定的な、平均値との差 int ans = 0; //暫定的な、平均に一番近い番号 for (int i = 0; i < N; i++) { //最小値を更新したとき if (diff > Math.Abs(sum - a[i] * N)) { diff = Math.Abs(sum - a[i] * N); ans = i; } } //出力 Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { //入力 int N = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); string[] t = s.Split(' '); int[] a = new int[N]; //数値を当てはめていく for (int i = 0; i < N; i++) { a[i] = int.Parse(t[i]); } float sum = 0; //全体の合計 float ave = 0; //全体の平均 //合計及び平均を求める for (int i = 0; i < N; i++) { sum += a[i]; } //平均値との差をとっていき、最小の値及びその時のiの値を保存する float diff = Math.Abs(sum - a[0] * N); //暫定的な、平均値との差 int ans = 0; //暫定的な、平均に一番近い番号 for (int i = 0; i < N; i++) { //最小値を更新したとき if (diff > Math.Abs(sum - a[i] * N)) { diff = Math.Abs(sum - a[i] * N); ans = i; } } //出力 Console.WriteLine(ans); } }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
227
5
using System; using System.Collections.Generic; using System.Linq; namespace Dwango_Thumbnail { internal class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); List<double> alist = new List<double>(); for (int i = 0; i < n; i++) { alist.Add(int.Parse(input[i])); } double aAvg = alist.Average(); int resultIndex = 0; double minAbs = Math.Abs(aAvg - alist[0]); for (int i = 0; i < n; i++) { double abs = Math.Abs(aAvg - alist[i]); if (abs == 0) { resultIndex = i; break; } else if (minAbs > abs) { resultIndex = i; } } Console.WriteLine(resultIndex); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Dwango_Thumbnail { internal class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); List<double> alist = new List<double>(); for (int i = 0; i < n; i++) { alist.Add(int.Parse(input[i])); } double aAvg = alist.Average(); int resultIndex = 0; double minAbs = Math.Abs(aAvg - alist[0]); for (int i = 0; i < n; i++) { double abs = Math.Abs(aAvg - alist[i]); if (abs == 0) { resultIndex = i; break; } else if (minAbs > abs) { minAbs = abs; resultIndex = i; } } Console.WriteLine(resultIndex); } } }
[["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35]]
8
207
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); } static int Solve(int N, int[] A) { int sum = A.Sum(); var tuples = new Tuple<int, int>[N]; for (int i = 0; i < N; ++i) { tuples[i] = new Tuple<int, int>(A[i], i); } return tuples.OrderBy(t => Math.Abs(t.Item1 * N - sum)) .ThenBy(t => t.Item1) .First() .Item2; } static void Main(string[] args) { int N = ReadInt(); int[] A = ReadInts(); Console.WriteLine(Solve(N, A)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Program { private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static int Solve(int N, int[] A) { int sum = A.Sum(); var tuples = new Tuple<int, int>[N]; for (int i = 0; i < N; ++i) { tuples[i] = new Tuple<int, int>(A[i], i); } return tuples.OrderBy(t => Math.Abs(t.Item1 * N - sum)) .ThenBy(t => t.Item2) .First() .Item2; } static void Main(string[] args) { int N = ReadInt(); int[] A = ReadInts(); Console.WriteLine(Solve(N, A)); } } }
[["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22]]
8
335
2
using System; using System.Linq; using System.Collections.Generic; class Bmondai { static void Main() { var n = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); var N = n[0]; var K = n[1]; var line = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); var list = new List<long>(); for (long i = 0; i < N; ++i) { var sum = 0L; for (long j = i; j < N; ++j) { sum += line[j]; if (sum != 0L) list.Add(sum); } } var max = (int)(Math.Log(list.Max(), 2)); var ans = 0L; for (var i = max; i > -1; --i) { var bit = (long)Math.Pow(2, i); var ansList = list.Where(x => (x & bit) != 0).ToList(); if (K <= ansList.Count()) { ans |= bit; } } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Bmondai { static void Main() { var n = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); var N = n[0]; var K = n[1]; var line = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray(); var list = new List<long>(); for (long i = 0; i < N; ++i) { var sum = 0L; for (long j = i; j < N; ++j) { sum += line[j]; if (sum != 0L) list.Add(sum); } } var max = (int)(Math.Log(list.Max(), 2)); var ans = 0L; for (var i = max; i > -1; --i) { var bit = (long)Math.Pow(2, i); var ansList = list.Where(x => (x & bit) != 0).ToList(); if (K <= ansList.Count()) { list = ansList; ans |= bit; } } Console.WriteLine(ans); } }
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
277
4
using System; public class AtCoder { public static void Main() { string[] s; s = Console.ReadLine().Trim().Split(' '); int n, k; n = int.Parse(s[0]); k = int.Parse(s[1]); s = Console.ReadLine().Trim().Split(' '); long[] a = new long[n]; long[] b = new long[n]; for (int i = 0; i < n; i++) { a[i] = long.Parse(s[i]); } b[0] = a[0]; for (int i = 1; i < n; i++) { b[i] = b[i - 1] + a[i]; } int c = 0; long[] x = new long[n * (n + 1) / 2]; long[] y = new long[n * (n + 1) / 2]; for (int i = 0; i < n; i++) { for (int j = -1; j < i; j++) { if (j == -1) x[c] = b[i]; else x[c] = b[i] - b[j]; y[c] = 1; c++; } } long p = 0; int d = 0; long[] z = new long[60]; for (int i = 59; i > -1; i--) { d = 0; p = (long)Math.Pow(2, i); for (int j = 0; j < c; j++) { if (y[j] == 1) if (x[j] - p >= 0) d++; } if (d >= k) { z[i] = 1; for (int j = 0; j < c; j++) { x[j] -= p; if (x[j] < 0) y[j] = 0; } } else { for (int j = 0; j < c; j++) { if (x[j] > p) x[j] -= p; } } } long ans = 0; for (int i = 59; i > -1; i--) { ans += (long)Math.Pow(2, i) * z[i]; } // for(int i = 0; i<z.Length; i++) Console.WriteLine(ans); } }
using System; public class AtCoder { public static void Main() { string[] s; s = Console.ReadLine().Trim().Split(' '); int n, k; n = int.Parse(s[0]); k = int.Parse(s[1]); s = Console.ReadLine().Trim().Split(' '); long[] a = new long[n]; long[] b = new long[n]; for (int i = 0; i < n; i++) { a[i] = long.Parse(s[i]); } b[0] = a[0]; for (int i = 1; i < n; i++) { b[i] = b[i - 1] + a[i]; } int c = 0; long[] x = new long[n * (n + 1) / 2]; long[] y = new long[n * (n + 1) / 2]; for (int i = 0; i < n; i++) { for (int j = -1; j < i; j++) { if (j == -1) x[c] = b[i]; else x[c] = b[i] - b[j]; y[c] = 1; c++; } } long p = 0; int d = 0; long[] z = new long[60]; for (int i = 59; i > -1; i--) { d = 0; p = (long)Math.Pow(2, i); for (int j = 0; j < c; j++) { if (y[j] == 1) if (x[j] - p >= 0) d++; } if (d >= k) { z[i] = 1; for (int j = 0; j < c; j++) { x[j] -= p; if (x[j] < 0) y[j] = 0; } } else { for (int j = 0; j < c; j++) { if (x[j] >= p) x[j] -= p; } } } long ans = 0; for (int i = 59; i > -1; i--) { ans += (long)Math.Pow(2, i) * z[i]; } // for(int i = 0; i<z.Length; i++) Console.WriteLine(ans); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
536
2
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace AtCoderABC113 { class Program { public static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int X = int.Parse(s[0]); int Y = int.Parse(s[1]); Console.WriteLine(X * Y / 2); } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace AtCoderABC113 { class Program { public static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int X = int.Parse(s[0]); int Y = int.Parse(s[1]); Console.WriteLine(X + Y / 2); } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
95
2
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int X = int.Parse(input[0]); int Y = int.Parse(input[0]); Console.WriteLine(X + Y / 2); } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int X = int.Parse(input[0]); int Y = int.Parse(input[1]); Console.WriteLine(X + Y / 2); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
77
2
using System; class B { static void Main() { int N = int.Parse(Console.ReadLine()); int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int T = Ar[0], A = Ar[1]; int[] place = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); double temp = 6000000000000; int ans = 0; for (int i = 0; i < N; i++) { if (temp > Math.Abs(A - T - (place[i] * 0.006))) { temp = Math.Abs(A - (T - (place[i] * 0.006))); ans = i + 1; } } Console.WriteLine(ans); } }
using System; class B { static void Main() { int N = int.Parse(Console.ReadLine()); int[] Ar = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int T = Ar[0], A = Ar[1]; int[] place = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); double temp = 6000000000000; int ans = 0; for (int i = 0; i < N; i++) { if (temp > Math.Abs(A - (T - (place[i] * 0.006)))) { temp = Math.Abs(A - (T - (place[i] * 0.006))); ans = i + 1; } } Console.WriteLine(ans); } }
[["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
8
182
2
using System; using System.Linq; namespace AtCorder { class Program { static void Main(string[] args) { var input1 = Console.ReadLine(); var input2 = Console.ReadLine().Split(' '); var input3 = Console.ReadLine(); var n = int.Parse(input1); var t = int.Parse(input2[0]); var a = int.Parse(input2[1]); var hs = input3.Split(' ').Select(s => int.Parse(s)).ToArray(); var pos = 0; var diff = long.MaxValue; for (var i = 0; i < n; i++) { var d = (t - hs[i] * 0.006) - a; if (d < 0) { d = -d; } if (d < diff) { diff = (int)d; pos = i + 1; } } Console.WriteLine(pos); } } }
using System; using System.Linq; namespace AtCorder { class Program { static void Main(string[] args) { var input1 = Console.ReadLine(); var input2 = Console.ReadLine().Split(' '); var input3 = Console.ReadLine(); var n = int.Parse(input1); var t = int.Parse(input2[0]); var a = int.Parse(input2[1]); var hs = input3.Split(' ').Select(s => int.Parse(s)).ToArray(); var pos = 0; var diff = long.MaxValue; for (var i = 0; i < n; i++) { var d = (t * 1000 - hs[i] * 6) - a * 1000; if (d < 0) { d = -d; } if (d < diff) { diff = (int)d; pos = i + 1; } } Console.WriteLine(pos); } } }
[["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 16, 31, 23, 0, 16, 12, 16, 12, 250], ["+", 0, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203]]
8
210
6
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.B { static class Program { public static void Solve(Scanner cin) { var (n, t, a) = cin.ReadValue<int, int, int>(); var h = cin.ReadIntArray(n); int ans = -1; double near = double.MaxValue; for (int i = 0; i < n; i++) { var v = Math.Abs(a - (t - h[i] * 0.006)); if (near > v) ans = i; } Console.WriteLine(ans + 1); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace FertiLib.Contest.B { static class Program { public static void Solve(Scanner cin) { var (n, t, a) = cin.ReadValue<int, int, int>(); var h = cin.ReadIntArray(n); int ans = -1; double near = double.MaxValue; for (int i = 0; i < n; i++) { var v = Math.Abs(a - (t - h[i] * 0.006)); if (near > v) { ans = i; near = v; } } Console.WriteLine(ans + 1); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); public static bool Chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) >= 0) return false; a = b; return true; } public static bool Chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) <= 0) return false; a = b; return true; } } static class Util { public static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
2,719
6
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] TA = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); double T = TA[0]; double A = TA[1]; double[] H = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray(); List<double> intlist = new List<double>(); for (int i = 0; i < N; i++) { intlist.Add((A - (T - H[i] * 0.006))); } Console.WriteLine(intlist.IndexOf(intlist.Min()) + 1); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] TA = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); double T = TA[0]; double A = TA[1]; double[] H = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray(); List<double> intlist = new List<double>(); for (int i = 0; i < N; i++) { intlist.Add(Math.Abs((A - (T - H[i] * 0.006)))); } Console.WriteLine(intlist.IndexOf(intlist.Min()) + 1); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 23, 0, 24], ["+", 0, 28, 0, 23, 0, 16, 12, 23, 0, 25]]
8
200
5
using System; namespace ABC113B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var target = Console.ReadLine().Split(' '); int T = int.Parse(target[0]); int A = int.Parse(target[0]); target = Console.ReadLine().Split(' '); int altitude = int.Parse(target[0]); double min_temp = Math.Abs(T - altitude * 0.006 - A); int min_ind = 0; for (int i = 1; i < N; i++) { altitude = int.Parse(target[i]); double temp = Math.Abs(T - altitude * 0.006 - A); if (temp < min_temp) { min_ind = i; min_temp = temp; } } Console.WriteLine("{0}", min_ind + 1); } } }
using System; namespace ABC113B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var target = Console.ReadLine().Split(' '); int T = int.Parse(target[0]); int A = int.Parse(target[1]); target = Console.ReadLine().Split(' '); int altitude = int.Parse(target[0]); double min_temp = Math.Abs(T - altitude * 0.006 - A); int min_ind = 0; for (int i = 1; i < N; i++) { altitude = int.Parse(target[i]); double temp = Math.Abs(T - altitude * 0.006 - A); if (temp < min_temp) { min_ind = i; min_temp = temp; } } Console.WriteLine("{0}", min_ind + 1); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
200
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var N = Int1; var o = Ints; var H = Ints; var h = Enumerable.Range(0, N) .Select(i => new Tuple<int, int>(H[i], i)) .ToArray(); Write( h.OrderBy(i => Abs(o[1] - i.Item1 * 0.006 - o[0])).ToArray()[0].Item2 + 1); } } public static class Graph {} public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const int MOD = 1000000007; public const int MOD2 = 998244353; public static long Pow(long i, long N, long MOD = 1000000007) { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] HorizontalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Horizontalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var N = Int1; var o = Ints; var H = Ints; var h = Enumerable.Range(0, N) .Select(i => new Tuple<int, int>(H[i], i)) .ToArray(); Write( h.OrderBy(i => Abs(o[0] - i.Item1 * 0.006 - o[1])).ToArray()[0].Item2 + 1); } } public static class Graph {} public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const int MOD = 1000000007; public const int MOD2 = 998244353; public static long Pow(long i, long N, long MOD = 1000000007) { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } public static Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public static List<long> DivisorEnumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] HorizontalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Horizontalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
1,125
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class34 { static void Main() { int N = int.Parse(Console.ReadLine()); var TA = Console.ReadLine().Split().Select(double.Parse).ToArray(); double T = TA[0], A = TA[1]; var H = Console.ReadLine().Split().Select(double.Parse).ToArray(); int num = 0; double min = int.MaxValue; for (int i = 0; i < N; i++) { double t = T - H[i] * 0.06; if (Math.Abs(A - t) < min) { min = Math.Abs(A - t); num = i; } } Console.WriteLine(num + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class34 { static void Main() { int N = int.Parse(Console.ReadLine()); var TA = Console.ReadLine().Split().Select(double.Parse).ToArray(); double T = TA[0], A = TA[1]; var H = Console.ReadLine().Split().Select(double.Parse).ToArray(); int num = 0; double min = int.MaxValue; for (int i = 0; i < N; i++) { double t = T - H[i] * 0.006; if (Math.Abs(A - t) < min) { min = Math.Abs(A - t); num = i; } } Console.WriteLine(num + 1); } } }
[["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 250], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 250]]
8
198
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class ABC { static int mod = 1000000007; // 10^9+7 static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); int n = int.Parse(Console.ReadLine()); // string s = Console.ReadLine(); int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); // long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray(); int t = vs[0]; int a = vs[1]; int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 1; double min = Math.Abs(t - h[0] * 0.006); // System.Diagnostics.Debug.WriteLine($"1:{min} = {t} - {h[0] * 0.006}"); for (int i = 1; i < n; i++) { double c = Math.Abs(t - h[i] * 0.006); // System.Diagnostics.Debug.WriteLine($"{i + 1}:{c} = {t} - {h[i] * // 0.006}"); if (min > c) { ans = i + 1; min = c; } } Console.WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class ABC { static int mod = 1000000007; // 10^9+7 static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); int n = int.Parse(Console.ReadLine()); // string s = Console.ReadLine(); int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); // long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray(); int t = vs[0]; int a = vs[1]; int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ans = 1; double min = Math.Abs(t - h[0] * 0.006 - a); // System.Diagnostics.Debug.WriteLine($"1:{min} = {t} - {h[0] * 0.006}"); for (int i = 1; i < n; i++) { double c = Math.Abs(t - h[i] * 0.006 - a); // System.Diagnostics.Debug.WriteLine($"{i + 1}:{c} = {t} - {h[i] * // 0.006}"); if (min > c) { ans = i + 1; min = c; } } Console.WriteLine(ans); Console.Out.Flush(); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
254
4
using System; using System.Linq; using System.Collections.Generic; using System.IO; public class Cell { public int X { get; set; } public int Y { get; set; } public string CellType { get; set; } public int Step { get; set; } public static Cell[] GetCells(char[] row, int y) { var cells = Enumerable.Range(0, row.Length) .Select(x => new Cell { X = x + 1, Y = y, CellType = Convert.ToString(row[x]), Step = -1, }); return cells.ToArray(); } } class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); var input = Reads(); var t = input[0]; var a = input[1]; input = Reads(); var d = new long[n]; for (int i = 0; i < n; i++) { d[i] = (long)(Math.Abs(a - (t - input[i] * 0.006))) * 1000; } long min = 0; for (int i = 0; i < n; i++) { if (d.Min() == d[i]) { min = i; } } Console.WriteLine(min + 1); Console.Out.Flush(); } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; public class Cell { public int X { get; set; } public int Y { get; set; } public string CellType { get; set; } public int Step { get; set; } public static Cell[] GetCells(char[] row, int y) { var cells = Enumerable.Range(0, row.Length) .Select(x => new Cell { X = x + 1, Y = y, CellType = Convert.ToString(row[x]), Step = -1, }); return cells.ToArray(); } } class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); var input = Reads(); var t = input[0]; var a = input[1]; input = Reads(); var d = new long[n]; for (int i = 0; i < n; i++) { d[i] = (long)(Math.Abs(a - (t - input[i] * 0.006)) * 1000); } long min = 0; for (int i = 0; i < n; i++) { if (d.Min() == d[i]) { min = i; } } Console.WriteLine(min + 1); Console.Out.Flush(); } }
[["-", 0, 11, 12, 16, 31, 74, 51, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 25]]
8
373
2
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); double T = input[0]; double A = input[1]; var inputh = Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); List<Tuple<double, int>> temp = new List<Tuple<double, int>>(); for (var i = 0; i < N; i++) { temp.Add(new Tuple<double, int>(Math.Abs(T - ((inputh[i]) * 0.006) - A), i + 1)); } temp.Sort(); Console.WriteLine(temp[0].Item2 + 1); } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); double T = input[0]; double A = input[1]; var inputh = Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); List<Tuple<double, int>> temp = new List<Tuple<double, int>>(); for (var i = 0; i < N; i++) { temp.Add(new Tuple<double, int>(Math.Abs(T - ((inputh[i]) * 0.006) - A), i + 1)); } temp.Sort(); Console.WriteLine(temp[0].Item2); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
233
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; namespace Program { public static class ABC113B { static public void Solve() { var N = NextInt; var T = NextInt; var A = NextInt; var HList = NextIntList(N); var ans = HList.Select((e, i) => new { s = Abs(A - T - e * 0.006), i = i }) .OrderBy(e => e.s) .First(); Console.WriteLine(ans.i + 1); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { private 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(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); static List<int> NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList(); static List<long> NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList(); static List<double> NextDoubleList(int N) => Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList(); static List<string> NextStringList(int N) => Enumerable.Repeat(0, N).Select(_ => NextString).ToList(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); static IEnumerable<T> Repeat<T>(T v, int n) => Enumerable.Repeat<T>(v, n); static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } static List<T> Sort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, comp); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => comp(y, x)); return tmp.ToList(); } static IEnumerable<long> Prime(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; public Tuple<TKey, TValue> Pop() => q.Pop(); } class Mod { static public long _mod = 1000000007; private long _val = 0; public Mod(long x) { _val = x % _mod; } static public implicit operator Mod(long x) => new Mod(x); static public explicit operator long(Mod x) => x._val; static public Mod operator +(Mod x) => x._val; static public Mod operator -(Mod x) => -x._val; static public Mod operator ++(Mod x) => x._val + 1; static public Mod operator --(Mod x) => x._val - 1; static public Mod operator +(Mod x, Mod y) => (x._val + y._val) % _mod; static public Mod operator -(Mod x, Mod y) => ((((x._val - y._val) % _mod) + _mod) % _mod); static public Mod operator *(Mod x, Mod y) => (x._val * y._val) % _mod; static public Mod operator /(Mod x, Mod y) => (x._val * Inverse(y._val)) % _mod; static public bool operator ==(Mod x, Mod y) => x._val == y._val; static public bool operator !=(Mod x, Mod y) => x._val != y._val; static public bool operator<(Mod x, Mod y) => x._val < y._val; static public bool operator>(Mod x, Mod y) => x._val > y._val; static public bool operator <=(Mod x, Mod y) => x._val <= y._val; static public bool operator >=(Mod x, Mod y) => x._val >= y._val; static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } override public bool Equals(object obj) => obj == null ? false : _val == ((Mod)obj)._val; public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; public override int GetHashCode() => _val.GetHashCode(); public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>(); static private List<Mod> _ifact = new List<Mod>(); static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) { _fact.Add(1); _ifact.Add(1); } else { _fact.Add(_fact[i - 1] * i); _ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2)); } } static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _ifact[n - k] * _ifact[k] * _fact[n]; } } class Mat<T> { private T[,] m; public Mat(T[,] v) { m = (T[,])v.Clone(); } static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return new Mat<T>(tm); } static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return new Mat<T>(tm); } static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return new Mat<T>(tm); } static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); static Mod Pow(Mod x, long y) => Mod.Pow(x, y); static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>(); static void _Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) _fact.Add(1); else _fact.Add(_fact[i - 1] * i); } static long Comb(int n, int k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; namespace Program { public static class ABC113B { static public void Solve() { var N = NextInt; var T = NextInt; var A = NextInt; var HList = NextIntList(N); var ans = HList.Select((e, i) => new { s = Abs(A - T + e * 0.006), i = i }) .OrderBy(e => e.s) .First(); Console.WriteLine(ans.i + 1); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { private 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(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); static List<int> NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList(); static List<long> NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList(); static List<double> NextDoubleList(int N) => Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList(); static List<string> NextStringList(int N) => Enumerable.Repeat(0, N).Select(_ => NextString).ToList(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); static IEnumerable<T> Repeat<T>(T v, int n) => Enumerable.Repeat<T>(v, n); static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } static List<T> Sort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, comp); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => comp(y, x)); return tmp.ToList(); } static IEnumerable<long> Prime(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; public Tuple<TKey, TValue> Pop() => q.Pop(); } class Mod { static public long _mod = 1000000007; private long _val = 0; public Mod(long x) { _val = x % _mod; } static public implicit operator Mod(long x) => new Mod(x); static public explicit operator long(Mod x) => x._val; static public Mod operator +(Mod x) => x._val; static public Mod operator -(Mod x) => -x._val; static public Mod operator ++(Mod x) => x._val + 1; static public Mod operator --(Mod x) => x._val - 1; static public Mod operator +(Mod x, Mod y) => (x._val + y._val) % _mod; static public Mod operator -(Mod x, Mod y) => ((((x._val - y._val) % _mod) + _mod) % _mod); static public Mod operator *(Mod x, Mod y) => (x._val * y._val) % _mod; static public Mod operator /(Mod x, Mod y) => (x._val * Inverse(y._val)) % _mod; static public bool operator ==(Mod x, Mod y) => x._val == y._val; static public bool operator !=(Mod x, Mod y) => x._val != y._val; static public bool operator<(Mod x, Mod y) => x._val < y._val; static public bool operator>(Mod x, Mod y) => x._val > y._val; static public bool operator <=(Mod x, Mod y) => x._val <= y._val; static public bool operator >=(Mod x, Mod y) => x._val >= y._val; static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } override public bool Equals(object obj) => obj == null ? false : _val == ((Mod)obj)._val; public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; public override int GetHashCode() => _val.GetHashCode(); public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>(); static private List<Mod> _ifact = new List<Mod>(); static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) { _fact.Add(1); _ifact.Add(1); } else { _fact.Add(_fact[i - 1] * i); _ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2)); } } static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _ifact[n - k] * _ifact[k] * _fact[n]; } } class Mat<T> { private T[,] m; public Mat(T[,] v) { m = (T[,])v.Clone(); } static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return new Mat<T>(tm); } static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return new Mat<T>(tm); } static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return new Mat<T>(tm); } static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); static Mod Pow(Mod x, long y) => Mod.Pow(x, y); static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>(); static void _Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) _fact.Add(1); else _fact.Add(_fact[i - 1] * i); } static long Comb(int n, int k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
3,603
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static ABC113.Util; using static System.Console; #if DEBUG using System.Diagnostics; #endif /// <summary> /// 感想 2019/05/14 /// </summary> namespace ABC113 { class Program { static void Main(string[] args) { START: // DiscountFare(); // 5m Palace(); #if DEBUG goto START; #endif } private static void Palace() { long N = ReadLong(); long[] line = ReadLongArray(); long T = line[0]; long A = line[1]; long[] H = ReadLongArray(); List<double> TList = H.Select(h => Math.Abs((T - h * 0.006) - A)).ToList(); double min = TList.Min(); int ans = 0; for (int i = 0; i < N; i++) { if (TList[i] == min) { ans = i; break; } } WriteLine(ans); } private static void DiscountFare() { long[] X = ReadLongArray(); long ans = X[0] + X[1] / 2; WriteLine(ans); } } #region ToolBox /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadIntArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static string ReadString() { return Console.ReadLine(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { return Console.ReadLine().Select(c => int.Parse(c.ToString())).ToArray(); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { return Console.ReadLine().Select(c => c == '1').ToArray(); } /// <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; } #if DEBUG static void SampleGenerator() { int A = 1000; int B = 1000; int Q = 1000; Random r = new Random(); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("{0} {1} {2}", A, B, Q)); A.Times(a => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); B.Times(b => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Q.Times(q => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Debug.WriteLine(sb.ToString()); } #endif } /// <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; } } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using static ABC113.Util; using static System.Console; #if DEBUG using System.Diagnostics; #endif /// <summary> /// 感想 2019/05/14 /// </summary> namespace ABC113 { class Program { static void Main(string[] args) { START: // DiscountFare(); // 5m Palace(); #if DEBUG goto START; #endif } private static void Palace() { long N = ReadLong(); long[] line = ReadLongArray(); long T = line[0]; long A = line[1]; long[] H = ReadLongArray(); List<double> TList = H.Select(h => Math.Abs((T - h * 0.006) - A)).ToList(); double min = TList.Min(); int ans = 0; for (int i = 0; i < N; i++) { if (TList[i] == min) { ans = i + 1; break; } } WriteLine(ans); } private static void DiscountFare() { long[] X = ReadLongArray(); long ans = X[0] + X[1] / 2; WriteLine(ans); } } #region ToolBox /// <summary> /// ユーティリティー /// </summary> public static class Util { // 10^17 public static readonly long INF = (long)1e17; public static int ReadInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadIntArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static string ReadString() { return Console.ReadLine(); } /// <summary> /// "00101001010"という様な入力をintの配列にして返す /// </summary> /// <returns></returns> public static int[] ReadIntArrayFromBinaryString() { return Console.ReadLine().Select(c => int.Parse(c.ToString())).ToArray(); } /// <summary> /// "00101001010"という様な入力をboolの配列にして返す /// </summary> /// <returns></returns> public static bool[] ReadBoolArrayFromBinaryString() { return Console.ReadLine().Select(c => c == '1').ToArray(); } /// <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; } #if DEBUG static void SampleGenerator() { int A = 1000; int B = 1000; int Q = 1000; Random r = new Random(); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("{0} {1} {2}", A, B, Q)); A.Times(a => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); B.Times(b => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Q.Times(q => sb.AppendLine(((long)r.Next() * r.Next()).ToString())); Debug.WriteLine(sb.ToString()); } #endif } /// <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; } } #endregion }
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
2,472
2
using System; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); int T = int.Parse(input[0]); int A = int.Parse(input[1]); var list = new int[N]; double ans = 100000; int goal = 0; input = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { list[i] = int.Parse(input[i]); double t = T - list[i] * 0.06; double a = Math.Abs(A - t); if (ans > a) { ans = a; goal = i; } } Console.WriteLine(goal + 1); } }
using System; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' '); int T = int.Parse(input[0]); int A = int.Parse(input[1]); var list = new int[N]; double ans = 100000; int goal = 0; input = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { list[i] = int.Parse(input[i]); double t = T - list[i] * 0.006; double a = Math.Abs(A - t); if (ans > a) { ans = a; goal = i; } } Console.WriteLine(goal + 1); } }
[["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 250], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 250]]
8
184
2
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var aaa = Console.ReadLine().Split(' '); var T = double.Parse(aaa[0]); var A = int.Parse(aaa[1]); var hei = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); double min = 2222222220; var ans = 0; for (var x = 0; x < N; ++x) { var temp = Math.Abs(T - hei[x] * 0.006); var tempa = Math.Abs(temp - A); if (min > tempa) { ans = x + 1; min = tempa; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ziyuutyou { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var aaa = Console.ReadLine().Split(' '); var T = double.Parse(aaa[0]); var A = int.Parse(aaa[1]); var hei = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); double min = 2222222220; var ans = 0; for (var x = 0; x < N; ++x) { var temp = T - hei[x] * 0.006; var tempa = Math.Abs(temp - A); if (min > tempa) { ans = x + 1; min = tempa; } } Console.WriteLine(ans); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
195
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var sc = new Scanner(); int n = sc.NextInt(); int t = sc.NextInt(); int a = sc.NextInt(); double[] h = new double[n]; int ans = 0; double min = 1000000; for (int i = 0; i < n; i++) { double d = Math.Abs(t - sc.NextInt()); if (d < min) { min = d; ans = i; } } Console.WriteLine(ans + 1); } } class Scanner { int index = -1; string[] buf; public Scanner() {} public int NextInt() { CheckNext(); return int.Parse(buf[index++]); } public long NextLong() { CheckNext(); return long.Parse(buf[index++]); } public double NextDouble() { CheckNext(); return double.Parse(buf[index++]); } public string NextString() { CheckNext(); return buf[index++]; } private void CheckNext() { if (index >= 0 && index < buf.Length) return; buf = Console.ReadLine().Split(' '); index = 0; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var sc = new Scanner(); int n = sc.NextInt(); int t = sc.NextInt(); int a = sc.NextInt(); double[] h = new double[n]; int ans = 0; double min = 1000000; for (int i = 0; i < n; i++) { double d = Math.Abs(t - sc.NextInt() * 0.006 - a); if (d < min) { min = d; ans = i; } } Console.WriteLine(ans + 1); } } class Scanner { int index = -1; string[] buf; public Scanner() {} public int NextInt() { CheckNext(); return int.Parse(buf[index++]); } public long NextLong() { CheckNext(); return long.Parse(buf[index++]); } public double NextDouble() { CheckNext(); return double.Parse(buf[index++]); } public string NextString() { CheckNext(); return buf[index++]; } private void CheckNext() { if (index >= 0 && index < buf.Length) return; buf = Console.ReadLine().Split(' '); index = 0; } }
[["+", 0, 28, 0, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 16, 12, 16, 12, 250], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
303
4
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static Scanner input; static void Main() { input = new Scanner(); int n = input.Int(); int[] ta = input.splitInt(); int[] h = input.splitInt(); int minIndex = 0; for (int a = 0; a < n; a++) { double temp = Math.Abs((double)ta[1] - ((double)ta[1] - (double)h[a] * 0.006)); if (Math.Abs((double)ta[1] - ((double)ta[1] - (double)h[minIndex] * 0.006)) > temp) minIndex = a; } WriteLine(minIndex + 1); } static int countChar(string s, string key) { return s.Length - s.Replace(key, "").Length; } } class Scanner { public Scanner() {} public void skip() { ReadLine(); return; } public string String() { return ReadLine(); } public string[] splitString() { return ReadLine().Split(); } public string[] linesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] jaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int Int() { return int.Parse(ReadLine()); } public int[] splitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] linesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] jaggedArrayInt(int len) { var arr = new int [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } return arr; } public long Long() { return long.Parse(ReadLine()); } public long[] splitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] linesLong(int len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] jaggedArrayLong(int len) { var arr = new long [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } return arr; } public double Double() { return double.Parse(ReadLine()); } public double[] splitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] linesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] jaggedArrayDouble(int len) { var arr = new double [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } return arr; } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static Scanner input; static void Main() { input = new Scanner(); int n = input.Int(); int[] ta = input.splitInt(); int[] h = input.splitInt(); int minIndex = 0; for (int a = 0; a < n; a++) { double temp = Math.Abs((double)ta[1] - ((double)ta[0] - (double)h[a] * 0.006)); if (Math.Abs((double)ta[1] - ((double)ta[0] - (double)h[minIndex] * 0.006)) > temp) minIndex = a; } WriteLine(minIndex + 1); } static int countChar(string s, string key) { return s.Length - s.Replace(key, "").Length; } } class Scanner { public Scanner() {} public void skip() { ReadLine(); return; } public string String() { return ReadLine(); } public string[] splitString() { return ReadLine().Split(); } public string[] linesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] jaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int Int() { return int.Parse(ReadLine()); } public int[] splitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] linesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] jaggedArrayInt(int len) { var arr = new int [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } return arr; } public long Long() { return long.Parse(ReadLine()); } public long[] splitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] linesLong(int len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] jaggedArrayLong(int len) { var arr = new long [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } return arr; } public double Double() { return double.Parse(ReadLine()); } public double[] splitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] linesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] jaggedArrayDouble(int len) { var arr = new double [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } return arr; } }
[["-", 31, 74, 51, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 74, 51, 204, 206, 207, 0, 28, 0, 203]]
8
921
4
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); double[] s = Console.ReadLine().Split().Select(double.Parse).ToArray(); List<double> h = Console.ReadLine() .Split() .Select(x => s[0] - double.Parse(x) * 0.006) .ToList(); Console.WriteLine(FindClosestIndex(h, s[1])); } static int FindClosestIndex(List<double> list, double value) { double closest = list.Aggregate( (x, y) => Math.Abs(x - value) < Math.Abs(y - value) ? x : y); return list.IndexOf(closest); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); double[] s = Console.ReadLine().Split().Select(double.Parse).ToArray(); List<double> h = Console.ReadLine() .Split() .Select(x => s[0] - double.Parse(x) * 0.006) .ToList(); Console.WriteLine(FindClosestIndex(h, s[1])); } static int FindClosestIndex(List<double> list, double value) { double closest = list.Aggregate( (x, y) => Math.Abs(x - value) < Math.Abs(y - value) ? x : y); return list.IndexOf(closest) + 1; } }
[["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 72], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 203]]
8
183
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC113 { class Program { static int n, t, a, ans; static int[] h; static void Main(string[] args) { Place(); } static void Place() { n = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(); t = int.Parse(input[0]); a = int.Parse(input[1]); h = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var dmin = 1000000000; for (int i = 0; i < n; i++) { var dtmp = Math.Abs(a - (t - 0.006 * h[i])); if (dmin > dtmp) { dmin = (int)dtmp; ans = i; } } Console.WriteLine(ans + 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC113 { class Program { static int n, t, a, ans; static int[] h; static void Main(string[] args) { Place(); } static void Place() { n = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(); t = int.Parse(input[0]); a = int.Parse(input[1]); h = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); double dmin = 1000000000d; for (int i = 0; i < n; i++) { var dtmp = Math.Abs(a - (t - 0.006 * h[i])); if (dmin > dtmp) { dmin = dtmp; ans = i; } } Console.WriteLine(ans + 1); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 0, 25]]
8
226
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { public Program() { int N = int.Parse(Console.ReadLine()); string[] inputs = Console.ReadLine().Split(); int T = int.Parse(inputs[0]); int A = int.Parse(inputs[1]); int[] hs = Console.ReadLine().Split().Select(int.Parse).ToArray(); int result = 0; double min = int.MaxValue; foreach (int i in Enumerable.Range(0, N)) { Double a = Math.Abs(A - (T - 0.06 * hs[i])); if (min > a) { min = a; result = i; } } Console.WriteLine(result + 1); } static void Main(string[] args) { var p = new Program(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { public Program() { int N = int.Parse(Console.ReadLine()); string[] inputs = Console.ReadLine().Split(); int T = int.Parse(inputs[0]); int A = int.Parse(inputs[1]); int[] hs = Console.ReadLine().Split().Select(int.Parse).ToArray(); int result = 0; double min = int.MaxValue; foreach (int i in Enumerable.Range(0, N)) { Double a = Math.Abs(A - (T - 0.006 * hs[i])); if (min > a) { min = a; result = i; } } Console.WriteLine(result + 1); } static void Main(string[] args) { var p = new Program(); } }
[["-", 0, 16, 12, 23, 0, 16, 12, 16, 31, 250], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 31, 250]]
8
211
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); double[] input = Console.ReadLine().Split(' ').Select(s => double.Parse(s)).ToArray(); double T = input[0]; double A = input[1]; double[] palace = new double[n]; input = Console.ReadLine().Split(' ').Select(s => double.Parse(s)).ToArray(); double min = 99999999; double index = 0; for (int i = 0; i < n; i++) { palace[i] = (T - input[i]) * 0.006; double sa = Math.Abs(A - palace[i]); if (sa < min) { min = sa; index = i + 1; } } Console.WriteLine(index); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace MyProgram { public class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); double[] input = Console.ReadLine().Split(' ').Select(s => double.Parse(s)).ToArray(); double T = input[0]; double A = input[1]; double[] palace = new double[n]; input = Console.ReadLine().Split(' ').Select(s => double.Parse(s)).ToArray(); double min = 99999999; double index = 0; for (int i = 0; i < n; i++) { palace[i] = T - input[i] * 0.006; double sa = Math.Abs(A - palace[i]); if (sa < min) { min = sa; index = i + 1; } } Console.WriteLine(index); } } }
[["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
8
229
2
using System; using System.Linq; class Program { static void Main(string[] args) { // 宮殿の設置候補の数を表します 問題文 N. int placeCount = int.Parse(Console.ReadLine()); // 気温を取得します 問題文 T, A. var parameters = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); // 標高を表します 問題文 Hi. var elevations = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); // 問題文 T. var T = parameters[0]; // 問題文 A. var fetchTemperature = parameters[1]; // 何番目に宮殿を建てるかを表します. var result = 0; // もっとも近い平均気温を求めるために使用します. var score = int.MaxValue; foreach (var elememt in elevations.Select( (e, index) => new { Value = e, Index = index })) { // xメートル時の平均気温 T - x * 0.006. var temperature = (int)(T - elememt.Value * 1000 * 0.006); // 前回計算したものより差分が小さいかを計算し、前回の評価より良い評価であれば記憶します. var _ = Math.Abs(fetchTemperature - temperature); if (_ > score) continue; score = _; result = elememt.Index + 1; } Console.WriteLine(result); } }
using System; using System.Linq; class Program { static void Main(string[] args) { // 宮殿の設置候補の数を表します 問題文 N. int placeCount = int.Parse(Console.ReadLine()); // 気温を取得します 問題文 T, A. var parameters = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); // 標高を表します 問題文 Hi. var elevations = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); // 問題文 T. var T = parameters[0]; // 問題文 A. var fetchTemperature = parameters[1] * 1000; // 何番目に宮殿を建てるかを表します. var result = 0; // もっとも近い平均気温を求めるために使用します. var score = int.MaxValue; foreach (var elememt in elevations.Select( (e, index) => new { Value = e, Index = index })) { // xメートル時の平均気温 T - x * 0.006. var temperature = (int)(T * 1000 - elememt.Value * 1000 * 0.006); // 前回計算したものより差分が小さいかを計算し、前回の評価より良い評価であれば記憶します. var _ = Math.Abs(fetchTemperature - temperature); if (_ > score) continue; score = _; result = elememt.Index + 1; } Console.WriteLine(result); } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 74, 51, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 74, 51, 23, 0, 16, 31, 16, 12, 203]]
8
224
4
using System; using System.Linq; using System.Collections.Generic; using static System.Math; public class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] ta = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] h = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int abs = 0; int answer = 0; for (int i = 0; i < n; i++) { if (i == 0) { abs = Abs(ta[1] - (ta[0] - h[i])); answer = i + 1; } int stock = Abs(ta[1] - (ta[0] - h[i])); if (stock < abs) { abs = stock; answer = i + 1; } } Console.WriteLine(answer); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Math; public class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] ta = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] h = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); double abs = 0; int answer = 0; for (int i = 0; i < n; i++) { if (i == 0) { abs = Abs(ta[1] - (ta[0] - h[i] * 0.006)); answer = i + 1; } double stock = Abs(ta[1] - (ta[0] - h[i] * 0.006)); if (stock < abs) { abs = stock; answer = i + 1; } } Console.WriteLine(answer); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 17, 48], ["+", 0, 16, 12, 23, 0, 16, 12, 16, 12, 250], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
8
220
8
using static System.Math; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var t = int.Parse(line[0]); var a = int.Parse(line[1]) * 1000; line = Console.ReadLine().Trim().Split(' '); var h = Array.ConvertAll(line, int.Parse); long ans = Abs(1000 * t - t * h[0] - a); var ansi = 0; for (int i = 1; i < n; i++) { long avt = 1000 * t - 6 * h[i]; if (Abs(avt - a) < ans) { ans = Abs(avt - a); ansi = i; } } Console.WriteLine(ansi + 1); } }
using static System.Math; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var t = int.Parse(line[0]); var a = int.Parse(line[1]) * 1000; line = Console.ReadLine().Trim().Split(' '); var h = Array.ConvertAll(line, int.Parse); int ans = Abs(1000 * t - 6 * h[0] - a); var ansi = 0; for (int i = 1; i < n; i++) { int avt = 1000 * t - 6 * h[i]; if (Abs(avt - a) < ans) { ans = Abs(avt - a); ansi = i; } } Console.WriteLine(ansi + 1); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 28, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 16, 12, 16, 31, 203], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
8
212
6
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var N = ReadInt(); var input = ReadArrayInt(); var T = input[0]; var A = input[0]; var H = ReadArrayInt(); var dif = double.MaxValue; var ans = 0; for (int i = 0; i < N; i++) { var tmp = Math.Abs(A - (T - H[i] * 0.006)); if (tmp < dif) { ans = i + 1; dif = tmp; } } Console.WriteLine(ans); Console.ReadLine(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var N = ReadInt(); var input = ReadArrayInt(); var T = input[0]; var A = input[1]; var H = ReadArrayInt(); var dif = double.MaxValue; var ans = 1; for (int i = 0; i < N; i++) { var tmp = Math.Abs(A - (T - H[i] * 0.006)); if (tmp < dif) { ans = i + 1; dif = tmp; } } Console.WriteLine(ans); Console.ReadLine(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } }
[["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
273
4
using System; using System.Linq; namespace Sample101 { class Program { static void Main(string[] args) { // 入力 var N = int.Parse(Console.ReadLine()); var line = Console.ReadLine().Split(' '); var T = int.Parse(line[0]); var A = int.Parse(line[1]); var H = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray(); // 各地点の温度を計算しAに最も近いものを求める var nearT = Math.Abs(A - (T - H[0] * 0.006)); var result = 0; for (int i = 1; i < N; i++) { // 温度を求めてAとの差を計算する var temp = Math.Abs(A - T - H[i] * 0.006); // 比較してAにより近ければ入れ替える if (nearT > temp) { nearT = temp; result = i; } } Console.WriteLine(result + 1); } } }
using System; using System.Linq; namespace Sample101 { class Program { static void Main(string[] args) { // 入力 var N = int.Parse(Console.ReadLine()); var line = Console.ReadLine().Split(' '); var T = int.Parse(line[0]); var A = int.Parse(line[1]); var H = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray(); // 各地点の温度を計算しAに最も近いものを求める var nearT = Math.Abs(A - (T - H[0] * 0.006)); var result = 0; for (int i = 1; i < N; i++) { // 温度を求めてAとの差を計算する var temp = Math.Abs(A - (T - H[i] * 0.006)); // 比較してAにより近ければ入れ替える if (nearT > temp) { nearT = temp; result = i; } } Console.WriteLine(result + 1); } } }
[["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
205
2
using System; using System.Linq; using System.Collections.Generic; public class P { public static void Main() { var s = Console.ReadLine(); long N = long.Parse(s); var s1 = Console.ReadLine().Split(' '); double T = double.Parse(s1[0]), A = double.Parse(s1[1]); s1 = Console.ReadLine().Split(' '); List<int> a = new List<int>(); for (int i = 0; i < N; i++) { a.Add(int.Parse(s1[i])); } var b = a.OrderBy(x => Math.Abs(T - 0.006 * x)).ToArray(); for (int i = 0; i < N; i++) { if (a[i] == b[0]) Console.WriteLine(i + 1); } } }
using System; using System.Linq; using System.Collections.Generic; public class P { public static void Main() { var s = Console.ReadLine(); long N = long.Parse(s); var s1 = Console.ReadLine().Split(' '); double T = double.Parse(s1[0]), A = double.Parse(s1[1]); s1 = Console.ReadLine().Split(' '); List<int> a = new List<int>(); for (int i = 0; i < N; i++) { a.Add(int.Parse(s1[i])); } var b = a.OrderBy(x => Math.Abs(T - 0.006 * x - A)).ToArray(); for (int i = 0; i < N; i++) { if (a[i] == b[0]) Console.WriteLine(i + 1); } } }
[["+", 8, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 8, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
210
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var temp = Console.ReadLine().Split(' '); var t = int.Parse(temp[0]); var a = int.Parse(temp[1]); var h = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var results = new List<double>(); foreach (var location in h) { var ave = t - location * 0.006; results.Add(Math.Abs(ave - a)); } System.Diagnostics.Debug.WriteLine(results.IndexOf(results.Min()) + 1); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var temp = Console.ReadLine().Split(' '); var t = int.Parse(temp[0]); var a = int.Parse(temp[1]); var h = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var results = new List<double>(); foreach (var location in h) { var ave = t - location * 0.006; results.Add(Math.Abs(ave - a)); } Console.WriteLine(results.IndexOf(results.Min()) + 1); } } }
[["-", 0, 213, 63, 214, 205, 214, 205, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 214, 205, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 214, 205, 214, 141, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
8
187
6
using System; using System.Linq; namespace ABC113B { internal class Program { public static void Main(string[] args) { int N = Input.Int(); int[] ints = Input.IntArray(); int T = ints[0]; int A = ints[1]; int[] H = Input.IntArray(); double diff = int.MaxValue; int ans = -1; for (int i = 0; i < H.Length; i++) { if (diff > Math.Abs(A - T - H[i] * 0.006)) { diff = Math.Abs(A - T - H[i] * 0.006); ans = i; } } Console.WriteLine(ans + 1); } } internal static class Input { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
using System; using System.Linq; namespace ABC113B { internal class Program { public static void Main(string[] args) { int N = Input.Int(); int[] ints = Input.IntArray(); int T = ints[0]; int A = ints[1]; int[] H = Input.IntArray(); double diff = int.MaxValue; int ans = -1; for (int i = 0; i < H.Length; i++) { if (diff > Math.Abs(A - T + H[i] * 0.006)) { diff = Math.Abs(A - T + H[i] * 0.006); ans = i; } } Console.WriteLine(ans + 1); } } internal static class Input { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
326
4
using System; using System.Linq; namespace abc113_b { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ret = 0; double min = double.MaxValue; for (int i = 0; i < n; i++) { double now = x[0] - a[0] * 0.006; now = Math.Abs(x[1] - now); if (min > now) { ret = i + 1; min = now; } } Console.WriteLine(ret); } } }
using System; using System.Linq; namespace abc113_b { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int ret = 0; double min = double.MaxValue; for (int i = 0; i < n; i++) { double now = x[0] - a[i] * 0.006; now = Math.Abs(x[1] - now); if (min > now) { ret = i + 1; min = now; } } Console.WriteLine(ret); } } }
[["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22]]
8
175
2
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { var r = ReadSplit(); var n = r[0].Int(); var m = r[1].Int(); var l = new Tuple<int, int, int>[m]; for (int i = 0; i < m; i++) { var r2 = ReadSplit(); var p = r2[0].Int(); var y = r2[1].Int(); l[i] = new Tuple<int, int, int>(p, y, i); } var tmpL = l.OrderBy(x => x.Item1).ThenBy(x => x.Item2).ToList(); var ans = new string[m]; int j = 1; var pre = tmpL[0].Item1; foreach (var item in tmpL) { if (pre != item.Item1) { j = 1; } ans[item.Item3] = item.Item1.ToString().PadLeft(6, '0') + j.ToString().PadLeft(6, '0'); j++; } for (int i = 0; i < m; i++) { Write(ans[i]); } Read(); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { var r = ReadSplit(); var n = r[0].Int(); var m = r[1].Int(); var l = new Tuple<int, int, int>[m]; for (int i = 0; i < m; i++) { var r2 = ReadSplit(); var p = r2[0].Int(); var y = r2[1].Int(); l[i] = new Tuple<int, int, int>(p, y, i); } var tmpL = l.OrderBy(x => x.Item1).ThenBy(x => x.Item2).ToList(); var ans = new string[m]; int j = 1; var pre = tmpL[0].Item1; foreach (var item in tmpL) { if (pre != item.Item1) { pre = item.Item1; j = 1; } ans[item.Item3] = item.Item1.ToString().PadLeft(6, '0') + j.ToString().PadLeft(6, '0'); j++; } for (int i = 0; i < m; i++) { Write(ans[i]); } Read(); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
636
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); var ipy = new List<Tuple<int, int, int>>(); for (int i = 0; i < m; i++) { ipy.Add(new Tuple<int, int, int>(i, cin.Int(), cin.Int())); } ipy.Sort((x, y) => y.Item3 - x.Item3); int[] cnt = new int[n + 1]; var numbers = new List<Tuple<int, string>>(); for (int i = 0; i < m; i++) { cnt[ipy[i].Item2] += 1; string number = $"{ipy[i].Item2.ToString("d6")}{cnt[ipy[i].Item2].ToString("d6")}"; numbers.Add(new Tuple<int, string>(ipy[i].Item1, number)); } numbers.Sort((x, y) => y.Item1 - x.Item1); StringBuilder sb = new StringBuilder(); for (int i = 0; i < m; i++) { sb.AppendLine(numbers[i].Item2); } Console.WriteLine(sb.ToString()); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); var ipy = new List<Tuple<int, int, int>>(m); for (int i = 0; i < m; i++) { ipy.Add(new Tuple<int, int, int>(i, cin.Int(), cin.Int())); } ipy.Sort((x, y) => x.Item3 - y.Item3); int[] cnt = new int[n + 1]; var numbers = new List<Tuple<int, string>>(m); for (int i = 0; i < m; i++) { cnt[ipy[i].Item2] += 1; string number = $"{ipy[i].Item2.ToString("d6")}{cnt[ipy[i].Item2].ToString("d6")}"; numbers.Add(new Tuple<int, string>(ipy[i].Item1, number)); } numbers.Sort((x, y) => x.Item1 - y.Item1); StringBuilder sb = new StringBuilder(); for (int i = 0; i < m; i++) { sb.AppendLine(numbers[i].Item2); } Console.WriteLine(sb.ToString()); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
[["+", 0, 212, 0, 230, 3, 4, 0, 28, 0, 22], ["-", 0, 28, 0, 218, 8, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 205, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22]]
8
702
10
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int[] NM = ReadLineParseIntArray(); int N = NM[0]; int M = NM[1]; List<Tuple<int, int>>[] tuples = new List<Tuple<int, int>>[N]; for (int i = 0; i < N; i++) tuples[i] = new List<Tuple<int, int>>(); for (int i = 0; i < M; i++) { int[] py = ReadLineParseIntArray(); tuples[py[0] - 1].Add(new Tuple<int, int>(py[1], i)); } PriorityQueue<ComparablePair<int, int>> priorityQueue = new PriorityQueue<ComparablePair<int, int>>(M); for (int i = 0; i < N; i++) { if (tuples[i].Count == 0) continue; tuples[i].Sort((a, b) => a.Item1.CompareTo(b.Item1)); int iter = 1; foreach (var v in tuples[i]) { priorityQueue.Push( new ComparablePair<int, int>(v.Item2, (i + 1) * 1000000 + iter++)); } } for (int i = 0; i < M; i++) { WriteLine($"{priorityQueue.Pop().Item2:000000000000}"); } } static int ReadLineParseInt() => int.Parse(ReadLine()); static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _size = 0; private int _count = 0; ///< summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } ///< summary> /// Priority queue ///</summary> ///< param name="maxSize">max size</param> ///< param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _size++; 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[--_size]; int i = 0; while (i * 2 + 1 < _size) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _size && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _size; 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[_size]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class ComparablePair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { ComparablePair<T, U> castedObj = (ComparablePair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public ComparablePair(T t, U u) { Item1 = t; Item2 = u; } } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { int[] NM = ReadLineParseIntArray(); int N = NM[0]; int M = NM[1]; List<Tuple<int, int>>[] tuples = new List<Tuple<int, int>>[N]; for (int i = 0; i < N; i++) tuples[i] = new List<Tuple<int, int>>(); for (int i = 0; i < M; i++) { int[] py = ReadLineParseIntArray(); tuples[py[0] - 1].Add(new Tuple<int, int>(py[1], i)); } PriorityQueue<ComparablePair<int, long>> priorityQueue = new PriorityQueue<ComparablePair<int, long>>(M); for (int i = 0; i < N; i++) { if (tuples[i].Count == 0) continue; tuples[i].Sort((a, b) => a.Item1.CompareTo(b.Item1)); int iter = 1; foreach (var v in tuples[i]) { priorityQueue.Push(new ComparablePair<int, long>( v.Item2, (i + 1) * 1000000L + iter++)); } } for (int i = 0; i < M; i++) { WriteLine($"{priorityQueue.Pop().Item2:000000000000}"); } } static int ReadLineParseInt() => int.Parse(ReadLine()); static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray(); public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _size = 0; private int _count = 0; ///< summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } ///< summary> /// Priority queue ///</summary> ///< param name="maxSize">max size</param> ///< param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _size++; 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[--_size]; int i = 0; while (i * 2 + 1 < _size) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _size && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _size; 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[_size]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class ComparablePair<T, U> : IComparable where T : IComparable<T> { public readonly T Item1; public readonly U Item2; public int CompareTo(object obj) { ComparablePair<T, U> castedObj = (ComparablePair<T, U>)obj; return this.Item1.CompareTo(castedObj.Item1); } public ComparablePair(T t, U u) { Item1 = t; Item2 = u; } } }
[["-", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["+", 39, 236, 237, 238, 0, 236, 237, 238, 0, 199], ["-", 0, 28, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 28, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203]]
8
1,026
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static int N; static int M; class Comare : IComparer<int> { public int Compare(int x, int y) { return x - y; } } class CityInfo { public CityInfo(int k, int y, int c) { Ken = k; Year = y; CityNo = c; } public int Ken; public int Year; public int CityNo; } public static void Main(string[] args) { N = Input.NextInt(); M = Input.NextInt(); var Cities = new List<CityInfo>(); var Kens = new Dictionary<int, List<CityInfo>>(); for (int i = 0; i < M; i++) { var l = Input.LineInt(); var ken_no = l[0]; var city_born = l[1]; if (!Kens.ContainsKey(ken_no)) Kens[ken_no] = new List<CityInfo>(); var city = new CityInfo(ken_no, city_born, 0); Cities.Add(city); Kens[ken_no].Add(city); } foreach (var en in Kens) { en.Value.Sort((a, b) => (a.Year - b.Year)); for (int i = 0; i < en.Value.Count; i++) { en.Value[i].CityNo = i + 1; } } foreach (var city in Cities) { Console.WriteLine($"{Make6(city.Ken)} {Make6(city.CityNo)}"); } } static string Make6(int x) { string s; s = "000000" + x.ToString(); return s.Substring(s.Length - 6); } } public static class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static int N; static int M; class Comare : IComparer<int> { public int Compare(int x, int y) { return x - y; } } class CityInfo { public CityInfo(int k, int y, int c) { Ken = k; Year = y; CityNo = c; } public int Ken; public int Year; public int CityNo; } public static void Main(string[] args) { N = Input.NextInt(); M = Input.NextInt(); var Cities = new List<CityInfo>(); var Kens = new Dictionary<int, List<CityInfo>>(); for (int i = 0; i < M; i++) { var l = Input.LineInt(); var ken_no = l[0]; var city_born = l[1]; if (!Kens.ContainsKey(ken_no)) Kens[ken_no] = new List<CityInfo>(); var city = new CityInfo(ken_no, city_born, 0); Cities.Add(city); Kens[ken_no].Add(city); } foreach (var en in Kens) { en.Value.Sort((a, b) => (a.Year - b.Year)); for (int i = 0; i < en.Value.Count; i++) { en.Value[i].CityNo = i + 1; } } foreach (var city in Cities) { Console.WriteLine($"{Make6(city.Ken)}{Make6(city.CityNo)}"); } } static string Make6(int x) { string s; s = "000000" + x.ToString(); return s.Substring(s.Length - 6); } } public static class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296]]
8
678
1
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace ID { class City { public int Order; public long Id; public City(int o, long i) { Order = o; Id = i; } } class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { var nm = GetArrayIntInput(); List<City>[] Prefectures = new List<City>[nm[0] + 1]; for (int i = 1; i <= nm[0]; i++) { Prefectures[i] = new List<City>(); } for (int i = 1; i <= nm[1]; i++) { var py = GetArrayIntInput(); Prefectures[py[0]].Add(new City(i, py[1])); } var results = new List<City>(); for (int i = 1; i <= nm[0]; i++) { Prefectures[i] = Prefectures[i].OrderBy(p => p.Id).ToList(); for (int j = 0; j < Prefectures[i].Count; j++) { Prefectures[i][j].Id = i * 1000000 + j + 1; results.Add(Prefectures[i][j]); } } foreach (var id in results.OrderBy(r => r.Order).Select(r => r.Id)) { CWrite(Convert.ToString(id, 10).PadLeft(12, '0')); } } } static string[] GetArrayCharInput() => Console.ReadLine().Split(); static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray(); static int GetIntInput() => Console.ReadLine().ToInt(); static void CWrite(string str) => Console.WriteLine(str); } class SetConsole : IDisposable { public SetConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); } } static class ExtentionsLibrary { public static int[] StringToIntArray(this string str) => str.Split().Select(int.Parse).ToArray(); public static int ToInt(this string str) => int.Parse(str); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace ID { class City { public int Order; public long Id; public City(int o, long i) { Order = o; Id = i; } } class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { var nm = GetArrayIntInput(); List<City>[] Prefectures = new List<City>[nm[0] + 1]; for (int i = 1; i <= nm[0]; i++) { Prefectures[i] = new List<City>(); } for (int i = 1; i <= nm[1]; i++) { var py = GetArrayIntInput(); Prefectures[py[0]].Add(new City(i, py[1])); } var results = new List<City>(); for (int i = 1; i <= nm[0]; i++) { Prefectures[i] = Prefectures[i].OrderBy(p => p.Id).ToList(); for (int j = 0; j < Prefectures[i].Count; j++) { Prefectures[i][j].Id = (long)i * 1000000 + j + 1; results.Add(Prefectures[i][j]); } } foreach (var id in results.OrderBy(r => r.Order).Select(r => r.Id)) { CWrite(Convert.ToString(id, 10).PadLeft(12, '0')); } } } static string[] GetArrayCharInput() => Console.ReadLine().Split(); static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray(); static int GetIntInput() => Console.ReadLine().ToInt(); static void CWrite(string str) => Console.WriteLine(str); } class SetConsole : IDisposable { public SetConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); } } static class ExtentionsLibrary { public static int[] StringToIntArray(this string str) => str.Split().Select(int.Parse).ToArray(); public static int ToInt(this string str) => int.Parse(str); } }
[["+", 12, 16, 31, 16, 31, 16, 31, 74, 0, 24], ["+", 12, 16, 31, 16, 31, 16, 31, 74, 39, 199], ["+", 12, 16, 31, 16, 31, 16, 31, 74, 0, 25]]
8
520
3
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder.ABC113 { class C { static void Main() => CustomMain(); class City { public int no; public int prefecture; public int year; } static void Solve() { int n, m; ReadMulti(out n, out m); var c = new List<City>(); for (int i = 0; i <= n; i++) { var a = ReadIntArray(); c.Add(new City() { no = i, prefecture = a[0], year = a[1] }); } var ca = c.OrderBy(x => x.prefecture).ThenBy(x => x.year); var p_now = 0; var y_now = 1; foreach (var city in ca) { if (city.prefecture != p_now) { p_now = city.prefecture; city.year = 1; y_now = 1; } else { y_now++; city.year = y_now; } } var cb = ca.OrderBy(x => x.no); foreach (var city in cb) { WriteAnswer($"{city.prefecture:D6}{city.year:D6}"); } } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む global::Common.ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace AtCoder.ABC113 { class C { static void Main() => CustomMain(); class City { public int no; public int prefecture; public int year; } static void Solve() { int n, m; ReadMulti(out n, out m); var c = new List<City>(); for (int i = 0; i < m; i++) { var a = ReadIntArray(); c.Add(new City() { no = i, prefecture = a[0], year = a[1] }); } var ca = c.OrderBy(x => x.prefecture).ThenBy(x => x.year); var p_now = 0; var y_now = 1; foreach (var city in ca) { if (city.prefecture != p_now) { p_now = city.prefecture; city.year = 1; y_now = 1; } else { y_now++; city.year = y_now; } } var cb = ca.OrderBy(x => x.no); foreach (var city in cb) { WriteAnswer($"{city.prefecture:D6}{city.year:D6}"); } } static void CustomMain() { #if DEBUG // ファイルからテストケースを読み込む global::Common.ChangeStdIn(); // 時間計測 var stopwatch = new Stopwatch(); stopwatch.Start(); #endif // 出力高速化 var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); // 回答 Solve(); #if DEBUG stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); #endif Console.Out.Flush(); } static string ReadString() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadString()); static long ReadLong() => long.Parse(ReadString()); static float ReadFloat() => float.Parse(ReadString()); static double ReadDouble => double.Parse(ReadString()); static string[] ReadStringArray() => ReadString().Split(' '); static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse); static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse); static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse); static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse); static T TypeConversion<T>(string s) { if (typeof(T) == typeof(int)) { return (T)Convert.ChangeType(int.Parse(s), typeof(T)); } else if (typeof(T) == typeof(long)) { return (T)Convert.ChangeType(long.Parse(s), typeof(T)); } else if (typeof(T) == typeof(double)) { return (T)Convert.ChangeType(double.Parse(s), typeof(T)); } else { return (T)Convert.ChangeType(s, typeof(T)); } } static void ReadMulti<T, U>(out T a, out U b) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); } static void ReadMulti<T, U, V>(out T a, out U b, out V c) { var str = ReadStringArray(); a = TypeConversion<T>(str[0]); b = TypeConversion<U>(str[1]); c = TypeConversion<V>(str[2]); } static void WriteAnswer(object ans) => Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
844
4
using System; using System.Linq; public class Test { struct city { public int sector; public int year; public int index; public city(int s, int y, int i) { sector = s; year = y; index = i; } } public static void Main() { int n, m; { var ins = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); n = ins[0]; m = ins[1]; } { var ins = new city[m]; for (int i = 0; i < m; i++) { var ins2 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); ins[i] = new city(ins2[0], ins2[1], i); } { int[] sectC = new int[m]; Array.Sort(ins, (v, w) => v.year - w.year); var ins3 = ins.Select((v, i) => new { index = v.index, str = v.sector.ToString("D6") + (++sectC[v.sector]).ToString("D6") }) .ToArray(); Array.Sort(ins3, (v, w) => v.index - w.index); Array.ForEach(ins3, v => Console.WriteLine(v.str)); } } } }
using System; using System.Linq; public class Test { struct city { public int sector; public int year; public int index; public city(int s, int y, int i) { sector = s; year = y; index = i; } } public static void Main() { int n, m; { var ins = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); n = ins[0]; m = ins[1]; } { var ins = new city[m]; for (int i = 0; i < m; i++) { var ins2 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); ins[i] = new city(ins2[0], ins2[1], i); } { int[] sectC = new int[n]; Array.Sort(ins, (v, w) => v.year - w.year); var ins3 = ins.Select((v, i) => new { index = v.index, str = v.sector.ToString("D6") + (++sectC[v.sector - 1]).ToString("D6") }) .ToArray(); Array.Sort(ins3, (v, w) => v.index - w.index); Array.ForEach(ins3, v => Console.WriteLine(v.str)); } } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
326
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC113C { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NM[0]; var M = NM[1]; City[] cities = new City[M]; for (int i = 0; i < M; i++) { var PY = Console.ReadLine().Split().Select(long.Parse).ToArray(); cities[i] = new City((int)PY[0], PY[1]); } cities = cities.OrderBy(x => x.Year).ThenBy(x => x.Prefecture).ToArray(); long nowPrefecture = -1; int nowCount = 1; for (int i = 0; i < M; i++) { if (cities[i].Prefecture != nowPrefecture) { nowPrefecture = cities[i].Prefecture; nowCount = 1; } cities[i].NumberInPrefecture = nowCount; nowCount++; } cities = cities.OrderBy(x => x.CityNumber).ToArray(); for (int i = 0; i < M; i++) { Console.WriteLine(cities[i].CognitionNumber); } Console.ReadKey(); } class City { static int CityNumberCount = 1; public int CityNumber; public long Year; public int Prefecture; public int NumberInPrefecture; public City(int prefecture, long year) { CityNumber = CityNumberCount; CityNumberCount++; Year = year; Prefecture = prefecture; } string P { get { return FillZero(Prefecture); } } string x { get { return FillZero(NumberInPrefecture); } } public string CognitionNumber { get { return P + x; } } private string FillZero(int number) { return string.Format("{0:000000}", number); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC113C { class Program { static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NM[0]; var M = NM[1]; City[] cities = new City[M]; for (int i = 0; i < M; i++) { var PY = Console.ReadLine().Split().Select(long.Parse).ToArray(); cities[i] = new City((int)PY[0], PY[1]); } cities = cities.OrderBy(x => x.Prefecture).ThenBy(x => x.Year).ToArray(); int nowPrefecture = -1; int nowCount = 1; for (int i = 0; i < M; i++) { if (cities[i].Prefecture != nowPrefecture) { nowPrefecture = cities[i].Prefecture; nowCount = 1; } cities[i].NumberInPrefecture = nowCount; nowCount++; } cities = cities.OrderBy(x => x.CityNumber).ToArray(); for (int i = 0; i < M; i++) { Console.WriteLine(cities[i].CognitionNumber); } Console.ReadKey(); } class City { static int CityNumberCount = 1; public int CityNumber; public long Year; public int Prefecture; public int NumberInPrefecture; public City(int prefecture, long year) { CityNumber = CityNumberCount; CityNumberCount++; Year = year; Prefecture = prefecture; } string P { get { return FillZero(Prefecture); } } string x { get { return FillZero(NumberInPrefecture); } } public string CognitionNumber { get { return P + x; } } private string FillZero(int number) { return string.Format("{0:000000}", number); } } } }
[["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
413
6
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int N = int.Parse(str[0]); int M = int.Parse(str[1]); int[][] B = new int [M][]; for (var i = 0; i < M; i++) { B[i] = new int[3]; string[] str2 = Console.ReadLine().Split(); B[i][0] = int.Parse(str2[0]); B[i][1] = int.Parse(str2[1]); B[i][2] = i; } Array.Sort(B, (x, y) => x[1] - y[1]); int[,] C = new int[M, 2]; int[] D = new int[M]; for (var i = 0; i < M; i++) { C[B[i][2], 0] = B[i][0]; C[B[i][2], 1] = D[B[i][0] - 1] + 1; D[B[i][0] - 1] += 1; } string[] E = new string[M]; for (var i = 0; i < M; i++) { string a1 = "000000" + C[i, 0].ToString(); a1 = a1.Substring(a1.Length - 6, 6); string a2 = "000000" + C[i, 1].ToString(); a2 = a2.Substring(a2.Length - 6, 6); E[i] = a1 + a2; } for (var i = 0; i < M; i++) { Console.WriteLine(E[i]); } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int N = int.Parse(str[0]); int M = int.Parse(str[1]); int[][] B = new int [M][]; for (var i = 0; i < M; i++) { B[i] = new int[3]; string[] str2 = Console.ReadLine().Split(); B[i][0] = int.Parse(str2[0]); B[i][1] = int.Parse(str2[1]); B[i][2] = i; } Array.Sort(B, (x, y) => x[1] - y[1]); int[,] C = new int[M, 2]; int[] D = new int[N]; for (var i = 0; i < M; i++) { C[B[i][2], 0] = B[i][0]; C[B[i][2], 1] = D[B[i][0] - 1] + 1; D[B[i][0] - 1] += 1; } string[] E = new string[M]; for (var i = 0; i < M; i++) { string a1 = "000000" + C[i, 0].ToString(); a1 = a1.Substring(a1.Length - 6, 6); string a2 = "000000" + C[i, 1].ToString(); a2 = a2.Substring(a2.Length - 6, 6); E[i] = a1 + a2; } for (var i = 0; i < M; i++) { Console.WriteLine(E[i]); } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22]]
8
425
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ABC113_C { public class Program { public class City { public int index { get; set; } public int year { get; set; } public int p { get; set; } public int BirthOrder { get; set; } public City(int i, int year, int p) { this.index = i; this.year = year; this.p = p; this.BirthOrder = 0; } } public static void Main(string[] args) { int[] line = ReadIntAr(); int n = line[0]; int m = line[1]; List<City> cities = new List<City>(); int[] tmp; for (int i = 0; i < m; i++) { tmp = ReadIntAr(); cities.Add(new City(i, tmp[1], tmp[0])); } var tmp2 = cities.OrderBy(x => x.p).ThenBy(x => x.year); int k = 1; int beforeP = 0; foreach (var item in tmp2) { if (beforeP != item.p) k = 1; item.BirthOrder = k; k++; } var res = cities.OrderBy(x => x.index).ToArray(); for (int i = 0; i < m; i++) { Console.WriteLine(res[i].p.ToString("000000") + res[i].BirthOrder.ToString("000000")); } } static string ReadSt() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static double ReadDouble() { return double.Parse(Console.ReadLine()); } static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ABC113_C { public class Program { public class City { public int index { get; set; } public int year { get; set; } public int p { get; set; } public int BirthOrder { get; set; } public City(int i, int year, int p) { this.index = i; this.year = year; this.p = p; this.BirthOrder = 0; } } public static void Main(string[] args) { int[] line = ReadIntAr(); int n = line[0]; int m = line[1]; List<City> cities = new List<City>(); int[] tmp; for (int i = 0; i < m; i++) { tmp = ReadIntAr(); cities.Add(new City(i, tmp[1], tmp[0])); } var tmp2 = cities.OrderBy(x => x.p).ThenBy(x => x.year); int k = 1; int beforeP = 0; foreach (var item in tmp2) { if (beforeP != item.p) k = 1; item.BirthOrder = k; beforeP = item.p; k++; } var res = cities.OrderBy(x => x.index).ToArray(); for (int i = 0; i < m; i++) { Console.WriteLine(res[i].p.ToString("000000") + res[i].BirthOrder.ToString("000000")); } } static string ReadSt() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static double ReadDouble() { return double.Parse(Console.ReadLine()); } static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } } }
[["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
558
6
using System; public class AtCoder { public static void Main() { string[] s; s = Console.ReadLine().Trim().Split(' '); int n, m; n = int.Parse(s[0]); m = int.Parse(s[1]); int[] cp = new int[m]; int[] y = new int[m]; int[] x = new int[m]; int[] o = new int[m]; for (int i = 0; i < m; i++) { o[i] = i; s = Console.ReadLine().Trim().Split(' '); cp[i] = int.Parse(s[0]); y[i] = int.Parse(s[1]); x[i] = int.Parse(s[1]); } Array.Sort(y, cp); Array.Sort(x, o); int[] p = new int[n]; long[] ans = new long[m]; string t; for (int i = 0; i < m; i++) { p[cp[i] - 1]++; ans[o[i]] = p[cp[i] - 1] + cp[i] * 1000000; } for (int i = 0; i < m; i++) { t = ans[i].ToString(); while (t.Length < 12) { t = "0" + t; } Console.WriteLine(t); } } }
using System; public class AtCoder { public static void Main() { string[] s; s = Console.ReadLine().Trim().Split(' '); int n, m; n = int.Parse(s[0]); m = int.Parse(s[1]); long[] cp = new long[m]; int[] y = new int[m]; int[] x = new int[m]; int[] o = new int[m]; for (int i = 0; i < m; i++) { o[i] = i; s = Console.ReadLine().Trim().Split(' '); cp[i] = long.Parse(s[0]); y[i] = int.Parse(s[1]); x[i] = int.Parse(s[1]); } Array.Sort(y, cp); Array.Sort(x, o); long[] p = new long[n]; long[] ans = new long[m]; string t; for (int i = 0; i < m; i++) { p[cp[i] - 1]++; ans[o[i]] = p[cp[i] - 1] + cp[i] * 1000000; } for (int i = 0; i < m; i++) { t = ans[i].ToString(); while (t.Length < 12) { t = "0" + t; } Console.WriteLine(t); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
347
10
using System; using System.Linq; using System.IO; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace AtCoder { public class Program { public static void Main() { string[] Keys = Console.ReadLine().Split(' '); int N = int.Parse(Keys[0]); int M = int.Parse(Keys[1]); City[] cities = new City[M]; for (int i = 0; i < M; i++) { Keys = Console.ReadLine().Split(' '); cities[i] = new City(int.Parse(Keys[0]), int.Parse(Keys[1]), i); } cities = cities.OrderBy(c => c.Year).ToArray(); int[] Count = new int[N]; for (int i = 0; i < M; i++) { cities[i].Generate(Count[cities[i].Prefacture] + 1); Count[cities[i].Prefacture]++; } cities = cities.OrderBy(c => c.No).ToArray(); for (int i = 0; i < M; i++) { Console.WriteLine(cities[i].Code); } } } public class City { public int Prefacture; public int Year; public int No; public string Code; public City(int P, int Y, int N) { Prefacture = P; Year = Y; No = N; } public void Generate(int i) { Code = Prefacture.ToString("000000") + i.ToString("000000"); } } }
using System; using System.Linq; using System.IO; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace AtCoder { public class Program { public static void Main() { string[] Keys = Console.ReadLine().Split(' '); int N = int.Parse(Keys[0]); int M = int.Parse(Keys[1]); City[] cities = new City[M]; for (int i = 0; i < M; i++) { Keys = Console.ReadLine().Split(' '); cities[i] = new City(int.Parse(Keys[0]), int.Parse(Keys[1]), i); } cities = cities.OrderBy(c => c.Year).ToArray(); int[] Count = new int[N]; for (int i = 0; i < M; i++) { cities[i].Generate(Count[cities[i].Prefacture - 1] + 1); Count[cities[i].Prefacture - 1]++; } cities = cities.OrderBy(c => c.No).ToArray(); for (int i = 0; i < M; i++) { Console.WriteLine(cities[i].Code); } } } public class City { public int Prefacture; public int Year; public int No; public string Code; public City(int P, int Y, int N) { Prefacture = P; Year = Y; No = N; } public void Generate(int i) { Code = Prefacture.ToString("000000") + i.ToString("000000"); } } }
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
362
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { SolveA(); // SolveB(); // SolveC(); // SolveD(); } private const long MOD = 1000000007; private struct Data { public int idx; public int year; } static void SolveA() { var nm = ReadAndParseIntArr(); int n = nm[0]; int m = nm[1]; int[] p = new int[m]; int[] y = new int[m]; for (int i = 0; i < m; ++i) { var tmp = ReadAndParseIntArr(); p[i] = tmp[0]; y[i] = tmp[1]; } var hash = new Dictionary<int, List<Data>>(); // key 県id、value yearの配列 long[] ids = new long[m]; for (int i = 0; i < m; ++i) { if (!hash.ContainsKey(p[i])) { hash[p[i]] = new List<Data>(); } var list = hash[p[i]]; list.Add(new Data() { idx = i, year = y[i] }); } foreach (var pair in hash) { pair.Value.Sort((a, b) => a.year.CompareTo(b.year)); } foreach (var pair in hash) { int ken = pair.Key; var datas = pair.Value; for (int i = 0; i < datas.Count; ++i) { Data data = datas[i]; long id = ken * 1000000 + i + 1; ids[data.idx] = id; } } foreach (long id in ids) { Console.WriteLine(id.ToString("D12")); } } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { static void Main(string[] args) { SolveA(); // SolveB(); // SolveC(); // SolveD(); } private const long MOD = 1000000007; private struct Data { public int idx; public int year; } static void SolveA() { var nm = ReadAndParseIntArr(); int n = nm[0]; int m = nm[1]; int[] p = new int[m]; int[] y = new int[m]; for (int i = 0; i < m; ++i) { var tmp = ReadAndParseIntArr(); p[i] = tmp[0]; y[i] = tmp[1]; } var hash = new Dictionary<int, List<Data>>(); // key 県id、value yearの配列 long[] ids = new long[m]; for (int i = 0; i < m; ++i) { if (!hash.ContainsKey(p[i])) { hash[p[i]] = new List<Data>(); } var list = hash[p[i]]; list.Add(new Data() { idx = i, year = y[i] }); } foreach (var pair in hash) { pair.Value.Sort((a, b) => a.year.CompareTo(b.year)); } foreach (var pair in hash) { long ken = pair.Key; var datas = pair.Value; for (int i = 0; i < datas.Count; ++i) { Data data = datas[i]; long id = ken * 1000000 + i + 1; ids[data.idx] = id; } } foreach (long id in ids) { Console.WriteLine(id.ToString("D12")); } } #region よく使う便利関数 private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } #endregion } }
[["-", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199]]
8
634
2
using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var num = ToInt32(ReadLine()); if (num == 1) WriteLine("Hello,World!"); else WriteLine(ToInt32(ReadLine()) + ToInt32(ReadLine())); } }
using static System.Console; using static System.Convert; using static System.Math; class Program { static void Main(string[] args) { var num = ToInt32(ReadLine()); if (num == 1) WriteLine("Hello World"); else WriteLine(ToInt32(ReadLine()) + ToInt32(ReadLine())); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
74
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderB { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int t = sc.NextInt(); int answer = int.MaxValue; for (int i = 0; i < n; i++) { int cost = sc.NextInt(); int time = sc.NextInt(); if (t <= time) { answer = Math.Min(answer, cost); } } if (answer == int.MaxValue) { Console.WriteLine("TLE"); return; } 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 AtCoderB { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int t = sc.NextInt(); int answer = int.MaxValue; for (int i = 0; i < n; i++) { int cost = sc.NextInt(); int time = sc.NextInt(); if (time <= t) { answer = Math.Min(answer, cost); } } if (answer == int.MaxValue) { Console.WriteLine("TLE"); return; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
440
4
using System; using System.Collections.Generic; using System.Linq; static class MainClass { public struct Routes { public long cost; public long time; public Routes(long c, long t) { cost = c; time = t; } } public static void Main(string[] args) { var temp = Console.ReadLine().Split(' ').Select(long.Parse); var N = temp.ElementAt(0); var T = temp.ElementAt(1); var routesList = new List<Routes>(); for (var i = 0; i < N; i++) { var temp2 = Console.ReadLine().Split(' ').Select(long.Parse); routesList.Add(new Routes(temp2.ElementAt(0), temp2.ElementAt(1))); } var okRoutes = routesList.Where(t => t.time <= T); var ans = okRoutes.Any() ? okRoutes.Select(c => c.cost).Min().ToString() : "TLS"; Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; static class MainClass { public struct Routes { public long cost; public long time; public Routes(long c, long t) { cost = c; time = t; } } public static void Main(string[] args) { var temp = Console.ReadLine().Split(' ').Select(long.Parse); var N = temp.ElementAt(0); var T = temp.ElementAt(1); var routesList = new List<Routes>(); for (var i = 0; i < N; i++) { var temp2 = Console.ReadLine().Split(' ').Select(long.Parse); routesList.Add(new Routes(temp2.ElementAt(0), temp2.ElementAt(1))); } var okRoutes = routesList.Where(t => t.time <= T); var ans = okRoutes.Any() ? okRoutes.Select(c => c.cost).Min().ToString() : "TLE"; Console.WriteLine(ans); } }
[["-", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
235
2
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int T = int.Parse(s[1]); int min = int.MaxValue; for (int i = 0; i < N; i++) { s = Console.ReadLine().Split(' '); int c = int.Parse(s[0]); int t = int.Parse(s[1]); if (t <= T && c < min) { min = c; } } Console.WriteLine((min == int.MaxValue ? "TEL" : min.ToString())); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int T = int.Parse(s[1]); int min = int.MaxValue; for (int i = 0; i < N; i++) { s = Console.ReadLine().Split(' '); int c = int.Parse(s[0]); int t = int.Parse(s[1]); if (t <= T && c < min) { min = c; } } Console.WriteLine((min == int.MaxValue ? "TLE" : min.ToString())); } }
[["-", 0, 28, 0, 23, 0, 41, 64, 5, 0, 222], ["+", 0, 28, 0, 23, 0, 41, 64, 5, 0, 222]]
8
177
2
using System; class Program { static void Main(string[] args) { var tmp = Read(2); var n = tmp[0]; var t = tmp[1]; long m = t + 1; for (long i = 0; i < n; i++) { tmp = Read(2); m = (tmp[1] <= t && tmp[0] < m) ? tmp[0] : m; } if (m == t + 1) { Write("TLE"); } else { Write(m); } } static void Write(string s) { Console.WriteLine(s); return; } static void Write(long n) { Console.WriteLine(n.ToString()); return; } static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrs() { return Console.ReadLine().Split(' '); } static long Read() { return long.Parse(Console.ReadLine()); } static long[] Read(long n) { long[] p = new long[n]; string[] t = Console.ReadLine().Split(' '); for (long i = 0; i < n; i++) { p[i] = long.Parse(t[i]); } return p; } static long abs(long n) { return (n > 0) ? n : -n; } static long gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = gcd(p, n[i]); } return p; } static long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); } static long lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = lcm(p, n[i]); } return p; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static long max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } static long min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } static string clip(string s, int start, int count) { if (start + count < s.Length) { s = s.Remove(start + count); } if (start > 0) { s = s.Remove(0, start); } return s; } }
using System; class Program { static void Main(string[] args) { var tmp = Read(2); var n = tmp[0]; var t = tmp[1]; long m = 1001; for (long i = 0; i < n; i++) { tmp = Read(2); m = (tmp[1] <= t && tmp[0] < m) ? tmp[0] : m; } if (m == 1001) { Write("TLE"); } else { Write(m); } } static void Write(string s) { Console.WriteLine(s); return; } static void Write(long n) { Console.WriteLine(n.ToString()); return; } static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrs() { return Console.ReadLine().Split(' '); } static long Read() { return long.Parse(Console.ReadLine()); } static long[] Read(long n) { long[] p = new long[n]; string[] t = Console.ReadLine().Split(' '); for (long i = 0; i < n; i++) { p[i] = long.Parse(t[i]); } return p; } static long abs(long n) { return (n > 0) ? n : -n; } static long gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = gcd(p, n[i]); } return p; } static long gcd(long a, long b) { return (a == 0) ? b : gcd(b % a, a); } static long lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = lcm(p, n[i]); } return p; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static long max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } static long min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } static string clip(string s, int start, int count) { if (start + count < s.Length) { s = s.Remove(start + count); } if (start > 0) { s = s.Remove(0, start); } return s; } }
[["-", 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], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
723
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { class Program { static void Main() { //ここから int[] vs = ReadLineToIntArray(); int ans = 1001; for (int i = 0; i < vs[0]; i++) { int[] str = ReadLineToIntArray(); if (str[1] <= vs[1]) { ans = ans > str[0] ? str[0] : ans; } } if (ans == 1001) { Console.WriteLine("TLE"); } //ここまで Console.WriteLine(ans); Console.ReadKey(); } static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(int a, int b) { return (long)a * b / GCD(a, b); } static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); } static public int Conbin(int n, int m) { return Factorial(n) / (Factorial(n - m) * Factorial(m)); } 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 string[] ReadLineToStringArray() { return Console.ReadLine().Split(' ').ToArray(); } static public int[] ReadLineToIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } 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(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { class Program { static void Main() { //ここから int[] vs = ReadLineToIntArray(); int ans = 1001; for (int i = 0; i < vs[0]; i++) { int[] str = ReadLineToIntArray(); if (str[1] <= vs[1]) { ans = ans > str[0] ? str[0] : ans; } } if (ans == 1001) { Console.WriteLine("TLE"); return; } //ここまで Console.WriteLine(ans); Console.ReadKey(); } static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(int a, int b) { return (long)a * b / GCD(a, b); } static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); } static public int Conbin(int n, int m) { return Factorial(n) / (Factorial(n - m) * Factorial(m)); } 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 string[] ReadLineToStringArray() { return Console.ReadLine().Split(' ').ToArray(); } static public int[] ReadLineToIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] ReadLineToLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } 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(); } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
8
552
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B_Time_Limit_Exceeded { class Program { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); int N = int.Parse(str1[0]); int T = int.Parse(str1[1]); int[] c = new int[N]; int[] t = new int[N]; for (int i = 0; i < N; i++) { string[] str = Console.ReadLine().Split(' '); c[i] = int.Parse(str[0]); t[i] = int.Parse(str[1]); } int cmin = int.MaxValue; int Count = 0; // int answer = 0; for (int i = 0; i < N; i++) { if (t[i] < T) { Count++; if (cmin > c[i]) { cmin = c[i]; } // answer = i; } } if (Count != 0) { Console.Write(cmin); } else { Console.Write("TLE"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B_Time_Limit_Exceeded { class Program { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); int N = int.Parse(str1[0]); int T = int.Parse(str1[1]); int[] c = new int[N]; int[] t = new int[N]; for (int i = 0; i < N; i++) { string[] str = Console.ReadLine().Split(' '); c[i] = int.Parse(str[0]); t[i] = int.Parse(str[1]); } int cmin = int.MaxValue; int Count = 0; // int answer = 0; for (int i = 0; i < N; i++) { if (t[i] <= T) { Count++; if (cmin > c[i]) { cmin = c[i]; } // answer = i; } } if (Count != 0) { Console.Write(cmin); } else { Console.Write("TLE"); } } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
265
2
using System; namespace regio { class Program { [STAThread] static void Main(string[] args) { string str; string[] arr; int kosuu, T; str = Console.ReadLine(); arr = str.Split(' '); kosuu = int.Parse(arr[0]); T = int.Parse(arr[1]); int[] c = new int[kosuu]; int[] t = new int[kosuu]; int min; for (int i = 0; i < kosuu; i++) { str = Console.ReadLine(); arr = str.Split(' '); c[i] = int.Parse(arr[0]); t[i] = int.Parse(arr[1]); } min = 2147483647; for (int i = 0; i < kosuu; i++) { if (t[i] < T) { if (c[i] < min) { min = c[i]; } } } if (min == 2147483647) { Console.WriteLine("TLE"); } else { Console.WriteLine("{0}", min); } } } }
using System; namespace regio { class Program { [STAThread] static void Main(string[] args) { string str; string[] arr; int kosuu, T; str = Console.ReadLine(); arr = str.Split(' '); kosuu = int.Parse(arr[0]); T = int.Parse(arr[1]); int[] c = new int[kosuu]; int[] t = new int[kosuu]; int min; for (int i = 0; i < kosuu; i++) { str = Console.ReadLine(); arr = str.Split(' '); c[i] = int.Parse(arr[0]); t[i] = int.Parse(arr[1]); } min = 2147483647; for (int i = 0; i < kosuu; i++) { if (t[i] <= T) { if (c[i] < min) { min = c[i]; } } } if (min == 2147483647) { Console.WriteLine("TLE"); } else { Console.WriteLine("{0}", min); } } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
251
2
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int T = int.Parse(input[1]); int C = 1001; for (int i = 0; i < n; i++) { string[] inputl = Console.ReadLine().Split(' '); int c = int.Parse(inputl[0]); int t = int.Parse(inputl[1]); if (t <= T) { if (c < C) { C = c; } } } if (C == 1001) { Console.WriteLine("TEL"); } else { Console.WriteLine(C); } } }
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int T = int.Parse(input[1]); int C = 1001; for (int i = 0; i < n; i++) { string[] inputl = Console.ReadLine().Split(' '); int c = int.Parse(inputl[0]); int t = int.Parse(inputl[1]); if (t <= T) { if (c < C) { C = c; } } } if (C == 1001) { Console.WriteLine("TLE"); } else { Console.WriteLine(C); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
170
2
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int inputCount = inpt[0]; int timeLimit = inpt[1]; string ans = "TLE"; int min = int.MaxValue; for (int i = 0; i < inputCount; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); if (inpt[1] >= timeLimit) { continue; } if (min > inpt[0]) { min = inpt[0]; ans = (i + 1).ToString(); } } Console.WriteLine(ans); } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 5 9 25 8 5 9 4 10 1000 1000 6 1 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int inputCount = inpt[0]; int timeLimit = inpt[1]; string ans = "TLE"; int min = int.MaxValue; for (int i = 0; i < inputCount; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); if (inpt[1] > timeLimit) { continue; } if (min > inpt[0]) { min = inpt[0]; ans = min.ToString(); } } Console.WriteLine(ans); } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 5 9 25 8 5 9 4 10 1000 1000 6 1 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 11, 12, 213, 63, 214, 205, 23, 0, 24], ["-", 12, 213, 63, 214, 205, 23, 0, 16, 31, 22], ["-", 12, 213, 63, 214, 205, 23, 0, 16, 17, 72], ["-", 12, 213, 63, 214, 205, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 213, 63, 214, 205, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22]]
8
309
8
using System; using System.Linq; namespace abc112_b { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int min = int.MaxValue; for (int i = 0; i < x[0]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (a[1] < x[1]) min = Math.Min(min, a[0]); } Console.WriteLine(min == int.MaxValue ? "TLE" : min.ToString()); } } }
using System; using System.Linq; namespace abc112_b { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int min = int.MaxValue; for (int i = 0; i < x[0]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (a[1] <= x[1]) min = Math.Min(min, a[0]); } Console.WriteLine(min == int.MaxValue ? "TLE" : min.ToString()); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
152
2
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { int kazu = int.Parse(ReadLine()); int[] xza = new int[kazu]; int[] yza = new int[kazu]; int[] hig = new int[kazu]; for (int i = 0; i < kazu; i++) { string[] temp = ReadLine().Split(' '); xza[i] = int.Parse(temp[0]); yza[i] = int.Parse(temp[1]); hig[i] = int.Parse(temp[2]); } //降順ソート for (int j = 0; j < 150; j++) { for (int i = 0; i < kazu - 1; i++) { if (hig[i] < hig[i + 1]) { int temp = hig[i]; hig[i] = hig[i + 1]; hig[i + 1] = temp; temp = xza[i]; xza[i] = xza[i + 1]; xza[i + 1] = temp; temp = yza[i]; yza[i] = yza[i + 1]; yza[i + 1] = temp; } } } int tyoux = -1; int tyouy = -1; int tyouh = -1; for (int x = 0; x <= 100; x++) { for (int y = 0; y <= 100; y++) { int count = 0; int suitei = hig[0] + Abs(x - xza[0]) + Abs(y - yza[0]); for (int i = 1; i < kazu; i++) { int takasa = suitei - Abs(x - xza[i]) - Abs(y - yza[i]); if (takasa == hig[i]) { count++; } } if (count == kazu - 1) { if (suitei > tyouh) { tyoux = x; tyouy = y; tyouh = suitei; } } } } WriteLine("{0} {1} {2}", tyoux, tyouy, tyouh); } }
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { int kazu = int.Parse(ReadLine()); int[] xza = new int[kazu]; int[] yza = new int[kazu]; int[] hig = new int[kazu]; for (int i = 0; i < kazu; i++) { string[] temp = ReadLine().Split(' '); xza[i] = int.Parse(temp[0]); yza[i] = int.Parse(temp[1]); hig[i] = int.Parse(temp[2]); } //降順ソート for (int j = 0; j < 150; j++) { for (int i = 0; i < kazu - 1; i++) { if (hig[i] < hig[i + 1]) { int temp = hig[i]; hig[i] = hig[i + 1]; hig[i + 1] = temp; temp = xza[i]; xza[i] = xza[i + 1]; xza[i + 1] = temp; temp = yza[i]; yza[i] = yza[i + 1]; yza[i + 1] = temp; } } } int tyoux = -1; int tyouy = -1; int tyouh = -1; for (int x = 0; x <= 100; x++) { for (int y = 0; y <= 100; y++) { int count = 0; int suitei = hig[0] + Abs(x - xza[0]) + Abs(y - yza[0]); for (int i = 1; i < kazu; i++) { int takasa = Max(suitei - Abs(x - xza[i]) - Abs(y - yza[i]), 0); if (takasa == hig[i]) { count++; } } if (count == kazu - 1) { if (suitei > tyouh) { tyoux = x; tyouy = y; tyouh = suitei; } } } } WriteLine("{0} {1} {2}", tyoux, tyouy, tyouh); } }
[["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203]]
8
467
5
using System; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x = new int[n]; int[] y = new int[n]; int[] h = new int[n]; for (int i = 0; i < n; i++) { int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray(); x[i] = tmp[0]; y[i] = tmp[1]; h[i] = tmp[2]; } solve(x, y, h, n); } static void solve(int[] x, int[] y, int[] h, int n) { for (int cx = 0; cx <= 100; ++cx) { for (int cy = 0; cy <= 100; ++cy) { int hmax = int.MaxValue; int high = -1; for (int i = 0; i < n; ++i) { var d = Math.Abs(x[i] - cx) + Math.Abs(y[i] - cy); if (h[i] == 0) hmax = Math.Min(hmax, d); else { if (high == -1) high = d + h[i]; else if (high != d + h[i]) goto end; } } if (high > hmax || hmax < 1) break; if (high == -1) high = hmax; Console.WriteLine("{0} {1} {2}", cx, cy, high); return; end:; } } return; } }
using System; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x = new int[n]; int[] y = new int[n]; int[] h = new int[n]; for (int i = 0; i < n; i++) { int[] tmp = Console.ReadLine().Split().Select(int.Parse).ToArray(); x[i] = tmp[0]; y[i] = tmp[1]; h[i] = tmp[2]; } solve(x, y, h, n); } static void solve(int[] x, int[] y, int[] h, int n) { for (int cx = 0; cx <= 100; ++cx) { for (int cy = 0; cy <= 100; ++cy) { int hmax = int.MaxValue; int high = -1; for (int i = 0; i < n; ++i) { var d = Math.Abs(x[i] - cx) + Math.Abs(y[i] - cy); if (h[i] == 0) hmax = Math.Min(hmax, d); else { if (high == -1) high = d + h[i]; else if (high != d + h[i]) goto end; } } if (high > hmax || hmax < 1) goto end; if (high == -1) high = hmax; Console.WriteLine("{0} {1} {2}", cx, cy, high); return; end:; } } } }
[["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 126, 0, 127], ["+", 0, 7, 8, 196, 0, 57, 64, 126, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35]]
8
364
5
using System; using System.Collections; using System.Collections.Generic; using System.Text; public class C { public static void Main() { int N = Int32.Parse(Console.ReadLine()); int[] x = new int[N]; int[] y = new int[N]; int[] h = new int[N]; for (int i = 0; i < N; i++) { string[] args = Console.ReadLine().Split(' '); x[i] = Int32.Parse(args[0]); y[i] = Int32.Parse(args[1]); h[i] = Int32.Parse(args[2]); } int iPlus = -1; for (int i = 0; i < N; i++) { if (h[i] > 0) { iPlus = i; break; } } for (int Cx = 0; Cx <= 100; Cx++) { for (int Cy = 0; Cy <= 100; Cy++) { bool correct = true; int H = h[iPlus] + Math.Abs(x[iPlus] - Cx) + Math.Abs(y[iPlus] - Cy); for (int i = iPlus + 1; i < N; i++) { if (h[i] == 0) continue; // next i if (h[i] + Math.Abs(x[i] - Cx) + Math.Abs(y[i] - Cy) != H) { correct = false; break; // end i-loop } } if (!correct) continue; // next Cy for (int i = 0; i < N; i++) { if (h[i] != 0) continue; // next i if (H >= Math.Abs(x[i] - Cx) + Math.Abs(y[i] - Cy)) { correct = false; break; // end i-loop } } if (correct) { Console.WriteLine("{0} {1} {2}", Cx, Cy, H); return; } } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; public class C { public static void Main() { int N = Int32.Parse(Console.ReadLine()); int[] x = new int[N]; int[] y = new int[N]; int[] h = new int[N]; for (int i = 0; i < N; i++) { string[] args = Console.ReadLine().Split(' '); x[i] = Int32.Parse(args[0]); y[i] = Int32.Parse(args[1]); h[i] = Int32.Parse(args[2]); } int iPlus = -1; for (int i = 0; i < N; i++) { if (h[i] > 0) { iPlus = i; break; } } for (int Cx = 0; Cx <= 100; Cx++) { for (int Cy = 0; Cy <= 100; Cy++) { bool correct = true; int H = h[iPlus] + Math.Abs(x[iPlus] - Cx) + Math.Abs(y[iPlus] - Cy); for (int i = iPlus + 1; i < N; i++) { if (h[i] == 0) continue; // next i if (h[i] + Math.Abs(x[i] - Cx) + Math.Abs(y[i] - Cy) != H) { correct = false; break; // end i-loop } } if (!correct) continue; // next Cy for (int i = 0; i < N; i++) { if (h[i] != 0) continue; // next i if (H > Math.Abs(x[i] - Cx) + Math.Abs(y[i] - Cy)) { correct = false; break; // end i-loop } } if (correct) { Console.WriteLine("{0} {1} {2}", Cx, Cy, H); return; } } } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47]]
8
435
2
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var x = new int[N]; var y = new int[N]; var h = new int[N]; for (int i = 0; i < N; i++) { var str = Console.ReadLine(); var strs = str.Split(' '); x[i] = int.Parse(strs[0]); y[i] = int.Parse(strs[1]); h[i] = int.Parse(strs[2]); } var MAX = 100; for (int posY = 0; posY <= MAX; posY++) { for (int posX = 0; posX <= MAX; posX++) { int needH = -1; for (int i = 0; i < N; i++) { if (h[i] > 0) { int tmp = h[i] + Math.Abs(posY - y[i]) + Math.Abs(posX - x[i]); if (needH == -1) { needH = tmp; } else { if (needH != tmp) { needH = -2; break; } } } } if (needH == -2) continue; for (int i = 0; i < N; i++) { if (h[i] == 0) { var dist = Math.Abs(posY - y[i]) + Math.Abs(posX - x[i]); if (needH > dist) { needH = -2; break; } } if (needH == -2) continue; Console.WriteLine(posX + " " + posY + " " + needH); return; } } } } } }
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var x = new int[N]; var y = new int[N]; var h = new int[N]; for (int i = 0; i < N; i++) { var str = Console.ReadLine(); var strs = str.Split(' '); x[i] = int.Parse(strs[0]); y[i] = int.Parse(strs[1]); h[i] = int.Parse(strs[2]); } var MAX = 100; for (int posY = 0; posY <= MAX; posY++) { for (int posX = 0; posX <= MAX; posX++) { int needH = -1; for (int i = 0; i < N; i++) { if (h[i] > 0) { int tmp = h[i] + Math.Abs(posY - y[i]) + Math.Abs(posX - x[i]); if (needH == -1) { needH = tmp; } else { if (needH != tmp) { needH = -2; break; } } } } if (needH == -2) continue; for (int i = 0; i < N; i++) { if (h[i] == 0) { var dist = Math.Abs(posY - y[i]) + Math.Abs(posX - x[i]); if (needH > dist) { needH = -2; break; } } } if (needH == -2) continue; Console.WriteLine(posX + " " + posY + " " + needH); return; } } } } }
[["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
8
386
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // using static System.Linq.Enumerable; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; using static AtCoder.StreamExtensions; using static AtCoder.Matrix; namespace AtCoder { using VI = VectorInt2; static class Program { static void Main() { var n = ReadInt(); var inputs = n.Times(() => new { X = ReadInt(), Y = ReadInt(), H = ReadLong() }) .ToList(); foreach (var cx in FromTo(0, 100)) foreach (var cy in FromTo(0, 100)) { //最初の標高が0の可能性があるので注意!て頂点高を求める参考にならない! var refPoint = inputs.First(x => x.H > 0); var ch = refPoint.H + Abs(cx - refPoint.X + Abs(cy - refPoint.Y)); if (inputs.All(data => calcHeight(cx, cy, ch, data.X, data.Y) == data.H)) { $"{cx} {cy} {ch}".WriteLine(); return; } } throw new InvalidOperationException(); } static long calcHeight(int cx, int cy, long ch, int x, int y) { return Max(ch - Abs(x - cx) - Abs(y - cy), 0); } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class Algorithm { public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, long width) => BinSearch(range, isBigger, x => range.Right - range.Left < width); public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, Func<LongRange, bool> stopCondition) { if (stopCondition(range)) return range; var middle = range.Left + (range.Right - range.Left) / 2; return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle), isBigger, stopCondition) : BinSearch(new LongRange(middle, range.Right), isBigger, stopCondition); } } static class MyMath { public static int DivRoundUp(int a, int b) { var q = a / b; if (a % b != 0) q++; return q; } public static long GCD(long a, long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a; public static long GCD(this IEnumerable<long> source) => source.Aggregate(GCD); public static long LCM(long a, long b) { var g = GCD(a, b); var a1 = a / g; var b1 = b / g; return g * a1 * b1; } public static long LCM(this IEnumerable<long> source) => source.Aggregate(LCM); public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Mul); public static long nPr(int n, int r) => r < 0 || r > n? 0 : FromTo(n - r + 1, n) .Select(x => (long)x) .Aggregate(1L, Mul); public static long nCr(int n, int r) => nPr(n, r) / Factorial(r); public static long Inc(long i) => i + 1; public static long Dec(long i) => i - 1; public static long Plus(long i, long j) => i + j; public static Func<long, long> Plus(long j) => i => i + j; public static long Minus(long i, long j) => i - j; public static Func<long, long> Minus(long j) => i => i - j; public static long Mul(long i, long j) => i * j; public static Func<long, long> Mul(long j) => i => i * j; public static long Div(long i, long j) => j / j; public static Func<long, long> Div(long j) => i => i * j; public static long Mod(long i, long j) => i % j; public static Func<long, long> Mod(long j) => i => i % j; public static Func<long, bool> Leq(long j) => i => i <= j; public static Func<long, bool> Gt(long j) => i => i > j; public static Func<long, bool> Geq(long j) => i => i >= j; public static Func<long, bool> Eq(long j) => i => i == j; public static Func<long, bool> Neq(long j) => i => i != j; public static int Plus(int i, int j) => i + j; public static Func<int, int> Plus(int j) => i => i + j; public static int Minus(int i, int j) => i - j; public static Func<int, int> Minus(int j) => i => i - j; public static int Mul(int i, int j) => i * j; public static Func<int, int> Mul(int j) => i => i * j; public static int Div(int i, int j) => j / j; public static Func<int, int> Div(int j) => i => i * j; public static int Mod(int i, int j) => i % j; public static Func<int, int> Mod(int j) => i => i % j; public static Func<int, bool> Lt(int j) => i => i < j; public static Func<int, bool> Leq(int j) => i => i <= j; public static Func<int, bool> Gt(int j) => i => i > j; public static Func<int, bool> Geq(int j) => i => i >= j; public static Func<int, bool> Eq(int j) => i => i == j; public static Func<int, bool> Neq(int j) => i => i != j; public static long Max(params long[] ns) => ns.Max(); public static long LowerBound(this long m, long lbound) => Max(m, lbound); public static long UpperBound(this long m, long ubound) => Min(m, ubound); public static long Bound(this long m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static long LowerBound(this int m, long lbound) => Max(m, lbound); public static long UpperBound(this int m, long ubound) => Min(m, ubound); public static long Bound(this int m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static bool InRange(this long x, long min, long max) => min <= x && x <= max; public static bool IsEven(this int x) => x % 2 == 0; public static bool IsOdd(this int x) => x % 2 != 0; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 0; public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits(); public static IEnumerable<int> Factors(this int n) { for (int i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<long> Factors(this long n) { for (long i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static MultiSet<long> Factorize(this long n) { var factors = new MultiSet<long>(); for (long i = 2; i * i <= n; i++) { while (n % i == 0) { n /= i; factors[i]++; } } if (n > 1) factors.Add(n); return factors; } public static IEnumerable<int> Natural() { for (int i = 0;; i++) yield return i; } public static IEnumerable<int> Positive() => Natural().Skip(1); public static long Pow(this long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static long Pow(this int i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static int IntLog(this long n, long baseNum) { int count = 0; while (n >= baseNum) { n /= baseNum; count++; } return count; } } static class Util { public static InvalidOperationException UnreachableException = new InvalidOperationException("unreachable."); public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t); public static bool IsPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } public readonly static VectorInt2[] Dir8 = { new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1), new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1), new VectorInt2(1, 0), new VectorInt2(1, 1) }; public const long MODCONST = 1000000007; public static T debug<T>(this T value) { Console.Error.WriteLine($"debug:{value}"); return value; } public static T Id<T>(T t) => t; public static long ToLong(this String s) => long.Parse(s); public static long ToLong(this char c) => c - '0'; public static int ToInt(this String s) => int.Parse(s); public static int ToInt(this char c) => c - '0'; public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static VectorDouble2 ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt()); public static string ReplaceX(this string input, string pattern, string replace) => Regex.Replace(input, pattern, replace); public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j); public static IEnumerable<long> Range(long i, long j) { for (long k = i; k < i + j; k++) yield return k; } public static void Swap<T>(this IList<T> enumerable, int i, int j) { var buf = enumerable[i]; enumerable[i] = enumerable[j]; enumerable[j] = buf; } public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); } static class ParametricExtensions { public static Func<S, U> Then<S, T, U>(this Func<S, T> f, Func<T, U> g) => x => g(f(x)); public static Func<S, U> Compose<S, T, U>(this Func<T, U> f, Func<S, T> g) => x => f(g(x)); public static void Call<T>(this T t, Action<T> action) => action(t); public static void WriteLine<T>(this T t) => Console.WriteLine(t); public static void Write<T>(this T t) => Console.Write(t); public static T Call<S, T>(this S s, Func<S, T> func) => func(s); public static S Call<S>(this S s, Func<S, S> func, int times) => times == 0 ? s : Call(func(s), func, times - 1); } static class StreamExtensions { public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) { int half = (j - i) / 2; for (int k = 0; k <= half; k++) enumerable.Swap(i + k, j - k); } public static bool isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any(); public static void Times(this int n, Action action) { for (int i = 0; i < n; i++) action(); } public static void Times(this long n, Action action) { for (long i = 0; i < n; i++) action(); } public static IEnumerable<T> Times<T>(this int n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Times<T>(this long n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Iterate<T>(this T init, Func<T, T> f) { yield return init; foreach (var item in Iterate(f(init), f)) yield return item; } public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) { foreach (var v in e) action(v); } public static long Prod(this IEnumerable<long> source) => source.Aggregate(Mul); public static IEnumerable<int> FromTo(int a, int b) => Range(a, Max(b - a + 1, 0)); public static IEnumerable<T> Repeat<T>(T t) { while (true) yield return t; } public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n); public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) { while (true) foreach (var v in e) yield return v; } public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { var result = init; foreach (var item in source) { result = accumulator(result, item); yield return result; } } public static T[] ToArray<T>(params T[] ns) => ns; public static List<T> ToList<T>(params T[] ns) => ns.ToList(); public static Dictionary<T1, T2> ToDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) { var dict = new Dictionary<T1, T2>(); source.ForEach(x => dict.Add(x.Key, x.Value)); return dict; } public static SortedDictionary<T1, T2> ToSortedDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) => new SortedDictionary<T1, T2>(source.ToDictionary()); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) => new MultiSet<T>(source); public static SortedMultiSet<T> ToSortedMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) => new SortedMultiSet<T>(source); public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { yield return init; foreach (var item in Scan(source, init, accumulator)) yield return item; } public static IEnumerable<Tuple<T1, T2>> Cartesian<T1, T2>(IEnumerable<T1> s1, IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select new Tuple<T1, T2>(v1, v2); public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>( IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select new Tuple<T1, T2, T3>(v1, v2, v3); public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3, IEnumerable<T4> s4) => from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4); public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source, int length) { while (source.Any()) { yield return source.Take(length).ToList(); source = source.Skip(length); } } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T max = source.First(); foreach (var item in source) if (selector(item) > selector(max)) max = item; return max; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T min = source.First(); foreach (var item in source) if (selector(item) < selector(min)) min = item; return min; } public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) { for (int i = 0; i < source.Count; i++) if (condition(source[i])) return i; return -1; } public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) => ChunkBy(source, Id, EqualityComparer<T>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector) => ChunkBy(source, selector, EqualityComparer<S>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector, IEqualityComparer<S> comparer) { while (source.Any()) { var v = selector(source.First()); var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList(); yield return l; source = source.Skip(l.Count()); } } } static class Matrix { public static List<List<T>> Transpose<T>(this List<List<T>> source) => Range(0, source[0].Count) .Select(i => source.Select(x => x[i]).ToList()) .ToList(); public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) { foreach (var line in source) line.Show().WriteLine(); } public static List<List<long>> ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList(); public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source, Func<S, T> f) => source.Select(x => x.Select(f).ToList()).ToList(); } static class Cin { private static Queue<string> tokens; static Cin() { string line; tokens = new Queue<string>(); while ((line = Console.ReadLine()) != null) { foreach (var token in line.Split(' ')) { tokens.Enqueue(token); } } } static public int ReadInt() => int.Parse(tokens.Dequeue()); static public List<int> ReadInt(long n) { var list = new List<int>(); n.Times(() => list.Add(ReadInt())); return list; } static public long ReadLong() => long.Parse(tokens.Dequeue()); static public List<long> ReadLong(long n) { var list = new List<long>(); n.Times(() => list.Add(ReadLong())); return list; } static public string ReadString() => tokens.Dequeue(); static public List<string> ReadString(long n) { var list = new List<string>(); n.Times(() => list.Add(ReadString())); return list; } static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine(); static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine(); } public struct VectorInt2 { public int X { get; set; } public int Y { get; set; } public VectorInt2(int x, int y) { X = x; Y = y; } static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X + v2.X, v1.Y + v2.Y); static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X - v2.X, v1.Y - v2.Y); static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X * v2.X, v1.Y *v2.Y); static public VectorInt2 operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i); static public VectorInt2 operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y); static public VectorInt2 operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; } struct VectorDouble2 { public double X { get; set; } public double Y { get; set; } public VectorDouble2(double x, double y) { X = x; Y = y; } static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y); static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i); static public VectorDouble2 operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y); static public VectorDouble2 operator /(VectorDouble2 v1, double i) => new VectorDouble2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; public VectorDouble2 Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian), X *Sin(radian) + Y * Cos(radian)); } public struct LongRange { public long Left; public long Right; public LongRange(long left, long right) { Left = left; Right = right; } } public struct LongFromToVector { public VectorInt2 Start; public VectorInt2 End; public LongFromToVector(VectorInt2 start, VectorInt2 end) { Start = start; End = end; } } } namespace AtCoder { using System.Collections.Generic; using System.Collections; using System.Linq; using System; class MultiSet<T> : ICollection<T> { // TODO: 順番がグチャグチャなので整理する Dictionary<T, long> occurrence; public MultiSet() { occurrence = new Dictionary<T, long>(); } public MultiSet(MultiSet<T> source) : this(source.occurrence) {} public MultiSet(Dictionary<T, long> source) { occurrence = new Dictionary<T, long>(source); Validate(); } public MultiSet(IEnumerable<T> source) { occurrence = new Dictionary<T, long>(); AddRange(source); } public MultiSet(IEnumerable<KeyValuePair<T, long>> source) { occurrence = new Dictionary<T, long>(); foreach (var item in source) this[item.Key] += item.Value; } public void Add(T data) { if (!occurrence.ContainsKey(data)) { occurrence[data] = 1; return; } occurrence[data]++; } public void Clear() => occurrence.Clear(); public void Add(T key, int value) { if (value <= 0) throw new ArgumentException(); if (!occurrence.ContainsKey(key)) { occurrence[key] = value; return; } occurrence[key] += value; } public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value); public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add); public bool Remove(T data) { if (!occurrence.ContainsKey(data)) return false; occurrence[data]--; if (occurrence[data] == 0) occurrence.Remove(data); return true; } // IDictionary public long this[T key] { get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; } set { if (value <= 0) throw new ArgumentException(); occurrence[key] = value; } } public ICollection<T> Keys { get { return occurrence.Keys; } } public ICollection<long> Values { get { return occurrence.Values; } } public IEnumerable<KeyValuePair<T, long>> KeyValuePairs { get { foreach (var pair in occurrence) yield return pair; } } public bool ContainsKey(T key) => occurrence.ContainsKey(key); public bool Contains(T key) => ContainsKey(key); public bool TryGetValue(T key, out long value) { value = this[key]; return true; } // /IDictionary public long LongCount() => occurrence.Values.Sum(); public int Count => (int)occurrence.Values.Sum(); public bool IsReadOnly => false; public void CopyTo(T[] array, int index) { foreach (var pair in occurrence) { for (int i = 0; i < pair.Value; i++) { array[index] = pair.Key; index++; } } } public IEnumerator<T> GetEnumerator() { foreach (var pair in occurrence) for (int i = 0; i < pair.Value; i++) yield return pair.Key; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); public void Validate() { if (occurrence.Values.Any(x => x <= 0)) throw new ArgumentException(); } } class SortedMultiSet<T> : ICollection<T> { // TODO: 順番がグチャグチャなので整理する SortedDictionary<T, long> occurrence; public SortedMultiSet() { occurrence = new SortedDictionary<T, long>(); } public SortedMultiSet(SortedMultiSet<T> source) : this(source.occurrence) {} public SortedMultiSet(SortedDictionary<T, long> source) { occurrence = new SortedDictionary<T, long>(source); Validate(); } public SortedMultiSet(IEnumerable<T> source) { occurrence = new SortedDictionary<T, long>(); AddRange(source); } public SortedMultiSet(IEnumerable<KeyValuePair<T, long>> source) { occurrence = new SortedDictionary<T, long>(); foreach (var item in source) this[item.Key] += item.Value; } public void Add(T data) { if (!occurrence.ContainsKey(data)) { occurrence[data] = 1; return; } occurrence[data]++; } public void Clear() => occurrence.Clear(); public void Add(T key, int value) { if (value <= 0) throw new ArgumentException(); if (!occurrence.ContainsKey(key)) { occurrence[key] = value; return; } occurrence[key] += value; } public long LongCount() => occurrence.Values.Sum(); public int Count => (int)occurrence.Values.Sum(); public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value); public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add); public bool Remove(T data) { if (!occurrence.ContainsKey(data)) return false; occurrence[data]--; if (occurrence[data] == 0) occurrence.Remove(data); return true; } // IDictionary public long this[T key] { get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; } set { if (value <= 0) throw new ArgumentException(); occurrence[key] = value; } } public ICollection<T> Keys => occurrence.Keys; public ICollection<long> Values => occurrence.Values; public bool ContainsKey(T key) => occurrence.ContainsKey(key); public bool Contains(T key) => ContainsKey(key); public bool TryGetValue(T key, out long value) { value = this[key]; return true; } // /IDictionary public bool IsReadOnly => false; public void CopyTo(T[] array, int index) { foreach (var pair in occurrence) { for (int i = 0; i < pair.Value; i++) { array[index] = pair.Key; index++; } } } public IEnumerator<T> GetEnumerator() { foreach (var pair in occurrence) for (int i = 0; i < pair.Value; i++) yield return pair.Key; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); public void Validate() { if (occurrence.Values.Any(x => x <= 0)) throw new ArgumentException(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // using static System.Linq.Enumerable; using static System.Console; using static AtCoder.Util; using static AtCoder.Cin; using static System.Math; using static AtCoder.MyMath; using static AtCoder.StreamExtensions; using static AtCoder.Matrix; namespace AtCoder { using VI = VectorInt2; static class Program { static void Main() { var n = ReadInt(); var inputs = n.Times(() => new { X = ReadInt(), Y = ReadInt(), H = ReadLong() }) .ToList(); foreach (var cx in FromTo(0, 100)) foreach (var cy in FromTo(0, 100)) { //最初の標高が0の可能性があるので注意!頂点高を求める参考にならない! var refPoint = inputs.First(x => x.H > 0); var ch = refPoint.H + Abs(cx - refPoint.X) + Abs(cy - refPoint.Y); if (inputs.All(data => calcHeight(cx, cy, ch, data.X, data.Y) == data.H)) { $"{cx} {cy} {ch}".WriteLine(); return; } } throw new InvalidOperationException(); } static long calcHeight(int cx, int cy, long ch, int x, int y) { return Max(ch - Abs(x - cx) - Abs(y - cy), 0); } } } /* ***************** Following Contents are my common library ******** */ namespace AtCoder { static class Algorithm { public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, long width) => BinSearch(range, isBigger, x => range.Right - range.Left < width); public static LongRange BinSearch(LongRange range, Func<long, bool> isBigger, Func<LongRange, bool> stopCondition) { if (stopCondition(range)) return range; var middle = range.Left + (range.Right - range.Left) / 2; return isBigger(middle) ? BinSearch(new LongRange(range.Left, middle), isBigger, stopCondition) : BinSearch(new LongRange(middle, range.Right), isBigger, stopCondition); } } static class MyMath { public static int DivRoundUp(int a, int b) { var q = a / b; if (a % b != 0) q++; return q; } public static long GCD(long a, long b) => a<b? GCD(b, a) : b> 0 ? GCD(b, a % b) : a; public static long GCD(this IEnumerable<long> source) => source.Aggregate(GCD); public static long LCM(long a, long b) { var g = GCD(a, b); var a1 = a / g; var b1 = b / g; return g * a1 * b1; } public static long LCM(this IEnumerable<long> source) => source.Aggregate(LCM); public static long Factorial(this long n) => Range(1, n).Aggregate(1L, Mul); public static long nPr(int n, int r) => r < 0 || r > n? 0 : FromTo(n - r + 1, n) .Select(x => (long)x) .Aggregate(1L, Mul); public static long nCr(int n, int r) => nPr(n, r) / Factorial(r); public static long Inc(long i) => i + 1; public static long Dec(long i) => i - 1; public static long Plus(long i, long j) => i + j; public static Func<long, long> Plus(long j) => i => i + j; public static long Minus(long i, long j) => i - j; public static Func<long, long> Minus(long j) => i => i - j; public static long Mul(long i, long j) => i * j; public static Func<long, long> Mul(long j) => i => i * j; public static long Div(long i, long j) => j / j; public static Func<long, long> Div(long j) => i => i * j; public static long Mod(long i, long j) => i % j; public static Func<long, long> Mod(long j) => i => i % j; public static Func<long, bool> Leq(long j) => i => i <= j; public static Func<long, bool> Gt(long j) => i => i > j; public static Func<long, bool> Geq(long j) => i => i >= j; public static Func<long, bool> Eq(long j) => i => i == j; public static Func<long, bool> Neq(long j) => i => i != j; public static int Plus(int i, int j) => i + j; public static Func<int, int> Plus(int j) => i => i + j; public static int Minus(int i, int j) => i - j; public static Func<int, int> Minus(int j) => i => i - j; public static int Mul(int i, int j) => i * j; public static Func<int, int> Mul(int j) => i => i * j; public static int Div(int i, int j) => j / j; public static Func<int, int> Div(int j) => i => i * j; public static int Mod(int i, int j) => i % j; public static Func<int, int> Mod(int j) => i => i % j; public static Func<int, bool> Lt(int j) => i => i < j; public static Func<int, bool> Leq(int j) => i => i <= j; public static Func<int, bool> Gt(int j) => i => i > j; public static Func<int, bool> Geq(int j) => i => i >= j; public static Func<int, bool> Eq(int j) => i => i == j; public static Func<int, bool> Neq(int j) => i => i != j; public static long Max(params long[] ns) => ns.Max(); public static long LowerBound(this long m, long lbound) => Max(m, lbound); public static long UpperBound(this long m, long ubound) => Min(m, ubound); public static long Bound(this long m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static long LowerBound(this int m, long lbound) => Max(m, lbound); public static long UpperBound(this int m, long ubound) => Min(m, ubound); public static long Bound(this int m, long lowerBound, long UpperBound) => m.LowerBound(lowerBound).UpperBound(UpperBound); public static bool InRange(this long x, long min, long max) => min <= x && x <= max; public static bool IsEven(this int x) => x % 2 == 0; public static bool IsOdd(this int x) => x % 2 != 0; public static bool IsEven(this long x) => x % 2 == 0; public static bool IsOdd(this long x) => x % 2 != 0; public static IEnumerable<int> ToDigits(this long n) => n.ToString().Select(x => x.ToInt()); public static IEnumerable<int> ToDigits(this int n) => ((long)n).ToDigits(); public static IEnumerable<int> Factors(this int n) { for (int i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static IEnumerable<long> Factors(this long n) { for (long i = 1; i <= n; i++) if (n % i == 0) yield return i; } public static MultiSet<long> Factorize(this long n) { var factors = new MultiSet<long>(); for (long i = 2; i * i <= n; i++) { while (n % i == 0) { n /= i; factors[i]++; } } if (n > 1) factors.Add(n); return factors; } public static IEnumerable<int> Natural() { for (int i = 0;; i++) yield return i; } public static IEnumerable<int> Positive() => Natural().Skip(1); public static long Pow(this long i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static long Pow(this int i, long exp) => (exp == 0) ? 1 : i * Pow(i, exp - 1); public static int IntLog(this long n, long baseNum) { int count = 0; while (n >= baseNum) { n /= baseNum; count++; } return count; } } static class Util { public static InvalidOperationException UnreachableException = new InvalidOperationException("unreachable."); public static string Show(this IEnumerable<char> source) => new string(source.ToArray()); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source) => new HashSet<T>(source); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<T> t) => new MultiSet<T>(t); public static bool IsPalindrome(string s) { for (int i = 0; i < s.Length / 2; i++) { if (s[i] != s[s.Length - 1 - i]) return false; } return true; } public readonly static VectorInt2[] Dir8 = { new VectorInt2(-1, -1), new VectorInt2(-1, 0), new VectorInt2(-1, 1), new VectorInt2(0, -1), new VectorInt2(0, 1), new VectorInt2(1, -1), new VectorInt2(1, 0), new VectorInt2(1, 1) }; public const long MODCONST = 1000000007; public static T debug<T>(this T value) { Console.Error.WriteLine($"debug:{value}"); return value; } public static T Id<T>(T t) => t; public static long ToLong(this String s) => long.Parse(s); public static long ToLong(this char c) => c - '0'; public static int ToInt(this String s) => int.Parse(s); public static int ToInt(this char c) => c - '0'; public static VectorInt2 ReadVectorInt2() => new VectorInt2(ReadInt(), ReadInt()); public static VectorDouble2 ReadVectorDouble2() => new VectorDouble2(ReadInt(), ReadInt()); public static string ReplaceX(this string input, string pattern, string replace) => Regex.Replace(input, pattern, replace); public static IEnumerable<int> Range(int i, int j) => Enumerable.Range(i, j); public static IEnumerable<long> Range(long i, long j) { for (long k = i; k < i + j; k++) yield return k; } public static void Swap<T>(this IList<T> enumerable, int i, int j) { var buf = enumerable[i]; enumerable[i] = enumerable[j]; enumerable[j] = buf; } public static bool In<T>(this T t, IEnumerable<T> range) => range.Contains(t); } static class ParametricExtensions { public static Func<S, U> Then<S, T, U>(this Func<S, T> f, Func<T, U> g) => x => g(f(x)); public static Func<S, U> Compose<S, T, U>(this Func<T, U> f, Func<S, T> g) => x => f(g(x)); public static void Call<T>(this T t, Action<T> action) => action(t); public static void WriteLine<T>(this T t) => Console.WriteLine(t); public static void Write<T>(this T t) => Console.Write(t); public static T Call<S, T>(this S s, Func<S, T> func) => func(s); public static S Call<S>(this S s, Func<S, S> func, int times) => times == 0 ? s : Call(func(s), func, times - 1); } static class StreamExtensions { public static void ReverseRange<T>(this IList<T> enumerable, int i, int j) { int half = (j - i) / 2; for (int k = 0; k <= half; k++) enumerable.Swap(i + k, j - k); } public static bool isEmpty<T>(this IEnumerable<T> enumerable) => !enumerable.Any(); public static void Times(this int n, Action action) { for (int i = 0; i < n; i++) action(); } public static void Times(this long n, Action action) { for (long i = 0; i < n; i++) action(); } public static IEnumerable<T> Times<T>(this int n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Times<T>(this long n, Func<T> func) { for (long i = 0; i < n; i++) yield return func(); } public static IEnumerable<T> Iterate<T>(this T init, Func<T, T> f) { yield return init; foreach (var item in Iterate(f(init), f)) yield return item; } public static void ForEach<T>(this IEnumerable<T> e, Action<T> action) { foreach (var v in e) action(v); } public static long Prod(this IEnumerable<long> source) => source.Aggregate(Mul); public static IEnumerable<int> FromTo(int a, int b) => Range(a, Max(b - a + 1, 0)); public static IEnumerable<T> Repeat<T>(T t) { while (true) yield return t; } public static IEnumerable<T> Replicate<T>(int n, T t) => Repeat(t).Take(n); public static IEnumerable<T> Cycle<T>(this IEnumerable<T> e) { while (true) foreach (var v in e) yield return v; } public static IEnumerable<T> Scan<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { var result = init; foreach (var item in source) { result = accumulator(result, item); yield return result; } } public static T[] ToArray<T>(params T[] ns) => ns; public static List<T> ToList<T>(params T[] ns) => ns.ToList(); public static Dictionary<T1, T2> ToDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) { var dict = new Dictionary<T1, T2>(); source.ForEach(x => dict.Add(x.Key, x.Value)); return dict; } public static SortedDictionary<T1, T2> ToSortedDictionary<T1, T2>(this IEnumerable<KeyValuePair<T1, T2>> source) => new SortedDictionary<T1, T2>(source.ToDictionary()); public static MultiSet<T> ToMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) => new MultiSet<T>(source); public static SortedMultiSet<T> ToSortedMultiSet<T>(this IEnumerable<KeyValuePair<T, long>> source) => new SortedMultiSet<T>(source); public static IEnumerable<T> Scan0<S, T>(this IEnumerable<S> source, T init, Func<T, S, T> accumulator) { yield return init; foreach (var item in Scan(source, init, accumulator)) yield return item; } public static IEnumerable<Tuple<T1, T2>> Cartesian<T1, T2>(IEnumerable<T1> s1, IEnumerable<T2> s2) => from v1 in s1 from v2 in s2 select new Tuple<T1, T2>(v1, v2); public static IEnumerable<Tuple<T1, T2, T3>> Cartesian<T1, T2, T3>( IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3) => from v1 in s1 from v2 in s2 from v3 in s3 select new Tuple<T1, T2, T3>(v1, v2, v3); public static IEnumerable<Tuple<T1, T2, T3, T4>> Cartesian<T1, T2, T3, T4>(IEnumerable<T1> s1, IEnumerable<T2> s2, IEnumerable<T3> s3, IEnumerable<T4> s4) => from v1 in s1 from v2 in s2 from v3 in s3 from v4 in s4 select new Tuple<T1, T2, T3, T4>(v1, v2, v3, v4); public static IEnumerable<List<T>> Buffer<T>(this IEnumerable<T> source, int length) { while (source.Any()) { yield return source.Take(length).ToList(); source = source.Skip(length); } } public static T MaxBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T max = source.First(); foreach (var item in source) if (selector(item) > selector(max)) max = item; return max; } public static T MinBy<T>(this IEnumerable<T> source, Func<T, long> selector) { T min = source.First(); foreach (var item in source) if (selector(item) < selector(min)) min = item; return min; } public static int IndexOf<T>(this IList<T> source, Func<T, bool> condition) { for (int i = 0; i < source.Count; i++) if (condition(source[i])) return i; return -1; } public static IEnumerable<List<T>> ChunkBy<T>(this IEnumerable<T> source) => ChunkBy(source, Id, EqualityComparer<T>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector) => ChunkBy(source, selector, EqualityComparer<S>.Default); public static IEnumerable<List<T>> ChunkBy<S, T>(this IEnumerable<T> source, Func<T, S> selector, IEqualityComparer<S> comparer) { while (source.Any()) { var v = selector(source.First()); var l = source.TakeWhile(x => comparer.Equals(selector(x), v)).ToList(); yield return l; source = source.Skip(l.Count()); } } } static class Matrix { public static List<List<T>> Transpose<T>(this List<List<T>> source) => Range(0, source[0].Count) .Select(i => source.Select(x => x[i]).ToList()) .ToList(); public static void WriteMatrix(this IEnumerable<IEnumerable<char>> source) { foreach (var line in source) line.Show().WriteLine(); } public static List<List<long>> ReadLongMatrix(int h, int w) => h.Times(() => ReadLong(w)).ToList(); public static List<List<T>> SelectMatrix<S, T>(this List<List<S>> source, Func<S, T> f) => source.Select(x => x.Select(f).ToList()).ToList(); } static class Cin { private static Queue<string> tokens; static Cin() { string line; tokens = new Queue<string>(); while ((line = Console.ReadLine()) != null) { foreach (var token in line.Split(' ')) { tokens.Enqueue(token); } } } static public int ReadInt() => int.Parse(tokens.Dequeue()); static public List<int> ReadInt(long n) { var list = new List<int>(); n.Times(() => list.Add(ReadInt())); return list; } static public long ReadLong() => long.Parse(tokens.Dequeue()); static public List<long> ReadLong(long n) { var list = new List<long>(); n.Times(() => list.Add(ReadLong())); return list; } static public string ReadString() => tokens.Dequeue(); static public List<string> ReadString(long n) { var list = new List<string>(); n.Times(() => list.Add(ReadString())); return list; } static public void SayYesNo(this bool b) => (b ? "Yes" : "No").WriteLine(); static public void SayYESNO(this bool b) => (b ? "YES" : "NO").WriteLine(); } public struct VectorInt2 { public int X { get; set; } public int Y { get; set; } public VectorInt2(int x, int y) { X = x; Y = y; } static public VectorInt2 operator +(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X + v2.X, v1.Y + v2.Y); static public VectorInt2 operator -(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X - v2.X, v1.Y - v2.Y); static public VectorInt2 operator *(VectorInt2 v1, VectorInt2 v2) => new VectorInt2(v1.X * v2.X, v1.Y *v2.Y); static public VectorInt2 operator *(VectorInt2 v1, int i) => new VectorInt2(v1.X * i, v1.Y *i); static public VectorInt2 operator *(int i, VectorInt2 v2) => new VectorInt2(i * v2.X, i *v2.Y); static public VectorInt2 operator /(VectorInt2 v1, int i) => new VectorInt2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; } struct VectorDouble2 { public double X { get; set; } public double Y { get; set; } public VectorDouble2(double x, double y) { X = x; Y = y; } static public VectorDouble2 operator +(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X + v2.X, v1.Y + v2.Y); static public VectorDouble2 operator -(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X - v2.X, v1.Y - v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, VectorDouble2 v2) => new VectorDouble2(v1.X * v2.X, v1.Y *v2.Y); static public VectorDouble2 operator *(VectorDouble2 v1, int i) => new VectorDouble2(v1.X * i, v1.Y *i); static public VectorDouble2 operator *(int i, VectorDouble2 v2) => new VectorDouble2(i * v2.X, i *v2.Y); static public VectorDouble2 operator /(VectorDouble2 v1, double i) => new VectorDouble2(v1.X / i, v1.Y / i); public override string ToString() => $"({X}, {Y})"; public VectorDouble2 Turn(double radian) => new VectorDouble2(X * Cos(radian) - Y * Sin(radian), X *Sin(radian) + Y * Cos(radian)); } public struct LongRange { public long Left; public long Right; public LongRange(long left, long right) { Left = left; Right = right; } } public struct LongFromToVector { public VectorInt2 Start; public VectorInt2 End; public LongFromToVector(VectorInt2 start, VectorInt2 end) { Start = start; End = end; } } } namespace AtCoder { using System.Collections.Generic; using System.Collections; using System.Linq; using System; class MultiSet<T> : ICollection<T> { // TODO: 順番がグチャグチャなので整理する Dictionary<T, long> occurrence; public MultiSet() { occurrence = new Dictionary<T, long>(); } public MultiSet(MultiSet<T> source) : this(source.occurrence) {} public MultiSet(Dictionary<T, long> source) { occurrence = new Dictionary<T, long>(source); Validate(); } public MultiSet(IEnumerable<T> source) { occurrence = new Dictionary<T, long>(); AddRange(source); } public MultiSet(IEnumerable<KeyValuePair<T, long>> source) { occurrence = new Dictionary<T, long>(); foreach (var item in source) this[item.Key] += item.Value; } public void Add(T data) { if (!occurrence.ContainsKey(data)) { occurrence[data] = 1; return; } occurrence[data]++; } public void Clear() => occurrence.Clear(); public void Add(T key, int value) { if (value <= 0) throw new ArgumentException(); if (!occurrence.ContainsKey(key)) { occurrence[key] = value; return; } occurrence[key] += value; } public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value); public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add); public bool Remove(T data) { if (!occurrence.ContainsKey(data)) return false; occurrence[data]--; if (occurrence[data] == 0) occurrence.Remove(data); return true; } // IDictionary public long this[T key] { get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; } set { if (value <= 0) throw new ArgumentException(); occurrence[key] = value; } } public ICollection<T> Keys { get { return occurrence.Keys; } } public ICollection<long> Values { get { return occurrence.Values; } } public IEnumerable<KeyValuePair<T, long>> KeyValuePairs { get { foreach (var pair in occurrence) yield return pair; } } public bool ContainsKey(T key) => occurrence.ContainsKey(key); public bool Contains(T key) => ContainsKey(key); public bool TryGetValue(T key, out long value) { value = this[key]; return true; } // /IDictionary public long LongCount() => occurrence.Values.Sum(); public int Count => (int)occurrence.Values.Sum(); public bool IsReadOnly => false; public void CopyTo(T[] array, int index) { foreach (var pair in occurrence) { for (int i = 0; i < pair.Value; i++) { array[index] = pair.Key; index++; } } } public IEnumerator<T> GetEnumerator() { foreach (var pair in occurrence) for (int i = 0; i < pair.Value; i++) yield return pair.Key; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); public void Validate() { if (occurrence.Values.Any(x => x <= 0)) throw new ArgumentException(); } } class SortedMultiSet<T> : ICollection<T> { // TODO: 順番がグチャグチャなので整理する SortedDictionary<T, long> occurrence; public SortedMultiSet() { occurrence = new SortedDictionary<T, long>(); } public SortedMultiSet(SortedMultiSet<T> source) : this(source.occurrence) {} public SortedMultiSet(SortedDictionary<T, long> source) { occurrence = new SortedDictionary<T, long>(source); Validate(); } public SortedMultiSet(IEnumerable<T> source) { occurrence = new SortedDictionary<T, long>(); AddRange(source); } public SortedMultiSet(IEnumerable<KeyValuePair<T, long>> source) { occurrence = new SortedDictionary<T, long>(); foreach (var item in source) this[item.Key] += item.Value; } public void Add(T data) { if (!occurrence.ContainsKey(data)) { occurrence[data] = 1; return; } occurrence[data]++; } public void Clear() => occurrence.Clear(); public void Add(T key, int value) { if (value <= 0) throw new ArgumentException(); if (!occurrence.ContainsKey(key)) { occurrence[key] = value; return; } occurrence[key] += value; } public long LongCount() => occurrence.Values.Sum(); public int Count => (int)occurrence.Values.Sum(); public void Add(KeyValuePair<T, int> pair) => Add(pair.Key, pair.Value); public void AddRange(IEnumerable<T> source) => source.ToList().ForEach(Add); public bool Remove(T data) { if (!occurrence.ContainsKey(data)) return false; occurrence[data]--; if (occurrence[data] == 0) occurrence.Remove(data); return true; } // IDictionary public long this[T key] { get { return occurrence.ContainsKey(key) ? occurrence[key] : 0; } set { if (value <= 0) throw new ArgumentException(); occurrence[key] = value; } } public ICollection<T> Keys => occurrence.Keys; public ICollection<long> Values => occurrence.Values; public bool ContainsKey(T key) => occurrence.ContainsKey(key); public bool Contains(T key) => ContainsKey(key); public bool TryGetValue(T key, out long value) { value = this[key]; return true; } // /IDictionary public bool IsReadOnly => false; public void CopyTo(T[] array, int index) { foreach (var pair in occurrence) { for (int i = 0; i < pair.Value; i++) { array[index] = pair.Key; index++; } } } public IEnumerator<T> GetEnumerator() { foreach (var pair in occurrence) for (int i = 0; i < pair.Value; i++) yield return pair.Key; } IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); public void Validate() { if (occurrence.Values.Any(x => x <= 0)) throw new ArgumentException(); } } }
[["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
8
6,570
2
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; // using System.Numerics; using static System.Math; using static System.Console; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var X = new int[n]; var Y = new int[n]; var K = new long[n]; for (int i = 0; i < n; i++) { X[i] = ri; Y[i] = ri; K[i] = rl; } for (int u = 0; u <= 100; u++) for (int v = 0; v <= 100; v++) { long hmax = -1; for (int i = 0; i < n; i++) { hmax = Max(hmax, Abs(X[i] - u) + Abs(Y[i] - v) + K[i]); } var ok = true; for (int i = 0; i < n; i++) { ok &= Max(hmax - Abs(X[i] - u) - Abs(Y[i] - v), 0) == K[i]; } if (ok) { Console.WriteLine($"{u} {v} {hmax}"); return; } } } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<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; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; 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) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; // using System.Numerics; using static System.Math; using static System.Console; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var X = new int[n]; var Y = new int[n]; var K = new long[n]; for (int i = 0; i < n; i++) { X[i] = ri; Y[i] = ri; K[i] = rl; } for (int u = 0; u <= 100; u++) for (int v = 0; v <= 100; v++) { long hmax = long.MaxValue; for (int i = 0; i < n; i++) { hmax = Min(hmax, Abs(X[i] - u) + Abs(Y[i] - v) + K[i]); } var ok = true; for (int i = 0; i < n; i++) { ok &= Max(hmax - Abs(X[i] - u) - Abs(Y[i] - v), 0) == K[i]; } if (ok) { Console.WriteLine($"{u} {v} {hmax}"); return; } } } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<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; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; 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) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
[["-", 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, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22]]
8
1,061
7
using System; namespace AtCoder { public class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x1 = new int[100]; int[] y1 = new int[100]; int[] h1 = new int[100]; int n1 = 0; int[] x0 = new int[100]; int[] y0 = new int[100]; int n0 = 0; for (int i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(); int x = int.Parse(s[0]); int y = int.Parse(s[1]); int h = int.Parse(s[2]); if (h > 0) { x1[n1] = x; y1[n1] = y; h1[n1] = h; n1++; } else { x0[n0] = x; y0[n0] = y; n0++; } } if (n1 == 1) { Console.WriteLine(string.Format("{0} {1} {2}", x1[0], y1[0], h1[0])); return; } for (int Cy = 0; Cy <= 100; Cy++) { for (int Cx = 0; Cx <= 100; Cx++) { bool f = true; int Ch = 0; Ch = h1[0] + Math.Abs(x1[0] - Cx) + Math.Abs(y1[0] - Cy); for (int i = 1; i < n1; i++) { if (Ch != h1[i] + Math.Abs(x1[i] - Cx) + Math.Abs(y1[i] - Cy)) { f = false; break; } } if (f) { for (int i = 0; i < n0; i++) { if (Ch - Math.Abs(x0[i] - Cx) - Math.Abs(y0[i] - Cy) > 0) { f = false; break; } if (f) { Console.WriteLine(string.Format("{0} {1} {2}", Cx, Cy, Ch)); return; } } } } } } } }
using System; namespace AtCoder { public class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x1 = new int[100]; int[] y1 = new int[100]; int[] h1 = new int[100]; int n1 = 0; int[] x0 = new int[100]; int[] y0 = new int[100]; int n0 = 0; for (int i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(); int x = int.Parse(s[0]); int y = int.Parse(s[1]); int h = int.Parse(s[2]); if (h > 0) { x1[n1] = x; y1[n1] = y; h1[n1] = h; n1++; } else { x0[n0] = x; y0[n0] = y; n0++; } } if (n1 == 1) { Console.WriteLine(string.Format("{0} {1} {2}", x1[0], y1[0], h1[0])); return; } for (int Cy = 0; Cy <= 100; Cy++) { for (int Cx = 0; Cx <= 100; Cx++) { bool f = true; int Ch = 0; Ch = h1[0] + Math.Abs(x1[0] - Cx) + Math.Abs(y1[0] - Cy); for (int i = 1; i < n1; i++) { if (Ch != h1[i] + Math.Abs(x1[i] - Cx) + Math.Abs(y1[i] - Cy)) { f = false; break; } } if (f) { for (int i = 0; i < n0; i++) { if (Ch - Math.Abs(x0[i] - Cx) - Math.Abs(y0[i] - Cy) > 0) { f = false; break; } } if (f) { Console.WriteLine(string.Format("{0} {1} {2}", Cx, Cy, Ch)); return; } } } } } } }
[["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
481
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; // https://beta.atcoder.jp/contests/abc112/tasks/abc112_c public class Program_ABC112_C // ←Class名変更!! { public static void Main(string[] args) { var n = int.Parse(ReadLine()); var points = new int [n][]; for (int i = 0; i < n; i++) { points[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse); } Array.Sort( points, (a, b) => b[2].CompareTo( a[2])); //高い順にソート //先頭が高さゼロだとh1が正しい値にならないのでソートする。 var crest = new int[3] { -1, -1, -1 }; for (var x = 0; x < 101; x++) { var xConst = points[0][2] + Abs(x - points[0][0]); for (var y = 0; y < 101; y++) { var h1 = xConst + Abs(y - points[0][1]); var isCrest = true; for (int i = 1; i < n; i++) { var h2 = points[i][2] + Abs(x - points[i][0]) + Abs(y - points[i][1]); if (0 < points[i][2]) { //座標に高さがあるということは、ピラミッドの一部なので、h1=h2が成り立つ if (h1 != h2) { isCrest = false; break; } } else { //座標の高さが0の場合、ピラミッドの底辺もしくは、ピラミッドの高さとは関係ない座標の2つが考えられる。 //ピラミッドの底辺の場合h1=h2となり、無関係な座標で頂点を計算すると、h2<h1となる。 //頂点を求めるのに十分な調査が行われたことは書いてあるが、余計な調査が行われていないとは書いてない if (h1 < h2) { isCrest = false; break; } } } if (isCrest) { crest = new[] { x, y, h1 }; Console.WriteLine($"{x} {y} {h1}"); return; // break; } } } // Console.WriteLine($"{crest[0]} {crest[1]} {crest[2]}"); } // Main } // Class
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; // https://beta.atcoder.jp/contests/abc112/tasks/abc112_c public class Program_ABC112_C // ←Class名変更!! { public static void Main(string[] args) { var n = int.Parse(ReadLine()); var points = new int [n][]; for (int i = 0; i < n; i++) { points[i] = Array.ConvertAll(ReadLine().Split(' '), int.Parse); } Array.Sort( points, (a, b) => b[2].CompareTo( a[2])); //高い順にソート //先頭が高さゼロだとh1が正しい値にならないのでソートする。 var crest = new int[3] { -1, -1, -1 }; for (var x = 0; x < 101; x++) { var xConst = points[0][2] + Abs(x - points[0][0]); for (var y = 0; y < 101; y++) { var h1 = xConst + Abs(y - points[0][1]); var isCrest = true; for (int i = 1; i < n; i++) { var h2 = points[i][2] + Abs(x - points[i][0]) + Abs(y - points[i][1]); if (0 < points[i][2]) { //座標に高さがあるということは、ピラミッドの一部なので、h1=h2が成り立つ if (h1 != h2) { isCrest = false; break; } } else { //座標の高さが0の場合、ピラミッドの底辺もしくは、ピラミッドの高さとは関係ない座標の2つが考えられる。 //ピラミッドの底辺の場合h1=h2となり、無関係な座標で頂点を計算すると、h2<h1となる。 //頂点を求めるのに十分な調査が行われたことは書いてあるが、余計な調査が行われていないとは書いてない // if (h1 < h2) if (h2 < h1) { isCrest = false; break; } } } if (isCrest) { crest = new[] { x, y, h1 }; Console.WriteLine($"{x} {y} {h1}"); return; // break; } } } // Console.WriteLine($"{crest[0]} {crest[1]} {crest[2]}"); } // Main } // Class
[["-", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 22]]
8
382
4
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int[] x = new int[N]; int[] y = new int[N]; int[] h = new int[N]; for (int i = 0; i < N; i++) { x[i] = cin.nextInt(); y[i] = cin.nextInt(); h[i] = cin.nextInt(); } for (int Y = 0; Y < 101; Y++) { for (int X = 0; X < 101; X++) { int needH = -1; for (int i = 0; i < N; i++) { if (h[i] == 0) continue; int dist = Math.Abs(Y - y[i]) + Math.Abs(X - x[i]); int tmp = Math.Abs(h[i] + dist); if (needH == -1) needH = tmp; else if (needH != tmp) { needH = -2; break; } } for (int i = 0; i < N; i++) { if (h[i] != 0) continue; int dist = Math.Abs(Y - y[i]) + Math.Abs(X - x[i]); if (needH > dist) { needH = -2; break; } } if (needH > 0) { Console.WriteLine("{0} {1} {2}", Y, X, needH); } } } } } 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; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int N = cin.nextInt(); int[] x = new int[N]; int[] y = new int[N]; int[] h = new int[N]; for (int i = 0; i < N; i++) { x[i] = cin.nextInt(); y[i] = cin.nextInt(); h[i] = cin.nextInt(); } for (int Y = 0; Y < 101; Y++) { for (int X = 0; X < 101; X++) { int needH = -1; for (int i = 0; i < N; i++) { if (h[i] == 0) continue; int dist = Math.Abs(Y - y[i]) + Math.Abs(X - x[i]); int tmp = Math.Abs(h[i] + dist); if (needH == -1) needH = tmp; else if (needH != tmp) { needH = -2; break; } } for (int i = 0; i < N; i++) { if (h[i] != 0) continue; int dist = Math.Abs(Y - y[i]) + Math.Abs(X - x[i]); if (needH > dist) { needH = -2; break; } } if (needH > 0) { Console.WriteLine("{0} {1} {2}", X, Y, needH); } } } } } 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, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
1,038
4
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System.Linq; using System.Diagnostics; using System.Globalization; using static System.Console; using static System.Math; namespace abc112_c { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var x = new int[n]; var y = new int[n]; var h = new int[n]; for (int i = 0; i < n; i++) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); x[i] = input[0]; y[i] = input[1]; h[i] = input[2]; } Tuple<int, int, int> sample = new Tuple<int, int, int>(0, 0, 0); for (int i = 0; i < n; i++) { if (h[i] != 0) { sample = new Tuple<int, int, int>(x[i], y[i], h[i]); } } for (int j = 0; j <= 100; j++) { for (int k = 0; k <= 100; k++) { int tmp = sample.Item1 + Abs(sample.Item2 - j) + Abs(sample.Item3 - k); bool judge = true; for (int i = 0; i < n; i++) { if (h[i] != Max(tmp - Abs(x[i] - j) - Abs(y[i] - k), 0)) { judge = false; } } if (judge) { WriteLine($"{j} {k} {tmp}"); return; } } } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; using System.Linq; using System.Diagnostics; using System.Globalization; using static System.Console; using static System.Math; namespace abc112_c { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var x = new int[n]; var y = new int[n]; var h = new int[n]; for (int i = 0; i < n; i++) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); x[i] = input[0]; y[i] = input[1]; h[i] = input[2]; } Tuple<int, int, int> sample = new Tuple<int, int, int>(0, 0, 0); for (int i = 0; i < n; i++) { if (h[i] != 0) { sample = new Tuple<int, int, int>(x[i], y[i], h[i]); break; } } for (int j = 0; j <= 100; j++) { for (int k = 0; k <= 100; k++) { int tmp = sample.Item3 + Abs(sample.Item1 - j) + Abs(sample.Item2 - k); bool judge = true; for (int i = 0; i < n; i++) { if (h[i] != Max(tmp - Abs(x[i] - j) - Abs(y[i] - k), 0)) { judge = false; } } if (judge) { WriteLine($"{j} {k} {tmp}"); return; } } } } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 212, 0, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 16, 31, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22]]
8
407
8
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using System.IO; using System.Numerics; using static System.Console; using static System.Math; namespace AtCoder { public class Program { const bool IsTest = false; const string t1 = "4\n2 3 5\n2 1 5\n1 2 5\n3 2 5"; const string t2 = "2\n0 0 100\n1 1 98"; const string t3 = "3\n99 1 191\n100 1 192\n99 0 192"; public static void Main(string[] args) { if (!IsTest) { new Program().Solve(new ConsoleInput(Console.In)); } else { new Program().Solve(new ConsoleInput(new StringReader(t1))); new Program().Solve(new ConsoleInput(new StringReader(t2))); new Program().Solve(new ConsoleInput(new StringReader(t3))); } } public void Solve(ConsoleInput cin) { var n = cin.ReadLineAs<int>(); var N = n.Item1; var x = new int[N]; var y = new int[N]; var h = new long[N]; for (var i = 0; i < N; i++) { var xyh = cin.ReadLineAs<int, int, long>(); x[i] = xyh.Item1; y[i] = xyh.Item2; h[i] = xyh.Item3; } // たった100*100*100 なので全部ためす for (var cx = 0; cx <= 100; cx++) { for (var cy = 0; cy <= 100; cy++) { long H = -1; var found = true; long hMax = 1000000001L; for (var i = 0; i < N; i++) { var mh = Math.Abs(cx - x[i]) + Math.Abs(cy - y[i]); if (h[i] == 0) { if (mh < hMax) { hMax = mh; if (H != -1 && H > hMax) { found = false; break; } } continue; } var H2 = mh + h[i]; if (H == -1) { H = H2; if (H > hMax) { found = false; break; } } else if (H != H2) { found = false; break; } } if (found == true) { Console.WriteLine(string.Format("{0} {1} {2}", cx, cy, H)); return; } } } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private readonly char _separator = ' '; private string _curLine; private string[] _curLineSplitted; private int _curItemIndex; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; } public T Read<T>() { var converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(T)); if (converter == null) { throw new Exception( string.Format("TypeDescriptor.GetConverter {0}", typeof(T).Name)); } return (T)converter.ConvertFromString(ReadString()); } public T[] ReadArray<T>(long N) { var ret = new T[N]; for (long i = 0; i < N; i++) { ret[i] = Read<T>(); } return ret; } public Tuple<T> ReadLineAs<T>() { ReadLine(); return new Tuple<T>(Read<T>()); } public Tuple<T, S> ReadLineAs<T, S>() { ReadLine(); return new Tuple<T, S>(Read<T>(), Read<S>()); } public Tuple<T, S, U> ReadLineAs<T, S, U>() { ReadLine(); return new Tuple<T, S, U>(Read<T>(), Read<S>(), Read<U>()); } public Tuple<T, S, U, V> ReadLineAs<T, S, U, V>() { ReadLine(); return new Tuple<T, S, U, V>(Read<T>(), Read<S>(), Read<U>(), Read<V>()); } public Tuple<T, S, U, V, R> ReadLineAs<T, S, U, V, R>() { ReadLine(); return new Tuple<T, S, U, V, R>(Read<T>(), Read<S>(), Read<U>(), Read<V>(), Read<R>()); } public string ReadString() { return _curLineSplitted[_curItemIndex++]; } public void ReadLine() { _curLine = _stream.ReadLine(); if (_curLine == null) { throw new System.Exception("No more lines"); } _curLineSplitted = _curLine.Split(_separator); _curItemIndex = 0; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using System.IO; using System.Numerics; using static System.Console; using static System.Math; namespace AtCoder { public class Program { const bool IsTest = false; const string t1 = "4\n2 3 5\n2 1 5\n1 2 5\n3 2 5"; const string t2 = "2\n0 0 100\n1 1 98"; const string t3 = "3\n99 1 191\n100 1 192\n99 0 192"; public static void Main(string[] args) { if (!IsTest) { new Program().Solve(new ConsoleInput(Console.In)); } else { new Program().Solve(new ConsoleInput(new StringReader(t1))); new Program().Solve(new ConsoleInput(new StringReader(t2))); new Program().Solve(new ConsoleInput(new StringReader(t3))); } } public void Solve(ConsoleInput cin) { var n = cin.ReadLineAs<int>(); var N = n.Item1; var x = new int[N]; var y = new int[N]; var h = new long[N]; for (var i = 0; i < N; i++) { var xyh = cin.ReadLineAs<int, int, long>(); x[i] = xyh.Item1; y[i] = xyh.Item2; h[i] = xyh.Item3; } // たった100*100*100 なので全部ためす for (var cx = 0; cx <= 100; cx++) { for (var cy = 0; cy <= 100; cy++) { long H = -1; var found = true; long hMax = 9000000000L; for (var i = 0; i < N; i++) { var mh = Math.Abs(cx - x[i]) + Math.Abs(cy - y[i]); if (h[i] == 0) { if (mh < hMax) { hMax = mh; if (H != -1 && H > hMax) { found = false; break; } } continue; } var H2 = mh + h[i]; if (H == -1) { H = H2; if (H > hMax) { found = false; break; } } else if (H != H2) { found = false; break; } } if (found == true) { Console.WriteLine(string.Format("{0} {1} {2}", cx, cy, H)); return; } } } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private readonly char _separator = ' '; private string _curLine; private string[] _curLineSplitted; private int _curItemIndex; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; } public T Read<T>() { var converter = System.ComponentModel.TypeDescriptor.GetConverter(typeof(T)); if (converter == null) { throw new Exception( string.Format("TypeDescriptor.GetConverter {0}", typeof(T).Name)); } return (T)converter.ConvertFromString(ReadString()); } public T[] ReadArray<T>(long N) { var ret = new T[N]; for (long i = 0; i < N; i++) { ret[i] = Read<T>(); } return ret; } public Tuple<T> ReadLineAs<T>() { ReadLine(); return new Tuple<T>(Read<T>()); } public Tuple<T, S> ReadLineAs<T, S>() { ReadLine(); return new Tuple<T, S>(Read<T>(), Read<S>()); } public Tuple<T, S, U> ReadLineAs<T, S, U>() { ReadLine(); return new Tuple<T, S, U>(Read<T>(), Read<S>(), Read<U>()); } public Tuple<T, S, U, V> ReadLineAs<T, S, U, V>() { ReadLine(); return new Tuple<T, S, U, V>(Read<T>(), Read<S>(), Read<U>(), Read<V>()); } public Tuple<T, S, U, V, R> ReadLineAs<T, S, U, V, R>() { ReadLine(); return new Tuple<T, S, U, V, R>(Read<T>(), Read<S>(), Read<U>(), Read<V>(), Read<R>()); } public string ReadString() { return _curLineSplitted[_curItemIndex++]; } public void ReadLine() { _curLine = _stream.ReadLine(); if (_curLine == null) { throw new System.Exception("No more lines"); } _curLineSplitted = _curLine.Split(_separator); _curItemIndex = 0; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
1,070
2