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; public static class Prg { public static Scanner sc = new Scanner(); public static void Main() { var n = sc.NextDouble(); var r = (int)Math.Sqrt(n); Console.WriteLine(r); } } public static class Extension { public static IEnumerable<int> To(this int from, int to) { return Enumerable.Range(from, to); } public static void Times(this int times, Action<int> action) { 0.To(times).ToList().ForEach(x => action(x)); } } public class Scanner { private string line; private string[] token; private int cursole = 0; public string ReadLine() { line = Console.ReadLine(); token = line.Split(' '); cursole = 0; return line; } public string Next() { if (token == null) ReadLine(); if (token.Length <= cursole) ReadLine(); var ret = token[cursole]; ++cursole; return ret; } public IEnumerable<double> NextDoubleList() { return NextList().Select(s => Double.Parse(s)); } public int NextInt() { return Int32.Parse(Next()); } public long NextLong() { return Int64.Parse(Next()); } public double NextDouble() { return Double.Parse(Next()); } public IEnumerable<string> NextList() { ReadLine(); cursole = Int32.MaxValue; return token; } public IEnumerable<int> NextIntList() { return NextList().Select(s => Int32.Parse(s)); } }
using System; using System.Collections.Generic; using System.Linq; public static class Prg { public static Scanner sc = new Scanner(); public static void Main() { var n = sc.NextDouble(); var r = (int)Math.Sqrt(n); Console.WriteLine(r * r); } } public static class Extension { public static IEnumerable<int> To(this int from, int to) { return Enumerable.Range(from, to); } public static void Times(this int times, Action<int> action) { 0.To(times).ToList().ForEach(x => action(x)); } } public class Scanner { private string line; private string[] token; private int cursole = 0; public string ReadLine() { line = Console.ReadLine(); token = line.Split(' '); cursole = 0; return line; } public string Next() { if (token == null) ReadLine(); if (token.Length <= cursole) ReadLine(); var ret = token[cursole]; ++cursole; return ret; } public IEnumerable<double> NextDoubleList() { return NextList().Select(s => Double.Parse(s)); } public int NextInt() { return Int32.Parse(Next()); } public long NextLong() { return Int64.Parse(Next()); } public double NextDouble() { return Double.Parse(Next()); } public IEnumerable<string> NextList() { ReadLine(); cursole = Int32.MaxValue; return token; } public IEnumerable<int> NextIntList() { return NextList().Select(s => Int32.Parse(s)); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
364
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200312.Cin; using static _20200312.Util; using Pair = _20200312.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200312 { public class Program { public static void Main(string[] args) { Joi2009ho_B(); Arc084_A(); } public static void Arc084_A() { long n = rl; long[] a = rla; long[] b = rla; long[] c = rla; Sort(a); Sort(b); Sort(c); Func<long, long[], long> nibutan = (target, ary) => { long ok = n; long ng = -1; while (Abs(ok - ng) != 1) { var mid = (ok + ng) / 2; if (target < ary[mid]) { ok = mid; } else { ng = mid; } } return ok; }; long[] b2 = new long[n]; for (int i = 0; i < n; i++) { b2[i] = n - nibutan(b[i], c); } Array.Reverse(b2); var b3 = Accumulate(b2); Array.Reverse(b3); long ans = 0; for (int i = 0; i < n; i++) { var bIdx = nibutan(a[i], b); if (bIdx == n) break; ans += b3[bIdx]; } Console.WriteLine(ans); } public static void Joi2009ho_B() { long d = rl; long n = rl; long m = rl; long[] a = new long[n + 1]; a[0] = 0; a[n] = d; for (int i = 1; i < n; i++) { a[i] = rl; } Sort(a); long[] b; ReadCol(out b, m); long ans = 0; foreach (var target in b) { long ok = n; long ng = 0; while (Abs(ok - ng) != 1) { long mid = (ok + ng) / 2; if (target < a[mid]) { ok = mid; } else { ng = mid; } } ans += Min(Abs(target - a[ok]), Abs(target - a[ng])); } Console.WriteLine(ans); } } public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>, IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200312.Cin; using static _20200312.Util; using Pair = _20200312.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200312 { public class Program { public static void Main(string[] args) { // Joi2009ho_B(); Arc084_A(); } public static void Arc084_A() { long n = rl; long[] a = rla; long[] b = rla; long[] c = rla; Sort(a); Sort(b); Sort(c); Func<long, long[], long> nibutan = (target, ary) => { long ok = n; long ng = -1; while (Abs(ok - ng) != 1) { var mid = (ok + ng) / 2; if (target < ary[mid]) { ok = mid; } else { ng = mid; } } return ok; }; long[] b2 = new long[n]; for (int i = 0; i < n; i++) { b2[i] = n - nibutan(b[i], c); } Array.Reverse(b2); var b3 = Accumulate(b2); Array.Reverse(b3); long ans = 0; for (int i = 0; i < n; i++) { var bIdx = nibutan(a[i], b); if (bIdx == n) break; ans += b3[bIdx]; } Console.WriteLine(ans); } public static void Joi2009ho_B() { long d = rl; long n = rl; long m = rl; long[] a = new long[n + 1]; a[0] = 0; a[n] = d; for (int i = 1; i < n; i++) { a[i] = rl; } Sort(a); long[] b; ReadCol(out b, m); long ans = 0; foreach (var target in b) { long ok = n; long ng = 0; while (Abs(ok - ng) != 1) { long mid = (ok + ng) / 2; if (target < a[mid]) { ok = mid; } else { ng = mid; } } ans += Min(Abs(target - a[ok]), Abs(target - a[ng])); } Console.WriteLine(ans); } } public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>, IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
2,594
4
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramC { static void Main() { int N = NextInt; var a = LongList.OrderBy(x => x).ToArray(); var b = LongList.OrderBy(y => y).ToArray(); var c = LongList.OrderBy(z => z).ToArray(); System.Console.WriteLine(b.Sum(x => { int aLeft = 0, aRight = N; while (aRight - aLeft > 1) { int mid = (aLeft + aRight) / 2; if (a[mid] >= x) aRight = mid; else aLeft = mid; } int cLeft = -1, cRight = N - 1; while (cRight - cLeft > 1) { int mid = (cLeft + cRight) / 2; if (c[mid] > x) cRight = mid; else cLeft = mid; } return (long)(aLeft + 1) * (N - cRight); })); } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, mod - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % mod)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } } namespace Library { class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } } namespace Library { public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } } namespace Library { public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramC { static void Main() { int N = NextInt; var a = LongList.OrderBy(x => x).ToArray(); var b = LongList.OrderBy(y => y).ToArray(); var c = LongList.OrderBy(z => z).ToArray(); System.Console.WriteLine(b.Sum(x => { int aLeft = -1, aRight = N; while (aRight - aLeft > 1) { int mid = (aLeft + aRight) / 2; if (a[mid] >= x) aRight = mid; else aLeft = mid; } int cLeft = -1, cRight = N; while (cRight - cLeft > 1) { int mid = (cLeft + cRight) / 2; if (c[mid] > x) cRight = mid; else cLeft = mid; } return (long)(aLeft + 1) * (N - cRight); })); } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, mod - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % mod)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } } namespace Library { class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } } namespace Library { public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } } namespace Library { public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
1,614
5
using System; using System.Collections.Generic; using System.Linq; namespace MyProgram { class AtCoder { static void Main() { var N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var B = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var C = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); Array.Sort(A); Array.Sort(B); Array.Sort(C); long sum = 0; for (var b = 0; b < N; b++) { long count_a = UpperBound(A, B[b] - 1); long count_c = N - LowerBound(C, B[b]); sum += count_a * count_c; } System.Console.WriteLine(sum); } public static int UpperBound<T>(T[] a, T v) { return UpperBound(a, v, Comparer<T>.Default); } public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp) { var l = 0; var r = a.Length - 1; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res <= 0) l = mid + 1; else r = mid - 1; } return l; } public static int LowerBound<T>(T[] a, T v) { return LowerBound(a, v, Comparer<T>.Default); } public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) { var l = 0; var r = a.Length - 1; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res == -1) l = mid + 1; else r = mid - 1; } return l; } } }
using System; using System.Collections.Generic; using System.Linq; namespace MyProgram { class AtCoder { static void Main() { var N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var B = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var C = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); Array.Sort(A); Array.Sort(B); Array.Sort(C); long sum = 0; for (var b = 0; b < N; b++) { long count_a = UpperBound(A, B[b] - 1); long count_c = N - LowerBound(C, B[b] + 1); sum += count_a * count_c; } System.Console.WriteLine(sum); } public static int UpperBound<T>(T[] a, T v) { return UpperBound(a, v, Comparer<T>.Default); } public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp) { var l = 0; var r = a.Length - 1; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res <= 0) l = mid + 1; else r = mid - 1; } return l; } public static int LowerBound<T>(T[] a, T v) { return LowerBound(a, v, Comparer<T>.Default); } public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) { var l = 0; var r = a.Length - 1; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res == -1) l = mid + 1; else r = mid - 1; } return l; } } }
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
471
2
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int itemCount = int.Parse(Reader.ReadLine()); this.PartsTop = Reader.ReadLine() .Split(' ') .Select(a => long.Parse(a)) .OrderBy(a => a) .ToArray(); this.PartsMiddle = Reader.ReadLine() .Split(' ') .Select(a => long.Parse(a)) .OrderBy(a => a) .ToArray(); this.PartsBottom = Reader.ReadLine() .Split(' ') .Select(a => long.Parse(a)) .OrderBy(a => a) .ToArray(); long ans = 0; for (int i = 0; i < PartsMiddle.Length; i++) { long topIdx = GetTopIdx(0, itemCount - 1, PartsMiddle[i]); long bottomIdx = GetBottomIdx(0, itemCount - 1, PartsMiddle[i]); long topCount = topIdx + 1; long bottomCount = itemCount - bottomIdx; ans += topCount * bottomCount; } Console.WriteLine(ans); } private long GetTopIdx(int min, int max, long val) { if (max - min <= 1) { if (val > PartsTop[max]) { return max; } else if (val > PartsTop[min]) { return min; } else { return min - 1; } } int mid = (max + min) / 2; if (PartsTop[mid] <= val) { return GetTopIdx(mid, max, val); } else { return GetTopIdx(min, mid, val); } } private long GetBottomIdx(int min, int max, long val) { if (max - min <= 1) { if (val >= PartsBottom[max]) { return max + 1; } else if (val >= PartsBottom[min]) { return max; } else { return min; } } int mid = (max + min) / 2; if (PartsBottom[mid] <= val) { return GetBottomIdx(mid, max, val); } else { return GetBottomIdx(min, mid, val); } } private long[] PartsTop; private long[] PartsMiddle; private long[] PartsBottom; public class Reader { private 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 = @" 6 3 14 159 2 6 53 58 9 79 323 84 6 2643 383 2 79 50 288 "; } 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 itemCount = int.Parse(Reader.ReadLine()); this.PartsTop = Reader.ReadLine() .Split(' ') .Select(a => long.Parse(a)) .OrderBy(a => a) .ToArray(); this.PartsMiddle = Reader.ReadLine() .Split(' ') .Select(a => long.Parse(a)) .OrderBy(a => a) .ToArray(); this.PartsBottom = Reader.ReadLine() .Split(' ') .Select(a => long.Parse(a)) .OrderBy(a => a) .ToArray(); long ans = 0; for (int i = 0; i < PartsMiddle.Length; i++) { long topIdx = GetTopIdx(0, itemCount - 1, PartsMiddle[i]); long bottomIdx = GetBottomIdx(0, itemCount - 1, PartsMiddle[i]); long topCount = topIdx + 1; long bottomCount = itemCount - bottomIdx; ans += topCount * bottomCount; } Console.WriteLine(ans); } private long GetTopIdx(int min, int max, long val) { if (max - min <= 1) { if (val > PartsTop[max]) { return max; } else if (val > PartsTop[min]) { return min; } else { return min - 1; } } int mid = (max + min) / 2; if (PartsTop[mid] < val) { return GetTopIdx(mid, max, val); } else { return GetTopIdx(min, mid, val); } } private long GetBottomIdx(int min, int max, long val) { if (max - min <= 1) { if (val >= PartsBottom[max]) { return max + 1; } else if (val >= PartsBottom[min]) { return max; } else { return min; } } int mid = (max + min) / 2; if (PartsBottom[mid] <= val) { return GetBottomIdx(mid, max, val); } else { return GetBottomIdx(min, mid, val); } } private long[] PartsTop; private long[] PartsMiddle; private long[] PartsBottom; public class Reader { private 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 = @" 4 2 2 1 2 2 2 2 2 2 2 2 3 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
8
599
4
using System; class Program { static void Main(string[] args) { // セル数の合計 int N_num = int.Parse(Console.ReadLine()); int cell_sum = N_num * 2; // 塗りつぶすセル数 int A_Math = int.Parse(Console.ReadLine()); // 解答マス数 int answer = cell_sum - A_Math; //出力 Console.WriteLine(answer); } }
using System; class Program { static void Main(string[] args) { // セル数の合計 int N_num = int.Parse(Console.ReadLine()); int cell_sum = N_num * N_num; // 塗りつぶすセル数 int A_Math = int.Parse(Console.ReadLine()); // 解答マス数 int answer = cell_sum - A_Math; //出力 Console.WriteLine(answer); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
71
2
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static void Main(string[] args) { try { Solve.Answer(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var n = IO.ReadInt; var k = IO.ReadInt; var a = IO.ReadSplitInt; int sum = 0; for (int i = 0; i < n; i++) { if (k / 2 > a[i]) { sum += a[i] * 2; } else { sum += (k - a[i]) * 2; } } WriteLine(sum); } public class IO { #region Input public static string ReadString => ReadLine(); public static int ReadInt => int.Parse(ReadLine()); public static long ReadLong => long.Parse(ReadLine()); public static double ReadDouble => double.Parse(ReadLine()); public static List<string> ReadSplitString => ReadLine().Split().ToList(); public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList(); public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList(); public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } public static long GCD(long x, long y) { #region if (x < y) { var tmp = x; x = y; y = tmp; } while (true) { if (x % y == 0) { return y; } else { var tmp = x; x = y; y = tmp % y; } } #endregion } public static long Choice2(long n) { #region if (n <= 1) return 0; if (n == 2) return 1; else return n * (n - 1) / 2; #endregion } } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static void Main(string[] args) { try { Solve.Answer(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var n = IO.ReadInt; var k = IO.ReadInt; var a = IO.ReadSplitInt; int sum = 0; for (int i = 0; i < n; i++) { if ((double)k / 2 > a[i]) { sum += a[i] * 2; } else { sum += (k - a[i]) * 2; } } WriteLine(sum); } public class IO { #region Input public static string ReadString => ReadLine(); public static int ReadInt => int.Parse(ReadLine()); public static long ReadLong => long.Parse(ReadLine()); public static double ReadDouble => double.Parse(ReadLine()); public static List<string> ReadSplitString => ReadLine().Split().ToList(); public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList(); public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList(); public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } public static long GCD(long x, long y) { #region if (x < y) { var tmp = x; x = y; y = tmp; } while (true) { if (x % y == 0) { return y; } else { var tmp = x; x = y; y = tmp % y; } } #endregion } public static long Choice2(long n) { #region if (n <= 1) return 0; if (n == 2) return 1; else return n * (n - 1) / 2; #endregion } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 0, 25]]
8
630
3
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 k = sc.NextInt(); int answer = 0; for (int i = 0; i < n; i++) { int x = sc.NextInt(); answer += Math.Min(x, k - x); } 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 k = sc.NextInt(); int answer = 0; for (int i = 0; i < n; i++) { int x = sc.NextInt(); answer += Math.Min(x * 2, (k - x) * 2); } 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(); } }
[["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
8
402
6
using System; public class Hello { public static void Main() { int N = int.Parse(Console.ReadLine()); int K = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); int[] num = new int[N]; int cnt = 0; for (int x = 0; x < N; x++) { num[x] = int.Parse(input[x]); if (num[x] < K / 2) { cnt = cnt + 2 * num[x]; } else { cnt = cnt + 2 * (K - num[x]); } } Console.WriteLine(cnt); } }
using System; public class Hello { public static void Main() { int N = int.Parse(Console.ReadLine()); int K = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); int[] num = new int[N]; int cnt = 0; for (int x = 0; x < N; x++) { num[x] = int.Parse(input[x]); if (num[x] <= K / 2) { cnt = cnt + 2 * num[x]; } else { cnt = cnt + 2 * (K - num[x]); } } Console.WriteLine(cnt); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
158
2
using System; using System.Linq; namespace ProgramingStydying { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = input[0]; var b = input[1]; var c = input[2]; var d = input[3]; var e = input[4]; var f = input[5]; var maxSugerWater = 0; var maxSuger = 0; var maxConcentration = 0.0; for (int i = 0; 100 * a * i <= f; i++) { for (int j = 0; 100 * (a * i + b * j) <= f; j++) { var water = 100 * (a * i + b * j); var sugerLimit = (a * i + b * j) * e; for (int k = 0; c * k <= sugerLimit && water + c * k <= f; k++) { for (int l = 0; c * k + d * l <= sugerLimit && water + c * k + d * l <= f; l++) { var suger = c * k + d * l; var concentration = (double)100 * (suger) / (water + suger); if (concentration == 0) { maxSugerWater = water + suger; maxSuger = suger; } if (concentration > maxConcentration) { maxConcentration = concentration; maxSugerWater = water + suger; maxSuger = suger; } } } } } Console.WriteLine(maxSugerWater + " " + maxSuger); } } }
using System; using System.Linq; namespace ProgramingStydying { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = input[0]; var b = input[1]; var c = input[2]; var d = input[3]; var e = input[4]; var f = input[5]; var maxSugerWater = 0; var maxSuger = 0; var maxConcentration = 0.0; for (int i = 0; 100 * a * i <= f; i++) { for (int j = 0; 100 * (a * i + b * j) <= f; j++) { var water = 100 * (a * i + b * j); var sugerLimit = (a * i + b * j) * e; for (int k = 0; c * k <= sugerLimit && water + c * k <= f; k++) { for (int l = 0; c * k + d * l <= sugerLimit && water + c * k + d * l <= f; l++) { var suger = c * k + d * l; var concentration = (double)100 * (suger) / (water + suger); if (maxConcentration == 0 && concentration == 0) { maxSugerWater = water + suger; maxSuger = suger; } if (concentration > maxConcentration) { maxConcentration = concentration; maxSugerWater = water + suger; maxSuger = suger; } } } } } Console.WriteLine(maxSugerWater + " " + maxSuger); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
332
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class ABC074C { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var A = NN; var B = NN; var C = NN; var D = NN; var E = NN; var F = NN; var max = 0.0; var maxWS = 0L; var maxS = 0L; for (var a = 0; a <= F / (A * 100) * 2; a++) { for (var b = 0; b <= F / (B * 100) * 2; b++) { var water = 100 * a * A + 100 * b * B; if (water > F) break; var rem = F - water; for (var c = 0; c <= rem / C * 2; c++) { for (var d = 0; d <= rem / D * 2; d++) { var sugar = c * C + d * D; if (water + sugar > F) break; if (sugar > E * water / 100) break; var noudo = 100.0 * sugar / (water + sugar); if (noudo > max) { max = noudo; maxWS = water + sugar; maxS = sugar; } } } } } Console.WriteLine($"{maxWS} {maxS}"); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } static IEnumerable<long> Primes(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> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } 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 uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); static Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; } 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>() { 1 }; static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } static List<T> LCS<T>(T[] s, T[] t) where T : IEquatable<T> { int sl = s.Length, tl = t.Length; var dp = new int[sl + 1, tl + 1]; for (var i = 0; i < sl; i++) for (var j = 0; j < tl; j++) dp[i + 1, j + 1] = s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]); { var r = new List<T>(); int i = sl, j = tl; while (i > 0 && j > 0) if (s[--i].Equals(t[--j])) r.Add(s[i]); else if (dp[i, j + 1] > dp[i + 1, j]) ++j; else ++i; r.Reverse(); return r; } } static long LIS<T>(T[] array, bool strict) { var l = new List<T>(); foreach (var e in array) { var i = l.BinarySearch(e); if (i < 0) i = ~i; else if (!strict) ++i; if (i == l.Count) l.Add(e); else l[i] = e; } return l.Count; } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; 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 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<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((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(TK k, TV v) => q.Push(Tuple.Create(k, v)); public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; public UF(long s) { d = Repeat(-1L, s).ToArray(); } public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } public bool IsSame(long x, long y) => Root(x) == Root(y); public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); public long Count(long x) => -d[Root(x)]; } struct Mod : IEquatable<Mod>, IEquatable<long> { static public long _mod = 1000000007; long v; public Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; } static public implicit operator Mod(long x) => new Mod(x); static public implicit operator long(Mod x) => x.v; public void Add(Mod x) { if ((v += x.v) >= _mod) v -= _mod; } public void Sub(Mod x) { if ((v -= x.v) < 0) v += _mod; } public void Mul(Mod x) => v = (v * x.v) % _mod; public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod; static public Mod operator +(Mod x, Mod y) { var t = x.v + y.v; return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t }; } static public Mod operator -(Mod x, Mod y) { var t = x.v - y.v; return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t }; } static public Mod operator *(Mod x, Mod y) => x.v * y.v; static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v); static public bool operator ==(Mod x, Mod y) => x.v == y.v; static public bool operator !=(Mod x, Mod y) => x.v != y.v; 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; } public bool Equals(Mod x) => v == x.v; public bool Equals(long x) => v == x; public override bool Equals(object x) => x == null ? false : Equals((Mod)x); public override int GetHashCode() => v.GetHashCode(); public override string ToString() => v.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { 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 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 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 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 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 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 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; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class Graph { int n; List<Tuple<int, int, long>> pathList; Dictionary<int, long>[] vtxPath; long INF = (long.MaxValue >> 1) - 1; public Graph(long _n) { n = (int)_n; pathList = new List<Tuple<int, int, long>>(); vtxPath = Repeat(0, n).Select(_ => new Dictionary<int, long>()).ToArray(); } public void AddPath(long a, long b, long c) { pathList.Add(Tuple.Create((int)a, (int)b, c)); vtxPath[a][(int)b] = vtxPath[a].ContainsKey((int)b) ? Min(vtxPath[a][(int)b], c) : c; } public long[,] WarshallFloyd() { var ret = new long[n, n]; for (var i = 0; i < n; i++) for (var j = 0; j < n; j++) ret[i, j] = vtxPath[i].ContainsKey(j) ? vtxPath[i][j] : INF; for (var k = 0; k < n; k++) for (var i = 0; i < n; i++) for (var j = 0; j < n; j++) ret[i, j] = Min(ret[i, j], ret[i, k] + ret[k, j]); return ret; } public Tuple<long[], int?[], bool[]> BellmanFord(long s) { var dist = Repeat(INF, n).ToArray(); var pred = new int?[n]; var neg = new bool[n]; dist[s] = 0; for (var i = 1; i < n; i++) foreach (var path in pathList) if (dist[path.Item2] > (dist[path.Item1] == INF ? INF : dist[path.Item1] + path.Item3)) { dist[path.Item2] = dist[path.Item1] + path.Item3; pred[path.Item2] = path.Item1; } for (var i = 0; i < n; i++) foreach (var path in pathList) if (dist[path.Item2] > (dist[path.Item1] == INF ? INF : dist[path.Item1] + path.Item3) || neg[path.Item1]) { dist[path.Item2] = dist[path.Item1] + path.Item3; neg[path.Item2] = true; } return Tuple.Create(dist, pred, neg); } public Tuple<long[], int?[]> Dijkstra(long s) { var dist = Repeat(long.MaxValue >> 2, n).ToArray(); var pred = new int?[n]; dist[s] = 0; var q = new PQ<long, int>(); q.Push(0, (int)s); while (q.Count > 0) { var u = q.Pop().Item2; foreach (var path in vtxPath[u]) { var v = path.Key; var alt = dist[u] + path.Value; if (dist[v] > alt) { dist[v] = alt; pred[v] = u; q.Push(alt, v); } } } return Tuple.Create(dist, pred); } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; public int c; } Comparison<T> c; Node r; bool ch; T lm; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} bool R(Node n) => n != null && !n.b; bool B(Node n) => n != null && n.b; long C(Node n) => n?.c ?? 0; Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } public void Add(T x) { r = A(r, x); r.b = true; } Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); } Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } public T this[long i] { get { return At(r, i); } } T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); } public bool Have(T x) { var t = FindUpper(x); return t < C(r) && At(r, t).CompareTo(x) == 0; } public long FindUpper(T x, bool allowSame = true) => allowSame ? FL(r, x) + 1 : FU(r, x); long FU(Node n, T x) { if (n == null) return 0; var r = c(x, n.v); if (r < 0) return FU(n.l, x); return C(n.l) + 1 + FU(n.r, x); } public long FindLower(T x, bool allowSame = true) { var t = FL(r, x); if (allowSame) return t + 1 < C(r) && At(r, t + 1).CompareTo(x) == 0 ? t + 1 : t < 0 ? C(r) : t; return t < 0 ? C(r) : t; } long FL(Node n, T x) { if (n == null) return -1; var r = c(x, n.v); if (r > 0) return C(n.l) + 1 + FL(n.r, x); return FL(n.l, x); } public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } public bool Any() => r != null; public long Count() => C(r); public IEnumerable<T> List() => L(r); IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; public Dict(Func<K, V> _d) { d = _d; } public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } public Deque(int cap = 16) { b = new T[c = cap]; } int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } class SegTree<T> { int n; T ti; Func<T, T, T> f; T[] dat; public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); } public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); } public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } } } class LazySegTree<T, E> { int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz; public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); } public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]); void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; } void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); } void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); } public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); } public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); } public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class ABC074C { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var A = NN; var B = NN; var C = NN; var D = NN; var E = NN; var F = NN; var max = 0.0; var maxWS = 0L; var maxS = 0L; for (var a = 0; a <= F / (A * 100) * 2; a++) { for (var b = 0; b <= F / (B * 100) * 2; b++) { var water = 100 * a * A + 100 * b * B; if (water > F) break; var rem = F - water; for (var c = 0; c <= rem / C * 2; c++) { for (var d = 0; d <= rem / D * 2; d++) { var sugar = c * C + d * D; if (water + sugar > F) break; if (sugar > E * water / 100) break; var noudo = 100.0 * sugar / (water + sugar); if (noudo > max - 1e-8) { max = noudo; maxWS = water + sugar; maxS = sugar; } } } } } Console.WriteLine($"{maxWS} {maxS}"); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } static IEnumerable<long> Primes(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> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } 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 uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); static Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; } 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>() { 1 }; static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } static List<T> LCS<T>(T[] s, T[] t) where T : IEquatable<T> { int sl = s.Length, tl = t.Length; var dp = new int[sl + 1, tl + 1]; for (var i = 0; i < sl; i++) for (var j = 0; j < tl; j++) dp[i + 1, j + 1] = s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]); { var r = new List<T>(); int i = sl, j = tl; while (i > 0 && j > 0) if (s[--i].Equals(t[--j])) r.Add(s[i]); else if (dp[i, j + 1] > dp[i + 1, j]) ++j; else ++i; r.Reverse(); return r; } } static long LIS<T>(T[] array, bool strict) { var l = new List<T>(); foreach (var e in array) { var i = l.BinarySearch(e); if (i < 0) i = ~i; else if (!strict) ++i; if (i == l.Count) l.Add(e); else l[i] = e; } return l.Count; } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; 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 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<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((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(TK k, TV v) => q.Push(Tuple.Create(k, v)); public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; public UF(long s) { d = Repeat(-1L, s).ToArray(); } public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } public bool IsSame(long x, long y) => Root(x) == Root(y); public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); public long Count(long x) => -d[Root(x)]; } struct Mod : IEquatable<Mod>, IEquatable<long> { static public long _mod = 1000000007; long v; public Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; } static public implicit operator Mod(long x) => new Mod(x); static public implicit operator long(Mod x) => x.v; public void Add(Mod x) { if ((v += x.v) >= _mod) v -= _mod; } public void Sub(Mod x) { if ((v -= x.v) < 0) v += _mod; } public void Mul(Mod x) => v = (v * x.v) % _mod; public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod; static public Mod operator +(Mod x, Mod y) { var t = x.v + y.v; return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t }; } static public Mod operator -(Mod x, Mod y) { var t = x.v - y.v; return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t }; } static public Mod operator *(Mod x, Mod y) => x.v * y.v; static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v); static public bool operator ==(Mod x, Mod y) => x.v == y.v; static public bool operator !=(Mod x, Mod y) => x.v != y.v; 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; } public bool Equals(Mod x) => v == x.v; public bool Equals(long x) => v == x; public override bool Equals(object x) => x == null ? false : Equals((Mod)x); public override int GetHashCode() => v.GetHashCode(); public override string ToString() => v.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { 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 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 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 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 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 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 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; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class Graph { int n; List<Tuple<int, int, long>> pathList; Dictionary<int, long>[] vtxPath; long INF = (long.MaxValue >> 1) - 1; public Graph(long _n) { n = (int)_n; pathList = new List<Tuple<int, int, long>>(); vtxPath = Repeat(0, n).Select(_ => new Dictionary<int, long>()).ToArray(); } public void AddPath(long a, long b, long c) { pathList.Add(Tuple.Create((int)a, (int)b, c)); vtxPath[a][(int)b] = vtxPath[a].ContainsKey((int)b) ? Min(vtxPath[a][(int)b], c) : c; } public long[,] WarshallFloyd() { var ret = new long[n, n]; for (var i = 0; i < n; i++) for (var j = 0; j < n; j++) ret[i, j] = vtxPath[i].ContainsKey(j) ? vtxPath[i][j] : INF; for (var k = 0; k < n; k++) for (var i = 0; i < n; i++) for (var j = 0; j < n; j++) ret[i, j] = Min(ret[i, j], ret[i, k] + ret[k, j]); return ret; } public Tuple<long[], int?[], bool[]> BellmanFord(long s) { var dist = Repeat(INF, n).ToArray(); var pred = new int?[n]; var neg = new bool[n]; dist[s] = 0; for (var i = 1; i < n; i++) foreach (var path in pathList) if (dist[path.Item2] > (dist[path.Item1] == INF ? INF : dist[path.Item1] + path.Item3)) { dist[path.Item2] = dist[path.Item1] + path.Item3; pred[path.Item2] = path.Item1; } for (var i = 0; i < n; i++) foreach (var path in pathList) if (dist[path.Item2] > (dist[path.Item1] == INF ? INF : dist[path.Item1] + path.Item3) || neg[path.Item1]) { dist[path.Item2] = dist[path.Item1] + path.Item3; neg[path.Item2] = true; } return Tuple.Create(dist, pred, neg); } public Tuple<long[], int?[]> Dijkstra(long s) { var dist = Repeat(long.MaxValue >> 2, n).ToArray(); var pred = new int?[n]; dist[s] = 0; var q = new PQ<long, int>(); q.Push(0, (int)s); while (q.Count > 0) { var u = q.Pop().Item2; foreach (var path in vtxPath[u]) { var v = path.Key; var alt = dist[u] + path.Value; if (dist[v] > alt) { dist[v] = alt; pred[v] = u; q.Push(alt, v); } } } return Tuple.Create(dist, pred); } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; public int c; } Comparison<T> c; Node r; bool ch; T lm; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} bool R(Node n) => n != null && !n.b; bool B(Node n) => n != null && n.b; long C(Node n) => n?.c ?? 0; Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } public void Add(T x) { r = A(r, x); r.b = true; } Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); } Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } public T this[long i] { get { return At(r, i); } } T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); } public bool Have(T x) { var t = FindUpper(x); return t < C(r) && At(r, t).CompareTo(x) == 0; } public long FindUpper(T x, bool allowSame = true) => allowSame ? FL(r, x) + 1 : FU(r, x); long FU(Node n, T x) { if (n == null) return 0; var r = c(x, n.v); if (r < 0) return FU(n.l, x); return C(n.l) + 1 + FU(n.r, x); } public long FindLower(T x, bool allowSame = true) { var t = FL(r, x); if (allowSame) return t + 1 < C(r) && At(r, t + 1).CompareTo(x) == 0 ? t + 1 : t < 0 ? C(r) : t; return t < 0 ? C(r) : t; } long FL(Node n, T x) { if (n == null) return -1; var r = c(x, n.v); if (r > 0) return C(n.l) + 1 + FL(n.r, x); return FL(n.l, x); } public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } public bool Any() => r != null; public long Count() => C(r); public IEnumerable<T> List() => L(r); IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; public Dict(Func<K, V> _d) { d = _d; } public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } public Deque(int cap = 16) { b = new T[c = cap]; } int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } class SegTree<T> { int n; T ti; Func<T, T, T> f; T[] dat; public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); } public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); } public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } } } class LazySegTree<T, E> { int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz; public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); } public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]); void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; } void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); } void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); } public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); } public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); } public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } } } } }
[["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 250]]
8
10,232
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var A = cin.ReadInt; var B = cin.ReadInt; var C = cin.ReadInt; var D = cin.ReadInt; var E = cin.ReadInt; var F = cin.ReadInt; var waters = new List<int>(); for (int i = 0; i <= F / (100 * A); i++) { for (int j = 0; i * A * 100 + j * B * 100 <= F; j++) { waters.Add(i * A * 100 + j * B * 100); } } waters = waters.GroupBy(x => x) .Select(x => x.Key) .Where(x => x != 0) .OrderBy(x => x) .ToList(); var sugars = new List<int>(); for (int i = 0; i <= F / C; i++) { for (int j = 0; i * C + j * D <= F; j++) { sugars.Add(i * C + j * D); } } sugars = sugars.GroupBy(x => x).Select(x => x.Key).OrderBy(x => x).ToList(); var maxPer = 0.0; var maxSuger = 0; var maxWeight = 0; foreach (var w in waters) { foreach (var s in sugars) { if (w + s > F) break; if ((double)(100 * s) / (double)w > (double)E) continue; if ((double)(100 * s) / (double)(s + w) > maxPer) { maxPer = (double)(100 * s) / (double)(s + w); maxSuger = s; maxWeight = s + w; } } } /* WriteLine("water"); waters.ForEach(x => WriteLine(x)); WriteLine("sugar"); sugars.ForEach(x => WriteLine(x)); */ WriteLine("{0} {1}", maxWeight, maxSuger); } } 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; } } struct ModInt { const int M = 1000000007; public long V; public ModInt(long v) { V = (v %= M) < 0 ? v + M : v; } public static implicit operator ModInt(long v) => new ModInt(v); public static ModInt operator +(ModInt x) => x; public static ModInt operator -(ModInt x) => -x.V; public static ModInt operator +(ModInt x, ModInt y) => x.V + y.V; public static ModInt operator -(ModInt x, ModInt y) => x.V - y.V; public static ModInt operator *(ModInt x, ModInt y) => x.V * y.V; public static ModInt operator /(ModInt x, ModInt y) => x.V * y.Inv(); public ModInt Pow(int i) => MPow(V, i); public ModInt Inv() => MPow(V, M - 2); public override string ToString() => $"{V}"; static long MPow(long b, int i) { for (var r = 1L;; b = b * b % M) { if (i % 2 > 0) r = r * b % M; if ((i /= 2) < 1) return r; } } public static long MFactorial(int n) { for (long x = 1, i = 1;; x = x * ++i % M) if (i >= n) return x; } public static long MNpr(int n, int r) { if (n < r) return 0; for (long x = 1, i = n - r;; x = x * ++i % M) if (i >= n) return x; } public static ModInt MNcr(int n, int r) => n < r ? 0 : n - r < r ? MNcr(n, n - r) : (ModInt)MNpr(n, r) / MFactorial(r); } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var A = cin.ReadInt; var B = cin.ReadInt; var C = cin.ReadInt; var D = cin.ReadInt; var E = cin.ReadInt; var F = cin.ReadInt; var waters = new List<int>(); for (int i = 0; i <= F / (100 * A); i++) { for (int j = 0; i * A * 100 + j * B * 100 <= F; j++) { waters.Add(i * A * 100 + j * B * 100); } } waters = waters.GroupBy(x => x) .Select(x => x.Key) .Where(x => x != 0) .OrderBy(x => x) .ToList(); var sugars = new List<int>(); for (int i = 0; i <= F / C; i++) { for (int j = 0; i * C + j * D <= F; j++) { sugars.Add(i * C + j * D); } } sugars = sugars.GroupBy(x => x).Select(x => x.Key).OrderBy(x => x).ToList(); var maxPer = -1.0; var maxSuger = 0; var maxWeight = 0; foreach (var w in waters) { foreach (var s in sugars) { if (w + s > F) break; if ((double)(100 * s) / (double)w > (double)E) continue; if ((double)(100 * s) / (double)(s + w) > maxPer) { maxPer = (double)(100 * s) / (double)(s + w); maxSuger = s; maxWeight = s + w; } } } /* WriteLine("water"); waters.ForEach(x => WriteLine(x)); WriteLine("sugar"); sugars.ForEach(x => WriteLine(x)); */ WriteLine("{0} {1}", maxWeight, maxSuger); } } 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; } } struct ModInt { const int M = 1000000007; public long V; public ModInt(long v) { V = (v %= M) < 0 ? v + M : v; } public static implicit operator ModInt(long v) => new ModInt(v); public static ModInt operator +(ModInt x) => x; public static ModInt operator -(ModInt x) => -x.V; public static ModInt operator +(ModInt x, ModInt y) => x.V + y.V; public static ModInt operator -(ModInt x, ModInt y) => x.V - y.V; public static ModInt operator *(ModInt x, ModInt y) => x.V * y.V; public static ModInt operator /(ModInt x, ModInt y) => x.V * y.Inv(); public ModInt Pow(int i) => MPow(V, i); public ModInt Inv() => MPow(V, M - 2); public override string ToString() => $"{V}"; static long MPow(long b, int i) { for (var r = 1L;; b = b * b % M) { if (i % 2 > 0) r = r * b % M; if ((i /= 2) < 1) return r; } } public static long MFactorial(int n) { for (long x = 1, i = 1;; x = x * ++i % M) if (i >= n) return x; } public static long MNpr(int n, int r) { if (n < r) return 0; for (long x = 1, i = n - r;; x = x * ++i % M) if (i >= n) return x; } public static ModInt MNcr(int n, int r) => n < r ? 0 : n - r < r ? MNcr(n, n - r) : (ModInt)MNpr(n, r) / MFactorial(r); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 250]]
8
1,220
3
using System; using System.Collections.Generic; class MainClass { public static void Main(string[] args) { var _ = LnInts(); var A = _[0]; var B = _[1]; var C = _[2]; var D = _[3]; var E = _[4]; var F = _[5]; var X = new HashSet<int>(); var Y = new HashSet<int>(); var maxCon = 0f; var mX = 0; var mY = 0; for (int i = 0; i < 10000; i++) { var a = A * i * 100; for (int j = 0; j < 10000; j++) { var v = a + B * j * 100; if (v != 0) X.Add(v); if (B * j * 100 + A * i > F) break; } if (A * i * 100 > F) break; } for (int i = 0; i < 10000; i++) { var a = C * i; for (int j = 0; j < 10000; j++) { Y.Add(a + D * j); if (D * j + C * i > F) break; } if (C * i > F) break; } var Xs = new int[X.Count]; X.CopyTo(Xs); var Ys = new int[Y.Count]; Y.CopyTo(Ys); for (var i = 0; i < Xs.Length; i++) { for (var j = 0; j < Ys.Length; j++) { if (Xs[i] + Ys[j] > F || Ys[j] * 100 > Xs[i] * E) continue; var con = (float)Ys[j] / (float)(Xs[i] + Ys[j]); if (con > maxCon) { maxCon = con; mX = Xs[i]; mY = Ys[j]; } } } Console.WriteLine((mX + mY) + " " + mY); } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
using System; using System.Collections.Generic; class MainClass { public static void Main(string[] args) { var _ = LnInts(); var A = _[0]; var B = _[1]; var C = _[2]; var D = _[3]; var E = _[4]; var F = _[5]; var X = new HashSet<int>(); var Y = new HashSet<int>(); var maxCon = 0f; var mX = 0; var mY = 0; for (int i = 0; i < 10000; i++) { var a = A * i * 100; for (int j = 0; j < 10000; j++) { var v = a + B * j * 100; if (v != 0) X.Add(v); if (B * j * 100 + A * i > F) break; } if (A * i * 100 > F) break; } for (int i = 0; i < 10000; i++) { var a = C * i; for (int j = 0; j < 10000; j++) { Y.Add(a + D * j); if (D * j + C * i > F) break; } if (C * i > F) break; } var Xs = new int[X.Count]; X.CopyTo(Xs); var Ys = new int[Y.Count]; Y.CopyTo(Ys); for (var i = 0; i < Xs.Length; i++) { for (var j = 0; j < Ys.Length; j++) { if (Xs[i] + Ys[j] > F || Ys[j] * 100 > Xs[i] * E) continue; var con = (float)Ys[j] / (float)(Xs[i] + Ys[j]); if (con >= maxCon) { maxCon = con; mX = Xs[i]; mY = Ys[j]; } } } Console.WriteLine((mX + mY) + " " + mY); } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
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(); int a = sc.NextInt(); int b = sc.NextInt(); int c = sc.NextInt(); int d = sc.NextInt(); int e = sc.NextInt(); int f = sc.NextInt(); int answerW = 0; int answerS = 0; float max = 0; for (int i = 0; i <= 30; i++) { if (a * i * 100 > f) { break; } for (int j = 0; j <= 30; j++) { int water = a * i * 100 + b * j * 100; if (water == 0) { continue; } int diff = f - water; if (diff < 0) { break; } int limit = Math.Min(water / 100 * e, diff); int maxSuger = 0; for (int k = 0; k <= 3000; k++) { int sugerC = k * c; if (sugerC > limit) { break; } for (int l = 0; l <= 3000; l++) { int sugerD = l * d; if (sugerC + sugerD > limit) { break; } maxSuger = Math.Max(maxSuger, sugerC + sugerD); } } float density = (float)(maxSuger * 100) / (float)(water + maxSuger); if (max < density) { max = density; answerW = water + maxSuger; answerS = maxSuger; } } } Console.WriteLine(answerW + " " + answerS); } 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(); int a = sc.NextInt(); int b = sc.NextInt(); int c = sc.NextInt(); int d = sc.NextInt(); int e = sc.NextInt(); int f = sc.NextInt(); int answerW = 0; int answerS = 0; float max = 0; for (int i = 0; i <= 30; i++) { if (a * i * 100 > f) { break; } for (int j = 0; j <= 30; j++) { int water = a * i * 100 + b * j * 100; if (water == 0) { continue; } int diff = f - water; if (diff < 0) { break; } int limit = Math.Min(water / 100 * e, diff); int maxSuger = 0; for (int k = 0; k <= 3000; k++) { int sugerC = k * c; if (sugerC > limit) { break; } for (int l = 0; l <= 3000; l++) { int sugerD = l * d; if (sugerC + sugerD > limit) { break; } maxSuger = Math.Max(maxSuger, sugerC + sugerD); } } float density = (float)(maxSuger * 100) / (float)(water + maxSuger); if (max <= density) { max = density; answerW = water + maxSuger; answerS = maxSuger; } } } Console.WriteLine(answerW + " " + answerS); } 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, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
649
2
using System; using System.Linq; namespace ConsoleApp95 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = st[0]; int B = st[1]; int C = st[2]; int D = st[3]; int E = st[4]; int F = st[5]; int ans_overall = 0; int ans_sugar = 0; double max_density = 0; for (int a = 0; a * 100 * A <= F; a++) { for (int b = 0; a * 100 * A + b * 100 * B <= F; b++) { for (int c = 0; a * 100 * A + b * 100 * B + c * C <= F; c++) { for (int d = 0; a * 100 * A + b * 100 * B + c * C + d * D <= F; d++) { int water = a * 100 * A + b * 100 * B; int sugar = c * C + d * D; int sum = water + sugar; if (sugar <= E * water / 100) { double density = (double)sugar * 100 / sum; if (density > max_density) { max_density = density; ans_overall = sum; ans_sugar = sugar; } } } } } } Console.WriteLine(ans_overall + " " + ans_sugar); } } }
using System; using System.Linq; namespace ConsoleApp95 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = st[0]; int B = st[1]; int C = st[2]; int D = st[3]; int E = st[4]; int F = st[5]; int ans_overall = 0; int ans_sugar = 0; double max_density = -1; for (int a = 0; a * 100 * A <= F; a++) { for (int b = 0; a * 100 * A + b * 100 * B <= F; b++) { for (int c = 0; a * 100 * A + b * 100 * B + c * C <= F; c++) { for (int d = 0; a * 100 * A + b * 100 * B + c * C + d * D <= F; d++) { int water = a * 100 * A + b * 100 * B; int sugar = c * C + d * D; int sum = water + sugar; if (sugar <= E * water / 100) { double density = (double)sugar * 100 / sum; if (density > max_density) { max_density = density; ans_overall = sum; ans_sugar = sugar; } } } } } } Console.WriteLine(ans_overall + " " + ans_sugar); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203]]
8
314
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_A(); } public static void Solve_A() { long a, b, c, d, e, f; MyIO.ReadMulti(out a, out b, out c, out d, out e, out f); double dmax = 0; long[] ans = { 0, 0 }; ll alim = f / (100 * a); ll blim = f / (100 * b); for (int i = 0; i <= alim; i++) { for (int j = 0; j <= blim; j++) { ll w = 100 * (i * a + j * b); if ((f < w) || (w == 0)) continue; ll slim = Math.Min(f - w, (i * a + j * b) * e); ll smax = 0; ll clim = slim / c; ll dlim = slim / d; for (int k = 0; k <= clim; k++) { for (int l = 0; l <= dlim; l++) { ll s = k * c + l * d; if (s <= slim) Chmax(ref smax, s); } } double dd = (double)smax / (double)(smax + w); if (dmax < dd) { dmax = dd; ans[0] = w + smax; ans[1] = smax; } } } MyIO.WriteArray(ans); } public static void Solve_B() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_A(); } public static void Solve_A() { long a, b, c, d, e, f; MyIO.ReadMulti(out a, out b, out c, out d, out e, out f); double dmax = -1; long[] ans = { 0, 0 }; ll alim = f / (100 * a); ll blim = f / (100 * b); for (int i = 0; i <= alim; i++) { for (int j = 0; j <= blim; j++) { ll w = 100 * (i * a + j * b); if ((f < w) || (w == 0)) continue; ll slim = Math.Min(f - w, (i * a + j * b) * e); ll smax = 0; ll clim = slim / c; ll dlim = slim / d; for (int k = 0; k <= clim; k++) { for (int l = 0; l <= dlim; l++) { ll s = k * c + l * d; if (s <= slim) Chmax(ref smax, s); } } double dd = (double)smax / (double)(smax + w); if (dmax < dd) { dmax = dd; ans[0] = w + smax; ans[1] = smax; } } } MyIO.WriteArray(ans); } public static void Solve_B() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_C() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_D() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_E() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } public static void Solve_F() { long n, m; MyIO.ReadMulti(out n, out m); long ans = 0; MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203]]
8
2,632
3
using System; using System.Linq; using System.Collections.Generic; using static System.Math; using static System.Console; using System.Text; class Program { static void Main(string[] args) { solve(); } static Scanner cin; static int A, B, C, D, E, F; static void input() { cin = new Scanner(); A = cin.nextInt() * 100; B = cin.nextInt() * 100; C = cin.nextInt(); D = cin.nextInt(); E = cin.nextInt(); F = cin.nextInt(); } static void solve() { input(); int suger = 1; int water = F; for (int a = 0; a < F; a += A) { for (int b = 0; a + b < F; b += B) { int w = a + b; for (int c = 0; w + c <= F; c += C) { for (int d = 0; w + c + d <= F; d += D) { int s = c + d; if (E * w < s * 100) continue; if (s * (suger + water) > suger * (s + w)) { suger = s; water = w; } } } } } WriteLine(water + suger + " " + suger); } 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[] ArrayDounble(int N, int add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Math; using static System.Console; using System.Text; class Program { static void Main(string[] args) { solve(); } static Scanner cin; static int A, B, C, D, E, F; static void input() { cin = new Scanner(); A = cin.nextInt() * 100; B = cin.nextInt() * 100; C = cin.nextInt(); D = cin.nextInt(); E = cin.nextInt(); F = cin.nextInt(); } static void solve() { input(); int suger = 1; int water = F; for (int a = 0; a <= F; a += A) { for (int b = 0; a + b <= F; b += B) { int w = a + b; for (int c = 0; w + c <= F; c += C) { for (int d = 0; w + c + d <= F; d += D) { int s = c + d; if (E * w < s * 100) continue; if (s * (suger + water) >= suger * (s + w)) { suger = s; water = w; } } } } } WriteLine(water + suger + " " + suger); } 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[] ArrayDounble(int N, int add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
649
6
using System; class Program { static void Main(string[] args) { var str = Console.ReadLine().Split(); var A = int.Parse(str[0]); var B = int.Parse(str[1]); var C = int.Parse(str[2]); var D = int.Parse(str[3]); var E = int.Parse(str[4]); var F = int.Parse(str[5]); var max_s = 0; var max_w = 0; for (int a = 0; (A * a) * 100 <= F; a++) { for (int b = 0; (A * a + B * b) * 100 <= F; b++) { var w = A * a + B * b; for (int c = 0; C * c <= E * w; c++) { for (int d = 0; C * c + D * d <= E * w; d++) { var s = C * c + D * d; if (F < w * 100 + s) break; if (p(max_s, max_w * 100) < p(s, w * 100)) { max_w = w; max_s = s; } } } } } Console.WriteLine($"{max_w * 100 + max_s} {max_s}"); } static double p(double s, double w) { if (s + w == 0) return 0; else return 100 * s / (s + w); } }
using System; class Program { static void Main(string[] args) { var str = Console.ReadLine().Split(); var A = int.Parse(str[0]); var B = int.Parse(str[1]); var C = int.Parse(str[2]); var D = int.Parse(str[3]); var E = int.Parse(str[4]); var F = int.Parse(str[5]); var max_s = 0; var max_w = 0; for (int a = 0; (A * a) * 100 <= F; a++) { for (int b = 0; (A * a + B * b) * 100 <= F; b++) { var w = A * a + B * b; for (int c = 0; C * c <= E * w; c++) { for (int d = 0; C * c + D * d <= E * w; d++) { var s = C * c + D * d; if (F < w * 100 + s) break; if (p(max_s, max_w * 100) <= p(s, w * 100)) { max_w = w; max_s = s; } } } } } Console.WriteLine($"{max_w * 100 + max_s} {max_s}"); } static double p(double s, double w) { if (s + w == 0) return 0; else return 100 * s / (s + w); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
329
2
using System; using System.Collections; using System.Collections.Generic; using System.Text; public class C { public static void Main() { string[] args = Console.ReadLine().Split(' '); int A = Int32.Parse(args[0]); int B = Int32.Parse(args[1]); int C = Int32.Parse(args[2]); int D = Int32.Parse(args[3]); int E = Int32.Parse(args[4]); int F = Int32.Parse(args[5]); int optSugarWater = 0; int optSugar = 0; double optDencity = 0; for (int i = 0; i <= F / (100 * A); i++) { int binRest1 = F - i * 100 * A; for (int j = 0; j <= binRest1 / (100 * B); j++) { int binRest2 = binRest1 - j * 100 * B; int sugarRest1 = (i * A + j * B) * E; for (int k = 0; k <= Math.Min(binRest2, sugarRest1) / C; k++) { int binRest3 = binRest2 - k * C; int sugarRest2 = sugarRest1 - k * C; for (int l = 0; l <= Math.Min(binRest3, sugarRest2) / D; l++) { if (i + j + k + l == 0) continue; double water = 100 * (i * A + j * B); double sugar = k * C + l * D; double dencity = sugar / (sugar + water); if (dencity > optDencity) { optDencity = dencity; optSugarWater = (int)(sugar + water); optSugar = (int)sugar; } } } } } Console.WriteLine("{0} {1}", optSugarWater, optSugar); } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; public class C { public static void Main() { string[] args = Console.ReadLine().Split(' '); int A = Int32.Parse(args[0]); int B = Int32.Parse(args[1]); int C = Int32.Parse(args[2]); int D = Int32.Parse(args[3]); int E = Int32.Parse(args[4]); int F = Int32.Parse(args[5]); int optSugarWater = 100 * A; int optSugar = 0; double optDencity = 0; for (int i = 0; i <= F / (100 * A); i++) { int binRest1 = F - i * 100 * A; for (int j = 0; j <= binRest1 / (100 * B); j++) { int binRest2 = binRest1 - j * 100 * B; int sugarRest1 = (i * A + j * B) * E; for (int k = 0; k <= Math.Min(binRest2, sugarRest1) / C; k++) { int binRest3 = binRest2 - k * C; int sugarRest2 = sugarRest1 - k * C; for (int l = 0; l <= Math.Min(binRest3, sugarRest2) / D; l++) { if (i + j + k + l == 0) continue; double water = 100 * (i * A + j * B); double sugar = k * C + l * D; double dencity = sugar / (sugar + water); if (dencity > optDencity) { optDencity = dencity; optSugarWater = (int)(sugar + water); optSugar = (int)sugar; } } } } } Console.WriteLine("{0} {1}", optSugarWater, optSugar); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
387
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_C { class C074 { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int A = int.Parse(s[0]), B = int.Parse(s[1]), C = int.Parse(s[2]); int D = int.Parse(s[3]), E = int.Parse(s[4]), F = int.Parse(s[5]); double pmax = 0; int sw = 0, ss = 0; for (int i = 0; i <= 30; i++) { for (int j = 0; j <= 30; j++) { if (i == 0 && j == 0) continue; int w = 100 * (A * i + B * j); int smax = Math.Min(E * w / 100, F - w); // k:操作3の回数 for (int k = 0; k <= 3000; k++) { if (C * k > smax) continue; // x:操作4の回数 int x = (smax - C * k) / D; int sg = k * C + x * D; double p = (double)sg / w; if (p > pmax) { pmax = p; sw = w + sg; ss = sg; } } } } Console.WriteLine(sw + " " + ss); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_C { class C074 { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int A = int.Parse(s[0]), B = int.Parse(s[1]), C = int.Parse(s[2]); int D = int.Parse(s[3]), E = int.Parse(s[4]), F = int.Parse(s[5]); double pmax = -1; int sw = 0, ss = 0; for (int i = 0; i <= 30; i++) { for (int j = 0; j <= 30; j++) { if (i == 0 && j == 0) continue; int w = 100 * (A * i + B * j); int smax = Math.Min(E * w / 100, F - w); // k:操作3の回数 for (int k = 0; k <= 3000; k++) { if (C * k > smax) continue; // x:操作4の回数 int x = (smax - C * k) / D; int sg = k * C + x * D; double p = (double)sg / w; if (p > pmax) { pmax = p; sw = w + sg; ss = sg; } } } } Console.WriteLine(sw + " " + ss); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203]]
8
326
3
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace AtTest.C_Challenge { class ABC_074 { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int[] vals = ReadInts(); float density = 0; int grams = 0, sugars = 0; for (int i = 1; i <= vals[5] / 100; i++) { int xTemp = -1, yTemp = -1; // Ax+By=iになるか判定 for (int j = 0; j * vals[0] <= i; j++) { if ((i - j * vals[0]) % vals[1] == 0) { xTemp = j; yTemp = (i - j * vals[0]) / vals[1]; break; } } if (xTemp == -1) continue; //最大の砂糖の量を計算 int limit = i * vals[4]; if (limit > vals[5] - i * 100) { limit = vals[5] - i * 100; } int maxSugars = 0; int pTemp = 0, qTemp = 0; for (int j = 0; j * vals[2] <= limit; j++) { int sugarsTemp = vals[2] * j + (limit - j * vals[2]) / vals[3] * vals[3]; if (sugarsTemp > maxSugars) { pTemp = j; qTemp = (limit - j * vals[2]) / vals[3]; maxSugars = sugarsTemp; } } int gramsTemp = (vals[0] * xTemp + vals[1] * yTemp) * 100 + maxSugars; float densityTemp = 100.0f * maxSugars / gramsTemp; if (densityTemp > density) { sugars = maxSugars; grams = gramsTemp; density = densityTemp; } } /*Console.WriteLine(x); Console.WriteLine(y); Console.WriteLine(p); Console.WriteLine(q); Console.WriteLine(density);*/ Console.Write(grams); Console.Write(" "); Console.Write(sugars); } private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace AtTest.C_Challenge { class ABC_074 { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int[] vals = ReadInts(); float density = 0; int grams = vals[0] * 100, sugars = 0; for (int i = 1; i <= vals[5] / 100; i++) { int xTemp = -1, yTemp = -1; // Ax+By=iになるか判定 for (int j = 0; j * vals[0] <= i; j++) { if ((i - j * vals[0]) % vals[1] == 0) { xTemp = j; yTemp = (i - j * vals[0]) / vals[1]; break; } } if (xTemp == -1) continue; //最大の砂糖の量を計算 int limit = i * vals[4]; if (limit > vals[5] - i * 100) { limit = vals[5] - i * 100; } int maxSugars = 0; int pTemp = 0, qTemp = 0; for (int j = 0; j * vals[2] <= limit; j++) { int sugarsTemp = vals[2] * j + (limit - j * vals[2]) / vals[3] * vals[3]; if (sugarsTemp > maxSugars) { pTemp = j; qTemp = (limit - j * vals[2]) / vals[3]; maxSugars = sugarsTemp; } } int gramsTemp = (vals[0] * xTemp + vals[1] * yTemp) * 100 + maxSugars; float densityTemp = 100.0f * maxSugars / gramsTemp; if (densityTemp > density) { sugars = maxSugars; grams = gramsTemp; density = densityTemp; } } /*Console.WriteLine(x); Console.WriteLine(y); Console.WriteLine(p); Console.WriteLine(q); Console.WriteLine(density);*/ Console.Write(grams); Console.Write(" "); Console.Write(sugars); } 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); } } }
[["+", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["+", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
561
5
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Simple { int A, B, C, D, E, F; void Solve() { // input A = io.Int; B = io.Int; C = io.Int; D = io.Int; E = io.Int; F = io.Int; // cal var kosa = 0D; var water = 0; var sugar = 0; for (int i = 0; i <= 31; ++i) { for (int j = 0; j <= 31; ++j) { for (int k = 0; k <= 101; ++k) { for (int l = 0; l <= 101; ++l) { var x = 100 * A * i + 100 * B * j; var y = C * k + D * l; if (x + y <= F && y <= E * A * i + E * B * j) if ((100 * y) != 0 && kosa < (100.0 * y) / (y + x)) { kosa = (100.0 * y) / (y + x); sugar = y; water = x + y; } } } } } // ret Console.WriteLine((water == 0 ? 100 : water) + " " + sugar); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) { new Simple().Stream(); } void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Simple { int A, B, C, D, E, F; void Solve() { // input A = io.Int; B = io.Int; C = io.Int; D = io.Int; E = io.Int; F = io.Int; // cal var kosa = 0D; var water = 0; var sugar = 0; for (int i = 0; i <= 31; ++i) { for (int j = 0; j <= 31; ++j) { for (int k = 0; k <= 101; ++k) { for (int l = 0; l <= 101; ++l) { var x = 100 * A * i + 100 * B * j; var y = C * k + D * l; if (x + y <= F && y <= E * A * i + E * B * j) if ((100 * y) != 0 && kosa < (100.0 * y) / (y + x)) { kosa = (100.0 * y) / (y + x); sugar = y; water = x + y; } } } } } // ret Console.WriteLine((water == 0 ? 100 * A : water) + " " + sugar); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) { new Simple().Stream(); } void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
[["+", 31, 16, 31, 23, 0, 41, 64, 16, 17, 48], ["+", 31, 16, 31, 23, 0, 41, 64, 16, 12, 22]]
8
554
2
using System; class ABC074D { static public void Main(string[] args) { int A, B, C, D, E, F; string[] vals = Console.ReadLine().Split(' '); A = int.Parse(vals[0]); B = int.Parse(vals[1]); C = int.Parse(vals[2]); D = int.Parse(vals[3]); E = int.Parse(vals[4]); F = int.Parse(vals[5]); int i, j, k, l; double maxcon = 0.0; double con; int answ = 0, anss = 0; for (i = 0; 100 * A * i <= F; i++) { for (j = 0; 100 * A * i + 100 * B * j <= F; j++) { for (k = 0; 100 * A * i + 100 * B * j + C * k <= F; k++) { for (l = 0; 100 * A * i + 100 * B * j + C * k + D * l <= F; l++) { if (C * k + D * l <= E * (A * i + B * j)) { con = (double)(C * k + D * l) / (100 * A * i + 100 * B * j); if (con > maxcon) { maxcon = con; answ = 100 * A * i + 100 * B * j + C * k + D * l; anss = C * k + D * l; } } } } } } Console.WriteLine("{0} {1}", answ, anss); } }
using System; class ABC074D { static public void Main(string[] args) { int A, B, C, D, E, F; string[] vals = Console.ReadLine().Split(' '); A = int.Parse(vals[0]); B = int.Parse(vals[1]); C = int.Parse(vals[2]); D = int.Parse(vals[3]); E = int.Parse(vals[4]); F = int.Parse(vals[5]); int i, j, k, l; double maxcon = 0.0; double con; int answ = 100 * A, anss = 0; for (i = 0; 100 * A * i <= F; i++) { for (j = 0; 100 * A * i + 100 * B * j <= F; j++) { for (k = 0; 100 * A * i + 100 * B * j + C * k <= F; k++) { for (l = 0; 100 * A * i + 100 * B * j + C * k + D * l <= F; l++) { if (C * k + D * l <= E * (A * i + B * j)) { con = (double)(C * k + D * l) / (100 * A * i + 100 * B * j); if (con > maxcon) { maxcon = con; answ = 100 * A * i + 100 * B * j + C * k + D * l; anss = C * k + D * l; } } } } } } Console.WriteLine("{0} {1}", answ, anss); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
364
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 A, B, C, D, E, F; A = cin.nextInt(); B = cin.nextInt(); C = cin.nextInt(); D = cin.nextInt(); E = cin.nextInt(); F = cin.nextInt(); int[] dp = new int[F + 1]; for (int i = 0; i < F + 1; i++) { if (dp[i] != i) continue; if (dp[i] + C <= F) dp[i + C] = i + C; if (dp[i] + D <= F) dp[i + D] = i + C; } for (int i = 1; i < F + 1; i++) { dp[i] = Math.Max(dp[i], dp[i - 1]); } long AnsAll = A * 100; long AnsSalt = 0; for (int i = 0; i < 31; i++) { for (int j = 0; j < 31; j++) { int Water = A * 100 * i + B * 100 * j; if (Water > F) continue; int MaxSalt = Math.Min(F - Water, Water / 100 * E); int Salt = dp[MaxSalt]; int Sum = Water + Salt; if (AnsSalt * Sum < Salt * AnsAll) { AnsAll = Sum; AnsSalt = Salt; } } } Console.WriteLine(AnsAll + " " + AnsSalt); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int A, B, C, D, E, F; A = cin.nextInt(); B = cin.nextInt(); C = cin.nextInt(); D = cin.nextInt(); E = cin.nextInt(); F = cin.nextInt(); int[] dp = new int[F + 1]; for (int i = 0; i < F + 1; i++) { if (dp[i] != i) continue; if (dp[i] + C <= F) dp[i + C] = i + C; if (dp[i] + D <= F) dp[i + D] = i + D; } for (int i = 1; i < F + 1; i++) { dp[i] = Math.Max(dp[i], dp[i - 1]); } long AnsAll = A * 100; long AnsSalt = 0; for (int i = 0; i < 31; i++) { for (int j = 0; j < 31; j++) { int Water = A * 100 * i + B * 100 * j; if (Water > F) continue; int MaxSalt = Math.Min(F - Water, Water / 100 * E); int Salt = dp[MaxSalt]; int Sum = Water + Salt; if (AnsSalt * Sum < Salt * AnsAll) { AnsAll = Sum; AnsSalt = Salt; } } } Console.WriteLine(AnsAll + " " + AnsSalt); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22]]
8
756
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; // using System.Numerics; // using static System.Math; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int N; List<int>[] G; int[] X; bool ans = true; void solve() { N = cin.nextint; if (N == 1) { WriteLine("POSSIBLE"); return; } var P = cin.scanint.Select(i => i - 1).ToArray(); X = cin.scanint; G = Enumerable.Range(0, N).Select(i => new List<int>()).ToArray(); for (int i = 0; i < N - 1; i++) { G[P[i]].Add(i + 1); } calc(0); WriteLine(ans ? "POSSIBLE" : "IMPOSSIBLE"); } const int inf = int.MaxValue / 3; int calc(int v) { if (G[v].Count == 0) return 0; var dp = new int [2][]; for (int i = 0; i < 2; i++) { dp[i] = Enumerable.Repeat(inf, X[v] + 1).ToArray(); } dp[X[v] % 2][0] = 0; int j = 0; foreach (var u in G[v]) { int p = calc(u); int now = j % 2; int upd = (j + 1) % 2; dp[upd] = Enumerable.Repeat(inf, X[v] + 1).ToArray(); for (int i = X[v]; i >= 0; i--) { if (i + p <= X[v]) { dp[upd][i + p] = Math.Min(dp[upd][i + p], dp[now][i] + X[u]); } if (i + X[u] <= X[v]) { dp[upd][i + X[u]] = Math.Min(dp[upd][i + X[u]], dp[now][i] + p); } } j++; } // WriteLine(string.Join(" ", dp[j % 2])); int ret = dp[j % 2].Min(); if (ret == inf) ans = false; return ret; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; // using System.Numerics; // using static System.Math; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int N; List<int>[] G; int[] X; bool ans = true; void solve() { N = cin.nextint; if (N == 1) { WriteLine("POSSIBLE"); return; } var P = cin.scanint.Select(i => i - 1).ToArray(); X = cin.scanint; G = Enumerable.Range(0, N).Select(i => new List<int>()).ToArray(); for (int i = 0; i < N - 1; i++) { G[P[i]].Add(i + 1); } calc(0); WriteLine(ans ? "POSSIBLE" : "IMPOSSIBLE"); } const int inf = int.MaxValue / 3; int calc(int v) { if (G[v].Count == 0) return 0; var dp = new int [2][]; for (int i = 0; i < 2; i++) { dp[i] = Enumerable.Repeat(inf, X[v] + 1).ToArray(); } dp[0][0] = 0; int j = 0; foreach (var u in G[v]) { int p = calc(u); // WriteLine(p); int now = j % 2; int upd = (j + 1) % 2; dp[upd] = Enumerable.Repeat(inf, X[v] + 1).ToArray(); for (int i = X[v]; i >= 0; i--) { if (i + p <= X[v]) { dp[upd][i + p] = Math.Min(dp[upd][i + p], dp[now][i] + X[u]); } if (i + X[u] <= X[v]) { dp[upd][i + X[u]] = Math.Min(dp[upd][i + X[u]], dp[now][i] + p); } } j++; } // WriteLine(string.Join(" ", dp[j % 2])); int ret = dp[j % 2].Min(); if (ret == inf) ans = false; return ret; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
[["-", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 109], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 203]]
8
837
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC073A { class Program { static void Main(string[] args) { int n; n = int.Parse(Console.ReadLine()); if (n % 10 == 9 || n / 10 == 9) Console.WriteLine("YES"); else Console.WriteLine("NO"); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC073A { class Program { static void Main(string[] args) { int n; n = int.Parse(Console.ReadLine()); if (n % 10 == 9 || n / 10 == 9) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
101
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using static CS_Contest.Utils; using System.IO; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ls = List<string>; using Ll = List<long>; using LLl = List<List<long>>; class Program { static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); return; } private class Calc { public void Solve() { string S = ReadLine(); if (S.Contains("9")) YES(); else NO(); return; } } } public static class Utils { public static int ModValue = (int)(1000000007); public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static int ReadInt() => int.Parse(ReadLine()); public static List<int> ReadInt(char s) => ReadLine().Split(s).Where(x => x != "").Select(int.Parse).ToList(); public static long ReadLong() => long.Parse(ReadLine()); public static List<long> ReadLong(char s) => ReadLine().Split(s).Select(long.Parse).ToList(); public static void ReadMulti(out int x, out int y) { var i = ReadInt(' '); x = i[0]; y = i[1]; } public static void ReadMulti(out long x, out long y) { var i = ReadLong(' '); x = i[0]; y = i[1]; } public static void ReadMulti(out int x, out int y, out int z) { var i = ReadInt(' '); x = i[0]; y = i[1]; z = i[2]; } public static void ReadMulti(out int x, out int y, out int z, out int v) { var i = ReadInt(' '); x = i[0]; y = i[1]; z = i[2]; v = i[3]; } public static string StringJoin<T>(this IEnumerable<T> l, string separator) => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (int i = 0; i < n; i++) { act(i); } } public static void RREP(int n, Action<int> act) { for (int i = n - 1; i >= 0; i--) { act(i); } } public static void REP(long n, Action<int> act) => REP((int)n, act); public static void RREP(long n, Action<int> act) => RREP((int)n, act); public static void Yes() => "Yes".WL(); public static void No() => "No".WL(); public static void YES() => "YES".WL(); public static void NO() => "NO".WL(); public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public class Vector2 { public int X { get; set; } public int Y { get; set; } public Vector2() { X = 0; Y = 0; } public Vector2(int x, int y) { X = x; Y = y; } public int ManhattanDistance(Vector2 v2) { return Utils.ManhattanDistance(X, Y, v2.X, v2.Y); } public static int ManhattanDistance(Vector2 v1, Vector2 v2) => v2.ManhattanDistance(v2); public double Distance(Vector2 v2) => Sqrt(Pow(X - v2.X, 2) + Pow(Y - v2.Y, 2)); public static Vector2 Zero { get { return new Vector2(); } } public void Clear() { X = 0; Y = 0; } } public struct IndexT<T> { public T Value { get; set; } public int Index { get; set; } public IndexT(T v, int i) { Value = v; Index = i; } } public static IEnumerable<IndexT<T>> ToIndexEnumerable<T>( this IEnumerable<T> list) => list.Select((x, i) => new IndexT<T>(x, i)); public static Tuple<TKey, TSource> ToTuple<TKey, TSource>(this KeyValuePair<TKey, TSource> kvp) => new Tuple<TKey, TSource>(kvp.Key, kvp.Value); public static IEnumerable<Tuple<TKey, TSource>> ToTupleList<TKey, TSource>( this Dictionary<TKey, TSource> d) => d.Select(_ => _.ToTuple()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using static CS_Contest.Utils; using System.IO; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ls = List<string>; using Ll = List<long>; using LLl = List<List<long>>; class Program { static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); return; } private class Calc { public void Solve() { string S = ReadLine(); if (S.Contains("9")) Yes(); else No(); return; } } } public static class Utils { public static int ModValue = (int)(1000000007); public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static int ReadInt() => int.Parse(ReadLine()); public static List<int> ReadInt(char s) => ReadLine().Split(s).Where(x => x != "").Select(int.Parse).ToList(); public static long ReadLong() => long.Parse(ReadLine()); public static List<long> ReadLong(char s) => ReadLine().Split(s).Select(long.Parse).ToList(); public static void ReadMulti(out int x, out int y) { var i = ReadInt(' '); x = i[0]; y = i[1]; } public static void ReadMulti(out long x, out long y) { var i = ReadLong(' '); x = i[0]; y = i[1]; } public static void ReadMulti(out int x, out int y, out int z) { var i = ReadInt(' '); x = i[0]; y = i[1]; z = i[2]; } public static void ReadMulti(out int x, out int y, out int z, out int v) { var i = ReadInt(' '); x = i[0]; y = i[1]; z = i[2]; v = i[3]; } public static string StringJoin<T>(this IEnumerable<T> l, string separator) => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (int i = 0; i < n; i++) { act(i); } } public static void RREP(int n, Action<int> act) { for (int i = n - 1; i >= 0; i--) { act(i); } } public static void REP(long n, Action<int> act) => REP((int)n, act); public static void RREP(long n, Action<int> act) => RREP((int)n, act); public static void Yes() => "Yes".WL(); public static void No() => "No".WL(); public static void YES() => "YES".WL(); public static void NO() => "NO".WL(); public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public class Vector2 { public int X { get; set; } public int Y { get; set; } public Vector2() { X = 0; Y = 0; } public Vector2(int x, int y) { X = x; Y = y; } public int ManhattanDistance(Vector2 v2) { return Utils.ManhattanDistance(X, Y, v2.X, v2.Y); } public static int ManhattanDistance(Vector2 v1, Vector2 v2) => v2.ManhattanDistance(v2); public double Distance(Vector2 v2) => Sqrt(Pow(X - v2.X, 2) + Pow(Y - v2.Y, 2)); public static Vector2 Zero { get { return new Vector2(); } } public void Clear() { X = 0; Y = 0; } } public struct IndexT<T> { public T Value { get; set; } public int Index { get; set; } public IndexT(T v, int i) { Value = v; Index = i; } } public static IEnumerable<IndexT<T>> ToIndexEnumerable<T>( this IEnumerable<T> list) => list.Select((x, i) => new IndexT<T>(x, i)); public static Tuple<TKey, TSource> ToTuple<TKey, TSource>(this KeyValuePair<TKey, TSource> kvp) => new Tuple<TKey, TSource>(kvp.Key, kvp.Value); public static IEnumerable<Tuple<TKey, TSource>> ToTupleList<TKey, TSource>( this Dictionary<TKey, TSource> d) => d.Select(_ => _.ToTuple()); } }
[["-", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 57, 75, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 57, 75, 1, 0, 213, 63, 22]]
8
1,356
4
using System; using System.Linq; using System.Collections.Generic; class Dmondai { static void Main() { var N = Int32.Parse(Console.ReadLine()); var a = Console.ReadLine() .Split(' ') .Select(x => Int32.Parse(x)) .OrderBy(x => x) .ToArray(); var array = new int[100001]; for (int i = 0; i < N; ++i) { array[a[i]]++; array[a[i] + 1]++; array[a[i] + 2]++; } var ans = array.Max(); Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Cmondai { static void Main() { var N = Int32.Parse(Console.ReadLine()); var a = Console.ReadLine() .Split(' ') .Select(x => Int32.Parse(x)) .OrderBy(x => x) .ToArray(); var array = new int[100002]; for (int i = 0; i < N; ++i) { array[a[i]]++; array[a[i] + 1]++; array[a[i] + 2]++; } var ans = array.Max(); Console.WriteLine(ans); } }
[["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
8
151
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Practice { class Program { static void Main(string[] args) { string szLine = Console.ReadLine(); szLine = Console.ReadLine(); string[] szArr = szLine.Split(' '); int[] arr = new int[szArr.Length]; int[] xArr = new int[szArr.Length + 10]; for (int i = 0; i < szArr.Length; ++i) { int val = int.Parse(szArr[i]); arr[i] = val; // 0 ~ 10^5 val += 1; xArr[val - 1] += 1; xArr[val] += 1; xArr[val + 1] += 1; } // 一番数の多いのをxとする int max = xArr.Max(); Console.WriteLine(max); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Practice { class Program { static void Main(string[] args) { string szLine = Console.ReadLine(); szLine = Console.ReadLine(); string[] szArr = szLine.Split(' '); int[] arr = new int[szArr.Length]; int[] xArr = new int[100000 + 10]; for (int i = 0; i < szArr.Length; ++i) { int val = int.Parse(szArr[i]); arr[i] = val; // 0 ~ 10^5 val += 1; xArr[val - 1] += 1; xArr[val] += 1; xArr[val + 1] += 1; } // 一番数の多いのをxとする int max = xArr.Max(); Console.WriteLine(max); } } }
[["-", 39, 224, 225, 226, 0, 16, 31, 214, 205, 22], ["-", 39, 224, 225, 226, 0, 16, 31, 214, 0, 131], ["-", 39, 224, 225, 226, 0, 16, 31, 214, 141, 22], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 31, 203]]
8
190
4
using System; using System.Collections.Generic; using System.Linq; namespace ABC072C { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split(' ').Select(b => int.Parse(b)).ToArray(); Dictionary<int, int> dic = new Dictionary<int, int>(); for (int i = 0; i < n; i++) { for (int j = -1; j < 2; j++) { int val = a[i] + j; if (!dic.ContainsKey(val)) { dic.Add(val, 1); } else { dic[val]++; } } } int ans = 0; foreach (KeyValuePair<int, int> kv in dic) { if (kv.Value > ans) { ans = kv.Value; } } Console.WriteLine(ans - 1); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC072C { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = Console.ReadLine().Split(' ').Select(b => int.Parse(b)).ToArray(); Dictionary<int, int> dic = new Dictionary<int, int>(); for (int i = 0; i < n; i++) { for (int j = -1; j < 2; j++) { int val = a[i] + j; if (!dic.ContainsKey(val)) { dic.Add(val, 1); } else { dic[val]++; } } } int ans = 0; foreach (KeyValuePair<int, int> kv in dic) { if (kv.Value > ans) { ans = kv.Value; } } Console.WriteLine(ans); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
217
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace atcoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int[] array = new int[10001]; for (int i = 0; i < input.Length; i++) { array[input[i]]++; array[input[i] + 1]++; array[input[i] + 2]++; } int ans = 0; for (int i = 0; i < array.Length; i++) { ans = Math.Max(ans, array[i]); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace atcoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int[] array = new int[100002]; for (int i = 0; i < input.Length; i++) { array[input[i]]++; array[input[i] + 1]++; array[input[i] + 2]++; } int ans = 0; for (int i = 0; i < array.Length; i++) { ans = Math.Max(ans, array[i]); } Console.WriteLine(ans); } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
8
196
2
using System; using System.Collections.Generic; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { Solve(); } private const int MOD = 1000000007; static void Solve() { var n = ReadAndParseInt(); var p = ReadAndParseIntArr(); int ans = 0; for (int i = 0; i < n - 1; ++i) { if (p[i] == i + 1) { int tmp = p[i]; p[i] = p[i + 1]; p[i + 1] = tmp; ans++; } } if (p[n - 1] == n) { int tmp = p[n - 1]; p[n - 1] = p[n - 2]; p[n - 2] = tmp; } Console.WriteLine(ans); } #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 long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static 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); } private static void Swap(ref long x, ref long y) { long t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } }
using System; using System.Collections.Generic; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { Solve(); } private const int MOD = 1000000007; static void Solve() { var n = ReadAndParseInt(); var p = ReadAndParseIntArr(); int ans = 0; for (int i = 0; i < n - 1; ++i) { if (p[i] == i + 1) { int tmp = p[i]; p[i] = p[i + 1]; p[i + 1] = tmp; ans++; } } if (p[n - 1] == n) { int tmp = p[n - 1]; p[n - 1] = p[n - 2]; p[n - 2] = tmp; ans++; } Console.WriteLine(ans); } #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 long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static 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); } private static void Swap(ref long x, ref long y) { long t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } }
[["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
1,127
3
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var w = new int[n + 1]; string[] line = Console.ReadLine().Trim().Split(' '); var count = 0; for (int i = 0; i < n; i++) w[i + 1] = int.Parse(line[i]); for (int i = 1; i < n; i++) { if (w[i] == i && i != n - 1) { swap(w, i); count++; } if (w[i] == i && i == n - 1) { swap(w, i - 1); count++; } } Console.WriteLine(count); } public static void swap(int[] w, int a) { var t = w[a]; w[a] = w[a + 1]; w[a + 1] = t; } }
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var w = new int[n + 1]; string[] line = Console.ReadLine().Trim().Split(' '); var count = 0; for (int i = 0; i < n; i++) w[i + 1] = int.Parse(line[i]); for (int i = 1; i <= n; i++) { if (w[i] == i && i != n) { swap(w, i); count++; } if (w[i] == i && i == n) { swap(w, i - 1); count++; } } Console.WriteLine(count); } public static void swap(int[] w, int a) { var t = w[a]; w[a] = w[a + 1]; w[a + 1] = t; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
8
226
6
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // long.Parseはstringをlongに変換。 long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long answer = 0; for (long i = 0; i < n; i++) { if (nums[i] == i) { answer++; i++; } } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // long.Parseはstringをlongに変換。 long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long answer = 0; for (long i = 0; i < n; i++) { if (nums[i] == i + 1) { answer++; i++; } } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
[["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
121
2
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; // using System.Numerics; using static System.Math; using Number = System.Int64; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var X = rl; var n = ri; var R = new long[n + 2]; for (int i = 1; i <= n; i++) R[i] = rl; R[n + 1] = 1L << 60; Debug.WriteLine(R.AsJoinedString()); var Q = ri; var p = 0; var l = 0L; var ly = 0L; var r = X; for (int i = 0; i < Q; i++) { var t = rl; if (R[p + 1] <= t) { var dt = R[p + 1] - R[p]; if (p % 2 == 0) { var ry = ly + r - l; l = Min(X, l + Max(0, dt - ly)); ly = Max(0, ly - dt); r = Min(X, Max(l, r)); } else { var ry = ly + r - l; var d = X - ry; r = Max(0, r - Max(0, dt - d)); ly = Min(X, ly + dt); l = Max(0, Min(l, r)); } p++; } { var dt = t - R[p]; Debug.WriteLine($"{p} {l} {ly} {r} {ly + r - l}"); var x = rl; if (x <= l) x = ly; else if (x >= r) x = ly + r - l; else x = ly + x - l; if (p % 2 == 0) Console.WriteLine(Max(0, x - dt)); else Console.WriteLine(Min(X, x + dt)); } } } const long INF = 1L << 60; int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static IEnumerable<int> Rep(int n) => Enumerable.Range(0, n); static IEnumerable<int> RRep(int n) => Enumerable.Range(0, n).Reverse(); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++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 => 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; 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 #region SortedMap < K, V> public class SortedMap<K, V> : SortedDictionary<K, V> where V : new() { // public SortedMap(IComparer<K> cmp) : base(cmp) { } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = new V(); } set { base[i] = value; } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; // using System.Numerics; using static System.Math; using Number = System.Int64; namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var X = rl; var n = ri; var R = new long[n + 2]; for (int i = 1; i <= n; i++) R[i] = rl; R[n + 1] = 1L << 60; Debug.WriteLine(R.AsJoinedString()); var Q = ri; var p = 0; var l = 0L; var ly = 0L; var r = X; for (int i = 0; i < Q; i++) { var t = rl; while (R[p + 1] <= t) { var dt = R[p + 1] - R[p]; if (p % 2 == 0) { var ry = ly + r - l; l = Min(X, l + Max(0, dt - ly)); ly = Max(0, ly - dt); r = Min(X, Max(l, r)); } else { var ry = ly + r - l; var d = X - ry; r = Max(0, r - Max(0, dt - d)); ly = Min(X, ly + dt); l = Max(0, Min(l, r)); } p++; } { var dt = t - R[p]; Debug.WriteLine($"{p} {l} {ly} {r} {ly + r - l} {dt}"); var x = rl; if (x <= l) x = ly; else if (x >= r) x = ly + r - l; else x = ly + x - l; if (p % 2 == 0) Console.WriteLine(Max(0, x - dt)); else Console.WriteLine(Min(X, x + dt)); } } } const long INF = 1L << 60; int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static IEnumerable<int> Rep(int n) => Enumerable.Range(0, n); static IEnumerable<int> RRep(int n) => Enumerable.Range(0, n).Reverse(); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++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 => 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; 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 #region SortedMap < K, V> public class SortedMap<K, V> : SortedDictionary<K, V> where V : new() { // public SortedMap(IComparer<K> cmp) : base(cmp) { } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = new V(); } set { base[i] = value; } } } #endregion
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 22]]
8
1,259
6
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 X = cin.nextInt(); int K = cin.nextInt(); int[] r = new int[K + 1]; for (int i = 0; i < K; i++) { r[i] = cin.nextInt(); } r[K] = int.MaxValue / 2; int Q = cin.nextInt(); int[] t = new int[Q]; int[] a = new int[Q]; for (int i = 0; i < Q; i++) { t[i] = cin.nextInt(); a[i] = cin.nextInt(); } int now = 0; int leftPoint = 0; int leftValue = 0; int rightPoint = X; int rightValue = X; int tp = 0; for (int i = 0; i < K + 1; i++) { while (tp < t.Length && t[tp] <= r[i]) { int nowA; if (a[tp] <= leftPoint) nowA = leftValue; else if (a[tp] >= rightPoint) nowA = rightValue; else nowA = leftValue + (a[tp] - leftPoint); if (i % 2 == 0) nowA -= (t[tp] - now); else nowA += (t[tp] - now); if (nowA < 0) nowA = 0; if (nowA > X) nowA = X; Console.WriteLine(nowA); tp++; } int move = r[i] - now; if (i % 2 == 0) { leftValue -= move; if (leftValue < 0) { leftPoint -= leftValue; leftValue = 0; } rightValue -= move; if (rightValue < 0) rightValue = 0; } else { leftValue += move; if (leftValue > X) { leftValue = X; } rightValue += X; if (rightValue >= X) { rightPoint -= (rightValue - X); rightValue = X; } } now = r[i]; } } // swap void swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } long calcT(long ax, long ay, long bx, long by) { return (ax * by) - (bx * ay); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int X = cin.nextInt(); int K = cin.nextInt(); int[] r = new int[K + 1]; for (int i = 0; i < K; i++) { r[i] = cin.nextInt(); } r[K] = int.MaxValue / 2; int Q = cin.nextInt(); int[] t = new int[Q]; int[] a = new int[Q]; for (int i = 0; i < Q; i++) { t[i] = cin.nextInt(); a[i] = cin.nextInt(); } int now = 0; int leftPoint = 0; int leftValue = 0; int rightPoint = X; int rightValue = X; int tp = 0; for (int i = 0; i < K + 1; i++) { while (tp < t.Length && t[tp] <= r[i]) { int nowA; if (a[tp] <= leftPoint) nowA = leftValue; else if (a[tp] >= rightPoint) nowA = rightValue; else nowA = leftValue + (a[tp] - leftPoint); if (i % 2 == 0) nowA -= (t[tp] - now); else nowA += (t[tp] - now); if (nowA < 0) nowA = 0; if (nowA > X) nowA = X; Console.WriteLine(nowA); tp++; } int move = r[i] - now; if (i % 2 == 0) { leftValue -= move; if (leftValue < 0) { leftPoint -= leftValue; leftValue = 0; } rightValue -= move; if (rightValue < 0) rightValue = 0; } else { leftValue += move; if (leftValue > X) { leftValue = X; } rightValue += move; if (rightValue >= X) { rightPoint -= (rightValue - X); rightValue = X; } } now = r[i]; } } // swap void swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } long calcT(long ax, long ay, long bx, long by) { return (ax * by) - (bx * ay); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22]]
8
911
2
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var qhsd = Reads(); var n = Read(); var q = qhsd[0]; var h = qhsd[1]; var s = qhsd[2]; var d = qhsd[3]; var x = new long[] { 8 * q, 4 * h, 2 * s, d }; Array.Sort(x); if (x.Min() == d) Console.WriteLine(n / 2 * x[1] * (n % 2) / 2); else Console.WriteLine(x.Min() * n / 2); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var qhsd = Reads(); var n = Read(); var q = qhsd[0]; var h = qhsd[1]; var s = qhsd[2]; var d = qhsd[3]; var x = new long[] { 8 * q, 4 * h, 2 * s, d }; Array.Sort(x); if (x.Min() == d) Console.WriteLine(n / 2 * x.Min() + x[1] * (n % 2) / 2); else Console.WriteLine(x.Min() * n / 2); Console.Out.Flush(); } } }
[["+", 0, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 16, 12, 16, 31, 16, 31, 204, 205, 22]]
8
248
6
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { AGC019.A(); } class AGC019 { public static void A() { var Q = Read.Int(); var H = Read.Int(); var S = Read.Int(); var D = Read.Int(); var N = Read.Int(); var p1 = Math.Min(Q * 4, Math.Min(H * 2, S)); var p2 = Math.Min(p1 * 2, D); Console.WriteLine(N / 2 * p2 + (N % 2) * p1); } public static void B() { var A = Read.Str(); int[] count = new int[26]; foreach (var a in A) { count[a - 'a']++; } Console.WriteLine(1L + (long)A.Length * (A.Length - 1) / 2 - count.Select(x => (long)x * (x - 1) / 2).Sum()); } } class Util {} static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { AGC019.A(); } class AGC019 { public static void A() { var Q = Read.Long(); var H = Read.Long(); var S = Read.Long(); var D = Read.Long(); var N = Read.Long(); var p1 = Math.Min(Q * 4, Math.Min(H * 2, S)); var p2 = Math.Min(p1 * 2, D); Console.WriteLine(N / 2 * p2 + (N % 2) * p1); } public static void B() { var A = Read.Str(); int[] count = new int[26]; foreach (var a in A) { count[a - 'a']++; } Console.WriteLine(1L + (long)A.Length * (A.Length - 1) / 2 - count.Select(x => (long)x * (x - 1) / 2).Sum()); } } class Util {} static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
1,273
10
using System; namespace agc019a { class Program { static void Main(string[] args) { int[] read = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int divByOne = Math.Min(2 * read[0], read[1]); divByOne = Math.Min(2 * divByOne, read[2]); int divByTwo = read[3]; int N = int.Parse(Console.ReadLine()); if (2 * divByOne <= divByTwo) { Console.WriteLine(N * divByOne); } else { Console.WriteLine(N / 2 * divByTwo + N % 2 * divByOne); } } } }
using System; namespace agc019a { class Program { static void Main(string[] args) { int[] read = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int divByOne = Math.Min(2 * read[0], read[1]); divByOne = Math.Min(2 * divByOne, read[2]); int divByTwo = read[3]; long N = long.Parse(Console.ReadLine()); if (2 * divByOne <= divByTwo) { Console.WriteLine(N * divByOne); } else { Console.WriteLine(N / 2 * divByTwo + N % 2 * divByOne); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
143
4
using System; using System.Collections.Generic; using static System.Console; class Program { static void Main() { var q = NextInt(); var h = NextInt(); var s = NextInt(); var d = NextInt(); var n = NextInt(); foreach (var v in new int[] { 4 * q, 2 * h }) { s = Math.Min(s, v); } WriteLine(s * (n % 2) + Math.Min(2 * s, d) * (n / 2)); } static int NextInt() { return int.Parse(NextString()); } static string NextString() { var result = new List<char>(); while (true) { int next = Read(); if (next < 0) break; var nextChar = (char)next; if (!char.IsWhiteSpace(nextChar)) result.Add(nextChar); else if (nextChar != '\r') break; } return string.Join("", result); } }
using System; using System.Collections.Generic; using static System.Console; class Program { static void Main() { var q = NextInt(); var h = NextInt(); var s = NextInt(); var d = NextInt(); var n = (long)NextInt(); foreach (var v in new int[] { 4 * q, 2 * h }) { s = Math.Min(s, v); } WriteLine(s * (n % 2) + Math.Min(2 * s, d) * (n / 2)); } static int NextInt() { return int.Parse(NextString()); } static string NextString() { var result = new List<char>(); while (true) { int next = Read(); if (next < 0) break; var nextChar = (char)next; if (!char.IsWhiteSpace(nextChar)) result.Add(nextChar); else if (nextChar != '\r') break; } return string.Join("", result); } }
[["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25]]
8
225
3
using System; class AGC019A { static public void Main(string[] args) { int Q, H, S, D; int N; string[] vals = Console.ReadLine().Split(' '); Q = int.Parse(vals[0]); H = int.Parse(vals[1]); S = int.Parse(vals[2]); D = int.Parse(vals[3]); N = int.Parse(Console.ReadLine()); int cost2l = int.MaxValue; ; int q2l = Q * 8; int h2l = H * 4; int s2l = S * 2; int d2l = D; if (cost2l > q2l) cost2l = q2l; if (cost2l > h2l) cost2l = h2l; if (cost2l > s2l) cost2l = s2l; if (cost2l > d2l) cost2l = d2l; int cost1l = int.MaxValue; int q1l = Q * 4; int h1l = H * 2; int s1l = S; if (cost1l > q1l) cost1l = q1l; if (cost1l > h1l) cost1l = h1l; if (cost1l > s1l) cost1l = s1l; Console.WriteLine((N / 2) * cost2l + (N % 2) * cost1l); } }
using System; class AGC019A { static public void Main(string[] args) { int Q, H, S, D; int N; string[] vals = Console.ReadLine().Split(' '); Q = int.Parse(vals[0]); H = int.Parse(vals[1]); S = int.Parse(vals[2]); D = int.Parse(vals[3]); N = int.Parse(Console.ReadLine()); long cost2l = long.MaxValue; ; int q2l = Q * 8; int h2l = H * 4; int s2l = S * 2; int d2l = D; if (cost2l > q2l) cost2l = q2l; if (cost2l > h2l) cost2l = h2l; if (cost2l > s2l) cost2l = s2l; if (cost2l > d2l) cost2l = d2l; long cost1l = long.MaxValue; int q1l = Q * 4; int h1l = H * 2; int s1l = S; if (cost1l > q1l) cost1l = q1l; if (cost1l > h1l) cost1l = h1l; if (cost1l > s1l) cost1l = s1l; Console.WriteLine((N / 2) * cost2l + (N % 2) * cost1l); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199]]
8
261
8
using System; using System.Collections.Generic; using System.Linq; class Solution { static void Main() { var size = new int[] { 1, 2, 4, 8 }; var costs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = int.Parse(Console.ReadLine()) * 4; for (int i = 0; i < 3; i++) { if (costs[i] * 2 < costs[i + 1]) { costs[i + 1] = costs[i] * 2; } } int money = 0; for (int i = 3; i >= 0; i--) { if (n >= size[i]) { var m = n / size[i]; n -= m * size[i]; money += m * costs[i]; } } Console.WriteLine(money); } }
using System; using System.Collections.Generic; using System.Linq; class Solution { static void Main() { var size = new int[] { 1, 2, 4, 8 }; var costs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); long n = long.Parse(Console.ReadLine()) * 4; for (int i = 0; i < 3; i++) { if (costs[i] * 2 < costs[i + 1]) { costs[i + 1] = costs[i] * 2; } } long money = 0; for (int i = 3; i >= 0; i--) { if (n >= size[i]) { var m = n / size[i]; n -= m * size[i]; money += m * costs[i]; } } Console.WriteLine(money); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 212, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 205, 199]]
8
201
6
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 x1, y1, x2, y2; x1 = cin.nextInt(); y1 = cin.nextInt(); x2 = cin.nextInt(); y2 = cin.nextInt(); if (x1 > x2 || (x1 == x2 && y1 > y2)) { swap(ref x1, ref x2); swap(ref y1, ref y2); } bool yflag = false; if (y1 > y2) { yflag = true; swap(ref y1, ref y2); } int N = cin.nextInt(); List<long> l = new List<long>(); for (int i = 0; i < N; i++) { int x = cin.nextInt(); int y = cin.nextInt(); if (yflag) { y = y1 + (y2 - y); } if (x < x1 || x > x2) continue; if (y < y1 || y > y2) continue; l.Add(((long)x << 32) + y); } long[] dp = new long[N + 1]; long MAX = long.MaxValue / 2; for (int i = 0; i < N + 1; i++) { dp[i] = MAX; } dp[0] = -1; l.Sort(); foreach (var now in l) { int y = (int)(now & 0xFFFFFFFF); int ok = 0; int ng = N + 1; while (ok + 1 < ng) { int mid = (ok + ng) / 2; if (dp[mid] <= y) ok = mid; else ng = mid; } dp[ng] = y; } int cnt = 0; for (int i = 0; i < N + 1; i++) { if (dp[i] != MAX) cnt = i; } double ans = 100L * ((x2 - x1) + (y2 - y1)); ans -= 20 * cnt; ans += Math.PI * 5 * cnt; if (cnt == Math.Min(x2 - x1, y2 - y1) + 1) ans += Math.PI * 5 * cnt; Console.WriteLine("{0:0.0000000000000000}", ans); } // swap void swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; void calc() { cin = new Scanner(); int x1, y1, x2, y2; x1 = cin.nextInt(); y1 = cin.nextInt(); x2 = cin.nextInt(); y2 = cin.nextInt(); if (x1 > x2 || (x1 == x2 && y1 > y2)) { swap(ref x1, ref x2); swap(ref y1, ref y2); } bool yflag = false; if (y1 > y2) { yflag = true; swap(ref y1, ref y2); } int N = cin.nextInt(); List<long> l = new List<long>(); for (int i = 0; i < N; i++) { int x = cin.nextInt(); int y = cin.nextInt(); if (yflag) { y = y1 + (y2 - y); } if (x < x1 || x > x2) continue; if (y < y1 || y > y2) continue; l.Add(((long)x << 32) + y); } long[] dp = new long[N + 1]; long MAX = long.MaxValue / 2; for (int i = 0; i < N + 1; i++) { dp[i] = MAX; } dp[0] = -1; l.Sort(); foreach (var now in l) { int y = (int)(now & 0xFFFFFFFF); int ok = 0; int ng = N + 1; while (ok + 1 < ng) { int mid = (ok + ng) / 2; if (dp[mid] <= y) ok = mid; else ng = mid; } dp[ng] = y; } int cnt = 0; for (int i = 0; i < N + 1; i++) { if (dp[i] != MAX) cnt = i; } double ans = 100L * ((x2 - x1) + (y2 - y1)); ans -= 20 * cnt; ans += Math.PI * 5 * cnt; if (cnt == Math.Min(x2 - x1, y2 - y1) + 1) ans += Math.PI * 5 * 1; Console.WriteLine("{0:0.0000000000000000}", ans); } // swap void swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203]]
8
933
2
using System; public class a { public static void Main() { int[] xab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine( Math.Abs(xab[0] - xab[1]) > Math.Abs(xab[0] - xab[2]) ? "A" : "B"); } }
using System; public class a { public static void Main() { int[] xab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine( Math.Abs(xab[0] - xab[1]) < Math.Abs(xab[0] - xab[2]) ? "A" : "B"); } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18]]
8
83
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int x = sc.NextInt(); int a = sc.NextInt(); int b = sc.NextInt(); string answer = Math.Abs(x - a) >= Math.Abs(x - b) ? "A" : "B"; 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(); int x = sc.NextInt(); int a = sc.NextInt(); int b = sc.NextInt(); string answer = Math.Abs(x - a) <= Math.Abs(x - b) ? "A" : "B"; 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, 200, 0, 212, 0, 41, 15, 16, 17, 20], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 19]]
8
397
2
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine((s[1] - s[0]) > (s[2] - s[0]) ? "B" : "A"); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(Math.Abs(s[1] - s[0]) > Math.Abs(s[2] - s[0]) ? "B" : "A"); } }
[["+", 0, 41, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 41, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 41, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 41, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 41, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 41, 15, 16, 12, 213, 63, 214, 141, 22]]
8
89
6
// optional using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; public static class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var xab = ReadLib.ReadAsIntArray(); Console.WriteLine( Math.Abs(xab[0] - xab[1]) > Math.Abs(xab[0] - xab[2]) ? "A" : "B"); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static char[][] ReadNTimesAsCharArray(int n) { return Enumerable.Range(1, n) .Select(i => Console.ReadLine().ToArray()) .ToArray(); } public static long[] ReadNTimesAsLong(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => long.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } namespace Heaps { /// <summary>優先度付きキュー</summary> public class PriorityQueue<T> : IEnumerable<T>, IReadOnlyCollection<T> where T : IComparable<T> { public List<T> HeapArray { get; } public T NIL { get; } public bool IsMax { get; } public int Count => HeapArray.Count; /// <param name="heapArray">ヒープ</param> /// <param name="NIL">NILの値</param> /// <param /// name="IsMax">True時:大きい方から取り出す、False時:小さい方から取り出す</param> public PriorityQueue(T NIL, IEnumerable<T> heapArray = null, bool IsMax = true) { this.HeapArray = heapArray == null ? new List<T>() : heapArray.ToList(); this.NIL = NIL; this.IsMax = IsMax; Update(); } /// <summary>KeyのValueを取得</summary> public T this[int id] { get { if (id <= 0 || id > HeapArray.Count) { return NIL; } return HeapArray[id - 1]; } } class Node { public int Key { get; } public T Value => outer[Key]; readonly PriorityQueue<T> outer; public Node(int key, PriorityQueue<T> outer) { Key = key; this.outer = outer; } public Node Left { get { var leftKey = 2 * Key; return new Node(leftKey, outer); } } public Node Right { get { var rightkey = 2 * Key + 1; return new Node(rightkey, outer); } } public Node Parent { get { var parentKey = Key / 2; return new Node(parentKey, outer); } } } private Node GetNode(int key) { return new Node(key, this); } /// <summary>max Heap木とする O(N)</summary> public void Update() { var n = HeapArray.Count() / 2; /// <summary>葉から順に処理を行う</summary> for (int i = n; i >= 1; i--) { Heapify(i); } } /// <summary>idを根とする部分木について、Heap木を維持したまま、idを下降させる</summary> private void Heapify(int key) { var current = GetNode(key); var left = current.Left; var right = current.Right; var largest = current; var sign = IsMax ? 1 : -1; if (left.Value.CompareTo(NIL) != 0 && left.Value.CompareTo(current.Value) * sign > 0) { largest = left; } if (right.Value.CompareTo(NIL) != 0 && right.Value.CompareTo(largest.Value) * sign > 0) { largest = right; } if (largest.Key != key) { HeapArray.Swap(key - 1, largest.Key - 1); // 元と異なるときはSwapする Heapify( largest .Key); // largest.Key は元のkeyの場所。葉で更にMaxHeaptyを行う。 } } /// <summary>keyの値を挿入する</summary> public void Enqueue(T value) { HeapArray.Add(value); var inserted = GetNode(HeapArray.Count); // 末尾に挿入 var parent = inserted.Parent; var sign = IsMax ? 1 : -1; // 挿入Nodeが根になる or 親 > 子になるまで親とNodeを交換 while (inserted.Key > 1 && value.CompareTo(parent.Value) * sign > 0) { HeapArray.Swap(inserted.Key - 1, parent.Key - 1); inserted = parent; parent = inserted.Parent; } } public T Dequeue() { if (HeapArray.Count == 0) { return NIL; } var popVal = HeapArray.First(); var newRootVal = HeapArray.Last(); // 新しい根となる。 HeapArray.RemoveAt(HeapArray.Count - 1); // del last if (HeapArray.Count > 0) { HeapArray[0] = newRootVal; Heapify(1); } return popVal; } public T Peek() { return HeapArray.First(); } public IEnumerator<T> GetEnumerator() { while (HeapArray.Count > 0) { yield return Dequeue(); } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Clear() { HeapArray.Clear(); } public bool Contains(T val) { return HeapArray.Contains(val); } public PriorityQueue<T> Clone() { return new PriorityQueue<T>(NIL, HeapArray.DeepCopy()); } } } /// <summary>拡張メソッドs</summary> static class MyExtention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } public static void Swap<T>(this List<T> list, int i, int j) { var buf = list[i]; list[i] = list[j]; list[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } public static string Left(this string str, int length) { return str.Substring(0, length); } public static string Right(this string str, int length) { return str.Substring(str.Length - length, length); } public static int Find<T>(this T[] array, T obj) { return Array.IndexOf(array, obj); } public static int LastFind<T>(this T[] array, T obj) { return Array.LastIndexOf(array, obj); } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[] array, T value) { for (int i = 0; i < array.Length; i++) { array[i] = value; } } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[,] array, T value) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { array[i, j] = value; } } } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(long a, long n, int mod = 1000000007) { long res = 1; long pow = a; while (n > 0) { if ((n & 1) == 1) { res = (pow * res) % mod; // resにaをかける } pow = (pow * pow) % mod; // 次のaはa^2 n >>= 1; } return (int)res; } /// <summary>約数を列挙</summary> public static long[] Divisors(long n) { var ret = new List<long>(); var sqrt = Math.Ceiling(Math.Sqrt(n)); for (long i = 1; i <= sqrt; i++) { if (i * i > n) { continue; } if (n % i != 0) { continue; } ret.Add(i); if (n / i == i) { continue; } ret.Add(n / i); } return ret.ToArray(); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] InducesOfValue<T>(this T[] arr, T searchValue) { return arr.Select((v, i) => new { v, i }) .Where(o => searchValue.Equals(o.v)) .Select(o => o.i) .ToArray(); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] Induces<T>(this IEnumerable<T> arr, T searchValue) { return arr.ToArray().InducesOfValue(searchValue); } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } // optional namespace Graph { /// <summary>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>有向グラフの隣接行列表現</summary> class AdjacencyMatrixCreator { public int[][] Matrix { get; } public AdjacencyMatrixCreator(int[][] matrix) { this.Matrix = matrix; } /// <summary>ノード数nの隣接行列表現を生成.1オリジン</summary> public AdjacencyMatrixCreator(int n, int defaultVal = 0) { Matrix = new int [n + 1][]; for (int i = 0; i <= n; i++) { Matrix[i] = new int[n + 1]; for (int j = 0; j <= n; j++) { Matrix[i][j] = defaultVal; } } } /// <summary> /// 辺の追加 (行列に1を足す) /// </summary> /// <param name="nodeNo">元ノードのNo</param> /// <param name="outDegree">出次数</param> /// <param name="outNodeNos">向かう先のノードNo</param> public void AddEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) { foreach (var outNodeNo in outNodeNos) { Matrix[nodeNo][outNodeNo] = 1; } } /// <summary> /// 辺の削除 (行列を0にする) /// </summary> /// <param name="nodeNo">元ノードのNo</param> /// <param name="outDegree">出次数</param> /// <param name="outNodeNos">向かう先のノードNo</param> public void DelEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) { foreach (var outNodeNo in outNodeNos) { Matrix[nodeNo][outNodeNo] = 0; } } } } namespace Sort { static class MergeSort { /// <summary>ソートを行う(mutable)</summary> public static void Sort(long[] arr) { Sort(arr, 0, arr.Count()); } private static void Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; Sort(sArr, left, mid); // left ~ mid-1をソート Sort(sArr, mid, right); // mid ~ rightをソート Merge(sArr, left, mid, right); // 昇順に並んだ2つの列を結合する。 } } // arrのleftとrightは昇順に並ぶのでO(n1+n2) private static void Merge(long[] arr, int left, int mid, int right) { var lArr = new long[mid - left + 1]; var rArr = new long[right - mid + 1]; for (int i = 0; i < mid - left; i++) { lArr[i] = arr[left + i]; } lArr[mid - left] = long.MaxValue; for (int i = 0; i < right - mid; i++) { rArr[i] = arr[mid + i]; } rArr[right - mid] = long.MaxValue; int l = 0, r = 0; // arrを並び替える for (int i = left; i < right; i++) { if (lArr[l] > rArr[r]) { arr[i] = rArr[r]; r++; } else { arr[i] = lArr[l]; l++; } } } } static class QuickSort { internal static void Sort(int[] ts) { Sort(ts, 0, ts.Count() - 1); } /// <summary>Quickソート</summary> private static void Sort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); Sort(ts, p, q - 1); Sort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } /// <summary>計数ソート</summary> static class CountingSort { public static int[] Sort(int[] aArr, int k) { int[] b, c; var n = aArr.Length; b = new int[n]; c = Enumerable.Repeat(0, k + 1).ToArray(); for (int i = 0; i < n; i++) { c[aArr[i]]++; } for (int i = 1; i <= k; i++) { c[i] += c[i - 1]; } for (int i = n - 1; i >= 0; i--) { b[c[aArr[i]] - 1] = aArr[i]; c[aArr[i]]--; } return b; } } } namespace Tree { /// <summary>UnionFind木</summary> public class UnionFind { Dictionary<int, int> nodeToRoot; Dictionary<int, int> rank; // その根が配下に何個nodeがぶら下がっているか public UnionFind(int n, int startAt = 0) { nodeToRoot = Enumerable.Range(startAt, n) .ToDictionary(i => i, i => i); // n個根を作る rank = Enumerable.Range(startAt, n).ToDictionary(i => i, i => 0); } /// <summary>根を得る</summary> public int GetRoot(int x) { if (nodeToRoot[x] == x) { // 渡されたノードが根 return x; } nodeToRoot[x] = GetRoot(nodeToRoot[x]); // parentの根を得てset。調べるたびに最適化。 return nodeToRoot[x]; } /// <summary>xとyの木を併合 => 根を同一にする</summary> public void Unite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) { return; // pass } if (rank[rootX] < rank[rootY]) { // yをxへ併合 nodeToRoot[rootX] = nodeToRoot[rootY]; } else { nodeToRoot[rootX] = nodeToRoot[rootY]; if (rank[rootX] == rank[rootY]) { rank[rootX]++; // yの下に配下が1つ追加される。 } } } public bool AreSameRoot(int x, int y) { return GetRoot(x) == GetRoot(y); } } /// <summary>根付き木</summary> public class RootedTree { readonly Dictionary<int, Node> nodes; const int NIL = -1; int startAt; int nNode; class Node { /// <summary>親のID</summary> public int Parent { get; set; } /// <summary>子の最左端</summary> public int LeftChild { get; set; } /// <summary>右の兄弟</summary> public int RightBrother { get; set; } /// <summary>深さ</summary> public int Depth { get; set; } public Node() { Parent = NIL; LeftChild = NIL; RightBrother = NIL; Depth = 0; } } /// <summary>根付き木</summary> public RootedTree(int n, int startAt = 0) { this.nodes = Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node()); this.startAt = startAt; this.nNode = n; } /// <summary>Nodeに子を追加</summary> public void SetChilds(int id, int[] childs) { if (childs.Length == 0) { return; } nodes[id].LeftChild = childs.First(); for (int i = 0; i < childs.Length - 1; i++) { int childId = childs[i]; nodes[childId].Parent = id; nodes[childId].RightBrother = childs[i + 1]; } nodes[childs.Last()].Parent = id; } /// <summary>親Idを取得</summary> public int GetParentId(int id) { return nodes[id].Parent; } /// <summary>子のidを取得</summary> public int[] GetChilds(int id) { var childs = new List<int>(); var child = nodes[id].LeftChild; while (child != NIL) { childs.Add(child); child = nodes[child].RightBrother; } return childs.ToArray(); } int Root = NIL; public int GetRoot() { if (Root == NIL) { var current = nodes.First().Key; // 何でもいい var parent = nodes[current].Parent; while (parent != NIL) { current = parent; parent = nodes[current].Parent; } Root = current; } return Root; } bool isSetedDepth = false; /// <summary>深さを取得</summary> public int GetDepth(int id) { if (!isSetedDepth) { var root = GetRoot(); SetDepth(root, depth: 0); isSetedDepth = true; } var current = id; var parent = nodes[id].Parent; var depth = 0; while (parent != NIL) { current = parent; parent = nodes[current].Parent; depth++; } return depth; } private void SetDepth(int id, int depth) { var node = nodes[id]; node.Depth = depth; if (node.RightBrother != NIL) { SetDepth(node.RightBrother, depth); } if (node.LeftChild != NIL) { SetDepth(node.LeftChild, depth + 1); } } public int NodesCount() { return nodes.Count(); } } /// <summary>二分木</summary> public class BinaryTree { const int NIL = int.MinValue; readonly int startAt; readonly int nNode; class Node { public int Parent { get; set; } public int LeftChild { get; set; } public int RightChild { get; set; } public int Depth { get; set; } public int Height { get; set; } /// <summary>唯一の兄弟</summary> public int Sibling { get; set; } public Node() { Parent = NIL; LeftChild = NIL; RightChild = NIL; Sibling = NIL; Depth = 0; Height = 0; } } Dictionary<int, Node> nodes; public BinaryTree(int n, int startAt) { this.nodes = Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node()); this.startAt = startAt; this.nNode = n; } /// <summary> /// 子をセットする /// </summary> /// <param name="id">ノードのID</param> /// <param name="left">左子ID。存在しない場合は-1</param> /// <param name="right">右子ID。存在しない場合は-1</param> public void SetChilds(int id, int left, int right) { nodes[id].LeftChild = left; nodes[id].RightChild = right; if (left != NIL) { nodes[left].Parent = id; nodes[left].Sibling = right; } if (right != NIL) { nodes[right].Parent = id; nodes[right].Sibling = left; } } /// <summary>Root</summary> int Root = NIL; public int GetRoot() { if (Root == NIL) { var current = nodes.First().Key; var parent = nodes[current].Parent; while (parent != NIL) { current = parent; parent = nodes[current].Parent; } Root = current; } return Root; } #region Depth bool isSetDepth = false; public int GetDepth(int id) { if (!isSetDepth) { var root = GetRoot(); SetDepth(root, 0); isSetDepth = true; } return nodes[id].Depth; } private void SetDepth(int id, int depth) { nodes[id].Depth = depth; if (nodes[id].LeftChild != NIL) { SetDepth(nodes[id].LeftChild, depth + 1); } if (nodes[id].RightChild != NIL) { SetDepth(nodes[id].RightChild, depth + 1); } } #endregion #region Height bool isSetHeight = false; /// <summary>高さを得る</summary> public int GetHeight(int id) { if (!isSetHeight) { var root = GetRoot(); SetHeight(root); isSetHeight = true; } return nodes[id].Height; } public int SetHeight(int id) { var node = nodes[id]; int hLeft = 0; int hRight = 0; if (node.LeftChild != NIL) { hLeft = SetHeight(node.LeftChild) + 1; } if (node.RightChild != NIL) { hRight = SetHeight(node.RightChild) + 1; } node.Height = Math.Max(hLeft, hRight); return node.Height; } #endregion /// <summary>兄弟を得る</summary> public int GetSibling(int id) { return nodes[id].Sibling; } /// <summary>親IDを得る</summary> public int GetParent(int id) { return nodes[id].Parent; } public int[] GetChilds(int id) { var ids = new List<int>(); if (nodes[id].LeftChild != NIL) { ids.Add(nodes[id].LeftChild); } if (nodes[id].RightChild != NIL) { ids.Add(nodes[id].RightChild); } return ids.ToArray(); } /// <summary>左子を取得。存在しない時はint.MinValue</summary> public int GetLeft(int id) { return nodes[id].LeftChild; } /// <summary>右子を取得。存在しない時はint.MinValue</summary> public int GetRight(int id) { return nodes[id].RightChild; } public int NodesCount() { return nodes.Count(); } #region 巡回 private enum OrderType { Pre, In, Post } /// <summary>先行順巡回のNodeIdを取得</summary> public IEnumerable<int> GetPreOrder() { return Process(OrderType.Pre); } /// <summary>中間順巡回のNodeIdを取得</summary> public IEnumerable<int> GetInOrder() { return Process(OrderType.In); } /// <summary>後方順巡回のNodeIdを取得</summary> public IEnumerable<int> GetPostOrder() { return Process(OrderType.Post); } /// <summary>巡回を出力。O(N)</summary> private IEnumerable<int> Process(OrderType orderType) { var order = new List<int>(); var stack = new Stack<int>(); var passed = Enumerable.Range(startAt, nNode) .ToDictionary(i => i, i => false); // 巡回済 var orderAdded = Enumerable.Range(startAt, nNode) .ToDictionary(i => i, i => false); // 処理済 Action<int> addOrder = id => { if (!orderAdded[id]) { order.Add(id); orderAdded[id] = true; } }; stack.Push(GetRoot()); while (stack.Count > 0) { var current = stack.First(); passed[current] = true; if (orderType == OrderType.Pre) { addOrder(current); // 先行順巡回 } int left = GetLeft(current); if (left != -1 && !passed[left]) { stack.Push(left); continue; } if (orderType == OrderType.In) { addOrder(current); // 中間順巡回 } int right = GetRight(current); if (right != -1 && !passed[right]) { stack.Push(right); continue; } if (orderType == OrderType.Post) { addOrder(current);   // 後方順巡回 } stack.Pop(); } return order; } #endregion } /// <summary>二分探索木</summary> public class BinarySearchTree { static readonly Node NIL = new Node(int.MinValue); class Node { public int Key { get; set; } public Node Parent { get; set; } public Node Left { get; set; } public Node Right { get; set; } public Node(int key) { this.Key = key; this.Parent = NIL; this.Left = NIL; this.Right = NIL; } } Node root = NIL; #region Operate public void Insert(int key) { var z = new Node(key); var y = NIL; // xの親 var x = root; // Treeの根 while (x != NIL) { y = x; if (z.Key < x.Key) { x = x.Left; } else { x = x.Right; } } z.Parent = y; if (y == NIL) { root = z; } else if (z.Key < y.Key) { y.Left = z; } else { y.Right = z; } } public bool Find(int key) { var nearLeaf = GetNearLeaf(key); return nearLeaf.Key == key; } private Node GetNearLeaf(int key) { var x = this.root; while (x != NIL && x.Key != key) { if (x.Key < key) { x = x.Right; } else { x = x.Left; } } return x; } public void Delete(int key) { var cand = GetNearLeaf(key); if (cand.Key != key) { throw new KeyNotFoundException(); } DeleteNode(cand); } private void DeleteNode(Node target) { // 削除対象ノードを選択 Node delTarget; if (target.Left == NIL || target.Right == NIL) { delTarget = target; } else { delTarget = NextInOrder(target); } // DelTargetの親の新規子を決める Node newChild; if (delTarget.Left != NIL) { newChild = delTarget.Left; } else { newChild = delTarget.Right; } // 新規子 => 親をつなぐ if (newChild != NIL) { newChild.Parent = delTarget.Parent; } // 親 => 新規子をつなぐ var parent = delTarget.Parent; if (parent == NIL) { root = newChild; } else if (parent.Left == delTarget) { parent.Left = newChild; } else if (parent.Right == delTarget) { parent.Right = newChild; } // 消したノードの値を渡されたNodeに入れる if (delTarget != target) { target.Key = delTarget.Key; } } /// <summary>次の中間順巡回のNodeを取得</summary> /// <returns>NILの時は木が空</returns> private Node NextInOrder(Node node) { if (node.Right == NIL) { var current = node; var parent = node.Parent; // 親をたどっていき、初めて左子となっているNodeを取得 while (parent != NIL && current == parent.Right) { current = parent; parent = current.Parent; } return node.Parent; } // 右部分木より最左を取得 var root = node.Right; while (root.Left != NIL) { root = root.Left; } return root; } /// <summary> /// targetの親の子を、新しい子につなぎ替える /// </summary> /// <param name="target">対象のTarget</param> /// <param name="newChild">つなぎ変えた先の子</param> private static void ChangeParentOfChild(Node target, Node newChild) { var parent = target.Parent; if (parent.Left == target) { parent.Left = newChild; } else if (parent.Right == target) { parent.Right = newChild; } else { throw new KeyNotFoundException(); } } #endregion #region Order public IEnumerable<int> GetInOrder() { var orderGetter = new OrderGetter(); return orderGetter.GetInOrder(root); } public IEnumerable<int> GetPreOrder() { var orderGetter = new OrderGetter(); return orderGetter.GetPreOrder(root); } class OrderGetter { private List<int> process = new List<int>(); public IEnumerable<int> GetInOrder(Node root) { SetInOrder(root); return process; } public IEnumerable<int> GetPreOrder(Node root) { SetPreOrder(root); return process; } private void SetInOrder(Node node) { if (node == NIL) { return; } SetInOrder(node.Left); process.Add(node.Key); SetInOrder(node.Right); } private void SetPreOrder(Node node) { if (node == NIL) { return; } process.Add(node.Key); SetPreOrder(node.Left); SetPreOrder(node.Right); } } #endregion } }
// optional using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; public static class Program { public static void Main() { #region SetAutoFlushIsFalse #if !DEBUG var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); #endif #endregion var xab = ReadLib.ReadAsIntArray(); Console.WriteLine( Math.Abs(xab[0] - xab[1]) < Math.Abs(xab[0] - xab[2]) ? "A" : "B"); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } } static class ReadLib { public static long ReadAsLong() { return long.Parse(Console.ReadLine()); } public static int ReadAsInt() { return int.Parse(Console.ReadLine()); } public static int[] ReadAsIntArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) + step) .ToArray(); } public static long[] ReadAsLongArray(int step = 0) { return Console.ReadLine() .Split(' ') .Select(s => long.Parse(s) + step) .ToArray(); } public static ulong[] ReadAsULongArray() { return Console.ReadLine().Split(' ').Select(s => ulong.Parse(s)).ToArray(); } public static string[] ReadAsStringArray() { return Console.ReadLine().Split(' '); } public static int[] ReadNTimesAsInt(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine()) + step) .ToArray(); } public static char[][] ReadNTimesAsCharArray(int n) { return Enumerable.Range(1, n) .Select(i => Console.ReadLine().ToArray()) .ToArray(); } public static long[] ReadNTimesAsLong(int n, int step = 0) { return Enumerable.Range(1, n) .Select(s => long.Parse(Console.ReadLine()) + step) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n, int step = 0) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray(step)).ToArray(); } public static string[] ReadNTimesAsString(int n) { return Enumerable.Range(1, n).Select(s => Console.ReadLine()).ToArray(); } } namespace Heaps { /// <summary>優先度付きキュー</summary> public class PriorityQueue<T> : IEnumerable<T>, IReadOnlyCollection<T> where T : IComparable<T> { public List<T> HeapArray { get; } public T NIL { get; } public bool IsMax { get; } public int Count => HeapArray.Count; /// <param name="heapArray">ヒープ</param> /// <param name="NIL">NILの値</param> /// <param /// name="IsMax">True時:大きい方から取り出す、False時:小さい方から取り出す</param> public PriorityQueue(T NIL, IEnumerable<T> heapArray = null, bool IsMax = true) { this.HeapArray = heapArray == null ? new List<T>() : heapArray.ToList(); this.NIL = NIL; this.IsMax = IsMax; Update(); } /// <summary>KeyのValueを取得</summary> public T this[int id] { get { if (id <= 0 || id > HeapArray.Count) { return NIL; } return HeapArray[id - 1]; } } class Node { public int Key { get; } public T Value => outer[Key]; readonly PriorityQueue<T> outer; public Node(int key, PriorityQueue<T> outer) { Key = key; this.outer = outer; } public Node Left { get { var leftKey = 2 * Key; return new Node(leftKey, outer); } } public Node Right { get { var rightkey = 2 * Key + 1; return new Node(rightkey, outer); } } public Node Parent { get { var parentKey = Key / 2; return new Node(parentKey, outer); } } } private Node GetNode(int key) { return new Node(key, this); } /// <summary>max Heap木とする O(N)</summary> public void Update() { var n = HeapArray.Count() / 2; /// <summary>葉から順に処理を行う</summary> for (int i = n; i >= 1; i--) { Heapify(i); } } /// <summary>idを根とする部分木について、Heap木を維持したまま、idを下降させる</summary> private void Heapify(int key) { var current = GetNode(key); var left = current.Left; var right = current.Right; var largest = current; var sign = IsMax ? 1 : -1; if (left.Value.CompareTo(NIL) != 0 && left.Value.CompareTo(current.Value) * sign > 0) { largest = left; } if (right.Value.CompareTo(NIL) != 0 && right.Value.CompareTo(largest.Value) * sign > 0) { largest = right; } if (largest.Key != key) { HeapArray.Swap(key - 1, largest.Key - 1); // 元と異なるときはSwapする Heapify( largest .Key); // largest.Key は元のkeyの場所。葉で更にMaxHeaptyを行う。 } } /// <summary>keyの値を挿入する</summary> public void Enqueue(T value) { HeapArray.Add(value); var inserted = GetNode(HeapArray.Count); // 末尾に挿入 var parent = inserted.Parent; var sign = IsMax ? 1 : -1; // 挿入Nodeが根になる or 親 > 子になるまで親とNodeを交換 while (inserted.Key > 1 && value.CompareTo(parent.Value) * sign > 0) { HeapArray.Swap(inserted.Key - 1, parent.Key - 1); inserted = parent; parent = inserted.Parent; } } public T Dequeue() { if (HeapArray.Count == 0) { return NIL; } var popVal = HeapArray.First(); var newRootVal = HeapArray.Last(); // 新しい根となる。 HeapArray.RemoveAt(HeapArray.Count - 1); // del last if (HeapArray.Count > 0) { HeapArray[0] = newRootVal; Heapify(1); } return popVal; } public T Peek() { return HeapArray.First(); } public IEnumerator<T> GetEnumerator() { while (HeapArray.Count > 0) { yield return Dequeue(); } } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public void Clear() { HeapArray.Clear(); } public bool Contains(T val) { return HeapArray.Contains(val); } public PriorityQueue<T> Clone() { return new PriorityQueue<T>(NIL, HeapArray.DeepCopy()); } } } /// <summary>拡張メソッドs</summary> static class MyExtention { /// <summary>iとjを入れ替える</summary> public static void Swap<T>(this T[] arr, int i, int j) { var buf = arr[i]; arr[i] = arr[j]; arr[j] = buf; } public static void Swap<T>(this List<T> list, int i, int j) { var buf = list[i]; list[i] = list[j]; list[j] = buf; } /// <summary> /// partition。末尾sArr[r]を基準として、左に基準より小さい数、右に基準より大きい数が存在するように配列を並び替える。 /// </summary> /// <param name="sArr"></param> /// <param name="p">partitionの先頭の添字</param> /// <param name="r">partitionの末尾の添字</param> /// <returns>partitionの基準が存在する添字</returns> public static int Partition(this int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } /// <summary>深いコピーをする</summary> public static T DeepCopy<T>(this T obj) { T result; var b = new BinaryFormatter(); using (var mem = new MemoryStream()) { b.Serialize(mem, obj); // binaryFormatterによりobjをmemにserial化して書き出す mem.Position = 0; // memのpotisionを先頭に戻す result = (T)b.Deserialize(mem); // memの内容を読み取る。 } return result; } public static string Left(this string str, int length) { return str.Substring(0, length); } public static string Right(this string str, int length) { return str.Substring(str.Length - length, length); } public static int Find<T>(this T[] array, T obj) { return Array.IndexOf(array, obj); } public static int LastFind<T>(this T[] array, T obj) { return Array.LastIndexOf(array, obj); } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[] array, T value) { for (int i = 0; i < array.Length; i++) { array[i] = value; } } /// <summary>同一の値で埋める</summary> public static void Initialize<T>(this T[,] array, T value) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { array[i, j] = value; } } } } static class MyMath { /// <summary>階乗</summary> public static long Factorial(int n) { if (n == 0) { return 1; } return Permutation(n, 0); } public static long Permutation(int n, int k) { return Enumerable.Range(0, n - k) .Select(i => n - i) .Aggregate(1, (b, i) => b * i); } #region FullPower /// <summary>総乗、π</summary> public static long FullPower(IEnumerable<long> vs) { return vs.Aggregate(1L, (a, b) => a * b); } public static long FullPower(IEnumerable<int> vs) { return vs.Aggregate(1L, (a, b) => a * b); } #endregion /// <summary>最大公約数</summary> public static long Gcd(long item1, long item2) { var a = Math.Max(item1, item2); var b = Math.Min(item1, item2); while (true) { long mod; Math.DivRem(a, b, out mod); if (mod == 0) { break; } a = b; b = mod; } return b; } /// <summary>約分。最大公約数で割ったものを返す。</summary> public static Tuple<long, long> DeviedByGcd(long item1, long item2) { var gcd = Gcd(item1, item2); return new Tuple<long, long>(item1 / gcd, item2 / gcd); } public static long Lcm(int item1, int item2) { return Math.BigMul(item1, item2) / Gcd(item1, item2); } public static ModCombination ModCombination(int maxN, int mod = 1000000007) { return new ModCombination(maxN, mod); } /// <summary>a^n mod</summary> public static int ModPow(long a, long n, int mod = 1000000007) { long res = 1; long pow = a; while (n > 0) { if ((n & 1) == 1) { res = (pow * res) % mod; // resにaをかける } pow = (pow * pow) % mod; // 次のaはa^2 n >>= 1; } return (int)res; } /// <summary>約数を列挙</summary> public static long[] Divisors(long n) { var ret = new List<long>(); var sqrt = Math.Ceiling(Math.Sqrt(n)); for (long i = 1; i <= sqrt; i++) { if (i * i > n) { continue; } if (n % i != 0) { continue; } ret.Add(i); if (n / i == i) { continue; } ret.Add(n / i); } return ret.ToArray(); } } static class MyMethod { /// <summary>数え上げて、key, 出現回数に変換</summary> public static Dictionary<T, int> CountUp<T>(IEnumerable<T> str) { return str.GroupBy(c => c) .Select(g => new KeyValuePair<T, int>(g.Key, g.Count())) .ToDictionary(e => e.Key, e => e.Value); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] InducesOfValue<T>(this T[] arr, T searchValue) { return arr.Select((v, i) => new { v, i }) .Where(o => searchValue.Equals(o.v)) .Select(o => o.i) .ToArray(); } /// <summary>ある要素を持つindexをすべて返す</summary> public static int[] Induces<T>(this IEnumerable<T> arr, T searchValue) { return arr.ToArray().InducesOfValue(searchValue); } } /// <summary>組み合わせ</summary> class ModCombination { private int mod; private int[] fac; private int[] finv; private int[] inv; public ModCombination(int max, int mod = 1000000007) { this.mod = mod; fac = new int[max]; // modが法のn!の列 inv = new int[max]; // indexの逆元の列 finv = new int[max]; // modを法とした、invの累積の累積 fac[0] = 1; fac[1] = 1; finv[0] = 1; finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = (int)(Math.BigMul(fac[i - 1], i) % mod); // factorを求める var s = Math.BigMul(inv[mod % i], mod / i) % mod; inv[i] = (int)(mod - s);   // iに対する逆元を求める finv[i] = (int)(Math.BigMul(finv[i - 1], inv[i]) % mod); } } /// <summary>nCk</summary> public int Calculation(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (int)(Math.BigMul(fac[n], (int)(Math.BigMul(finv[k], finv[n - k]) % mod)) % mod); } } /// <summary>あまりを計算するためのintのラッパー</summary> struct ModInt { int Value { get; } int Mod { get; } public override string ToString() { return Value.ToString(); } public static explicit operator ModInt(long value) { return new ModInt(value); } public ModInt(long value, int mod = 1000000007) { this.Value = (int)(value % mod); this.Mod = mod; } public static explicit operator int(ModInt modInt) { return modInt.Value; } private static void CheckNotEqualMod(ModInt item1, ModInt item2) { if (item1.Mod != item2.Mod) { throw new Exception("mod not equal"); } } public static ModInt operator +(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value + item2.Value; return new ModInt(value, item1.Mod); } public static ModInt operator *(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = Math.BigMul(item1.Value, item2.Value); return new ModInt(value, item1.Mod); } public static ModInt operator -(ModInt item1, ModInt item2) { CheckNotEqualMod(item1, item2); long value = item1.Value - item2.Value; if (value < 0) { value += item1.Mod; } return new ModInt(value, item1.Mod); } public static ModInt operator +(ModInt item1, int item2) { return item1 + new ModInt(item2, item1.Mod); } public static ModInt operator *(ModInt item1, int item2) { return item1 * new ModInt(item2, item1.Mod); } public static ModInt operator -(ModInt item1, int item2) { return item1 - new ModInt(item2, item1.Mod); } public override int GetHashCode() { return this.Value; } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } var modIntObj = (ModInt)obj; return modIntObj.Value == this.Value; } public static bool operator ==(ModInt item1, ModInt item2) { return item1.Value == item2.Value; } public static bool operator !=(ModInt item1, ModInt item2) { return !(item1 == item2); } public static bool operator ==(ModInt item1, int item2) { return item1.Value == item2; } public static bool operator !=(ModInt item1, int item2) { return !(item1.Value == item2); } public static bool operator >=(ModInt item1, ModInt item2) { return item1.Value >= item2.Value; } public static bool operator <=(ModInt item1, ModInt item2) { return item1.Value <= item2.Value; } public static bool operator >=(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator <=(ModInt item1, int item2) { return item1.Value <= item2; } public static bool operator>(ModInt item1, ModInt item2) { return item1.Value > item2.Value; } public static bool operator<(ModInt item1, ModInt item2) { return item1.Value < item2.Value; } public static bool operator>(ModInt item1, int item2) { return item1.Value >= item2; } public static bool operator<(ModInt item1, int item2) { return item1.Value <= item2; } } // optional namespace Graph { /// <summary>無向グラフ</summary> class UndirectedGraph { public Dictionary<int, List<int>> Graph { get; } /// <param name="graphArr">point1 to point2</param> /// <param name="n">グラフの全要素数</param> public UndirectedGraph(int[][] graphArr, int n) { Graph = new Dictionary<int, List<int>>(); for (int i = 1; i <= n; i++) { Graph.Add(i, new List<int>()); } foreach (var arr in graphArr) { Graph[arr[0]].Add(arr[1]); Graph[arr[1]].Add(arr[0]); } } } /// <summary>有向グラフの隣接行列表現</summary> class AdjacencyMatrixCreator { public int[][] Matrix { get; } public AdjacencyMatrixCreator(int[][] matrix) { this.Matrix = matrix; } /// <summary>ノード数nの隣接行列表現を生成.1オリジン</summary> public AdjacencyMatrixCreator(int n, int defaultVal = 0) { Matrix = new int [n + 1][]; for (int i = 0; i <= n; i++) { Matrix[i] = new int[n + 1]; for (int j = 0; j <= n; j++) { Matrix[i][j] = defaultVal; } } } /// <summary> /// 辺の追加 (行列に1を足す) /// </summary> /// <param name="nodeNo">元ノードのNo</param> /// <param name="outDegree">出次数</param> /// <param name="outNodeNos">向かう先のノードNo</param> public void AddEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) { foreach (var outNodeNo in outNodeNos) { Matrix[nodeNo][outNodeNo] = 1; } } /// <summary> /// 辺の削除 (行列を0にする) /// </summary> /// <param name="nodeNo">元ノードのNo</param> /// <param name="outDegree">出次数</param> /// <param name="outNodeNos">向かう先のノードNo</param> public void DelEdgeVal(int nodeNo, int outDegree, int[] outNodeNos) { foreach (var outNodeNo in outNodeNos) { Matrix[nodeNo][outNodeNo] = 0; } } } } namespace Sort { static class MergeSort { /// <summary>ソートを行う(mutable)</summary> public static void Sort(long[] arr) { Sort(arr, 0, arr.Count()); } private static void Sort(long[] sArr, int left, int right) { if (left + 1 < right) { var mid = (left + right) / 2; Sort(sArr, left, mid); // left ~ mid-1をソート Sort(sArr, mid, right); // mid ~ rightをソート Merge(sArr, left, mid, right); // 昇順に並んだ2つの列を結合する。 } } // arrのleftとrightは昇順に並ぶのでO(n1+n2) private static void Merge(long[] arr, int left, int mid, int right) { var lArr = new long[mid - left + 1]; var rArr = new long[right - mid + 1]; for (int i = 0; i < mid - left; i++) { lArr[i] = arr[left + i]; } lArr[mid - left] = long.MaxValue; for (int i = 0; i < right - mid; i++) { rArr[i] = arr[mid + i]; } rArr[right - mid] = long.MaxValue; int l = 0, r = 0; // arrを並び替える for (int i = left; i < right; i++) { if (lArr[l] > rArr[r]) { arr[i] = rArr[r]; r++; } else { arr[i] = lArr[l]; l++; } } } } static class QuickSort { internal static void Sort(int[] ts) { Sort(ts, 0, ts.Count() - 1); } /// <summary>Quickソート</summary> private static void Sort(int[] ts, int p, int r) { if (p < r) { var q = Partition(ts, p, r); Sort(ts, p, q - 1); Sort(ts, q + 1, r); } } public static int Partition(int[] sArr, int p, int r) { var x = sArr[r]; var i = p - 1; for (int j = p; j < r; j++) { if (sArr[j] <= x) { i++; sArr.Swap(i, j); } } sArr.Swap(i + 1, r); return i + 1; } } /// <summary>計数ソート</summary> static class CountingSort { public static int[] Sort(int[] aArr, int k) { int[] b, c; var n = aArr.Length; b = new int[n]; c = Enumerable.Repeat(0, k + 1).ToArray(); for (int i = 0; i < n; i++) { c[aArr[i]]++; } for (int i = 1; i <= k; i++) { c[i] += c[i - 1]; } for (int i = n - 1; i >= 0; i--) { b[c[aArr[i]] - 1] = aArr[i]; c[aArr[i]]--; } return b; } } } namespace Tree { /// <summary>UnionFind木</summary> public class UnionFind { Dictionary<int, int> nodeToRoot; Dictionary<int, int> rank; // その根が配下に何個nodeがぶら下がっているか public UnionFind(int n, int startAt = 0) { nodeToRoot = Enumerable.Range(startAt, n) .ToDictionary(i => i, i => i); // n個根を作る rank = Enumerable.Range(startAt, n).ToDictionary(i => i, i => 0); } /// <summary>根を得る</summary> public int GetRoot(int x) { if (nodeToRoot[x] == x) { // 渡されたノードが根 return x; } nodeToRoot[x] = GetRoot(nodeToRoot[x]); // parentの根を得てset。調べるたびに最適化。 return nodeToRoot[x]; } /// <summary>xとyの木を併合 => 根を同一にする</summary> public void Unite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) { return; // pass } if (rank[rootX] < rank[rootY]) { // yをxへ併合 nodeToRoot[rootX] = nodeToRoot[rootY]; } else { nodeToRoot[rootX] = nodeToRoot[rootY]; if (rank[rootX] == rank[rootY]) { rank[rootX]++; // yの下に配下が1つ追加される。 } } } public bool AreSameRoot(int x, int y) { return GetRoot(x) == GetRoot(y); } } /// <summary>根付き木</summary> public class RootedTree { readonly Dictionary<int, Node> nodes; const int NIL = -1; int startAt; int nNode; class Node { /// <summary>親のID</summary> public int Parent { get; set; } /// <summary>子の最左端</summary> public int LeftChild { get; set; } /// <summary>右の兄弟</summary> public int RightBrother { get; set; } /// <summary>深さ</summary> public int Depth { get; set; } public Node() { Parent = NIL; LeftChild = NIL; RightBrother = NIL; Depth = 0; } } /// <summary>根付き木</summary> public RootedTree(int n, int startAt = 0) { this.nodes = Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node()); this.startAt = startAt; this.nNode = n; } /// <summary>Nodeに子を追加</summary> public void SetChilds(int id, int[] childs) { if (childs.Length == 0) { return; } nodes[id].LeftChild = childs.First(); for (int i = 0; i < childs.Length - 1; i++) { int childId = childs[i]; nodes[childId].Parent = id; nodes[childId].RightBrother = childs[i + 1]; } nodes[childs.Last()].Parent = id; } /// <summary>親Idを取得</summary> public int GetParentId(int id) { return nodes[id].Parent; } /// <summary>子のidを取得</summary> public int[] GetChilds(int id) { var childs = new List<int>(); var child = nodes[id].LeftChild; while (child != NIL) { childs.Add(child); child = nodes[child].RightBrother; } return childs.ToArray(); } int Root = NIL; public int GetRoot() { if (Root == NIL) { var current = nodes.First().Key; // 何でもいい var parent = nodes[current].Parent; while (parent != NIL) { current = parent; parent = nodes[current].Parent; } Root = current; } return Root; } bool isSetedDepth = false; /// <summary>深さを取得</summary> public int GetDepth(int id) { if (!isSetedDepth) { var root = GetRoot(); SetDepth(root, depth: 0); isSetedDepth = true; } var current = id; var parent = nodes[id].Parent; var depth = 0; while (parent != NIL) { current = parent; parent = nodes[current].Parent; depth++; } return depth; } private void SetDepth(int id, int depth) { var node = nodes[id]; node.Depth = depth; if (node.RightBrother != NIL) { SetDepth(node.RightBrother, depth); } if (node.LeftChild != NIL) { SetDepth(node.LeftChild, depth + 1); } } public int NodesCount() { return nodes.Count(); } } /// <summary>二分木</summary> public class BinaryTree { const int NIL = int.MinValue; readonly int startAt; readonly int nNode; class Node { public int Parent { get; set; } public int LeftChild { get; set; } public int RightChild { get; set; } public int Depth { get; set; } public int Height { get; set; } /// <summary>唯一の兄弟</summary> public int Sibling { get; set; } public Node() { Parent = NIL; LeftChild = NIL; RightChild = NIL; Sibling = NIL; Depth = 0; Height = 0; } } Dictionary<int, Node> nodes; public BinaryTree(int n, int startAt) { this.nodes = Enumerable.Range(startAt, n).ToDictionary(i => i, i => new Node()); this.startAt = startAt; this.nNode = n; } /// <summary> /// 子をセットする /// </summary> /// <param name="id">ノードのID</param> /// <param name="left">左子ID。存在しない場合は-1</param> /// <param name="right">右子ID。存在しない場合は-1</param> public void SetChilds(int id, int left, int right) { nodes[id].LeftChild = left; nodes[id].RightChild = right; if (left != NIL) { nodes[left].Parent = id; nodes[left].Sibling = right; } if (right != NIL) { nodes[right].Parent = id; nodes[right].Sibling = left; } } /// <summary>Root</summary> int Root = NIL; public int GetRoot() { if (Root == NIL) { var current = nodes.First().Key; var parent = nodes[current].Parent; while (parent != NIL) { current = parent; parent = nodes[current].Parent; } Root = current; } return Root; } #region Depth bool isSetDepth = false; public int GetDepth(int id) { if (!isSetDepth) { var root = GetRoot(); SetDepth(root, 0); isSetDepth = true; } return nodes[id].Depth; } private void SetDepth(int id, int depth) { nodes[id].Depth = depth; if (nodes[id].LeftChild != NIL) { SetDepth(nodes[id].LeftChild, depth + 1); } if (nodes[id].RightChild != NIL) { SetDepth(nodes[id].RightChild, depth + 1); } } #endregion #region Height bool isSetHeight = false; /// <summary>高さを得る</summary> public int GetHeight(int id) { if (!isSetHeight) { var root = GetRoot(); SetHeight(root); isSetHeight = true; } return nodes[id].Height; } public int SetHeight(int id) { var node = nodes[id]; int hLeft = 0; int hRight = 0; if (node.LeftChild != NIL) { hLeft = SetHeight(node.LeftChild) + 1; } if (node.RightChild != NIL) { hRight = SetHeight(node.RightChild) + 1; } node.Height = Math.Max(hLeft, hRight); return node.Height; } #endregion /// <summary>兄弟を得る</summary> public int GetSibling(int id) { return nodes[id].Sibling; } /// <summary>親IDを得る</summary> public int GetParent(int id) { return nodes[id].Parent; } public int[] GetChilds(int id) { var ids = new List<int>(); if (nodes[id].LeftChild != NIL) { ids.Add(nodes[id].LeftChild); } if (nodes[id].RightChild != NIL) { ids.Add(nodes[id].RightChild); } return ids.ToArray(); } /// <summary>左子を取得。存在しない時はint.MinValue</summary> public int GetLeft(int id) { return nodes[id].LeftChild; } /// <summary>右子を取得。存在しない時はint.MinValue</summary> public int GetRight(int id) { return nodes[id].RightChild; } public int NodesCount() { return nodes.Count(); } #region 巡回 private enum OrderType { Pre, In, Post } /// <summary>先行順巡回のNodeIdを取得</summary> public IEnumerable<int> GetPreOrder() { return Process(OrderType.Pre); } /// <summary>中間順巡回のNodeIdを取得</summary> public IEnumerable<int> GetInOrder() { return Process(OrderType.In); } /// <summary>後方順巡回のNodeIdを取得</summary> public IEnumerable<int> GetPostOrder() { return Process(OrderType.Post); } /// <summary>巡回を出力。O(N)</summary> private IEnumerable<int> Process(OrderType orderType) { var order = new List<int>(); var stack = new Stack<int>(); var passed = Enumerable.Range(startAt, nNode) .ToDictionary(i => i, i => false); // 巡回済 var orderAdded = Enumerable.Range(startAt, nNode) .ToDictionary(i => i, i => false); // 処理済 Action<int> addOrder = id => { if (!orderAdded[id]) { order.Add(id); orderAdded[id] = true; } }; stack.Push(GetRoot()); while (stack.Count > 0) { var current = stack.First(); passed[current] = true; if (orderType == OrderType.Pre) { addOrder(current); // 先行順巡回 } int left = GetLeft(current); if (left != -1 && !passed[left]) { stack.Push(left); continue; } if (orderType == OrderType.In) { addOrder(current); // 中間順巡回 } int right = GetRight(current); if (right != -1 && !passed[right]) { stack.Push(right); continue; } if (orderType == OrderType.Post) { addOrder(current);   // 後方順巡回 } stack.Pop(); } return order; } #endregion } /// <summary>二分探索木</summary> public class BinarySearchTree { static readonly Node NIL = new Node(int.MinValue); class Node { public int Key { get; set; } public Node Parent { get; set; } public Node Left { get; set; } public Node Right { get; set; } public Node(int key) { this.Key = key; this.Parent = NIL; this.Left = NIL; this.Right = NIL; } } Node root = NIL; #region Operate public void Insert(int key) { var z = new Node(key); var y = NIL; // xの親 var x = root; // Treeの根 while (x != NIL) { y = x; if (z.Key < x.Key) { x = x.Left; } else { x = x.Right; } } z.Parent = y; if (y == NIL) { root = z; } else if (z.Key < y.Key) { y.Left = z; } else { y.Right = z; } } public bool Find(int key) { var nearLeaf = GetNearLeaf(key); return nearLeaf.Key == key; } private Node GetNearLeaf(int key) { var x = this.root; while (x != NIL && x.Key != key) { if (x.Key < key) { x = x.Right; } else { x = x.Left; } } return x; } public void Delete(int key) { var cand = GetNearLeaf(key); if (cand.Key != key) { throw new KeyNotFoundException(); } DeleteNode(cand); } private void DeleteNode(Node target) { // 削除対象ノードを選択 Node delTarget; if (target.Left == NIL || target.Right == NIL) { delTarget = target; } else { delTarget = NextInOrder(target); } // DelTargetの親の新規子を決める Node newChild; if (delTarget.Left != NIL) { newChild = delTarget.Left; } else { newChild = delTarget.Right; } // 新規子 => 親をつなぐ if (newChild != NIL) { newChild.Parent = delTarget.Parent; } // 親 => 新規子をつなぐ var parent = delTarget.Parent; if (parent == NIL) { root = newChild; } else if (parent.Left == delTarget) { parent.Left = newChild; } else if (parent.Right == delTarget) { parent.Right = newChild; } // 消したノードの値を渡されたNodeに入れる if (delTarget != target) { target.Key = delTarget.Key; } } /// <summary>次の中間順巡回のNodeを取得</summary> /// <returns>NILの時は木が空</returns> private Node NextInOrder(Node node) { if (node.Right == NIL) { var current = node; var parent = node.Parent; // 親をたどっていき、初めて左子となっているNodeを取得 while (parent != NIL && current == parent.Right) { current = parent; parent = current.Parent; } return node.Parent; } // 右部分木より最左を取得 var root = node.Right; while (root.Left != NIL) { root = root.Left; } return root; } /// <summary> /// targetの親の子を、新しい子につなぎ替える /// </summary> /// <param name="target">対象のTarget</param> /// <param name="newChild">つなぎ変えた先の子</param> private static void ChangeParentOfChild(Node target, Node newChild) { var parent = target.Parent; if (parent.Left == target) { parent.Left = newChild; } else if (parent.Right == target) { parent.Right = newChild; } else { throw new KeyNotFoundException(); } } #endregion #region Order public IEnumerable<int> GetInOrder() { var orderGetter = new OrderGetter(); return orderGetter.GetInOrder(root); } public IEnumerable<int> GetPreOrder() { var orderGetter = new OrderGetter(); return orderGetter.GetPreOrder(root); } class OrderGetter { private List<int> process = new List<int>(); public IEnumerable<int> GetInOrder(Node root) { SetInOrder(root); return process; } public IEnumerable<int> GetPreOrder(Node root) { SetPreOrder(root); return process; } private void SetInOrder(Node node) { if (node == NIL) { return; } SetInOrder(node.Left); process.Add(node.Key); SetInOrder(node.Right); } private void SetPreOrder(Node node) { if (node == NIL) { return; } process.Add(node.Key); SetPreOrder(node.Left); SetPreOrder(node.Right); } } #endregion } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18]]
8
7,311
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace At { class Program { static void Main(string[] args) { var input = ReadInts(); var A = Math.Abs(input[0] - input[1]); var B = Math.Abs(input[2] - input[1]); if (A > B) { WriteLine("A"); } else { WriteLine("B"); } } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace At { class Program { static void Main(string[] args) { var input = ReadInts(); var A = Math.Abs(input[0] - input[1]); var B = Math.Abs(input[0] - input[2]); if (A < B) { WriteLine("A"); } else { WriteLine("B"); } } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 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], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
291
6
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); Console.WriteLine( Math.Abs(input[0] - input[1]) > Math.Abs(input[0] - input[2]) ? "A" : "B"); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int n = 100; /* long n = long.Parse(Console.ReadLine()); long[] input = new long[5]; for(int a = 0; a < 5; a++) { input[a]=long.Parse(Console.ReadLine()); } */ int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); Console.WriteLine( Math.Abs(input[0] - input[1]) < Math.Abs(input[0] - input[2]) ? "A" : "B"); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18]]
8
121
2
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; static void SolveA() { var o = ReadAndParseIntArr(); int x = o[0]; int a = o[1]; int b = o[2]; string ans = Math.Abs(x - a) > Math.Abs(x - b) ? "A" : "B"; Console.WriteLine(ans); } #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 long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static 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; static void SolveA() { var o = ReadAndParseIntArr(); int x = o[0]; int a = o[1]; int b = o[2]; string ans = Math.Abs(x - a) < Math.Abs(x - b) ? "A" : "B"; Console.WriteLine(ans); } #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 long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static 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, 200, 0, 212, 0, 41, 15, 16, 17, 47], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 18]]
8
428
2
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] input = ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int b = int.Parse(input[2]); // string temp = ReadLine(); // int a = int.Parse(ReadLine()); if (Abs(n - m) > Abs(n - b)) { WriteLine("A"); } else { WriteLine("B"); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] input = ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int b = int.Parse(input[2]); // string temp = ReadLine(); // int a = int.Parse(ReadLine()); if (Abs(n - m) < Abs(n - b)) { WriteLine("A"); } else { WriteLine("B"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
132
2
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int x = int.Parse(input[0]); int a = int.Parse(input[1]); int b = int.Parse(input[2]); int xa, xb; if (x < a) xa = a - x; else xa = x - a; if (x < b) xb = b - x; else xb = x - b; if (xa < xb) Console.WriteLine("{0}", xa); else Console.WriteLine("{0}", xb); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int x = int.Parse(input[0]); int a = int.Parse(input[1]); int b = int.Parse(input[2]); int xa, xb; if (x < a) xa = a - x; else xa = x - a; if (x < b) xb = b - x; else xb = x - b; if (xa < xb) Console.WriteLine("A"); else Console.WriteLine("B"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 57, 64, 1, 0, 213, 3, 4, 0, 21], ["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 75, 1, 0, 213, 3, 4, 0, 21], ["-", 75, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
147
8
using System; using System.Linq; namespace abc071_a { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(Math.Abs(x[0] - x[1]) > Math.Abs(x[0] - x[2]) ? "A" : "B"); } } }
using System; using System.Linq; namespace abc071_a { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(Math.Abs(x[0] - x[1]) < Math.Abs(x[0] - x[2]) ? "A" : "B"); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18]]
8
96
2
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { // int N = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); for (int i = 0; i < 26; i++) { if (!s.Contains(char.ConvertFromUtf32('a' + i))) { Console.WriteLine(char.ConvertFromUtf32('a' + i)); return; } } Console.WriteLine("none"); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { // int N = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); for (int i = 0; i < 26; i++) { if (!s.Contains(char.ConvertFromUtf32('a' + i))) { Console.WriteLine(char.ConvertFromUtf32('a' + i)); return; } } Console.WriteLine("None"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
100
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var S = sc.ReadStr(); var table = new bool[26]; foreach (var c in S) { var i = (int)c - (int)'a'; table[i] = true; } if (table.All(t => t)) { Console.WriteLine("None"); } else { var ans = ""; for (int i = 0; i < 26; i++) { if (table[i] == false) { ans += (char)('A' + i); } } Console.WriteLine(ans); } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var S = sc.ReadStr(); var table = new bool[26]; foreach (var c in S) { var i = (int)c - (int)'a'; table[i] = true; } if (table.All(t => t)) { Console.WriteLine("None"); } else { var ans = ""; for (int i = 0; i < 26; i++) { if (table[i] == false) { ans += (char)('a' + i); break; } } Console.WriteLine(ans); } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 12, 74, 51, 23, 0, 16, 31, 252, 0, 253], ["+", 12, 74, 51, 23, 0, 16, 31, 252, 0, 253], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
1,128
4
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { int N = re.i(); string S = re.s(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = (S[i] == '1') ? 1 : 0; } int count = 0; List<int> L = new List<int>(); int c = 0; for (int i = 0; i < N; i++) { if (A[i] == 1) { c++; } else if (c == 0) { count += Calc(L.ToArray()); L = new List<int>(); } else { L.Add(c); c = 0; } } if (c != 0) { L.Add(c); } count += Calc(L.ToArray()); sb.Append(count + "\n"); } int Calc(int[] A) { int N = A.Length; if (A.Length <= 1) { return 0; } int[] DPL = new int[N - 1]; int[] DPR = new int[N - 1]; int[] DPN = new int[N - 1]; DPL[0] = A[0]; DPR[0] = A[1]; DPN[0] = 0; for (int i = 1; i < N - 1; i++) { int count1 = A[i] == 1 ? 0 : DPL[i - 1] + A[i] - 1; int count2 = DPN[i - 1] + A[i]; DPL[i] = Math.Max(count1, count2); DPN[i] = Math.Max(DPL[i - 1], Math.Max(DPR[i - 1], DPN[i - 1])); DPR[i] = DPN[i - 1] + A[i + 1]; if (A[i] != 1) { DPR[i] = Math.Max(DPR[i], DPL[i - 1] + A[i + 1]); DPR[i] = Math.Max(DPR[i], DPL[i - 1] + A[i + 1] - 1); } } return Math.Max(DPL[N - 2], Math.Max(DPR[N - 2], DPN[N - 2])); } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { int N = re.i(); string S = re.s(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = (S[i] == '1') ? 1 : 0; } int count = 0; List<int> L = new List<int>(); int c = 0; for (int i = 0; i < N; i++) { if (A[i] == 1) { c++; } else if (c == 0) { count += Calc(L.ToArray()); L = new List<int>(); } else { L.Add(c); c = 0; } } if (c != 0) { L.Add(c); } count += Calc(L.ToArray()); sb.Append(count + "\n"); } int Calc(int[] A) { int N = A.Length; if (A.Length <= 1) { return 0; } int[] DPL = new int[N - 1]; int[] DPR = new int[N - 1]; int[] DPN = new int[N - 1]; DPL[0] = A[0]; DPR[0] = A[1]; DPN[0] = 0; for (int i = 1; i < N - 1; i++) { int count1 = A[i] == 1 ? 0 : DPL[i - 1] + A[i] - 1; int count2 = DPN[i - 1] + A[i]; DPL[i] = Math.Max(count1, count2); DPN[i] = Math.Max(DPL[i - 1], Math.Max(DPR[i - 1], DPN[i - 1])); DPR[i] = DPN[i - 1] + A[i + 1]; if (A[i] != 1) { DPR[i] = Math.Max(DPR[i], DPL[i - 1] + A[i + 1]); DPR[i] = Math.Max(DPR[i], DPR[i - 1] + A[i + 1] - 1); } } return Math.Max(DPL[N - 2], Math.Max(DPR[N - 2], DPN[N - 2])); } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
[["-", 0, 28, 0, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 204, 205, 22]]
8
2,192
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { long tot = 0; int v = 0; for (int i = 0; i < N; i++) { tot += B[i]; v |= A[i]; } if (v <= K) { Console.WriteLine(tot); return; } long min = long.MaxValue; bool[] del = new bool[N]; for (int j = 30; j >= 0; j--) { int kj = (K >> j) & 1; int vj = (v >> j) & 1; // Console.WriteLine("j:{0},kj:{1},vj:{2}",j,kj,vj); if (kj == 0 && vj == 0) continue; if (kj == 1 && vj == 0) { //ここまでひきわけにできていれば ここで決着がつく. long t = 0; for (int i = 0; i < N; i++) if (del[i]) t += A[i]; min = Math.Min(min, t); } if (kj == 1 && vj == 1) { //ここまで引き分けにしてきた分プラス今回分で決着をつけられる long t = 0; for (int i = 0; i < N; i++) if (del[i] || ((A[i] >> j) & 1) == 1) t += A[i]; min = Math.Min(min, t); } if (kj == 0 && vj == 1) { //ここは引き分けにして下位で決着をつける for (int i = 0; i < N; i++) if (((A[i] >> j) & 1) == 1) del[i] = true; } } // 完全に引き分けにできた場合もOK long t0 = 0; for (int i = 0; i < N; i++) if (del[i]) t0 += A[i]; min = Math.Min(min, t0); Console.WriteLine(tot - min); } int N, K; int[] A; long[] B; public Sol() { var d = ria(); N = d[0]; K = d[1]; A = new int[N]; B = new long[N]; for (int i = 0; i < N; i++) { d = ria(); A[i] = d[0]; B[i] = d[1]; } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { long tot = 0; int v = 0; for (int i = 0; i < N; i++) { tot += B[i]; v |= A[i]; } if (v <= K) { Console.WriteLine(tot); return; } long min = long.MaxValue; bool[] del = new bool[N]; for (int j = 30; j >= 0; j--) { int kj = (K >> j) & 1; int vj = (v >> j) & 1; // Console.WriteLine("j:{0},kj:{1},vj:{2}",j,kj,vj); if (kj == 0 && vj == 0) continue; if (kj == 1 && vj == 0) { //ここまでひきわけにできていれば ここで決着がつく. long t = 0; for (int i = 0; i < N; i++) if (del[i]) t += B[i]; min = Math.Min(min, t); } if (kj == 1 && vj == 1) { //ここまで引き分けにしてきた分プラス今回分で決着をつけられる long t = 0; for (int i = 0; i < N; i++) if (del[i] || ((A[i] >> j) & 1) == 1) t += B[i]; min = Math.Min(min, t); } if (kj == 0 && vj == 1) { //ここは引き分けにして下位で決着をつける for (int i = 0; i < N; i++) if (((A[i] >> j) & 1) == 1) del[i] = true; } } // 完全に引き分けにできた場合もOK long t0 = 0; for (int i = 0; i < N; i++) if (del[i]) t0 += B[i]; min = Math.Min(min, t0); Console.WriteLine(tot - min); } int N, K; int[] A; long[] B; public Sol() { var d = ria(); N = d[0]; K = d[1]; A = new int[N]; B = new long[N]; for (int i = 0; i < N; i++) { d = ria(); A[i] = d[0]; B[i] = d[1]; } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 8, 57, 64, 1, 0, 11, 12, 204, 205, 22], ["+", 8, 57, 64, 1, 0, 11, 12, 204, 205, 22]]
8
742
6
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; public static class TemplateExtension { public static X[] MakeArray<X>(this int count, Func<int, X> func) { var xs = new X[count]; for (var i = 0; i < count; i++) { xs[i] = func(i); } return xs; } public static int[] Range(this int count, int start = 0) { return count.MakeArray(i => i + start); } public static string Intercalate<X>(this IEnumerable<X> @this, string separator) { return string.Join(separator, @this); } public sealed class ValueIndexPair<T> : Tuple<T, int> { public T Value { get { return Item1; } } public int Index { get { return Item2; } } public ValueIndexPair(T value, int index) : base(value, index) {} } public static IEnumerable<ValueIndexPair<X>> Indexed<X>(this IEnumerable<X> @this) { var i = 0; foreach (var x in @this) { yield return new ValueIndexPair<X>(x, i); i++; } } } public sealed class Scanner { readonly TextReader reader; readonly StringBuilder sb = new StringBuilder(); /// <summary> /// Reads next word separated by spaces. /// </summary> public string Word() { sb.Clear(); while (true) { var r = reader.Read(); if (r == '\r') { if (reader.Peek() == '\n') reader.Read(); break; } else if (r == -1 || r == ' ' || r == '\n') { break; } else { sb.Append((char)r); } } return sb.ToString(); } /// <summary> /// Reads next word as <see cref="int"/>. /// </summary> public int N() { return int.Parse(Word()); } /// <summary> /// Reads next word as <see cref="long"/>. /// </summary> public long L() { return long.Parse(Word()); } /// <summary> /// Reads next word as <see cref="double"/>. /// </summary> public double F() { return double.Parse(Word()); } public int[] Ns(int count) { return count.MakeArray(_ => N()); } public long[] Ls(int count) { return count.MakeArray(_ => L()); } public double[] Fs(int count) { return count.MakeArray(_ => F()); } /// <summary> /// Reads next line and splits it by spaces. /// </summary> public X[] Words<X>(Func<string, X> func) { return reader.ReadLine().Split(' ').Select(func).ToArray(); } public Scanner(TextReader reader) { this.reader = reader; } } public partial class Program { readonly TextReader input; readonly TextWriter output; readonly Scanner scanner; void WriteLine(int value) { output.WriteLine(value); } void WriteLine(long value) { output.WriteLine(value); } void WriteLine(double value) { output.WriteLine(value); } void WriteLine(char value) { output.WriteLine(value); } void WriteLine(string value) { output.WriteLine(value); } public Program(TextReader input, TextWriter output) { this.input = input; this.output = output; scanner = new Scanner(input); } public static void Main(string[] args) { #if DEBUG using (var writer = new VainZero.IO.DebugTextWriter(Console.Out)) #else var writer = Console.Out; #endif { new Program(Console.In, writer).EntryPoint(); } } } public sealed partial class Program { // NOTE: // - 解説を読んで実装した。 // - 符号付き整数にビットORを使うと警告が出るので ulong を使う。 public struct Item { public readonly ulong X; public readonly long V; public Item(ulong x, long v) { X = x; V = v; } } int n; ulong k; Item[] items; bool Contains(ulong superset, ulong subset) { return (subset & ~superset) == 0; } // これが出力する集合の和集合は k 以下の数全体に等しい。 /* 例: K = 0b110101 の例だと、 x <= 0b110101 ⇔ x = 0b110101 || x = 0b110100 || x = 0b1100?? || x = 0b10???? || x = 0b0????? */ IEnumerable<ulong> UpperboundSets(ulong k) { yield return k; for (var r = 0; r < 31; r++) { if ((k & (1UL << r)) == 0) continue; // このとき、k の下から r 桁目は 1。 // k の下から r 桁目を 0 にして、それより下の桁を 1 で埋めた数を出力する。 yield return k & ~(1UL << r) | ((1UL << r) - 1); } } long Solve() { return UpperboundSets(k) .SelectMany(mask => items.Where(item => Contains(mask, item.X))) .Max(item => item.V); } void Read() { var a = scanner; n = a.N(); k = (ulong)a.N(); items = n.MakeArray(i => new Item((ulong)a.N(), a.L())); } public void EntryPoint() { Read(); WriteLine(Solve()); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; public static class TemplateExtension { public static X[] MakeArray<X>(this int count, Func<int, X> func) { var xs = new X[count]; for (var i = 0; i < count; i++) { xs[i] = func(i); } return xs; } public static int[] Range(this int count, int start = 0) { return count.MakeArray(i => i + start); } public static string Intercalate<X>(this IEnumerable<X> @this, string separator) { return string.Join(separator, @this); } public sealed class ValueIndexPair<T> : Tuple<T, int> { public T Value { get { return Item1; } } public int Index { get { return Item2; } } public ValueIndexPair(T value, int index) : base(value, index) {} } public static IEnumerable<ValueIndexPair<X>> Indexed<X>(this IEnumerable<X> @this) { var i = 0; foreach (var x in @this) { yield return new ValueIndexPair<X>(x, i); i++; } } } public sealed class Scanner { readonly TextReader reader; readonly StringBuilder sb = new StringBuilder(); /// <summary> /// Reads next word separated by spaces. /// </summary> public string Word() { sb.Clear(); while (true) { var r = reader.Read(); if (r == '\r') { if (reader.Peek() == '\n') reader.Read(); break; } else if (r == -1 || r == ' ' || r == '\n') { break; } else { sb.Append((char)r); } } return sb.ToString(); } /// <summary> /// Reads next word as <see cref="int"/>. /// </summary> public int N() { return int.Parse(Word()); } /// <summary> /// Reads next word as <see cref="long"/>. /// </summary> public long L() { return long.Parse(Word()); } /// <summary> /// Reads next word as <see cref="double"/>. /// </summary> public double F() { return double.Parse(Word()); } public int[] Ns(int count) { return count.MakeArray(_ => N()); } public long[] Ls(int count) { return count.MakeArray(_ => L()); } public double[] Fs(int count) { return count.MakeArray(_ => F()); } /// <summary> /// Reads next line and splits it by spaces. /// </summary> public X[] Words<X>(Func<string, X> func) { return reader.ReadLine().Split(' ').Select(func).ToArray(); } public Scanner(TextReader reader) { this.reader = reader; } } public partial class Program { readonly TextReader input; readonly TextWriter output; readonly Scanner scanner; void WriteLine(int value) { output.WriteLine(value); } void WriteLine(long value) { output.WriteLine(value); } void WriteLine(double value) { output.WriteLine(value); } void WriteLine(char value) { output.WriteLine(value); } void WriteLine(string value) { output.WriteLine(value); } public Program(TextReader input, TextWriter output) { this.input = input; this.output = output; scanner = new Scanner(input); } public static void Main(string[] args) { #if DEBUG using (var writer = new VainZero.IO.DebugTextWriter(Console.Out)) #else var writer = Console.Out; #endif { new Program(Console.In, writer).EntryPoint(); } } } public sealed partial class Program { // NOTE: // - 解説を読んで実装した。 // - 符号付き整数にビットORを使うと警告が出るので ulong を使う。 public struct Item { public readonly ulong X; public readonly long V; public Item(ulong x, long v) { X = x; V = v; } } int n; ulong k; Item[] items; bool Contains(ulong superset, ulong subset) { return (subset & ~superset) == 0; } // これが出力する集合の和集合は k 以下の数全体に等しい。 /* 例: K = 0b110101 の例だと、 x <= 0b110101 ⇔ x = 0b110101 || x = 0b110100 || x = 0b1100?? || x = 0b10???? || x = 0b0????? */ IEnumerable<ulong> UpperboundSets(ulong k) { yield return k; for (var r = 0; r < 31; r++) { if ((k & (1UL << r)) == 0) continue; // このとき、k の下から r 桁目は 1。 // k の下から r 桁目を 0 にして、それより下の桁を 1 で埋めた数を出力する。 yield return k & ~(1UL << r) | ((1UL << r) - 1); } } long Solve() { return UpperboundSets(k).Max( mask => items.Where(item => Contains(mask, item.X)).Sum(item => item.V)); } void Read() { var a = scanner; n = a.N(); k = (ulong)a.N(); items = n.MakeArray(i => new Item((ulong)a.N(), a.L())); } public void EntryPoint() { Read(); WriteLine(Solve()); } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 37, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 37, 0, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25]]
8
1,047
6
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { string w = Input.ScanStr(); Console.WriteLine(w.Substring(0, 4) == "YAKI" ? "Yes" : "No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { string w = Input.ScanStr(); Console.WriteLine(w.Length >= 4 && w.Substring(0, 4) == "YAKI" ? "Yes" : "No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public double ScanDouble() { return double.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
[["+", 0, 41, 15, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 20], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 0, 131]]
8
596
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static bool f = false, t = true; static void Main(string[] args) { string a = Console.ReadLine(); if (a.Length < 4) { Console.WriteLine("No"); } else if (a.Substring(0, 4) == "YAKI") { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } public static long gcd(long a, long b) { while (true) { if (a == 0) { return b; } if (b == 0) { return a; } if (a > b) { a -= b; } else { b -= a; } } } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (long i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } } public static class Read { public static void outl(string n = "") { Console.WriteLine(n); return; } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static bool f = false, t = true; static void Main(string[] args) { string a = Console.ReadLine(); if (a.Length < 4) { Console.WriteLine("No"); } else if (a.Substring(0, 4) == "YAKI") { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } public static long gcd(long a, long b) { while (true) { if (a == 0) { return b; } if (b == 0) { return a; } if (a > b) { a -= b; } else { b -= a; } } } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (long i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } } public static class Read { public static void outl(string n = "") { Console.WriteLine(n); return; } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
424
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { string s = Console.ReadLine(); if (s.Substring(0, 4) == "YAKI") Console.WriteLine("Yes"); else Console.WriteLine("No"); } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { string s = Console.ReadLine(); if (s.Length >= 4 && s.Substring(0, 4) == "YAKI") Console.WriteLine("Yes"); else Console.WriteLine("No"); } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } }
[["+", 0, 57, 15, 16, 31, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 0, 131]]
8
1,207
6
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { string S = re.s(); if (S.Length >= 4 && S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'i') { sb.Append("Yes\n"); } else { sb.Append("No\n"); } } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { string S = re.s(); if (S.Length >= 4 && S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I') { sb.Append("Yes\n"); } else { sb.Append("No\n"); } } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
[["-", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253]]
8
1,743
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var (N, M, K) = ReadTuple<int, int, int>(); int sum = 0; for (int i = 0; i <= N; i++) { for (int j = 0; j <= M; j++) { sum = i * M + (N - i) * j; if (sum == K) { WriteLine("Yes"); return; } } } WriteLine("No"); } } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadTuple<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var (N, M, K) = ReadTuple<int, int, int>(); int sum = 0; for (int i = 0; i <= N; i++) { for (int j = 0; j <= M; j++) { sum = i * M + (N - i - i) * j; if (sum == K) { WriteLine("Yes"); return; } } } WriteLine("No"); } } class Scanner { public static string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadTuple<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["+", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 12, 22]]
8
743
2
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace MSL001 { // public class A //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // var S = c.Read; // var A = c.ReadLong; // var B = c.ReadLong; // var C = c.ReadLong; // var D = c.ReadLong; // var sb = new StringBuilder(S.Length + 10); // for (int i = 0; i < S.Length; i++) // { // if(i == A || i == B || i == C || i == D) // { // sb.Append("\""); // } // sb.Append(S[i]); // } // if (D == S.Length) sb.Append("\""); // Console.WriteLine(sb.ToString()); // } //} // public class B //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // Dictionary<string, long> dic = new Dictionary<string, long>(); // var N = c.ReadLong; // for (int i = 0; i < N; i++) // { // string k = c.Read; // if(dic.TryGetValue(k,out long value)) // { // dic[k] = value + 1; // } // else{ // dic.Add(k, 1); // } // } // var M = c.ReadLong; // for (int i = 0; i < M; i++) // { // string k = c.Read; // if(dic.TryGetValue(k,out long value)) // { // dic[k] = value - 1; // } // } // long max = dic.Values.Max(); // Console.WriteLine(max > 0 ? max : 0); // } //} // public class C //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // var N = c.ReadInt; // var A = new long[N]; // var B = new long[N]; // for (int i = 0; i < N; i++) // { // A[i] = c.ReadLong; // B[i] = c.ReadLong; // } // long count = 0; // for (int i = N - 1; i >= 0; i--) // { // long diff = B[i] - ((A[i] + count) % B[i]); // if (diff == B[i]) diff = 0; // count += diff; // } // Console.WriteLine(count); // } //} public class D { public static void Main(string[] args) { var c = new ConsoleInput(Console.In); var N = c.ReadInt; var M = c.ReadInt; var K = c.ReadLong; for (int y = 0; y < N; y++) { for (int x = 0; x < M; x++) { if (y * M + x * N - 2 * x * y == K) { Console.WriteLine("Yes"); Environment.Exit(0); } } } Console.WriteLine("No"); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Trim().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i].Trim()); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace MSL001 { // public class A //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // var S = c.Read; // var A = c.ReadLong; // var B = c.ReadLong; // var C = c.ReadLong; // var D = c.ReadLong; // var sb = new StringBuilder(S.Length + 10); // for (int i = 0; i < S.Length; i++) // { // if(i == A || i == B || i == C || i == D) // { // sb.Append("\""); // } // sb.Append(S[i]); // } // if (D == S.Length) sb.Append("\""); // Console.WriteLine(sb.ToString()); // } //} // public class B //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // Dictionary<string, long> dic = new Dictionary<string, long>(); // var N = c.ReadLong; // for (int i = 0; i < N; i++) // { // string k = c.Read; // if(dic.TryGetValue(k,out long value)) // { // dic[k] = value + 1; // } // else{ // dic.Add(k, 1); // } // } // var M = c.ReadLong; // for (int i = 0; i < M; i++) // { // string k = c.Read; // if(dic.TryGetValue(k,out long value)) // { // dic[k] = value - 1; // } // } // long max = dic.Values.Max(); // Console.WriteLine(max > 0 ? max : 0); // } //} // public class C //{ // public static void Main(string[] args) // { // var c = new ConsoleInput(Console.In); // var N = c.ReadInt; // var A = new long[N]; // var B = new long[N]; // for (int i = 0; i < N; i++) // { // A[i] = c.ReadLong; // B[i] = c.ReadLong; // } // long count = 0; // for (int i = N - 1; i >= 0; i--) // { // long diff = B[i] - ((A[i] + count) % B[i]); // if (diff == B[i]) diff = 0; // count += diff; // } // Console.WriteLine(count); // } //} public class D { public static void Main(string[] args) { var c = new ConsoleInput(Console.In); long N = c.ReadInt; long M = c.ReadInt; var K = c.ReadLong; for (int y = 0; y <= N; y++) { for (int x = 0; x <= M; x++) { if (y * M + x * N - 2 * x * y == K) { Console.WriteLine("Yes"); Environment.Exit(0); } } } Console.WriteLine("No"); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Trim().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i].Trim()); 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; } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
572
8
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); int[] nmk = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nmk[0]; var m = nmk[1]; var k = nmk[2]; var ans = "No"; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { var x = n - j; if (x < 0) x = 0; var y = m - i; if (y < 0) y = 0; var tmp = i * x + j * y; if (tmp == k) ans = "Yes"; } } // 出力 Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); int[] nmk = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nmk[0]; var m = nmk[1]; var k = nmk[2]; var ans = "No"; for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { var x = n - j; if (x < 0) x = 0; var y = m - i; if (y < 0) y = 0; var tmp = i * x + j * y; if (tmp == k) ans = "Yes"; } } // 出力 Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22]]
8
197
4
using System; class c { static void Main() { var nmk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int n = nmk[0], m = nmk[1], k = nmk[2]; bool judge = false; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((n - i) * (m - j) + i * j == k) judge = true; } } Console.WriteLine(judge ? "Yes" : "No"); } }
using System; class c { static void Main() { var nmk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int n = nmk[0], m = nmk[1], k = nmk[2]; bool judge = false; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if ((n - i) * (m - j) + i * j == k) judge = true; } } Console.WriteLine(judge ? "Yes" : "No"); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
134
4
using System; using System.Linq; namespace AtCoder { class Program { public static void Main() { int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = input[0]; int m = input[1]; int k = input[2]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (i * (m - j) + j * (n - i) == k) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
using System; using System.Linq; namespace AtCoder { class Program { public static void Main() { int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = input[0]; int m = input[1]; int k = input[2]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { if (i * (m - j) + j * (n - i) == k) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
151
4
using System; using System.Linq; namespace CF2017qA { class B { static void Main(string[] args) { // input int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int K = input[2]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (i * (M - j) + j * (N - i) == K) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
using System; using System.Linq; namespace CF2017qA { class B { static void Main(string[] args) { // input int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int K = input[2]; for (int i = 0; i <= N; i++) { for (int j = 0; j <= M; j++) { if (i * (M - j) + j * (N - i) == K) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
152
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCorder { public class Program { static void Main(string[] args) { var nmk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = nmk[0]; int m = nmk[1]; int k = nmk[2]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int num = i * m; int delta = n - i - i; num += delta * j; if (k == num) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCorder { public class Program { static void Main(string[] args) { var nmk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = nmk[0]; int m = nmk[1]; int k = nmk[2]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { int num = i * m; int delta = n - i - i; num += delta * j; if (k == num) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
173
4
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Diagnostics; using System.Text; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { int[] nmk = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < nmk[0]; i++) { for (int j = 0; j < nmk[1]; j++) { if (i * j + (nmk[0] - i) * (nmk[1] - j) == nmk[2]) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Diagnostics; using System.Text; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { int[] nmk = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i <= nmk[0]; i++) { for (int j = 0; j <= nmk[1]; j++) { if (i * j + (nmk[0] - i) * (nmk[1] - j) == nmk[2]) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
181
4
using System; using System.Linq; namespace code_festival_2017_quala_b { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); bool ret = false; for (int i = 0; i < x[0]; i++) { for (int j = 0; j < x[1]; j++) { if ((x[0] - i) * j + (x[1] - j) * i == x[2]) ret = true; } } Console.WriteLine(ret ? "Yes" : "No"); } } }
using System; using System.Linq; namespace code_festival_2017_quala_b { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); bool ret = false; for (int i = 0; i <= x[0]; i++) { for (int j = 0; j <= x[1]; j++) { if ((x[0] - i) * j + (x[1] - j) * i == x[2]) ret = true; } } Console.WriteLine(ret ? "Yes" : "No"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
144
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { //////////////////////////////////////////////////////////// int N, M, K; int[,] G; void Solve() { io.i(out N, out M, out K); for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { if (j > M || i > N) continue; int sum = (M - j) * i + (N - i) * j; if (sum == K) { io.o("Yes"); return; } } } io.o("No"); return; } bool check() { int sum = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { if (G[i, j].Odd()) sum++; } } return sum == K; } //////////////////////////////////////////////////////////// public static void Main() { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // cannot use break,continue,goto void FOR(int a, int b, Action<int> act) { for (int i = a; i < b; ++i) act(i); } void FORR(int a, int b, Action<int> act) { for (int i = a - 1; i >= b; --i) act(i); } #endregion //////////////////////////////////////////////////////////// } #region default class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return suitType<T>(String); } public void i<T>(out T v) { v = suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) a[i] = suitType<T>(String); } public void ini<T, U>(out T[] a, out U[] b, int n) { a = new T[n]; b = new U[n]; for (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<U>(); } } public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) { a = new T[n]; b = new U[n]; c = new V[n]; for (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<U>(); c[i] = i<V>(); } } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void o<T>(T[,] a) { int a0 = a.GetLength(0), a1 = a.GetLength(1); for (int i = 0; i < a0; ++i) { for (int j = 0; j < a1 - 1; ++j) Console.Write(a[i, j] + " "); Console.WriteLine(a[i, a1 - 1]); } } public void ol<T>(params T[] a) { o(connect<T>(a)); } public void or<T>(T a) { Console.Write(a); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } private string connect<T>(params T[] s) { return string.Join(" ", s); } private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size; private int type; // type=0->min public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { public long mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { long ret = 1; for (long i = 1; i <= n; i++) ret = (ret * i) % mod; return ret; } public long ModC(long n, long r) { if (r == 0 || n == r) return 1; if (n == 0) return 0; if (n < 0 || n < r) throw new ArgumentException("n,r invalid"); else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long[,] C(int N) { long[,] Co = new long[N + 1, N + 1]; (N + 1).REP(i => (i + 1).REP(j => Co[i, j] = (j == 0 || j == i) ? 1L : Co[i - 1, j - 1] + Co[i - 1, j])); return Co; } public long DupC(long n, long r) { return ModC(n + r - 1, r); } public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, n) => GCD(v, n)); } public T Max<T>(params T[] a) { return a.Max(); } public T Min<T>(params T[] a) { return a.Min(); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int[] DigArr(int n) { int[] ret = new int[Digit(n)]; ret.Length.REP(i => ret[i] = DigVal(n, i + 1)); return ret; } public long DigArr2Num(IEnumerable<int> enu) { return enu.Aggregate((v, n) => v * 10 + n); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public long Tousa(long a, long d, long n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, long n) { return n * (2 * a + (n - 1) * d) / 2; } public long[] EnuDivsor(long N) { var ret = new SortedSet<long>(); for (long i = 1; i * i <= N; i++) if (N % i == 0) { ret.Add(i); ret.Add(N / i); } return ret.ToArray(); } public Dictionary<long, long> PrimeFactor(long n) { var ret = new Dictionary<long, long>(); for (int i = 2; i * i <= n; ++i) { if (!ret.ContainsKey(i)) ret[i] = 0; while (n % i == 0) { ++ret[i]; n /= i; } } return ret.Where(kp => kp.Value != 0) .ToDictionary(kp => kp.Key, kp => kp.Value); } public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<List<int>>(); for (int i = Arr.Length - 1; i >= 0; i--) s.Push(new List<int>() { i }); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) { var ret = new List<int>(); cur.ForEach(X => ret.Add(Arr[X])); yield return ret.ToArray(); } else for (int i = Arr.Length - 1; i >= 0; i--) if (!cur.Contains(i)) s.Push(new List<int>(cur) { i }); } } public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<List<int>>(); Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] })); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) yield return cur.ToArray(); else Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] })); } } public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<string[]> enuPart(string str) { var s = new Stack<Tuple<string, List<string>, int>>(); s.Push(Tuple.Create(str[0].ToString(), new List<string>(), 1)); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item3 >= str.Length) yield return (new List<string>(cur.Item2) { cur.Item1 }).ToArray(); else { s.Push(Tuple.Create(cur.Item1 + str[cur.Item3], new List<string>(cur.Item2), cur.Item3 + 1)); s.Push(Tuple.Create(str[cur.Item3].ToString(), new List<string>(cur.Item2) { cur.Item1 }, cur.Item3 + 1)); } } } } #endregion #region Data class AssociativeArray<T> : IEnumerable { public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(T a) { if (!conK(a)) dic[a] = 0; dic[a]++; } public void Add(params T[] a) { a.Length.REP(i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { a.Length.REP(i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => MaxK(); public T MinKey => MinK(); public T MaxK() { var maxV = MaxVal; return dic.First(d => d.Value == maxV).Key; } public T MinK() { var minV = MinVal; return dic.First(d => d.Value == minV).Key; } public T[] MaxKeys() { var maxV = MaxVal; return dic.Where(kp => kp.Value == maxV) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } public T[] MinKeys() { var minV = MinVal; return dic.Where(kp => kp.Value == minV) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } public T[] ValueSortedKey(bool inc = true) { // test return (inc ? (dic.OrderBy(kp => kp.Value)) : (dic.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } //:sort->array } class TreeDis { // TODO:shortestPath public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; g.Length.REP(i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class ShortestPath { protected int I = -1; protected int V; protected int E; public long INF = (long)1e15; protected bool isNonDir = true; public long[] cost; public List<Tuple<int, long>>[] Adj; public void Init(int n) { I = n + 1; V = n; Adj = new List<Tuple<int, long>>[I]; I.REP(i => Adj[i] = new List<Tuple<int, long>>()); } public void AddPath(int f, int t, long c) { E++; if (isNonDir) { Adj[f].Add(Tuple.Create(t, c)); Adj[t].Add(Tuple.Create(f, c)); } else { Adj[f].Add(Tuple.Create(t, c)); } } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } } class Dijkstra : ShortestPath { //隣接対応後検証不足,有向とか public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; var pq = new PQueue<Tuple<int, long>>(); pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost) while (pq.Count > 0) { var cur = pq.Dequeue(); if (cost[cur.Item1] < cur.Item2) continue; Adj[cur.Item1].Count.REP(i => { var tmp = Adj[cur.Item1][i]; if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) { cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2; pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1])); } }); } return cost[t]; } } class BellmanFord : ShortestPath { private bool[] neg; public BellmanFord() {} public BellmanFord(bool isNonDir) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; neg = new bool[I]; for (int i = 0; i < I - 1; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) cost[cur.Item1] = cost[j] + cur.Item2; })); } for (int i = 0; i < I; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) { cost[cur.Item1] = cost[j] + cur.Item2; neg[cur.Item1] = true; } if (neg[j]) neg[cur.Item1] = true; })); } return cost[t]; } public bool loopExist() { return neg[I - 1]; } } class WF : ShortestPath { public WF() {} // } class WarshallFloyd { private int E; private bool isNonDir; public long INF = (long)1e15; public long[,] BefG; public long[,] G; public WarshallFloyd(bool isNonDir = true) { this.isNonDir = isNonDir; } public void Init(int n) { E = n + 1; G = new long[E, E]; BefG = new long[E, E]; for (int i = 0; i < E; ++i) for (int j = 0; j < E; ++j) { G[i, j] = INF; BefG[i, j] = INF; } for (int i = 0; i < E; ++i) { G[i, i] = 0; BefG[i, i] = 0; } } public void AddPath(int f, int t, long c) { if (isNonDir) { G[f, t] = c; G[t, f] = c; BefG[f, t] = c; BefG[t, f] = c; } else { G[f, t] = c; BefG[f, t] = c; } } public void AddPath(int[] f, int[] t) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i], 1); } public void AddPath(int[] f, int[] t, long[] c) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i], c[i]); } public void Run() { G = MinCostArr(); } public long[,] MinCostArr() { for (int i = 1; i < E; ++i) for (int j = 1; j < E; ++j) for (int k = 1; k < E; ++k) G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]); return G; } //使う?使わない? public int[] MinPath(int from, int to) { var ret = new List<int>(); var cur = from; while (cur != to) { ret.Add(cur); for (int i = 1; i < E; ++i) { if (BefG[cur, i] + G[i, to] == G[cur, to]) { if (i == cur) continue; cur = i; break; } } } ret.Add(cur); return ret.ToArray(); } public bool isMinPath(int a, int b, long c) { for (int i = 1; i < E; ++i) if (G[i, a] + c == G[i, b]) return true; return false; } //全地点間を繋ぐ最小コスト public long MinCost() { long orig = 0; for (int i = 1; i < E; ++i) for (int j = i + 1; j < E; ++j) { bool isOrig = true; for (int k = 1; k < E; ++k) { if (k == i || k == j) continue; if (G[i, j] == G[i, k] + G[k, j]) { isOrig = false; break; } } if (isOrig) orig += G[i, j]; } return orig; } } class oldUnionFind { public long[] parent; public long[] depth; private long I; public void Init(long n) { I = n + 1; parent = new long[I]; depth = new long[I]; for (int i = 0; i < I; ++i) parent[i] = i; } public long Find(long x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(long x, long y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(long a, long b) { return Find(a) == Find(b); } public long Size(long x) { return depth[Find(x)]; } // refactor } class UnionFind { // intでよくないか? int[] dat; public void Init(int n) { dat = new int[n + 1]; for (int i = 0; i <= n; ++i) dat[i] = -1; } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return; if (dat[y] < dat[x]) swap(ref x, ref y); dat[x] += dat[y]; dat[y] = x; } public bool Find(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return dat[x] < 0 ? x : dat[x] = Root(dat[x]); } public int Size(int x) { return -dat[Root(x)]; } void swap(ref int a, ref int b) { int tmp = b; b = a; a = tmp; } } class Kruskal : ShortestPath { public long Run() { var L = new List<Tuple<int, int, long>>(); for (int i = 0; i < I; ++i) foreach (var t in Adj[i]) L.Add(Tuple.Create(i, t.Item1, t.Item2)); L = L.OrderBy(t => t.Item3).ToList(); var uf = new UnionFind(); uf.Init(V); long ret = 0; foreach (var t in L) if (!uf.Find(t.Item1, t.Item2)) { ret += t.Item3; uf.Unite(t.Item1, t.Item2); } return ret; } } #endregion #region Ex static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static long toLong(this string s) { long n; return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0; } public static long toLong(this char c) { return toLong(c.ToString()); } public static long toLong(this char[] c) { return toLong(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); } public static bool Odd(this int v) { return v % 2 != 0; } public static bool Odd(this long v) { return v % 2 != 0; } public static void REP(this int v, Action<int> act) { for (int i = 0; i < v; ++i) act(i); } public static void REPR(this int v, Action<int> act) { for (int i = v - 1; i >= 0; --i) act(i); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static T[] SortR<T>(this T[] a) { Array.Sort(a); Array.Reverse(a); return a; } public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v)); } public static int[] toIntArr(this string[] a) { return Array.ConvertAll(a, int.Parse); } public static long[] toLongArr(this string[] a) { return Array.ConvertAll(a, long.Parse); } public static double[] toDoubleArr(this string[] a) { return Array.ConvertAll(a, double.Parse); } public static char[] toCharArr(this string[] a) { return Array.ConvertAll(a, char.Parse); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class IEnumerableEx {} #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { //////////////////////////////////////////////////////////// int N, M, K; int[,] G; void Solve() { io.i(out N, out M, out K); for (int i = 0; i <= N; ++i) { for (int j = 0; j <= M; ++j) { if (j > M || i > N) continue; int sum = (M - j) * i + (N - i) * j; if (sum == K) { io.o("Yes"); return; } } } io.o("No"); return; } bool check() { int sum = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { if (G[i, j].Odd()) sum++; } } return sum == K; } //////////////////////////////////////////////////////////// public static void Main() { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // cannot use break,continue,goto void FOR(int a, int b, Action<int> act) { for (int i = a; i < b; ++i) act(i); } void FORR(int a, int b, Action<int> act) { for (int i = a - 1; i >= b; --i) act(i); } #endregion //////////////////////////////////////////////////////////// } #region default class IO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return suitType<T>(String); } public void i<T>(out T v) { v = suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) a[i] = suitType<T>(String); } public void ini<T, U>(out T[] a, out U[] b, int n) { a = new T[n]; b = new U[n]; for (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<U>(); } } public void ini<T, U, V>(out T[] a, out U[] b, out V[] c, int n) { a = new T[n]; b = new U[n]; c = new V[n]; for (int i = 0; i < n; ++i) { a[i] = i<T>(); b[i] = i<U>(); c[i] = i<V>(); } } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void o<T>(T[,] a) { int a0 = a.GetLength(0), a1 = a.GetLength(1); for (int i = 0; i < a0; ++i) { for (int j = 0; j < a1 - 1; ++j) Console.Write(a[i, j] + " "); Console.WriteLine(a[i, a1 - 1]); } } public void ol<T>(params T[] a) { o(connect<T>(a)); } public void or<T>(T a) { Console.Write(a); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } private string connect<T>(params T[] s) { return string.Join(" ", s); } private bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } private T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } private T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size; private int type; // type=0->min public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { public long mod = 1000000007; // 10^9+7 public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { long ret = 1; for (long i = 1; i <= n; i++) ret = (ret * i) % mod; return ret; } public long ModC(long n, long r) { if (r == 0 || n == r) return 1; if (n == 0) return 0; if (n < 0 || n < r) throw new ArgumentException("n,r invalid"); else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public long[,] C(int N) { long[,] Co = new long[N + 1, N + 1]; (N + 1).REP(i => (i + 1).REP(j => Co[i, j] = (j == 0 || j == i) ? 1L : Co[i - 1, j - 1] + Co[i - 1, j])); return Co; } public long DupC(long n, long r) { return ModC(n + r - 1, r); } public long P(long n, long r) { return Fact(n) / (Fact(n - r)); } // test public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, n) => GCD(v, n)); } public T Max<T>(params T[] a) { return a.Max(); } public T Min<T>(params T[] a) { return a.Min(); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int[] DigArr(int n) { int[] ret = new int[Digit(n)]; ret.Length.REP(i => ret[i] = DigVal(n, i + 1)); return ret; } public long DigArr2Num(IEnumerable<int> enu) { return enu.Aggregate((v, n) => v * 10 + n); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public long Tousa(long a, long d, long n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, long n) { return n * (2 * a + (n - 1) * d) / 2; } public long[] EnuDivsor(long N) { var ret = new SortedSet<long>(); for (long i = 1; i * i <= N; i++) if (N % i == 0) { ret.Add(i); ret.Add(N / i); } return ret.ToArray(); } public Dictionary<long, long> PrimeFactor(long n) { var ret = new Dictionary<long, long>(); for (int i = 2; i * i <= n; ++i) { if (!ret.ContainsKey(i)) ret[i] = 0; while (n % i == 0) { ++ret[i]; n /= i; } } return ret.Where(kp => kp.Value != 0) .ToDictionary(kp => kp.Key, kp => kp.Value); } public IEnumerable<int[]> enuP(int[] Arr, int Use = -1) { //列挙順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<List<int>>(); for (int i = Arr.Length - 1; i >= 0; i--) s.Push(new List<int>() { i }); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) { var ret = new List<int>(); cur.ForEach(X => ret.Add(Arr[X])); yield return ret.ToArray(); } else for (int i = Arr.Length - 1; i >= 0; i--) if (!cur.Contains(i)) s.Push(new List<int>(cur) { i }); } } public IEnumerable<int[]> enuC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0 || Arr.Length < Use) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i > cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<int[]> enuDupP(int[] Arr, int Use = -1) { //列挙重複順列 Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<List<int>>(); Arr.Length.REPR(i => s.Push(new List<int>() { Arr[i] })); while (s.Count > 0) { var cur = s.Pop(); if (cur.Count == Use) yield return cur.ToArray(); else Arr.Length.REPR(i => s.Push(new List<int>(cur) { Arr[i] })); } } public IEnumerable<int[]> enuDupC(int[] Arr, int Use = -1) { //列挙組み合わせ Use = (Use != -1) ? Use : Arr.Length; if (Use == 0) yield break; var s = new Stack<Tuple<int, List<int>>>(); Arr.Length.REPR(i => s.Push(Tuple.Create(i, new List<int>() { Arr[i] }))); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item2.Count == Use) yield return cur.Item2.ToArray(); else for (int i = Arr.GetUpperBound(0); i >= cur.Item1; i--) s.Push(Tuple.Create(i, new List<int>(cur.Item2) { Arr[i] })); } } public IEnumerable<string[]> enuPart(string str) { var s = new Stack<Tuple<string, List<string>, int>>(); s.Push(Tuple.Create(str[0].ToString(), new List<string>(), 1)); while (s.Count > 0) { var cur = s.Pop(); if (cur.Item3 >= str.Length) yield return (new List<string>(cur.Item2) { cur.Item1 }).ToArray(); else { s.Push(Tuple.Create(cur.Item1 + str[cur.Item3], new List<string>(cur.Item2), cur.Item3 + 1)); s.Push(Tuple.Create(str[cur.Item3].ToString(), new List<string>(cur.Item2) { cur.Item1 }, cur.Item3 + 1)); } } } } #endregion #region Data class AssociativeArray<T> : IEnumerable { public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(T a) { if (!conK(a)) dic[a] = 0; dic[a]++; } public void Add(params T[] a) { a.Length.REP(i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { a.Length.REP(i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => MaxK(); public T MinKey => MinK(); public T MaxK() { var maxV = MaxVal; return dic.First(d => d.Value == maxV).Key; } public T MinK() { var minV = MinVal; return dic.First(d => d.Value == minV).Key; } public T[] MaxKeys() { var maxV = MaxVal; return dic.Where(kp => kp.Value == maxV) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } public T[] MinKeys() { var minV = MinVal; return dic.Where(kp => kp.Value == minV) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } public T[] ValueSortedKey(bool inc = true) { // test return (inc ? (dic.OrderBy(kp => kp.Value)) : (dic.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key) .ToDictionary(kp => kp.Key, kp => kp.Value) .Keys.ToArray(); } //:sort->array } class TreeDis { // TODO:shortestPath public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; g.Length.REP(i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class ShortestPath { protected int I = -1; protected int V; protected int E; public long INF = (long)1e15; protected bool isNonDir = true; public long[] cost; public List<Tuple<int, long>>[] Adj; public void Init(int n) { I = n + 1; V = n; Adj = new List<Tuple<int, long>>[I]; I.REP(i => Adj[i] = new List<Tuple<int, long>>()); } public void AddPath(int f, int t, long c) { E++; if (isNonDir) { Adj[f].Add(Tuple.Create(t, c)); Adj[t].Add(Tuple.Create(f, c)); } else { Adj[f].Add(Tuple.Create(t, c)); } } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } } class Dijkstra : ShortestPath { //隣接対応後検証不足,有向とか public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; var pq = new PQueue<Tuple<int, long>>(); pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost) while (pq.Count > 0) { var cur = pq.Dequeue(); if (cost[cur.Item1] < cur.Item2) continue; Adj[cur.Item1].Count.REP(i => { var tmp = Adj[cur.Item1][i]; if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) { cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2; pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1])); } }); } return cost[t]; } } class BellmanFord : ShortestPath { private bool[] neg; public BellmanFord() {} public BellmanFord(bool isNonDir) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { cost = new long[I]; cost.Set(INF); cost[f] = 0; neg = new bool[I]; for (int i = 0; i < I - 1; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) cost[cur.Item1] = cost[j] + cur.Item2; })); } for (int i = 0; i < I; i++) { I.REP(j => Adj[j].Count.REP(k => { var cur = Adj[j][k]; if (cost[cur.Item1] > cost[j] + cur.Item2) { cost[cur.Item1] = cost[j] + cur.Item2; neg[cur.Item1] = true; } if (neg[j]) neg[cur.Item1] = true; })); } return cost[t]; } public bool loopExist() { return neg[I - 1]; } } class WF : ShortestPath { public WF() {} // } class WarshallFloyd { private int E; private bool isNonDir; public long INF = (long)1e15; public long[,] BefG; public long[,] G; public WarshallFloyd(bool isNonDir = true) { this.isNonDir = isNonDir; } public void Init(int n) { E = n + 1; G = new long[E, E]; BefG = new long[E, E]; for (int i = 0; i < E; ++i) for (int j = 0; j < E; ++j) { G[i, j] = INF; BefG[i, j] = INF; } for (int i = 0; i < E; ++i) { G[i, i] = 0; BefG[i, i] = 0; } } public void AddPath(int f, int t, long c) { if (isNonDir) { G[f, t] = c; G[t, f] = c; BefG[f, t] = c; BefG[t, f] = c; } else { G[f, t] = c; BefG[f, t] = c; } } public void AddPath(int[] f, int[] t) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i], 1); } public void AddPath(int[] f, int[] t, long[] c) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i], c[i]); } public void Run() { G = MinCostArr(); } public long[,] MinCostArr() { for (int i = 1; i < E; ++i) for (int j = 1; j < E; ++j) for (int k = 1; k < E; ++k) G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k]); return G; } //使う?使わない? public int[] MinPath(int from, int to) { var ret = new List<int>(); var cur = from; while (cur != to) { ret.Add(cur); for (int i = 1; i < E; ++i) { if (BefG[cur, i] + G[i, to] == G[cur, to]) { if (i == cur) continue; cur = i; break; } } } ret.Add(cur); return ret.ToArray(); } public bool isMinPath(int a, int b, long c) { for (int i = 1; i < E; ++i) if (G[i, a] + c == G[i, b]) return true; return false; } //全地点間を繋ぐ最小コスト public long MinCost() { long orig = 0; for (int i = 1; i < E; ++i) for (int j = i + 1; j < E; ++j) { bool isOrig = true; for (int k = 1; k < E; ++k) { if (k == i || k == j) continue; if (G[i, j] == G[i, k] + G[k, j]) { isOrig = false; break; } } if (isOrig) orig += G[i, j]; } return orig; } } class oldUnionFind { public long[] parent; public long[] depth; private long I; public void Init(long n) { I = n + 1; parent = new long[I]; depth = new long[I]; for (int i = 0; i < I; ++i) parent[i] = i; } public long Find(long x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(long x, long y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(long a, long b) { return Find(a) == Find(b); } public long Size(long x) { return depth[Find(x)]; } // refactor } class UnionFind { // intでよくないか? int[] dat; public void Init(int n) { dat = new int[n + 1]; for (int i = 0; i <= n; ++i) dat[i] = -1; } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return; if (dat[y] < dat[x]) swap(ref x, ref y); dat[x] += dat[y]; dat[y] = x; } public bool Find(int x, int y) { return Root(x) == Root(y); } public int Root(int x) { return dat[x] < 0 ? x : dat[x] = Root(dat[x]); } public int Size(int x) { return -dat[Root(x)]; } void swap(ref int a, ref int b) { int tmp = b; b = a; a = tmp; } } class Kruskal : ShortestPath { public long Run() { var L = new List<Tuple<int, int, long>>(); for (int i = 0; i < I; ++i) foreach (var t in Adj[i]) L.Add(Tuple.Create(i, t.Item1, t.Item2)); L = L.OrderBy(t => t.Item3).ToList(); var uf = new UnionFind(); uf.Init(V); long ret = 0; foreach (var t in L) if (!uf.Find(t.Item1, t.Item2)) { ret += t.Item3; uf.Unite(t.Item1, t.Item2); } return ret; } } #endregion #region Ex static class StringEX { public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static long toLong(this string s) { long n; return (long.TryParse(s.TrimStart('0'), out n)) ? n : (long)0; } public static long toLong(this char c) { return toLong(c.ToString()); } public static long toLong(this char[] c) { return toLong(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); } public static bool Odd(this int v) { return v % 2 != 0; } public static bool Odd(this long v) { return v % 2 != 0; } public static void REP(this int v, Action<int> act) { for (int i = 0; i < v; ++i) act(i); } public static void REPR(this int v, Action<int> act) { for (int i = v - 1; i >= 0; --i) act(i); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static T[] SortR<T>(this T[] a) { Array.Sort(a); Array.Reverse(a); return a; } public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v)); } public static int[] toIntArr(this string[] a) { return Array.ConvertAll(a, int.Parse); } public static long[] toLongArr(this string[] a) { return Array.ConvertAll(a, long.Parse); } public static double[] toDoubleArr(this string[] a) { return Array.ConvertAll(a, double.Parse); } public static char[] toCharArr(this string[] a) { return Array.ConvertAll(a, char.Parse); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class IEnumerableEx {} #endregion }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
8,331
4
using System; using System.Collections.Generic; using System.Linq; class Solution { static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = vals[0]; int m = vals[1]; int k = vals[2]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { var blackLine = n; var whiteLine = n - i; var black = blackLine * (m - j) + whiteLine * m; var v = k - black; // if (v >= 0 && v % 2 == 0) if (v == 0) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } }
using System; using System.Collections.Generic; using System.Linq; class Solution { static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = vals[0]; int m = vals[1]; int k = vals[2]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { var blackLine = i; var whiteLine = n - i; var black = blackLine * (m - j) + whiteLine * j; var v = k - black; // if (v >= 0 && v % 2 == 0) if (k == black) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
172
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; namespace AtCoder { class Program { #region Reserve static int cin() { return cin(-1); } static int cin(int D) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return D; return int.Parse(s); } static long cln(long D = -1) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return D; return long.Parse(s); } static int[] cins(char spliter) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return new int[] {}; string[] ss = s.Split(spliter); var Res = new int[ss.Length]; for (int i = 0; i < ss.Length; i++) Res[i] = int.Parse(ss[i]); return Res; } static int[] cins() { return cins(' '); } static void print(object j) { Console.WriteLine(j.ToString()); } static void print(string j) { Console.WriteLine(j); } static string read() { return Console.ReadLine(); } #endregion static void Main(string[] args) { var L = cins(); int N = L[0], M = L[1], K = L[2]; var aim = N * M - K; var res = false; for (int b = 0; b < N; b++) { for (int a = 0; a < M; a++) { if (aim == a * N + b * M - 2 * a * b) res = true; } } print(res ? "Yes" : "No"); read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; namespace AtCoder { class Program { #region Reserve static int cin() { return cin(-1); } static int cin(int D) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return D; return int.Parse(s); } static long cln(long D = -1) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return D; return long.Parse(s); } static int[] cins(char spliter) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return new int[] {}; string[] ss = s.Split(spliter); var Res = new int[ss.Length]; for (int i = 0; i < ss.Length; i++) Res[i] = int.Parse(ss[i]); return Res; } static int[] cins() { return cins(' '); } static void print(object j) { Console.WriteLine(j.ToString()); } static void print(string j) { Console.WriteLine(j); } static string read() { return Console.ReadLine(); } #endregion static void Main(string[] args) { var L = cins(); int N = L[0], M = L[1], K = L[2]; var aim = N * M - K; var res = false; for (int b = 0; b <= N; b++) { for (int a = 0; a <= M; a++) { if (aim == a * N + b * M - 2 * a * b) res = true; } } print(res ? "Yes" : "No"); read(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
426
4
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(); this.RowCount = inpt[0]; this.ColCount = inpt[1]; this.Target = inpt[2]; string ans = "No"; for (int i = 0; i < this.RowCount; i++) { if (this.ColCount * i == Target) { ans = "Yes"; break; } for (int j = 0; j < this.ColCount; j++) { int calc = this.ColCount * i; calc -= (i * j * 2); calc += this.RowCount * j; if (calc == Target) { ans = "Yes"; break; } } if (ans.Equals("Yes")) { break; } } Console.WriteLine(ans); } private int RowCount; private int ColCount; private int Target; public class Reader { private 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 = @" 7 9 20 "; } 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(); this.RowCount = inpt[0]; this.ColCount = inpt[1]; this.Target = inpt[2]; string ans = "No"; for (int i = 0; i <= this.RowCount; i++) { if (this.ColCount * i == Target) { ans = "Yes"; break; } for (int j = 0; j <= this.ColCount; j++) { long calc = this.ColCount * i; calc -= (i * j * 2); calc += this.RowCount * j; if (calc == Target) { ans = "Yes"; break; } } if (ans.Equals("Yes")) { break; } } Console.WriteLine(ans); } private int RowCount; private int ColCount; private int Target; public class Reader { private 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 = @" 7 9 20 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
8
350
6
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; // using System.Numerics; // using static System.Math; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int N; // int H, W; void solve() { // H = cin.nextint; // W = cin.nextint; // var A = new int[26]; // for (int i = 0; i < H; i++) //{ // var S = cin.next; // for (int j = 0; j < W; j++) // { // int k = S[j] - 'a'; // A[k]++; // } //} N = cin.nextint; int M = cin.nextint; int K = cin.nextint; bool flag = false; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { int B = i * M + j * N - 2 * i * j; if (B == K) { flag = true; } } } WriteLine(flag ? "Yes" : "No"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; // using System.Numerics; // using static System.Math; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int N; // int H, W; void solve() { // H = cin.nextint; // W = cin.nextint; // var A = new int[26]; // for (int i = 0; i < H; i++) //{ // var S = cin.next; // for (int j = 0; j < W; j++) // { // int k = S[j] - 'a'; // A[k]++; // } //} N = cin.nextint; int M = cin.nextint; int K = cin.nextint; bool flag = false; for (int i = 0; i <= N; i++) { for (int j = 0; j <= M; j++) { int B = i * M + j * N - 2 * i * j; if (B == K) { flag = true; } } } WriteLine(flag ? "Yes" : "No"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
482
4
using System; using System.Collections.Generic; using System.Text; namespace AtTest._400Problems_remain_ { class CF2017Final_C { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int[] hw = ReadInts(); int h = hw[0]; int w = hw[1]; int[] counts = new int[26]; for (int i = 0; i < h; i++) { string s = Read(); for (int j = 0; j < w; j++) { counts[s[j] - 'a']++; } } Array.Sort(counts); Array.Reverse(counts); int count1 = (h % 2) * (w % 2); int count2 = (w / 2) * (h % 2) + (h / 2) * (w % 2); int count4 = (h / 2) * (w / 2); for (int i = 0; i < counts.Length; i++) { int minusCount; minusCount = Math.Min(counts[i] / 4, count4); count4 -= minusCount; counts[i] -= minusCount * 4; minusCount = Math.Min(counts[i] / 2, count2); count2 -= minusCount; counts[i] -= minusCount * 2; minusCount = Math.Min(counts[i], count2); count1 -= minusCount; counts[i] -= minusCount; if (counts[i] > 0) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Text; namespace AtTest._400Problems_remain_ { class CF2017Final_C { static void Main(string[] args) { Method(args); Console.ReadLine(); } static void Method(string[] args) { int[] hw = ReadInts(); int h = hw[0]; int w = hw[1]; int[] counts = new int[26]; for (int i = 0; i < h; i++) { string s = Read(); for (int j = 0; j < w; j++) { counts[s[j] - 'a']++; } } Array.Sort(counts); Array.Reverse(counts); int count1 = (h % 2) * (w % 2); int count2 = (w / 2) * (h % 2) + (h / 2) * (w % 2); int count4 = (h / 2) * (w / 2); for (int i = 0; i < counts.Length; i++) { int minusCount; minusCount = Math.Min(counts[i] / 4, count4); count4 -= minusCount; counts[i] -= minusCount * 4; minusCount = Math.Min(counts[i] / 2, count2); count2 -= minusCount; counts[i] -= minusCount * 2; minusCount = Math.Min(counts[i], count1); count1 -= minusCount; counts[i] -= minusCount; if (counts[i] > 0) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } 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); } } }
[["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
8
505
2
static class Program { static void Main() { var sqSide = int.Parse(System.Console.ReadLine()); var white = int.Parse(System.Console.ReadLine()); var sq = sqSide * sqSide; System.Console.WriteLine(sq); } }
static class Program { static void Main() { var sqSide = int.Parse(System.Console.ReadLine()); var white = int.Parse(System.Console.ReadLine()); var sq = sqSide * sqSide; System.Console.WriteLine(sq - white); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
60
2
using System; class Program2 { static void Main(string[] args) { int i = int.Parse(Console.ReadLine()); Console.WriteLine(i ^ 2 - int.Parse(Console.ReadLine())); } }
using System; class Program2 { static void Main(string[] args) { int i = int.Parse(Console.ReadLine()); Console.WriteLine(i * i - int.Parse(Console.ReadLine())); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 140], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
8
52
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int[] nums = new int[input.Length]; for (int i = 0; i < input.Length; i++) { nums[i] = int.Parse(input[i]); } int a, b; if (nums[0] < nums[2]) { a = nums[2]; } else { a = nums[0]; } if (nums[1] < nums[3]) { b = nums[1]; } else { b = nums[3]; } if (b - a < 0) { Console.WriteLine(b - a); } else { Console.WriteLine(0); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int[] nums = new int[input.Length]; for (int i = 0; i < input.Length; i++) { nums[i] = int.Parse(input[i]); } int a, b; if (nums[0] < nums[2]) { a = nums[2]; } else { a = nums[0]; } if (nums[1] < nums[3]) { b = nums[1]; } else { b = nums[3]; } if (b - a > 0) { Console.WriteLine(b - a); } else { Console.WriteLine(0); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47]]
8
206
2
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { void solve() { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); int D = int.Parse(str[3]); if (A < B) A = B; if (C > D) C = D; if (A > C) A = 0; else A = C - A; Console.WriteLine(A); } public static int Main() { bool loop = false; #if ES_DEBUG loop = true; #endif do { new Program().solve(); } while (loop); return 0; } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { void solve() { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); int D = int.Parse(str[3]); if (A < C) A = C; if (B > D) B = D; if (A > B) A = 0; else A = B - A; Console.WriteLine(A); } public static int Main() { bool loop = false; #if ES_DEBUG loop = true; #endif do { new Program().solve(); } while (loop); return 0; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 31, 22]]
8
186
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static bool f = false, t = true; static void Main(string[] args) { int[] a = Read.ints(); int sum = 0; for (int i = 1; i <= 100; i++) { if (a[0] <= i && i < a[1] && a[2] <= i && i < a[3]) { sum++; } } Console.WriteLine(sum); Console.ReadLine(); } public static long gcd(long a, long b) { while (true) { if (a == 0) { return b; } if (b == 0) { return a; } if (a > b) { a -= b; } else { b -= a; } } } public static long lcm(long a, long b) { return a * b / gcd(a, b); } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (long i = 2; i < Math.Sqrt(n); i++) { if (n % i == 0) return false; } return true; } } public static class Read { public static void outl(string n = "") { Console.WriteLine(n); return; } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static bool f = false, t = true; static void Main(string[] args) { int[] a = Read.ints(); int sum = 0; for (int i = 1; i <= 100; i++) { if (a[0] < i && i <= a[1] && a[2] < i && i <= a[3]) { sum++; } } Console.WriteLine(sum); Console.ReadLine(); } public static long gcd(long a, long b) { while (true) { if (a == 0) { return b; } if (b == 0) { return a; } if (a > b) { a -= b; } else { b -= a; } } } public static long lcm(long a, long b) { return a * b / gcd(a, b); } public static bool IsPrime(long n) { if (n < 2) return false; if (n == 2) return true; for (long i = 2; i < Math.Sqrt(n); i++) { if (n % i == 0) return false; } return true; } } public static class Read { public static void outl(string n = "") { Console.WriteLine(n); return; } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Str() { return Console.ReadLine(); } public static string[] Strs() { return Console.ReadLine().Split(); } }
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
442
8
// // ABC070C // URL : https://atcoder.jp/contests/abc070/tasks/abc070_c // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; namespace AtCoder { class ABC070C { static void Main(string[] args) { preprocess(); // 整数の入力 long N = long.Parse(Console.ReadLine()); var TList = new Dictionary<int, ulong>((int)N); int cnt = 0; for (int i = 0; i < N; ++i) { ulong x = ulong.Parse(Console.ReadLine()); //重複を含めない if (TList.ContainsValue(x) == false) { TList.Add(cnt, x); cnt++; } } var ans = Solve(TList); Console.WriteLine(ans.ToString()); Console.Out.Flush(); } static ulong Solve(Dictionary<int, ulong> TList) { // TListにある数の最小公倍数を求める ulong ans = TList[0]; for (int i = 1; i < TList.Count; ++i) { ans = Lcm(ans, TList[i]); } return ans; } //--------------------------------------------------------------------------------- /// <summary> /// /// </summary> public static void preprocess() { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 0; i <= n; ++i) { ans *= (m - i + 1) / i; } return ans; } static ulong Gcd(ulong m, ulong n) { if (n == 0) return m; return Gcd(n, m % n); } static ulong Lcm(ulong m, ulong n) { var gcd = Gcd(m, n); return (m * n) / gcd; } } }
// // ABC070C // URL : https://atcoder.jp/contests/abc070/tasks/abc070_c // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; namespace AtCoder { class ABC070C { static void Main(string[] args) { preprocess(); // 整数の入力 long N = long.Parse(Console.ReadLine()); var TList = new Dictionary<int, ulong>((int)N); int cnt = 0; for (int i = 0; i < N; ++i) { ulong x = ulong.Parse(Console.ReadLine()); //重複を含めない if (TList.ContainsValue(x) == false) { TList.Add(cnt, x); cnt++; } } var ans = Solve(TList); Console.WriteLine(ans.ToString()); Console.Out.Flush(); } static ulong Solve(Dictionary<int, ulong> TList) { // TListにある数の最小公倍数を求める ulong ans = TList[0]; for (int i = 1; i < TList.Count; ++i) { ans = Lcm(ans, TList[i]); } return ans; } //--------------------------------------------------------------------------------- /// <summary> /// /// </summary> public static void preprocess() { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 0; i <= n; ++i) { ans *= (m - i + 1) / i; } return ans; } static ulong Gcd(ulong m, ulong n) { if (n == 0) return m; return Gcd(n, m % n); } static ulong Lcm(ulong m, ulong n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } } }
[["-", 8, 196, 0, 37, 0, 16, 31, 23, 0, 24], ["-", 0, 37, 0, 16, 31, 23, 0, 16, 17, 48], ["-", 0, 37, 0, 16, 31, 23, 0, 16, 12, 22], ["-", 8, 196, 0, 37, 0, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 22]]
8
536
6
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 var n = int.Parse(Console.ReadLine()); ulong[] t = new ulong[n]; for (int i = 0; i < n; i++) { t[i] = ulong.Parse(Console.ReadLine()); } ulong[] tmp = t.Distinct().ToArray(); ulong ans = tmp[0]; for (int i = 1; i < tmp.Length; i++) { ans = Lcm(ans, tmp[i]); } Console.WriteLine(ans); } // 最小公倍数 public static ulong Lcm(ulong a, ulong b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 public static ulong Gcd(ulong a, ulong b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 var n = int.Parse(Console.ReadLine()); ulong[] t = new ulong[n]; for (int i = 0; i < n; i++) { t[i] = ulong.Parse(Console.ReadLine()); } ulong[] tmp = t.Distinct().ToArray(); ulong ans = tmp[0]; for (int i = 1; i < tmp.Length; i++) { ans = Lcm(ans, tmp[i]); } Console.WriteLine(ans); } // 最小公倍数 public static ulong Lcm(ulong a, ulong b) { // return a * b / Gcd(a, b); return a / Gcd(a, b) * b; } // ユークリッドの互除法 public static ulong Gcd(ulong a, ulong b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } }
[["-", 8, 196, 0, 37, 0, 16, 31, 16, 17, 48], ["-", 8, 196, 0, 37, 0, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 22]]
8
239
4
using System; using System.Collections.Generic; using System.Linq; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); long ret = 0; for (int i = 0; i < N; i++) { var input = long.Parse(Console.ReadLine()); if (i == 0) { ret = input; continue; } ret = Lcm(ret, input); } Console.WriteLine(ret); } public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } } }
using System; using System.Collections.Generic; using System.Linq; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); long ret = 0; for (int i = 0; i < N; i++) { var input = long.Parse(Console.ReadLine()); if (i == 0) { ret = input; continue; } ret = Lcm(ret, input); } Console.WriteLine(ret); } public static long Lcm(long a, long b) { return a * (b / Gcd(a, b)); } public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } } }
[["+", 8, 196, 0, 37, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
198
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Multiple Clocks int n = int.Parse(Console.ReadLine()); var t = ReadLines(n); long lcm = t[0]; var math = new MyMath(); for (int i = 1; i < n; i++) { long newLcm = GetLcm(lcm, t[i]); if (newLcm == 0) { lcm = math.GetLcm(lcm, t[i]); } else { lcm = newLcm; } } Console.WriteLine(lcm); } static long GetLcm(long a, long b) { if (a >= b) { if (a % b == 0) { return a; } } else { if (b % a == 0) { return b; } } return 0; } static List<long> ReadLines(long count = 0) { //[summary]コンソールの値を読み込む var lines = new List<long>(); string s; //読み込む行数が未指定のときは、1行目の値を"count"とみなす if (count == 0) { s = Console.ReadLine().TrimEnd(); count = long.Parse(s); } for (long i = 0; i < count; i++) { s = Console.ReadLine().TrimEnd(); lines.Add(long.Parse(s)); } return lines; } } class MyMath { public long GetGcd(long a, long b) { //[summary]a,b2つの数の最大公約数を求める //以下リンクを参考に実装 // https://qiita.com/gushwell/items/e9614b4ac2bea3fc6486 if (a < b) { //引数を入れ替えて自分を呼び出す return GetGcd(b, a); } else { while (b > 0) { long remainder = a % b; a = b; b = remainder; } return a; } } public long GetLcm(long a, long b) { //[summary]a,b2つの数の最小公倍数を求める // Lcm: least Common Multiple //以下リンクを参考に実装 // https://qiita.com/gushwell/items/f08d0e71fa0480dbb396 long gcd = GetGcd(a, b); return a * b / gcd; } public long GetLcmByFactoring(long a, long b) { long gcd = GetGcd(a, b); long upper = (long)Math.Pow(10, 9); if (a <= upper && b <= upper) { return a * b / gcd; } else { var factoring = new Factoring(a); var factorsA = factoring.GetFactors(); factoring = new Factoring(b); var factorsB = factoring.GetFactors(); factorsA.AddRange(factorsB); factoring = new Factoring(gcd); var factorsGcd = factoring.GetFactors(); foreach (var factor in factorsGcd) { factorsA.Remove(factor); } long lcm = 1; foreach (var factor in factorsA) { lcm *= factor; } return lcm; } } } class Factoring { private List<long> factors = new List<long>(); public Factoring(long num) { //[summary]ある数を素因数分解する if (num < 2) { // 2より小さい数を受け取った場合 factors.Add(num); } else { //平方根以下の素数で総当りで割って行く //以下リンクを参考に実装 // https://qiita.com/gushwell/items/561afde2e00bf3380c98 //平方根を求める long sqrt = (long)Math.Sqrt(num); // 2,3,5で割る(割れなくなるまで割り続ける) num = DevideWith(num, 2); num = DevideWith(num, 3); num = DevideWith(num, 5); var primes = new List<int> { 7, 11, 13, 17, 19, 23, 29, 31 }; long i = 0; //平方根以下の素数(候補)で総当りで割る while (num > 1) { foreach (var p in primes) { if (p + i > sqrt) { factors.Add(num); return; } else { num = DevideWith(num, p + i); } } i += 30; } } } private long DevideWith(long num, long d) { while (num % d == 0) { factors.Add(d); num /= d; } return num; } public List<long> GetFactors() { //[summary]素因数分解した結果を取得 return factors; } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Multiple Clocks int n = int.Parse(Console.ReadLine()); var t = ReadLines(n); long lcm = t[0]; var math = new MyMath(); for (int i = 1; i < n; i++) { long newLcm = GetLcm(lcm, t[i]); if (newLcm == 0) { lcm = math.GetLcmByFactoring(lcm, t[i]); } else { lcm = newLcm; } } Console.WriteLine(lcm); } static long GetLcm(long a, long b) { if (a >= b) { if (a % b == 0) { return a; } } else { if (b % a == 0) { return b; } } return 0; } static List<long> ReadLines(long count = 0) { //[summary]コンソールの値を読み込む var lines = new List<long>(); string s; //読み込む行数が未指定のときは、1行目の値を"count"とみなす if (count == 0) { s = Console.ReadLine().TrimEnd(); count = long.Parse(s); } for (long i = 0; i < count; i++) { s = Console.ReadLine().TrimEnd(); lines.Add(long.Parse(s)); } return lines; } } class MyMath { public long GetGcd(long a, long b) { //[summary]a,b2つの数の最大公約数を求める //以下リンクを参考に実装 // https://qiita.com/gushwell/items/e9614b4ac2bea3fc6486 if (a < b) { //引数を入れ替えて自分を呼び出す return GetGcd(b, a); } else { while (b > 0) { long remainder = a % b; a = b; b = remainder; } return a; } } public long GetLcm(long a, long b) { //[summary]a,b2つの数の最小公倍数を求める // Lcm: least Common Multiple //以下リンクを参考に実装 // https://qiita.com/gushwell/items/f08d0e71fa0480dbb396 long gcd = GetGcd(a, b); return a * b / gcd; } public long GetLcmByFactoring(long a, long b) { long gcd = GetGcd(a, b); long upper = (long)Math.Pow(10, 9); if (a <= upper && b <= upper) { return a * b / gcd; } else { var factoring = new Factoring(a); var factorsA = factoring.GetFactors(); factoring = new Factoring(b); var factorsB = factoring.GetFactors(); factorsA.AddRange(factorsB); factoring = new Factoring(gcd); var factorsGcd = factoring.GetFactors(); foreach (var factor in factorsGcd) { factorsA.Remove(factor); } long lcm = 1; foreach (var factor in factorsA) { lcm *= factor; } return lcm; } } } class Factoring { private List<long> factors = new List<long>(); public Factoring(long num) { //[summary]ある数を素因数分解する if (num < 2) { // 2より小さい数を受け取った場合 factors.Add(num); } else { //平方根以下の素数で総当りで割って行く //以下リンクを参考に実装 // https://qiita.com/gushwell/items/561afde2e00bf3380c98 //平方根を求める long sqrt = (long)Math.Sqrt(num); // 2,3,5で割る(割れなくなるまで割り続ける) num = DevideWith(num, 2); num = DevideWith(num, 3); num = DevideWith(num, 5); var primes = new List<int> { 7, 11, 13, 17, 19, 23, 29, 31 }; long i = 0; //平方根以下の素数(候補)で総当りで割る while (num > 1) { foreach (var p in primes) { if (p + i > sqrt) { factors.Add(num); return; } else { num = DevideWith(num, p + i); } } i += 30; } } } private long DevideWith(long num, long d) { while (num % d == 0) { factors.Add(d); num /= d; } return num; } public List<long> GetFactors() { //[summary]素因数分解した結果を取得 return factors; } } }
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22]]
8
773
2
using System; public class Hello { static long GCM(long a, long b) { long A = Math.Max(a, b); long B = Math.Min(a, b); while (A % B != 0) { long C = A % B; A = B; B = C; } return B; } static long LCM(long a, long b) { long A = Math.Max(a, b); long B = Math.Min(a, b); return A * B / GCM(a, b); } public static void Main() { int N = int.Parse(Console.ReadLine()); long[] time = new long[N]; for (var i = 0; i < N; i++) { time[i] = long.Parse(Console.ReadLine()); } long ans = time[0]; for (var i = 1; i < N; i++) { ans = LCM(ans, time[i]); } Console.WriteLine(ans); } }
using System; public class Hello { static long GCM(long a, long b) { long A = Math.Max(a, b); long B = Math.Min(a, b); while (A % B != 0) { long C = A % B; A = B; B = C; } return B; } static long LCM(long a, long b) { long A = Math.Max(a, b); long B = Math.Min(a, b); return A / GCM(a, b) * B; } public static void Main() { int N = int.Parse(Console.ReadLine()); long[] time = new long[N]; for (var i = 0; i < N; i++) { time[i] = long.Parse(Console.ReadLine()); } long ans = time[0]; for (var i = 1; i < N; i++) { ans = LCM(ans, time[i]); } Console.WriteLine(ans); } }
[["-", 8, 196, 0, 37, 0, 16, 31, 16, 17, 48], ["-", 8, 196, 0, 37, 0, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 22]]
8
228
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using static System.Globalization.CultureInfo; class Program { struct P { public int index; public List<int> ad; public Dictionary<int, int> weights; public long Weight; public P(int index) { this.index = index; ad = new List<int>(); weights = new Dictionary<int, int>(); Weight = 0; } } static void Main(string[] args) { var num = Input.num; var ps = new P[num]; for (var i = 0; i < num; i++) ps[i] = new P(i); for (var i = 0; i < num - 1; i++) { var inp = Input.ar; for (var j = 0; j < 2; j++) { ps[inp[j] - 1].ad.Add(inp[(j + 1) % 2] - 1); ps[inp[j] - 1].weights[inp[(j + 1) % 2] - 1] = inp[2]; } } var qk = Input.ar; dfs(ps, new bool[num], qk[1] - 1); var res = new long[qk[0]]; for (var i = 0; i < qk[0]; i++) { var qer = Input.ar; res[i] = ps[qer[0] - 1].Weight + ps[qer[1] - 1].Weight; } WriteLine(string.Join("\n", res)); } private static void dfs(P[] ps, bool[] set, int index) { set[index] = true; foreach (var ad in ps[index].ad) if (!set[index]) { ps[ad].Weight = ps[index].weights[ad] + ps[index].Weight; dfs(ps, set, ad); } } } public class Input { public static string read => ReadLine(); public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse); public static int num => ToInt32(read); public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse); public static long numL => ToInt64(read); public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using static System.Globalization.CultureInfo; class Program { struct P { public int index; public List<int> ad; public Dictionary<int, int> weights; public long Weight; public P(int index) { this.index = index; ad = new List<int>(); weights = new Dictionary<int, int>(); Weight = 0; } } static void Main(string[] args) { var num = Input.num; var ps = new P[num]; for (var i = 0; i < num; i++) ps[i] = new P(i); for (var i = 0; i < num - 1; i++) { var inp = Input.ar; for (var j = 0; j < 2; j++) { ps[inp[j] - 1].ad.Add(inp[(j + 1) % 2] - 1); ps[inp[j] - 1].weights[inp[(j + 1) % 2] - 1] = inp[2]; } } var qk = Input.ar; dfs(ps, new bool[num], qk[1] - 1); var res = new long[qk[0]]; for (var i = 0; i < qk[0]; i++) { var qer = Input.ar; res[i] = ps[qer[0] - 1].Weight + ps[qer[1] - 1].Weight; } WriteLine(string.Join("\n", res)); } private static void dfs(P[] ps, bool[] set, int index) { set[index] = true; foreach (var ad in ps[index].ad) if (!set[ad]) { ps[ad].Weight = ps[index].weights[ad] + ps[index].Weight; dfs(ps, set, ad); } } } public class Input { public static string read => ReadLine(); public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse); public static int num => ToInt32(read); public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse); public static long numL => ToInt64(read); public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["-", 15, 241, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 241, 0, 204, 206, 207, 0, 28, 0, 22]]
8
546
2
using System; class Program { static void Main(string[] args) { string str = Console.ReadLine(); Console.WriteLine(str[0].ToString() + str.Length.ToString() + str[str.Length - 1].ToString()); } }
using System; class Program { static void Main(string[] args) { string str = Console.ReadLine(); Console.WriteLine(str[0].ToString() + (str.Length - 2).ToString() + str[str.Length - 1].ToString()); } }
[["+", 31, 16, 12, 213, 63, 214, 205, 23, 0, 24], ["+", 12, 213, 63, 214, 205, 23, 0, 16, 17, 33], ["+", 12, 213, 63, 214, 205, 23, 0, 16, 12, 203], ["+", 31, 16, 12, 213, 63, 214, 205, 23, 0, 25]]
8
62
4
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp3 { class Program { static void Main(string[] args) { var input = Console.ReadLine(); var Length = input.Length.ToString(); Console.WriteLine(input[0] + Length + input[input.Length - 1]); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp3 { class Program { static void Main(string[] args) { var input = Console.ReadLine(); var Length = (input.Length - 2).ToString(); Console.WriteLine(input[0] + Length + input[input.Length - 1]); } } }
[["+", 0, 212, 0, 213, 63, 214, 205, 23, 0, 24], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 17, 33], ["+", 0, 213, 63, 214, 205, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 213, 63, 214, 205, 23, 0, 25]]
8
75
4
using System; class Program { static void Main() { string s = Console.ReadLine(); Console.WriteLine( s[0] + (s.Length - 2) + s[s.Length - 1]); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; class Program { static void Main() { string s = Console.ReadLine(); Console.WriteLine( "" + s[0] + (s.Length - 2) + s[s.Length - 1]); // WriteLineをWriteとすると、改行なしで出力。 } }
[["+", 0, 16, 31, 16, 31, 16, 31, 5, 0, 62], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 72]]
8
51
4
using System; class Program { static void Main() { string s = Console.ReadLine(); Console.WriteLine( s[0] + (s.Length - 2) + s[s.Length - 1]); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; class Program { static void Main() { string s = Console.ReadLine(); Console.WriteLine( s[0] + (s.Length - 2).ToString() + s[s.Length - 1]); // WriteLineをWriteとすると、改行なしで出力。 } }
[["+", 0, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 25]]
8
51
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program2 { static void Main(string[] args) { string s = Console.ReadLine(); int i = s.Length - 2; string res = s[0] + i.ToString() + s[1]; Console.Write(res); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program2 { static void Main(string[] args) { string s = Console.ReadLine(); int i = s.Length - 2; string res = s[0] + i.ToString() + s[s.Length - 1]; Console.Write(res); } }
[["+", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33]]
8
86
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int[] a = sc.IntArray(); int x4 = a.Where(num => num % 4 == 0).Count(); int x2 = a.Where(num => num % 2 == 0).Count() - x4; int can = x4 * 3; can += x2 >= 2 ? x2 - 1 : 0; bool ok = can >= a.Count(); string answer = ok ? "Yes" : "No"; 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(); int n = sc.NextInt(); int[] a = sc.IntArray(); int x4 = a.Where(num => num % 4 == 0).Count(); int x2 = a.Where(num => num % 2 == 0).Count() - x4; int can = x4 * 2 + 1; can += x2 >= 2 ? x2 - 1 : 0; bool ok = can >= a.Count(); string answer = ok ? "Yes" : "No"; 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, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
446
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N = GetInt(); var f = 0; var o = 0; var A = GetIntArray(); for (int i = 0; i < N; i++) { if (A[i] % 4 == 0) f++; else if (A[i] % 2 != 0) o++; } var ans = (o <= f).YesNo(); Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N = GetInt(); var f = 0; var o = 0; var A = GetIntArray(); for (int i = 0; i < N; i++) { if (A[i] % 4 == 0) f++; else if (A[i] % 2 != 0) o++; } var ans = (o <= f || f >= N / 2).YesNo(); Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } }
[["+", 0, 213, 63, 214, 205, 23, 0, 16, 17, 106], ["+", 63, 214, 205, 23, 0, 16, 12, 16, 31, 22], ["+", 63, 214, 205, 23, 0, 16, 12, 16, 17, 20], ["+", 205, 23, 0, 16, 12, 16, 12, 16, 31, 22], ["+", 205, 23, 0, 16, 12, 16, 12, 16, 17, 85], ["+", 205, 23, 0, 16, 12, 16, 12, 16, 12, 203]]
8
1,214
6
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static cp; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { // public static cp alg; static void Main() { var alg = new cp(); var s = alg.inputString(); var notfound = new List<string>(); for (char a = 'A'; a <= 'Z'; a++) { if (!s.Contains(a) && !notfound.Contains(a.ToString())) notfound.Add(a.ToString()); } notfound.Sort(); WriteLine(notfound.Count == 26 ? "None" : notfound[0]); } } class cp { public cp() {} public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); } public int LCM(int a, int b) { return a * b / GCD(a, b); } public int countChar(string s, string key) { return s.Length - s.Replace(key, "").Length; } public string yesno(bool f, string type = null) { string str; if (f) str = "Yes"; else str = "No"; if (type == "lower") return str.ToLower(); else if (type == "upper") return str.ToUpper(); else return str; } public void inputSkip() { ReadLine(); return; } public string inputString() { return ReadLine(); } public string[] inputSplitString() { return ReadLine().Split(); } public string[] inputLinesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] inputJaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int inputInt() { return int.Parse(ReadLine()); } public int[] inputSplitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] inputLinesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] inputJaggedArrayInt(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 inputLong() { return long.Parse(ReadLine()); } public long[] inputSplitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] inputLinesLong(int len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] inputJaggedArrayLong(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 inputDouble() { return double.Parse(ReadLine()); } public double[] inputSplitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] inputLinesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] inputJaggedArrayDouble(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 static cp; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { // public static cp alg; static void Main() { var alg = new cp(); var s = alg.inputString(); var notfound = new List<string>(); for (char a = 'a'; a <= 'z'; a++) { if (!s.Contains(a) && !notfound.Contains(a.ToString())) notfound.Add(a.ToString()); } notfound.Sort(); WriteLine(notfound.Count == 0 ? "None" : notfound[0]); } } class cp { public cp() {} public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); } public int LCM(int a, int b) { return a * b / GCD(a, b); } public int countChar(string s, string key) { return s.Length - s.Replace(key, "").Length; } public string yesno(bool f, string type = null) { string str; if (f) str = "Yes"; else str = "No"; if (type == "lower") return str.ToLower(); else if (type == "upper") return str.ToUpper(); else return str; } public void inputSkip() { ReadLine(); return; } public string inputString() { return ReadLine(); } public string[] inputSplitString() { return ReadLine().Split(); } public string[] inputLinesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] inputJaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int inputInt() { return int.Parse(ReadLine()); } public int[] inputSplitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] inputLinesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] inputJaggedArrayInt(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 inputLong() { return long.Parse(ReadLine()); } public long[] inputSplitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] inputLinesLong(int len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] inputJaggedArrayLong(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 inputDouble() { return double.Parse(ReadLine()); } public double[] inputSplitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] inputLinesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] inputJaggedArrayDouble(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; } }
[["-", 10, 198, 0, 200, 0, 212, 0, 252, 0, 253], ["+", 10, 198, 0, 200, 0, 212, 0, 252, 0, 253], ["-", 8, 196, 0, 7, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 7, 15, 16, 12, 252, 0, 253], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203]]
8
1,006
6
using System; class Problem { public static void Main() { var n = Console.ReadLine(); var arr = new bool[26]; foreach (var c in n) arr[c - 'a'] = true; for (var i = 0; i < arr.Length; i++) { if (!arr[i]) { Console.WriteLine($"{'a' + i}"); return; } } Console.WriteLine("None"); } }
using System; class Problem { public static void Main() { var n = Console.ReadLine(); var arr = new bool[26]; foreach (var c in n) arr[c - 'a'] = true; for (var i = 0; i < arr.Length; i++) { if (!arr[i]) { Console.WriteLine($"{Convert.ToChar('a' + i)}"); return; } } Console.WriteLine("None"); } }
[["+", 0, 283, 0, 284, 0, 213, 63, 214, 205, 22], ["+", 0, 283, 0, 284, 0, 213, 63, 214, 0, 131], ["+", 0, 283, 0, 284, 0, 213, 63, 214, 141, 22], ["+", 0, 283, 0, 284, 0, 213, 3, 4, 0, 24], ["+", 0, 283, 0, 284, 0, 213, 3, 4, 0, 25]]
8
105
5
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { // C#Lover/////////////////////////////////////////////////// string S; void Solve() { io.i(out S); var aa = new AssociativeArray<char>(S.ToCharArray()); string ans = "none"; for (char c = 'a'; c <= 'z'; c++) { if (!aa.conK(c)) { ans = c.ToString(); break; } } io.o(ans); } //////////////////////////////////////////////////////////// public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // cannot use break,continue,goto void FOR(int a, int b, Action<int> act) { for (int i = a; i < b; i++) act(i); } // void REP(int n, Action<int> act) { for (int i = 0; i < n; i++) act(i); } #endregion } #region default class IO { TYPE tp; string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); tp = new TYPE(); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return tp.suitType<T>(String); } public void i<T>(out T v) { v = tp.suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; i++) a[i] = tp.suitType<T>(String); } public void ini<T>(out T[] a, out T[] b, int n) { a = new T[n]; b = new T[n]; for (int i = 0; i < n; i++) { a[i] = i<T>(); b[i] = i<T>(); } } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { o(connect<T>(a)); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } private string connect<T>(params T[] s) { return string.Join(" ", s); } } class TYPE { public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } public T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } public T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size = 0; private int type; public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { public int mod = 1000000007; // 10^9+7 public long MulMod(long a, long b) { return (a % mod) * (b % mod) % mod; } public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { long ret = 1; for (long i = 1; i <= n; i++) ret = (ret * i) % mod; return ret; } public long Comb(long n, long r) { if (r == 0 || n == r) return 1; else if (n == 0) return 0; else if (n < 0 || n < r) throw new ArgumentException("n,r invalid"); else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, n) => GCD(v, n)); } public T Max<T>(params T[] a) { return a.Max(); } public T Min<T>(params T[] a) { return a.Min(); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public int[] DigValArr(int n) { int[] ret = new int[Digit(n)]; ret.Length.REP(i => ret[i] = DigVal(n, i + 1)); return ret; } public long Tousa(long a, long d, int n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, int n) { return n * (2 * a + (n - 1) * d) / 2; } } class AssociativeArray<T> : IEnumerable { // hack:配列時要初期化 public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(params T[] a) { a.Length.REP(i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { a.Length.REP(i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => dic.First(d => d.Value == MaxVal).Key; public T MinKey => dic.First(d => d.Value == MinVal).Key; public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } // KeyValuePairの利用に制限がかかる //:sort->array } class UnionFind { public int[] parent; public int[] depth; public void Init(int n) { parent = new int[n]; depth = new int[n]; n.REP(i => parent[i] = i); } public int Find(int x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(int x, int y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(int a, int b) { return Find(a) == Find(b); } } class Time { public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } #endregion #region Graph class Index { public int[] Comp(int[] bef) { int[] aft = new int[bef.Length]; var tmp = bef.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); aft = bef.Select(v => tmp[v]).ToArray(); return aft; } } class BasicGraph { //まとめよう public List<Tuple<int, long>>[] G; public void Init(int n) { G = new List<Tuple<int, long>>[n + 1]; G.Length.REP(i => G[i] = new List<Tuple<int, long>>()); } public void Dir(int[] f, int[] t) { f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], 1L))); } public void Dir(int[] f, int[] t, long[] c) { f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], c[i]))); } public void NonDir(int[] f, int[] t) { f.Length.REP(i => { G[f[i]].Add(Tuple.Create(t[i], 1L)); G[t[i]].Add(Tuple.Create(f[i], 1L)); }); } public void NonDir(int[] f, int[] t, long[] c) { f.Length.REP(i => { G[f[i]].Add(Tuple.Create(t[i], c[i])); G[t[i]].Add(Tuple.Create(f[i], c[i])); }); } } class TreeDis { // test public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; g.Length.REP(i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class ShortestPath { protected int I = -1; protected long INF = (int)1e9; public List<Tuple<int, long>>[] Adj; public void Init(int n) { I = n + 1; Adj = new List<Tuple<int, long>>[I]; I.REP(i => Adj[i] = new List<Tuple<int, long>>()); } public void AddPath(int f, int t, long c) { Adj[f].Add(Tuple.Create(t, c)); Adj[t].Add(Tuple.Create(f, c)); } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } } class Dijkstra : ShortestPath { //隣接対応後未検証 public long MinCost(int f, int t) { long[] cost = new long[I]; cost.Set(INF); cost[f] = 0; var pq = new PQueue<Tuple<int, long>>(); pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost) while (pq.Count > 0) { var cur = pq.Dequeue(); if (cost[cur.Item1] < cur.Item2) continue; Adj[cur.Item1].Count.REP(i => { var tmp = Adj[cur.Item1][i]; if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) { cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2; pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1])); } }); } return cost[t]; } } class BellmanFord : ShortestPath { public long MinCost(int f, int t) { long[] cost = new long[I]; cost.Set(INF); cost[f] = 0; bool isUpdate = true; while (isUpdate) { isUpdate = false; I.REP(i => Adj[i].Count.REP(j => { var cur = Adj[i][j]; if (cost[cur.Item1] > cost[i] + cur.Item2) { cost[cur.Item1] = cost[i] + cur.Item2; isUpdate = true; } })); } return cost[t]; } } class WarshallFloyd { //要チェック private int E; private int INF = (int)1e9; public long[,] G; public void Init(int n) { E = n + 1; G = new long[E, E]; G.Set(INF); E.REP(i => G[i, i] = 0); } public void AddPath(int f, int t, long c) { G[f, t] = c; G[t, f] = c; } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } public long[,] MinCostArr() { E.REP(i => E.REP( j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k])))); return G; } } #endregion #region Ex static class StringEX { //文字 public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { //数値 public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); } public static bool isOdd(this int v) { return v % 2 != 0; } public static void REP(this int v, Action<int> act) { for (int i = 0; i < v; i++) act(i); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v)); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class TestEx {} #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Program { class MainClass { // C#Lover/////////////////////////////////////////////////// string S; void Solve() { io.i(out S); var aa = new AssociativeArray<char>(S.ToCharArray()); string ans = "None"; for (char c = 'a'; c <= 'z'; c++) { if (!aa.conK(c)) { ans = c.ToString(); break; } } io.o(ans); } //////////////////////////////////////////////////////////// public static void Main(string[] args) { new MainClass().Stream(); } IO io = new IO(); void Stream() { Solve(); io.writeFlush(); } // void Stream() { Test(); io.writeFlush(); } void Test() {} #region MockMacro // cannot use break,continue,goto void FOR(int a, int b, Action<int> act) { for (int i = a; i < b; i++) act(i); } // void REP(int n, Action<int> act) { for (int i = 0; i < n; i++) act(i); } #endregion } #region default class IO { TYPE tp; string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public IO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); tp = new TYPE(); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string[] arr => Console.ReadLine().Split(' '); public char[] arrChar => Array.ConvertAll(arr, char.Parse); public int[] arrInt => Array.ConvertAll(arr, int.Parse); public long[] arrLong => Array.ConvertAll(arr, long.Parse); public double[] arrDouble => Array.ConvertAll(arr, double.Parse); public T i<T>() { return tp.suitType<T>(String); } public void i<T>(out T v) { v = tp.suitType<T>(String); } public void i<T, U>(out T v1, out U v2) { i(out v1); i(out v2); } public void i<T, U, V>(out T v1, out U v2, out V v3) { i(out v1); i(out v2); i(out v3); } public void i<T, U, V, W>(out T v1, out U v2, out V v3, out W v4) { i(out v1); i(out v2); i(out v3); i(out v4); } public void i<T, U, V, W, X>(out T v1, out U v2, out V v3, out W v4, out X v5) { i(out v1); i(out v2); i(out v3); i(out v4); i(out v5); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; i++) a[i] = tp.suitType<T>(String); } public void ini<T>(out T[] a, out T[] b, int n) { a = new T[n]; b = new T[n]; for (int i = 0; i < n; i++) { a[i] = i<T>(); b[i] = i<T>(); } } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) a[i, j] = i<T>(); } public void o<T>(T v) { Console.WriteLine(v); } public void o<T>(params T[] a) { Array.ForEach(a, n => o(n)); } public void ol<T>(T v) { Console.Write(v + " "); } public void ol<T>(params T[] a) { o(connect<T>(a)); } public void br() { o(""); } public void writeFlush() { Console.Out.Flush(); } private string connect<T>(params T[] s) { return string.Join(" ", s); } } class TYPE { public bool typeEQ<T, U>() { return typeof(T).Equals(typeof(U)); } public T convertType<T, U>(U v) { return (T)Convert.ChangeType(v, typeof(T)); } public T suitType<T>(string s) { if (typeEQ<T, int>()) return convertType<T, int>(int.Parse(s)); if (typeEQ<T, long>()) return convertType<T, long>(long.Parse(s)); if (typeEQ<T, double>()) return convertType<T, double>(double.Parse(s)); if (typeEQ<T, char>()) return convertType<T, char>(char.Parse(s)); return convertType<T, string>(s); } } class PQueue<T> where T : IComparable { public List<T> heap; private Comparison<T> comp; private IComparer<T> comparer; private int size = 0; private int type; public PQueue(int type = 0) : this(Comparer<T>.Default) { this.type = type; } public PQueue(IComparer<T> comparer) : this(16, comparer.Compare) { this.comparer = comparer; } public PQueue(Comparison<T> comparison) : this(16, comparison) {} public PQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.comp = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (Compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } public bool Empty() { return !Any(); } public bool Contains(T v) { return heap.Contains(v); } private int Compare(T x, T y) { return type == 0 ? x.CompareTo(y) : y.CompareTo(x); } } #endregion #region other class Mat { public int mod = 1000000007; // 10^9+7 public long MulMod(long a, long b) { return (a % mod) * (b % mod) % mod; } public long Pow(long a, long b) { if (b == 0) return 1; if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod; else return Pow(a * a % mod, b / 2) % mod; } public long Fact(long n) { long ret = 1; for (long i = 1; i <= n; i++) ret = (ret * i) % mod; return ret; } public long Comb(long n, long r) { if (r == 0 || n == r) return 1; else if (n == 0) return 0; else if (n < 0 || n < r) throw new ArgumentException("n,r invalid"); else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod; } public bool isPrime(long n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (long v = 3; v <= (long)Math.Sqrt(n); v += 2) if (n % v == 0) return false; return true; } public long LCM(long a, long b) { return a * (b / GCD(a, b)); } public long LCM(params long[] a) { return a.Aggregate((v, n) => LCM(v, n)); } public long GCD(long a, long b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); } public long GCD(params long[] array) { return array.Aggregate((v, n) => GCD(v, n)); } public T Max<T>(params T[] a) { return a.Max(); } public T Min<T>(params T[] a) { return a.Min(); } public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } public double Dis(int x1, int y1, int x2, int y2) { return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2)); } public int mDis(int x1, int y1, int x2, int y2) { return Math.Abs(x1 - x2) + Math.Abs(y1 - y2); } public int Digit(long n) { return (n == 0) ? 1 : (int)Math.Log10(n) + 1; } public int DigVal(int n, int dig) { return (n % (int)Pow(10, dig)) / (int)Pow(10, dig - 1); } public int[] DigValArr(int n) { int[] ret = new int[Digit(n)]; ret.Length.REP(i => ret[i] = DigVal(n, i + 1)); return ret; } public long Tousa(long a, long d, int n) { return a + (n - 1) * d; } public long TousaSum(long a, long d, int n) { return n * (2 * a + (n - 1) * d) / 2; } } class AssociativeArray<T> : IEnumerable { // hack:配列時要初期化 public Dictionary<T, int> dic; public AssociativeArray() { dic = new Dictionary<T, int>(); } public AssociativeArray(params T[] a) { dic = new Dictionary<T, int>(); Add(a); } public void Add(params T[] a) { a.Length.REP(i => { if (!conK(a[i])) dic[a[i]] = 0; dic[a[i]]++; }); } public void Set(T k, int v) { if (!dic.ContainsKey(k)) dic[k] = 0; dic[k] = v; } public void Remove(params T[] a) { a.Length.REP(i => { if (conK(a[i])) dic.Remove(a[i]); }); } public T[] Keys() { return dic.Keys.ToArray<T>(); } public int Val(T k) { return (dic.ContainsKey(k)) ? dic[k] : 0; } public int ValSum => dic.Values.Sum(); public int KeyNum => dic.Keys.Count; public int MaxVal => dic.Values.Max(); public int MinVal => dic.Values.Min(); public T MaxKey => dic.First(d => d.Value == MaxVal).Key; public T MinKey => dic.First(d => d.Value == MinVal).Key; public bool conK(T k) { return dic.ContainsKey(k); } public bool anyK(params T[] k) { return k.Any(key => conK(key)); } public bool allK(params T[] k) { return k.All(key => conK(key)); } public void Show() { foreach (var v in dic) { Console.WriteLine(v.Key + " : " + v.Value); } } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } // KeyValuePairの利用に制限がかかる //:sort->array } class UnionFind { public int[] parent; public int[] depth; public void Init(int n) { parent = new int[n]; depth = new int[n]; n.REP(i => parent[i] = i); } public int Find(int x) { return (parent[x] == x) ? x : parent[x] = Find(parent[x]); } public void Unite(int x, int y) { x = Find(x); y = Find(y); if (x == y) return; if (depth[x] < depth[y]) parent[x] = y; else { parent[y] = x; if (depth[x] == depth[y]) depth[x]++; } } public bool Same(int a, int b) { return Find(a) == Find(b); } } class Time { public bool isLeapYear(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); } } #endregion #region Graph class Index { public int[] Comp(int[] bef) { int[] aft = new int[bef.Length]; var tmp = bef.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); aft = bef.Select(v => tmp[v]).ToArray(); return aft; } } class BasicGraph { //まとめよう public List<Tuple<int, long>>[] G; public void Init(int n) { G = new List<Tuple<int, long>>[n + 1]; G.Length.REP(i => G[i] = new List<Tuple<int, long>>()); } public void Dir(int[] f, int[] t) { f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], 1L))); } public void Dir(int[] f, int[] t, long[] c) { f.Length.REP(i => G[f[i]].Add(Tuple.Create(t[i], c[i]))); } public void NonDir(int[] f, int[] t) { f.Length.REP(i => { G[f[i]].Add(Tuple.Create(t[i], 1L)); G[t[i]].Add(Tuple.Create(f[i], 1L)); }); } public void NonDir(int[] f, int[] t, long[] c) { f.Length.REP(i => { G[f[i]].Add(Tuple.Create(t[i], c[i])); G[t[i]].Add(Tuple.Create(f[i], c[i])); }); } } class TreeDis { // test public List<Tuple<long, long>>[] g; public long[] a2other; private int type; public TreeDis(int type = 0) { this.type = type; } // 0->bfs,other->dfs public void Init(long n) { g = new List<Tuple<long, long>>[n + 1]; g.Length.REP(i => g[i] = new List<Tuple<long, long>>()); } public void Run(long[] a, long[] b) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], 1L)); g[b[i]].Add(Tuple.Create(a[i], 1L)); }); } public void Run(long[] a, long[] b, long[] w) { a.Length.REP(i => { g[a[i]].Add(Tuple.Create(b[i], w[i])); g[b[i]].Add(Tuple.Create(a[i], w[i])); }); } public long[] a2iArr(long a) { a2other = new long[g.Count()]; if (type == 0) BFS(a); else DFS(a); return a2other; } private void BFS(long a) { var q = new Queue<Tuple<long, long>>(); q.Enqueue(Tuple.Create(a, -1L)); while (q.Count > 0) { var c = q.Dequeue(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; q.Enqueue(Tuple.Create(v.Item1, c.Item1)); } } } private void DFS(long a) { var s = new Stack<Tuple<long, long>>(); s.Push(Tuple.Create(a, -1L)); while (s.Count > 0) { var c = s.Pop(); foreach (var v in g[c.Item1]) { if (v.Item1 == c.Item2) continue; a2other[v.Item1] = a2other[c.Item1] + v.Item2; s.Push(Tuple.Create(v.Item1, c.Item1)); } } } } class ShortestPath { protected int I = -1; protected long INF = (int)1e9; public List<Tuple<int, long>>[] Adj; public void Init(int n) { I = n + 1; Adj = new List<Tuple<int, long>>[I]; I.REP(i => Adj[i] = new List<Tuple<int, long>>()); } public void AddPath(int f, int t, long c) { Adj[f].Add(Tuple.Create(t, c)); Adj[t].Add(Tuple.Create(f, c)); } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } } class Dijkstra : ShortestPath { //隣接対応後未検証 public long MinCost(int f, int t) { long[] cost = new long[I]; cost.Set(INF); cost[f] = 0; var pq = new PQueue<Tuple<int, long>>(); pq.Enqueue(Tuple.Create(f, 0L)); //(from,cost) while (pq.Count > 0) { var cur = pq.Dequeue(); if (cost[cur.Item1] < cur.Item2) continue; Adj[cur.Item1].Count.REP(i => { var tmp = Adj[cur.Item1][i]; if (cost[tmp.Item1] > cost[cur.Item1] + tmp.Item2) { cost[tmp.Item1] = cost[cur.Item1] + tmp.Item2; pq.Enqueue(Tuple.Create(tmp.Item1, cost[tmp.Item1])); } }); } return cost[t]; } } class BellmanFord : ShortestPath { public long MinCost(int f, int t) { long[] cost = new long[I]; cost.Set(INF); cost[f] = 0; bool isUpdate = true; while (isUpdate) { isUpdate = false; I.REP(i => Adj[i].Count.REP(j => { var cur = Adj[i][j]; if (cost[cur.Item1] > cost[i] + cur.Item2) { cost[cur.Item1] = cost[i] + cur.Item2; isUpdate = true; } })); } return cost[t]; } } class WarshallFloyd { //要チェック private int E; private int INF = (int)1e9; public long[,] G; public void Init(int n) { E = n + 1; G = new long[E, E]; G.Set(INF); E.REP(i => G[i, i] = 0); } public void AddPath(int f, int t, long c) { G[f, t] = c; G[t, f] = c; } public void AddPath(int[] f, int[] t, long[] c) { f.Length.REP(i => AddPath(f[i], t[i], c[i])); } public long[,] MinCostArr() { E.REP(i => E.REP( j => E.REP(k => G[j, k] = Math.Min(G[j, k], G[j, i] + G[i, k])))); return G; } } #endregion #region Ex static class StringEX { //文字 public static string Reversed(this string s) { return string.Join("", s.Reverse()); } public static string Repeat(this string s, int n) { return string.Concat(Enumerable.Repeat(s, n).ToArray()); } public static int toInt(this string s) { int n; return (int.TryParse(s.TrimStart('0'), out n)) ? n : 0; } public static int toInt(this char c) { return toInt(c.ToString()); } public static int toInt(this char[] c) { return toInt(new string(c)); } public static string toString(this char[] c) { return new string(c); } } static class NumericEx { //数値 public static string pad0<T>(this T v, int n) { return v.ToString().PadLeft(n, '0'); } public static double RoundOff(this double v, int n) { return Math.Round(v, n - 1, MidpointRounding.AwayFromZero); } public static bool isOdd(this int v) { return v % 2 != 0; } public static void REP(this int v, Action<int> act) { for (int i = 0; i < v; i++) act(i); } } static class ArrayEX { public static T[] Sort<T>(this T[] a) { Array.Sort(a); return a; } public static void Set<T>(this T[] a, T v) { a.Length.REP(i => a[i] = v); } public static void Set<T>(this T[,] a, T v) { a.GetLength(0).REP(i => a.GetLength(1).REP(j => a[i, j] = v)); } } static class BitEx { public static bool Any(this BitArray b) { foreach (bool f in b) if (f) return true; return false; } public static bool All(this BitArray b) { foreach (bool f in b) if (!f) return false; return true; } public static bool None(this BitArray b) { return !Any(b); } public static void Flip(this BitArray b, int index) { b.Set(index, !b.Get(index)); } } static class TestEx {} #endregion }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
8
5,527
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { string S = Console.ReadLine(); bool[] found = new bool[26]; // found[0] = a for (int i = 0; i < S.Length; i++) { found[S[i] - 'a'] = true; } for (int i = 0; i < 26; i++) { if (found[i] == false) { char c = (char)('a' + i); Console.WriteLine(c); break; } } Console.WriteLine("None"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { string S = Console.ReadLine(); bool[] found = new bool[26]; // found[0] = a for (int i = 0; i < S.Length; i++) { found[S[i] - 'a'] = true; } for (int i = 0; i < 26; i++) { if (found[i] == false) { char c = (char)('a' + i); Console.WriteLine(c); return; } } Console.WriteLine("None"); } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
8
158
2
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; class Test { public static void Main() { var n = int.Parse(Console.ReadLine()); var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Array.Sort(arr, (x, y) => { return y.CompareTo(x); }); long h = 0; long w = 0; for (int i = 1; i < arr.Length; i++) { if (arr[i] == arr[i - 1]) { if (h == 0) h = arr[i]; else if (w == 0) w = arr[i]; } if (h != 0 && w != 0) break; } Console.Write(h * w); } }
using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; class Test { public static void Main() { var n = int.Parse(Console.ReadLine()); var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); Array.Sort(arr, (x, y) => { return y.CompareTo(x); }); long h = 0; long w = 0; for (int i = 1; i < arr.Length; i++) { if (arr[i] == arr[i - 1]) { if (h == 0) h = arr[i]; else if (w == 0) w = arr[i]; i++; } if (h != 0 && w != 0) break; } Console.Write(h * w); } }
[["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
199
3