buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Hello { private const int INF = 1000000007; public static void Main() { string S = NextString(); ///'x'は無限に追加できるから'x'を除いたものが回文なら可能 List<char> list = new List<char>(); List<char> A = new List<char>(); for (int i = 0; i < S.Length; i++) if (S[i] != 'x') list.Add(S[i]); int M = (int)Math.Ceiling(list.Count() / 2.0); for (int i = 0; i < M; i++) if (list[i] != list[list.Count() - 1 - i]) { Console.WriteLine(-1); return; } else A.Add(list[i]); ///それぞれの文字間隔に'x'が何個含まれているか int a = 0; int b = S.Length - 1; int ans = 0; foreach (var c in A) { int a_c = 0; for (; a < S.Length; a++) if (S[a] != c) { a_c++; } else break; int b_c = 0; for (; b >= 0; b--) if (S[b] != c) { b_c++; } else break; ans += Math.Abs(a_c - b_c); } Console.WriteLine(ans); } } public class Input { private static Queue<string> queue = new Queue<string>(); private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); } public static string NextString() { Confirm(); return queue.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Hello { private const int INF = 1000000007; public static void Main() { string S = NextString(); ///'x'は無限に追加できるから'x'を除いたものが回文なら可能 List<char> list = new List<char>(); List<char> A = new List<char>(); for (int i = 0; i < S.Length; i++) if (S[i] != 'x') list.Add(S[i]); int M = (int)Math.Ceiling(list.Count() / 2.0); for (int i = 0; i < M; i++) if (list[i] != list[list.Count() - 1 - i]) { Console.WriteLine(-1); return; } else A.Add(list[i]); ///それぞれの文字間隔に'x'が何個含まれているか int a = 0; int b = S.Length - 1; int ans = 0; foreach (var c in A) { int a_c = 0; for (; a < S.Length; a++) if (S[a] != c) { a_c++; } else break; int b_c = 0; for (; b >= 0; b--) if (S[b] != c) { b_c++; } else break; a += 1; b -= 1; ans += Math.Abs(a_c - b_c); } Console.WriteLine(ans); } } public class Input { private static Queue<string> queue = new Queue<string>(); private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); } public static string NextString() { Confirm(); return queue.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
[["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110]]
8
587
8
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 { //////////////////////////////////////////////////////////// string S; void Solve() { io.i(out S); if (S == S.Reversed()) { io.o(0); return; } var sWithoutX = new string(S.Where(c => c != 'x').ToArray()); var sr = sWithoutX.Reversed(); if (sWithoutX != sr) { io.o(-1); return; } var R = S.Reversed(); var ans = 0; var sIndex = 0; var rIndex = 0; for (int i = 0; i < S.Length; ++i) { // io.ol(i, S[sIndex], R[rIndex]); if (S[sIndex] == 'x' && R[rIndex] == 'x') { sIndex++; rIndex++; } else if (S[sIndex] == 'x') { sIndex++; ans++; } else if (R[rIndex] == 'x') { rIndex++; ans++; } else if (S[sIndex] == R[rIndex]) { sIndex++; rIndex++; } else { io.o(-1); return; } } io.o(ans); } //////////////////////////////////////////////////////////// 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, U>(out Tuple<T, U>[] t, int n) { t = new Tuple<T, U>[n]; for (int j = 0; j < n; ++j) { T i1; U i2; i(out i1); i(out i2); t[j] = Tuple.Create(i1, i2); } } public void ini<T, U, V>(out Tuple<T, U, V>[] t, int n) { t = new Tuple<T, U, V>[n]; for (int j = 0; j < n; ++j) { T i1; U i2; V i3; i(out i1); i(out i2); i(out i3); t[j] = Tuple.Create(i1, i2, i3); } } 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 YN(bool f) { o(f ? "YES" : "NO"); } public void Yn(bool f) { o(f ? "Yes" : "No"); } public void yn(bool f) { o(f ? "yes" : "no"); } 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 : struct, IComparable<T> { 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); } } 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 T[] ValueSortedKey(bool inc = true) { 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(); } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } //:sort->array } public struct edge : IComparable<edge> { public int to; public long cost; public edge(int to, long cost) { this.to = to; this.cost = cost; } public int CompareTo(edge e) { return cost.CompareTo(e.cost); } } #endregion #region test // interface IField<T> { T Add(T that) ; T Subtract(T that); T // Multiply(T that); T Devide(T that); } #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)); } } } //そのうちrefacter public List<int[]> gRangedArr(int content, int rangeStart, int rangeEnd) { var result = new List<int[]>(); _gRangedArr(content - 1, new int[content], result, rangeStart, rangeEnd); return result; } private void _gRangedArr(int n, int[] Arr, List<int[]> result, int rs, int re) { if (n < 0) { result.Add(Arr); return; } for (int i = rs; i <= re; ++i) { var newArr = Arr.ToArray(); newArr[n] = i; _gRangedArr(n - 1, newArr, result, rs, re); } } } #endregion #region Data 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; //辺は1~N protected int V; //頂点数 protected int E; //辺の数 protected bool isNonDir = true; //有向? public long INF = (long)1e15; //初期化 public long[] cost; //重み public List<edge>[] Adj; //隣接リスト public void Init(int n) { I = n + 1; V = n; Adj = new List<edge>[I]; for (int i = 0; i < I; ++i) Adj[i] = new List<edge>(); } public void AddPath(int f, int t, long c = 1) { E++; Adj[f].Add(new edge(t, c)); if (isNonDir) Adj[t].Add(new edge(f, c)); } 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 AddPath(int[] f, int[] t) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i]); } public bool PathExist(int t) { return cost[t] != INF; } } class Dijkstra : ShortestPath { public Dijkstra(bool isNonDir = true) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { Run(f); return cost[t]; } public long MinCost(int t) { return cost[t]; } public void Run(int f) { cost = new long[I]; for (int i = 0; i < I; ++i) cost[i] = INF; cost[f] = 0; var pq = new PQueue<edge>(); pq.Enqueue(new edge(f, 0L)); while (!pq.Empty()) { var cur = pq.Dequeue(); if (cost[cur.to] < cur.cost) continue; for (int i = 0; i < Adj[cur.to].Count; ++i) { var tmp = Adj[cur.to][i]; if (cost[tmp.to] > cur.cost + tmp.cost) { cost[tmp.to] = cur.cost + tmp.cost; pq.Enqueue(new edge(tmp.to, cost[tmp.to])); } } } } } class BellmanFord : ShortestPath { private bool[] neg; public BellmanFord(bool isNonDir = true) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { Run(f); return cost[t]; } public long MinCost(int t) { return cost[t]; } public void Run(int f) { cost = new long[I]; cost.Set(INF); cost[f] = 0; neg = new bool[I]; for (int i = 0; i < I - 1; i++) for (int j = 0; j < I; ++j) for (int k = 0; k < Adj[j].Count; ++k) { var cur = Adj[j][k]; if (cost[cur.to] > cost[j] + cur.cost) cost[cur.to] = cost[j] + cur.cost; } for (int i = 0; i < I; i++) for (int j = 0; j < I; ++j) for (int k = 0; k < Adj[j].Count; ++k) { var cur = Adj[j][k]; if (cost[cur.to] > cost[j] + cur.cost) { cost[cur.to] = cost[j] + cur.cost; neg[cur.to] = true; } if (neg[j]) neg[cur.to] = true; } } public bool loopExist() { return neg[I - 1]; } } class WF : ShortestPath { public WF() {} public WF(bool isNonDir) { this.isNonDir = isNonDir; } public void Run() {} } 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 = 1) { 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 = 0; i < E; ++i) for (int j = 0; j < E; ++j) for (int k = 0; 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 = 0; i < E; ++i) if (G[i, a] + c == G[i, b]) return true; return false; } //全地点間を繋ぐ最小コスト public long MinCost() { long orig = 0; for (int i = 0; i < E; ++i) for (int j = i + 1; j < E; ++j) { bool isOrig = true; for (int k = 0; 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 UnionFind { 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 Kruskal(bool isNonDir = true) { this.isNonDir = isNonDir; } public long Run() { var uf = new UnionFind(); var ret = 0L; var L = new List<Tuple<int, int, long>>(); uf.Init(V); for (int i = 0; i < I; ++i) for (int j = 0; j < Adj[i].Count; ++i) L.Add(Tuple.Create(i, Adj[i][j].to, Adj[i][j].cost)); L = L.OrderBy(t => t.Item3).ToList(); for (int i = 0; i < L.Count; ++i) if (!uf.Find(L[i].Item1, L[i].Item2)) { ret += L[i].Item3; uf.Unite(L[i].Item1, L[i].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); } public static int LowerBound<T>(this T[] a, T x) where T : IComparable { Array.Sort(a); int lb = -1, ub = a.Length; while (ub - lb > 1) { int mid = (ub + lb) / 2; if (a[mid].CompareTo(x) >= 0) ub = mid; else lb = mid; } return ub; } public static int UpperBound<T>(this T[] a, T x) where T : IComparable { Array.Sort(a); int lb = -1, ub = a.Length; while (ub - lb > 1) { int mid = (ub + lb) / 2; if (a[mid].CompareTo(x) > 0) ub = mid; else lb = mid; } return ub; } } 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 {} static class Test { public static int add(this int a, int b) { return a + b; } public static double add(this double a, int b) { return a + b; } public static double add(this int a, double b) { return a + b; } public static double add(this double a, double b) { return a + b; } public static long add(this long a, int b) { return a + b; } public static long add(this int a, long b) { return a + b; } public static long add(this long a, long b) { return a + b; } } #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 { //////////////////////////////////////////////////////////// string S; void Solve() { io.i(out S); if (S == S.Reversed()) { io.o(0); return; } var sWithoutX = new string(S.Where(c => c != 'x').ToArray()); var sr = sWithoutX.Reversed(); if (sWithoutX != sr) { io.o(-1); return; } var R = S.Reversed(); var ans = 0; var sIndex = 0; var rIndex = 0; for (int i = 0; i <= sWithoutX.Length / 2; ++i) { // io.ol(i, S[sIndex], R[rIndex]); while (true) { // if (sIndex > 0) { // io.o(sIndex,rIndex); // return; //} if (S[sIndex] == 'x' && R[rIndex] == 'x') { sIndex++; rIndex++; } else if (S[sIndex] == 'x') { sIndex++; ans++; } else if (R[rIndex] == 'x') { rIndex++; ans++; } else if (S[sIndex] == R[rIndex]) { sIndex++; rIndex++; break; } else { io.o(-1); return; } } } io.o(ans); } //////////////////////////////////////////////////////////// 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, U>(out Tuple<T, U>[] t, int n) { t = new Tuple<T, U>[n]; for (int j = 0; j < n; ++j) { T i1; U i2; i(out i1); i(out i2); t[j] = Tuple.Create(i1, i2); } } public void ini<T, U, V>(out Tuple<T, U, V>[] t, int n) { t = new Tuple<T, U, V>[n]; for (int j = 0; j < n; ++j) { T i1; U i2; V i3; i(out i1); i(out i2); i(out i3); t[j] = Tuple.Create(i1, i2, i3); } } 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 YN(bool f) { o(f ? "YES" : "NO"); } public void Yn(bool f) { o(f ? "Yes" : "No"); } public void yn(bool f) { o(f ? "yes" : "no"); } 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 : struct, IComparable<T> { 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); } } 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 T[] ValueSortedKey(bool inc = true) { 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(); } public IEnumerator GetEnumerator() { foreach (var kp in dic) yield return kp; } //:sort->array } public struct edge : IComparable<edge> { public int to; public long cost; public edge(int to, long cost) { this.to = to; this.cost = cost; } public int CompareTo(edge e) { return cost.CompareTo(e.cost); } } #endregion #region test // interface IField<T> { T Add(T that) ; T Subtract(T that); T // Multiply(T that); T Devide(T that); } #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)); } } } //そのうちrefacter public List<int[]> gRangedArr(int content, int rangeStart, int rangeEnd) { var result = new List<int[]>(); _gRangedArr(content - 1, new int[content], result, rangeStart, rangeEnd); return result; } private void _gRangedArr(int n, int[] Arr, List<int[]> result, int rs, int re) { if (n < 0) { result.Add(Arr); return; } for (int i = rs; i <= re; ++i) { var newArr = Arr.ToArray(); newArr[n] = i; _gRangedArr(n - 1, newArr, result, rs, re); } } } #endregion #region Data 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; //辺は1~N protected int V; //頂点数 protected int E; //辺の数 protected bool isNonDir = true; //有向? public long INF = (long)1e15; //初期化 public long[] cost; //重み public List<edge>[] Adj; //隣接リスト public void Init(int n) { I = n + 1; V = n; Adj = new List<edge>[I]; for (int i = 0; i < I; ++i) Adj[i] = new List<edge>(); } public void AddPath(int f, int t, long c = 1) { E++; Adj[f].Add(new edge(t, c)); if (isNonDir) Adj[t].Add(new edge(f, c)); } 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 AddPath(int[] f, int[] t) { for (int i = 0; i < f.Length; ++i) AddPath(f[i], t[i]); } public bool PathExist(int t) { return cost[t] != INF; } } class Dijkstra : ShortestPath { public Dijkstra(bool isNonDir = true) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { Run(f); return cost[t]; } public long MinCost(int t) { return cost[t]; } public void Run(int f) { cost = new long[I]; for (int i = 0; i < I; ++i) cost[i] = INF; cost[f] = 0; var pq = new PQueue<edge>(); pq.Enqueue(new edge(f, 0L)); while (!pq.Empty()) { var cur = pq.Dequeue(); if (cost[cur.to] < cur.cost) continue; for (int i = 0; i < Adj[cur.to].Count; ++i) { var tmp = Adj[cur.to][i]; if (cost[tmp.to] > cur.cost + tmp.cost) { cost[tmp.to] = cur.cost + tmp.cost; pq.Enqueue(new edge(tmp.to, cost[tmp.to])); } } } } } class BellmanFord : ShortestPath { private bool[] neg; public BellmanFord(bool isNonDir = true) { this.isNonDir = isNonDir; } public long MinCost(int f, int t) { Run(f); return cost[t]; } public long MinCost(int t) { return cost[t]; } public void Run(int f) { cost = new long[I]; cost.Set(INF); cost[f] = 0; neg = new bool[I]; for (int i = 0; i < I - 1; i++) for (int j = 0; j < I; ++j) for (int k = 0; k < Adj[j].Count; ++k) { var cur = Adj[j][k]; if (cost[cur.to] > cost[j] + cur.cost) cost[cur.to] = cost[j] + cur.cost; } for (int i = 0; i < I; i++) for (int j = 0; j < I; ++j) for (int k = 0; k < Adj[j].Count; ++k) { var cur = Adj[j][k]; if (cost[cur.to] > cost[j] + cur.cost) { cost[cur.to] = cost[j] + cur.cost; neg[cur.to] = true; } if (neg[j]) neg[cur.to] = true; } } public bool loopExist() { return neg[I - 1]; } } class WF : ShortestPath { public WF() {} public WF(bool isNonDir) { this.isNonDir = isNonDir; } public void Run() {} } 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 = 1) { 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 = 0; i < E; ++i) for (int j = 0; j < E; ++j) for (int k = 0; 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 = 0; i < E; ++i) if (G[i, a] + c == G[i, b]) return true; return false; } //全地点間を繋ぐ最小コスト public long MinCost() { long orig = 0; for (int i = 0; i < E; ++i) for (int j = i + 1; j < E; ++j) { bool isOrig = true; for (int k = 0; 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 UnionFind { 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 Kruskal(bool isNonDir = true) { this.isNonDir = isNonDir; } public long Run() { var uf = new UnionFind(); var ret = 0L; var L = new List<Tuple<int, int, long>>(); uf.Init(V); for (int i = 0; i < I; ++i) for (int j = 0; j < Adj[i].Count; ++i) L.Add(Tuple.Create(i, Adj[i][j].to, Adj[i][j].cost)); L = L.OrderBy(t => t.Item3).ToList(); for (int i = 0; i < L.Count; ++i) if (!uf.Find(L[i].Item1, L[i].Item2)) { ret += L[i].Item3; uf.Unite(L[i].Item1, L[i].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); } public static int LowerBound<T>(this T[] a, T x) where T : IComparable { Array.Sort(a); int lb = -1, ub = a.Length; while (ub - lb > 1) { int mid = (ub + lb) / 2; if (a[mid].CompareTo(x) >= 0) ub = mid; else lb = mid; } return ub; } public static int UpperBound<T>(this T[] a, T x) where T : IComparable { Array.Sort(a); int lb = -1, ub = a.Length; while (ub - lb > 1) { int mid = (ub + lb) / 2; if (a[mid].CompareTo(x) > 0) ub = mid; else lb = mid; } return ub; } } 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 {} static class Test { public static int add(this int a, int b) { return a + b; } public static double add(this double a, int b) { return a + b; } public static double add(this int a, double b) { return a + b; } public static double add(this double a, double b) { return a + b; } public static long add(this long a, int b) { return a + b; } public static long add(this int a, long b) { return a + b; } public static long add(this long a, long b) { return a + b; } } #endregion }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 24], ["+", 0, 7, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 75, 57, 64, 196, 0, 93, 0, 94], ["+", 75, 57, 75, 57, 75, 57, 75, 196, 0, 46]]
8
9,169
14
using System; public class Program { private string S; private int L = 1 << 26; private int[] Dp; public void Solve() { var sc = new Scanner(); S = sc.Next(); // Dp = new int[L]; for (int i = 0; i < L; i++) { Dp[i] = 200000; } Dp[0] = 0; int state = 0; foreach (char c in S) { state ^= 1 << (c - 'a'); int ans = Dp[state]; for (char cc = 'a'; cc <= 'z'; cc++) { int tmp = state ^ (1 << (cc - 'a')); ans = Math.Min(ans, Dp[tmp] + 1); } Dp[state] = ans; // Console.WriteLine($"{Convert.ToString(state, 2)} {Dp[state]}"); } Console.WriteLine(Dp[state]); } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; public class Program { private string S; private int L = 1 << 26; private int[] Dp; public void Solve() { var sc = new Scanner(); S = sc.Next(); Dp = new int[L]; for (int i = 0; i < L; i++) { Dp[i] = 200000; } Dp[0] = 0; int state = 0; foreach (char c in S) { state ^= 1 << (c - 'a'); int ans = int.MaxValue; for (char cc = 'a'; cc <= 'z'; cc++) { int tmp = state ^ (1 << (cc - 'a')); ans = Math.Min(ans, Dp[tmp] + 1); } Dp[state] = Math.Min(Dp[state], ans); // Console.WriteLine($"{Convert.ToString(state, 2)} {Dp[state]}"); } if (state == 0) { Console.WriteLine(1); } else { Console.WriteLine(Dp[state]); } } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
631
35
using System; namespace ChokudaiScanner { class MainClass { static void Main() { Scanner cin = new Scanner(); int n = cin.NextInt(); int k = cin.NextInt(); int[] x = new int[n]; for (int i = 0; i < n; i++) { x[i] = cin.NextInt(); } int sum = 0; for (int i = 0; i < n; i++) { if (x[i] < k / 2) { sum += x[i] * 2; } else { sum += (k - x[i]) * 2; } } Console.WriteLine(sum); } } 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; namespace ChokudaiScanner { class MainClass { static void Main() { Scanner cin = new Scanner(); int n = cin.NextInt(); int k = cin.NextInt(); int[] x = new int[n]; for (int i = 0; i < n; i++) { x[i] = cin.NextInt(); } int sum = 0; for (int i = 0; i < n; i++) { if (x[i] * 2 < (k - x[i]) * 2) { sum += x[i] * 2; } else { sum += (k - x[i]) * 2; } } Console.WriteLine(sum); } } 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; } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 15, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 48]]
8
498
11
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = rint(); var k = rint(); int total = 0; for (int i = 0; i < n; i++) { int r = rint(); int min = Min(r, k - r); total += min * 2; } WriteLine(total); } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = rint(); var k = rint(); int total = 0; var r = inta(); for (int j = 0; j < r.Length; j++) { int min = Min(r[j], k - r[j]); total += min * 2; } WriteLine(total); } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73]]
8
1,242
30
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // 入力 string[] sS = Console.ReadLine().Trim().Split(' '); int iN = int.Parse(sS[0]); sS = Console.ReadLine().Trim().Split(' '); int iK = int.Parse(sS[0]); sS = Console.ReadLine().Trim().Split(' '); List<int> lstInp = new List<int>(); for (int i = 0; i < sS.Length; i++) { lstInp.Add(int.Parse(sS[i])); } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // 解析 int iOut = 0; for (int i = 0; i < lstInp.Count; i++) { List<int> lstBuf = new List<int>(); lstBuf.Add(lstInp[i]); lstBuf.Add(iK - lstInp[i]); iOut += lstBuf.Min() * 2; } sw.Stop(); #if DEBUG Console.WriteLine(); Console.WriteLine("{0}", sw.Elapsed.ToString()); Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // 入力 string[] sS = Console.ReadLine().Trim().Split(' '); int iN = int.Parse(sS[0]); sS = Console.ReadLine().Trim().Split(' '); int iK = int.Parse(sS[0]); sS = Console.ReadLine().Trim().Split(' '); List<int> lstInp = new List<int>(); for (int i = 0; i < sS.Length; i++) { lstInp.Add(int.Parse(sS[i])); } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // 解析 int iOut = 0; for (int i = 0; i < lstInp.Count; i++) { List<int> lstBuf = new List<int>(); lstBuf.Add(lstInp[i]); lstBuf.Add(iK - lstInp[i]); iOut += lstBuf.Min() * 2; } // 出力 Console.WriteLine("{0}", iOut.ToString().Trim()); sw.Stop(); #if DEBUG Console.WriteLine(); Console.WriteLine("{0}", sw.Elapsed.ToString()); Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
310
19
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 n = Read.Int(); int K = Read.Int(); int[] a = Read.ints(); long ans = 0; for (int i = 0; i < a.Length; i++) { ans += 2 * (Math.Max(a[i], K - a[i])); } Console.WriteLine(ans); } 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) { int n = Read.Int(); int K = Read.Int(); int[] a = Read.ints(); long ans = 0; for (int i = 0; i < a.Length; i++) { ans += 2 * (Math.Min(a[i], K - a[i])); } Console.WriteLine(ans); 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 / 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(); } }
[["-", 12, 16, 12, 23, 0, 213, 63, 214, 141, 22], ["+", 12, 16, 12, 23, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
8
439
8
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var r = ReadLine().Split().Select(int.Parse).ToArray(); int A = r[0], B = r[1], C = r[2], D = r[3], E = r[4], F = r[5]; var dp = new(double, double)[F + 1]; //水 砂糖 for (int i = 0; i < F + 1; i++) { dp[i] = (-1, 0); } dp[0] = (0, 0); for (int i = 0; i < F + 1; i++) { if (dp[i].Item1 != -1) { var nxt = i + 100 * A; if (nxt > F) continue; dp[nxt] = (nxt, 0); } } for (int i = 0; i < F + 1; i++) { if (dp[i].Item1 != -1) { var nxt = i + 100 * B; if (nxt > F) continue; dp[nxt] = (nxt, 0); } } for (int i = 0; i < F + 1; i++) { if (dp[i].Item1 != -1) { var nxt = i + C; var (a, b) = dp[i]; if (nxt > F) continue; if (b + C > a / 100 * E) continue; if (dp[nxt].Item2 > 0) { dp[nxt] = (a, Max(b + C, dp[nxt].Item2)); } else { dp[nxt] = (a, b + C); } } } for (int i = 0; i < F + 1; i++) { if (dp[i].Item1 != -1) { var nxt = i + D; var (a, b) = dp[i]; if (nxt > F) continue; if (b + D > a / 100 * E) continue; if (dp[nxt].Item2 > 0) { dp[nxt] = (a, Max(b + D, dp[nxt].Item2)); } else { dp[nxt] = (a, b + D); } } } double max = 0; var ans = new int[2]; for (int i = 1; i < F + 1; i++) { if (dp[i].Item1 != -1) { var (a, b) = dp[i]; double p = 100 * b / (a + b); double lb = 0, ub = 100; int cnt = 0; while (cnt++ < 1000) { var mid = (lb + ub) / 2; if ((a + b) * mid < 100 * b) lb = mid; else ub = mid; } p = lb; if (max < p) { ans = new int[2] { (int)(a + b), (int)b }; max = p; } } } WriteLine(string.Join(" ", ans)); } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[0], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[0], 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 r = ReadLine().Split().Select(int.Parse).ToArray(); int A = r[0], B = r[1], C = r[2], D = r[3], E = r[4], F = r[5]; var dp = new(double, double)[F + 1]; //水 砂糖 for (int i = 0; i < F + 1; i++) { dp[i] = (-1, 0); } dp[0] = (0, 0); for (int i = 0; i < F + 1; i++) { if (dp[i].Item1 != -1) { var nxt = i + 100 * A; if (nxt > F) continue; dp[nxt] = (nxt, 0); } } for (int i = 0; i < F + 1; i++) { if (dp[i].Item1 != -1) { var nxt = i + 100 * B; if (nxt > F) continue; dp[nxt] = (nxt, 0); } } for (int i = 0; i < F + 1; i++) { if (dp[i].Item1 != -1) { var nxt = i + C; var (a, b) = dp[i]; if (nxt > F) continue; if ((int)b + C > (int)a / 100 * E) continue; if (dp[nxt].Item2 > 0) { dp[nxt] = (a, Max(b + C, dp[nxt].Item2)); } else { dp[nxt] = (a, b + C); } } } for (int i = 0; i < F + 1; i++) { if (dp[i].Item1 != -1) { var nxt = i + D; var (a, b) = dp[i]; if (nxt > F) continue; if ((int)b + D > (int)a / 100 * E) continue; if (dp[nxt].Item2 > 0) { dp[nxt] = (a, Max(b + D, dp[nxt].Item2)); } else { dp[nxt] = (a, b + D); } } } double max = 0; var ans = new int[2]; for (int i = 1; i < F + 1; i++) { if (dp[i].Item1 != -1) { var (a, b) = dp[i]; double p = 100 * b / (a + b); double lb = 0, ub = 100; int cnt = 0; while (cnt++ < 1000) { var mid = (lb + ub) / 2; if ((a + b) * mid < 100 * b) lb = mid; else ub = mid; } p = ub; if (max <= p) { ans = new int[2] { (int)(a + b), (int)b }; max = p; } } } WriteLine(string.Join(" ", ans)); } } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[0], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[0], typeof(T4)); return (r1, r2, r3, r4); } }
[["+", 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], ["+", 15, 16, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 15, 16, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 15, 16, 12, 16, 31, 16, 31, 74, 0, 25], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19]]
8
1,336
16
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Diagnostics; using static System.Math; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; static int A, B, C, D, E, F; public static void Input() { var cin = new Solve(); var input = cin.SplitReader(); A = input[0]; B = input[1]; C = input[2]; D = input[3]; E = input[4]; F = input[5]; } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); int ans1 = 0; int ans2 = 0; double max = 0; List<int> mizu = new List<int>(); List<int> sato = new List<int>(); for (var i = 0; i <= F / (100 * A); i++) { for (var j = 0; j <= F / 100 * B; j++) { if (100 * i * A + 100 * j * B <= F) { mizu.Add(100 * i * A + 100 * j * B); } } } for (var i = 0; i <= F / C; i++) { for (var j = 0; j <= F / D; j++) { if (i * C + j * D <= F) { sato.Add(i * C + j * D); } } } foreach (var x in mizu) { foreach (var y in sato) { if (x + y <= F && y <= (x / 100) * E) { double c = (double)y / (x + y); if (c > max) { max = c; ans1 = x + y; ans2 = y; } } } } Console.WriteLine($"{ans1} {ans2}"); // Console.Out.Flush(); } public int[] SplitReader() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReaderL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Diagnostics; using static System.Math; // var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); namespace AtCoderSolve { class Solve { const int mod = 1000000007; const int INF = 2147483647; const long SINF = 9223372036854775807; static int A, B, C, D, E, F; public static void Input() { var cin = new Solve(); var input = cin.SplitReader(); A = input[0]; B = input[1]; C = input[2]; D = input[3]; E = input[4]; F = input[5]; } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); int ans1 = 0; int ans2 = 0; double max = 0; List<int> mizu = new List<int>(); List<int> sato = new List<int>(); for (var i = 0; i <= F / (100 * A); i++) { for (var j = 0; j <= F / 100 * B; j++) { if (i == 0 && j == 0) { continue; } if (100 * i * A + 100 * j * B <= F) { mizu.Add(100 * i * A + 100 * j * B); } } } for (var i = 0; i <= F / C; i++) { for (var j = 0; j <= F / D; j++) { if (i * C + j * D <= F) { sato.Add(i * C + j * D); } } } foreach (var x in mizu) { foreach (var y in sato) { if (x + y <= F && y <= (x / 100) * E) { double c = (double)y / (x + y); if (c >= max) { max = c; ans1 = x + y; ans2 = y; } } } } Console.WriteLine($"{ans1} {ans2}"); // Console.Out.Flush(); } public int[] SplitReader() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] SplitReaderL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } }
[["+", 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, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20]]
8
512
16
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var ABCDEF = Sarray(); var A = ABCDEF[0]; var B = ABCDEF[1]; var C = ABCDEF[2]; var D = ABCDEF[3]; var E = ABCDEF[4]; var F = ABCDEF[5]; var ww = 100 * A; var sg = 0L; for (var a = 0; a <= 30; ++a) for (var b = 0; b <= 30; ++b) { var w = 100 * (A * a + B * b); if (0 == w) continue; var sl = w / 100 * E; for (var c = 0; c <= sl / C; ++c) { var d = (sl - C * c) / D; var s = C * c + D * d; if (F < w + s) continue; var t = 100.0 * s / (w + s); if (100.0 * sg / ww < t) { ww = w + s; sg = s; } } } WriteLine($"{ww} {sg}"); } static long Mod = (long)1e9 + 7; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var ABCDEF = Sarray(); var A = ABCDEF[0]; var B = ABCDEF[1]; var C = ABCDEF[2]; var D = ABCDEF[3]; var E = ABCDEF[4]; var F = ABCDEF[5]; var ww = 100 * A; var sg = 0L; for (var a = 0; a <= 30; ++a) for (var b = 0; b <= 30; ++b) { var w = 100 * (A * a + B * b); if (0 == w) continue; var sl = w / 100 * E; for (var c = 0; c <= sl / C; ++c) { if (F < w + C * c) continue; var d = Min((sl - C * c) / D, (F - w - C * c) / D); var s = C * c + D * d; var t = 100.0 * s / (w + s); if (100.0 * sg / ww < t) { ww = w + s; sg = s; } } } WriteLine($"{ww} {sg}"); } static long Mod = (long)1e9 + 7; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 16, 12, 16, 17, 48], ["+", 0, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117]]
8
605
37
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var ABCDEF = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var A = ABCDEF[0]; var B = ABCDEF[1]; var C = ABCDEF[2]; var D = ABCDEF[3]; var E = ABCDEF[4]; var F = ABCDEF[5]; var answerVolume = 0; var answerSugar = 0; double max = 0; for (var i = 0; 100 * A * i <= F; i++) { for (var j = 0; 100 * A * i + 100 * B * j <= F; j++) { var water = 100 * (A * i + B * j); for (var k = 0; water + C * k <= F; k++) { for (var l = 0; water + C * k + D * l <= F; l++) { var sugar = C * k + D * l; if (100 * sugar <= E * water) { var tmp = (double)sugar / water; if (tmp > max) { max = tmp; answerVolume = water + sugar; answerSugar = sugar; } } } } } } Console.WriteLine($"{answerVolume} {answerSugar}"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var ABCDEF = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var A = ABCDEF[0]; var B = ABCDEF[1]; var C = ABCDEF[2]; var D = ABCDEF[3]; var E = ABCDEF[4]; var F = ABCDEF[5]; var answerVolume = 100 * A; var answerSugar = 0; double max = 0; for (var i = 0; 100 * A * i <= F; i++) { for (var j = 0; 100 * A * i + 100 * B * j <= F; j++) { var water = 100 * (A * i + B * j); for (var k = 0; water + C * k <= F; k++) { for (var l = 0; water + C * k + D * l <= F; l++) { var sugar = C * k + D * l; if (100 * sugar <= E * water) { var tmp = (double)(100 * sugar) / (water + sugar); if (tmp > max) { max = tmp; answerVolume = water + sugar; answerSugar = sugar; } } } } } } Console.WriteLine($"{answerVolume} {answerSugar}"); } } }
[["-", 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], ["+", 0, 212, 0, 16, 31, 74, 51, 23, 0, 24], ["+", 0, 16, 31, 74, 51, 23, 0, 16, 31, 203], ["+", 0, 16, 31, 74, 51, 23, 0, 16, 17, 48], ["+", 0, 212, 0, 16, 31, 74, 51, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
8
359
12
using System; namespace ABC074C { class Program { static void Main(string[] args) { var target = Console.ReadLine().Split(' '); int A = int.Parse(target[0]); int B = int.Parse(target[1]); int C = int.Parse(target[2]); int D = int.Parse(target[3]); int E = int.Parse(target[4]); int F = int.Parse(target[5]); int weight = 0; int w_sugar = 0; double max_ratio = 0.0; double e_ratio = (double)E / (100 + E) * 100.0; for (int i = 0; i <= 30; i++) { for (int j = 0; j <= 30; j++) { int water = 100 * (i * A + j * B); if (water > F) continue; for (int k = 0; k <= 3000; k++) { for (int p = 0; p <= 3000; p++) { int sugar = C * k + D * p; if (water + sugar <= F && water > 0) { double ratio = (double)sugar / (water + sugar) * 100.0; if (ratio == e_ratio) { Console.WriteLine("{0} {1}", sugar + water, sugar); return; } if (ratio > max_ratio && ratio < e_ratio) { max_ratio = ratio; w_sugar = sugar; weight = sugar + water; } } } } } } Console.WriteLine("{0} {1}", weight, w_sugar); } } }
using System; namespace ABC074C { class Program { static void Main(string[] args) { var target = Console.ReadLine().Split(' '); int A = int.Parse(target[0]); int B = int.Parse(target[1]); int C = int.Parse(target[2]); int D = int.Parse(target[3]); int E = int.Parse(target[4]); int F = int.Parse(target[5]); int weight = A * 100; int w_sugar = 0; double max_ratio = 0.0; double e_ratio = (double)E / (100 + E) * 100.0; for (int i = 0; i <= F / 100 + 1; i++) { for (int j = 0; j <= F / 100 + 1; j++) { int water = 100 * (i * A + j * B); if (water > F) continue; for (int k = 0; k <= F / C + 1; k++) { for (int p = 0; p <= F / D + 1; p++) { int sugar = C * k + D * p; if (water + sugar <= F && water > 0) { double ratio = (double)sugar / (water + sugar) * 100.0; if (ratio == e_ratio) { Console.WriteLine("{0} {1}", sugar + water, sugar); return; } if (ratio > max_ratio && ratio < e_ratio) { max_ratio = ratio; w_sugar = sugar; weight = sugar + water; } } } } } } Console.WriteLine("{0} {1}", weight, w_sugar); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 17, 85], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 12, 22]]
8
339
28
using System; namespace ABC074 { class C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int C = int.Parse(input[2]); int D = int.Parse(input[3]); int E = int.Parse(input[4]); int F = int.Parse(input[5]); int waterSum = 0; int waterSumRes = 0; int sugarSum = 0; double maxDens = 0; double dens = 0; for (int i = 0; i * A * 100 <= F; i++) { for (int j = 0; (i * A * 100) + (j * B * 100) <= F; j++) { if (i == 0 && j == 0) continue; waterSum = (i * A * 100) + (j * B * 100); for (int k = 0; (waterSum + (k * C) <= F); k++) { for (int l = 0; (waterSum + (k * C) + (l * D)) <= F; l++) { if (k == 0 && l == 0) continue; dens = (double)((k * C) + (l * D)) / waterSum; // Console.WriteLine("dens : " + dens); // Console.WriteLine("maxdens : " + maxDens); if (dens < maxDens || E / 100d < dens) continue; sugarSum = (k * C) + (l * D); // Console.WriteLine("sugarSum : " + sugarSum); waterSumRes = waterSum; maxDens = dens; } } } } Console.WriteLine($"{waterSumRes + sugarSum} {sugarSum}"); } } }
using System; namespace ABC074 { class C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int C = int.Parse(input[2]); int D = int.Parse(input[3]); int E = int.Parse(input[4]); int F = int.Parse(input[5]); int waterSum = 0; int waterSumRes = 0; int sugarSum = 0; double maxDens = 0; double dens = 0; for (int i = 0; i * A * 100 <= F; i++) { for (int j = 0; (i * A * 100) + (j * B * 100) <= F; j++) { if (i == 0 && j == 0) continue; waterSum = (i * A * 100) + (j * B * 100); for (int k = 0; (waterSum + (k * C) <= F); k++) { for (int l = 0; (waterSum + (k * C) + (l * D)) <= F; l++) { dens = (double)((k * C) + (l * D)) / waterSum; // Console.WriteLine("dens : " + dens); // Console.WriteLine("maxdens : " + maxDens); if (dens < maxDens || E / 100d < dens) continue; sugarSum = (k * C) + (l * D); // Console.WriteLine("sugarSum : " + sugarSum); waterSumRes = waterSum; maxDens = dens; } } } } Console.WriteLine($"{waterSumRes + sugarSum} {sugarSum}"); } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
363
12
namespace AtCoder.ABC.C074 { using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.IO; using AtCoder.ABC.IO; public class Quest { public object Solve(Parser parser) { int a = parser.Integer(); int b = parser.Integer(); int c = parser.Integer(); int d = parser.Integer(); int e = parser.Integer(); int f = parser.Integer(); var waters = new List<int>(); var sugars = new List<int>(); for (var i = 0; i <= f / (100 * a); i++) { for (var j = 0; j <= f / (100 * b); j++) { if (i == 0 && j == 0) { continue; } int sum = 100 * a * i + 100 * b * j; if (sum <= f) { waters.Add(sum); } } } for (var i = 0; i <= f / c; i++) { for (var j = 0; j <= f / d; j++) { int sum = c * i + d * j; if (sum <= f) { sugars.Add(sum); } } } double density = 0; int solution = 0; int solute = 0; foreach (var water in waters) { foreach (var sugar in sugars) { if (sugar + water <= f && sugar <= (water / 100) * e) { if (density * (double)(sugar + water) < (double)sugar) { solution = sugar + water; solute = sugar; density = (double)solute / (double)solution; } } } } return $"{solution} {solute}"; } static class Program { static void Main(string[] args) { var i = new Parser(Console.OpenStandardInput()); var o = new Printer(Console.OpenStandardOutput()); var got = new Quest().Solve(i); o.WriteLine(got); o.Flush(); } } } } namespace AtCoder.ABC.IO { #region IO using System; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Globalization; public class Parser { public Parser(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } public IEnumerable<Parser> Take(int n) { return Enumerable.Range(1, n).Select(_ => this); } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } #endregion }
namespace AtCoder.ABC.C074 { using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.IO; using AtCoder.ABC.IO; public class Quest { public object Solve(Parser parser) { int a = parser.Integer(); int b = parser.Integer(); int c = parser.Integer(); int d = parser.Integer(); int e = parser.Integer(); int f = parser.Integer(); var waters = new List<int>(); var sugars = new List<int>(); for (var i = 0; i <= f / (100 * a); i++) { for (var j = 0; j <= f / (100 * b); j++) { if (i == 0 && j == 0) { continue; } int sum = 100 * a * i + 100 * b * j; if (sum <= f) { waters.Add(sum); } } } for (var i = 0; i <= f / c; i++) { for (var j = 0; j <= f / d; j++) { int sum = c * i + d * j; if (sum <= f) { sugars.Add(sum); } } } double density = 0; int solution = 0; int solute = 0; foreach (var water in waters) { foreach (var sugar in sugars) { if (sugar + water <= f && sugar <= (water / 100) * e) { double x = (double)sugar / (sugar + water); if (x >= density) { solution = sugar + water; solute = sugar; density = (double)solute / (double)solution; } } } } return $"{solution} {solute}"; } static class Program { static void Main(string[] args) { var i = new Parser(Console.OpenStandardInput()); var o = new Printer(Console.OpenStandardOutput()); var got = new Quest().Solve(i); o.WriteLine(got); o.Flush(); } } } } namespace AtCoder.ABC.IO { #region IO using System; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Globalization; public class Parser { public Parser(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } public IEnumerable<Parser> Take(int n) { return Enumerable.Range(1, n).Select(_ => this); } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } #endregion }
[["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 51, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 64, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["-", 64, 196, 0, 57, 15, 16, 12, 74, 0, 25], ["-", 64, 196, 0, 57, 15, 16, 12, 74, 51, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22]]
8
1,292
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { int a, b, c, d, e, f; void Run() { var sc = new Scanner(); a = sc.NextInt(); b = sc.NextInt(); c = sc.NextInt(); d = sc.NextInt(); e = sc.NextInt(); f = sc.NextInt(); int maxw = 0; int maxs = 0; double maxd = 0; for (int i = 0; i <= 30; i++) { for (int j = 0; j <= 30; j++) { int w = i * a * 100 + j * b * 100; if (i + j == 0 || w > f) continue; int lims = w / 100 * e; int s = 0; int cc = 0; while (cc <= lims) { s = Math.Max(cc + (lims - cc) / d * d, s); cc += c; } double dd = (double)s / (w + s); if (w + s <= f && dd > maxd) { maxd = dd; maxw = w; maxs = s; } } } Console.WriteLine("{0} {1}", maxw + maxs, maxs); } static void Main(string[] args) { new Program().Run(); } static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } } class Scanner { int index = -1; string[] buf; public Scanner() {} public int NextInt() { CheckNext(); return int.Parse(buf[index++]); } public long NextLong() { CheckNext(); return long.Parse(buf[index++]); } public double NextDouble() { CheckNext(); return double.Parse(buf[index++]); } public string NextString() { CheckNext(); return buf[index++]; } private void CheckNext() { if (index >= 0 && index < buf.Length) return; buf = Console.ReadLine().Split(' '); index = 0; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { int a, b, c, d, e, f; void Run() { var sc = new Scanner(); a = sc.NextInt(); b = sc.NextInt(); c = sc.NextInt(); d = sc.NextInt(); e = sc.NextInt(); f = sc.NextInt(); int maxw = 0; int maxs = 0; double maxd = -1; for (int i = 0; i <= 30; i++) { for (int j = 0; j <= 30; j++) { int w = i * a * 100 + j * b * 100; if (i + j == 0 || w > f) continue; int lims = w / 100 * e; int s = 0; int cc = 0; while (cc <= Math.Min(lims, f - w)) { s = Math.Max(cc + (Math.Min(lims, f - w) - cc) / d * d, s); cc += c; } double dd = (double)s / (w + s); if (w + s <= f && dd > maxd) { maxd = dd; maxw = w; maxs = s; } } } Console.WriteLine("{0} {1}", maxw + maxs, maxs); } static void Main(string[] args) { new Program().Run(); } static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } } class Scanner { int index = -1; string[] buf; public Scanner() {} public int NextInt() { CheckNext(); return int.Parse(buf[index++]); } public long NextLong() { CheckNext(); return long.Parse(buf[index++]); } public double NextDouble() { CheckNext(); return double.Parse(buf[index++]); } public string NextString() { CheckNext(); return buf[index++]; } private void CheckNext() { if (index >= 0 && index < buf.Length) return; buf = Console.ReadLine().Split(' '); index = 0; } }
[["-", 0, 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, 52, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 52, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 52, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 52, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 52, 15, 16, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 25], ["+", 0, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 31, 23, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 31, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 23, 0, 16, 31, 213, 3, 4, 0, 21], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 31, 23, 0, 16, 31, 213, 3, 4, 0, 25]]
8
502
21
using System; using System.Linq; using System.Collections.Generic; class Cmondai { static void Main() { var line = Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToArray(); var A = line[0]; var B = line[1]; var C = line[2]; var D = line[3]; var E = line[4]; var F = line[5]; var waterAmax = F / (A * 100); decimal max = -1; decimal maxSugarWater = 0; decimal maxSugar = 0; for (int i = 0; i <= waterAmax; ++i) { var bCount = (F - (A * i * 100)) / (B * 100); for (int j = 0; j <= bCount; ++j) { if (i == 0 && j == 0) continue; var cCount = (F - (A * i * 100 + B * j * 100)) / C; for (int k = 0; k < cCount; ++k) { var dCount = (F - ((A * i * 100 + B * j * 100) + C * k)) / D; for (int l = 0; l < dCount; ++l) { if ((C * k + D * l) <= (i * A + j * B) * E) { var sugarWater = (A * i) * 100 + (B * j) * 100 + C * k + D * l; var sugar = C * k + D * l; var concentration = sugar == 0 ? 0 : sugar / sugarWater * 100; if (max < concentration) { max = concentration; maxSugarWater = sugarWater; maxSugar = sugar; } } } } } } Console.WriteLine($"{maxSugarWater} {maxSugar}"); } }
using System; using System.Linq; using System.Collections.Generic; class Cmondai { static void Main() { var line = Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToArray(); var A = line[0]; var B = line[1]; var C = line[2]; var D = line[3]; var E = line[4]; var F = line[5]; decimal max = -1; decimal maxSugarWater = 0; decimal maxSugar = 0; var waterAmax = F / (A * 100); for (int i = 0; i <= waterAmax; ++i) { var bCount = (F - (A * i * 100)) / (B * 100); for (int j = 0; j <= bCount; ++j) { if (i == 0 && j == 0) continue; var cCount = (F - (A * i * 100 + B * j * 100)) / C; for (int k = 0; k <= cCount; ++k) { var dCount = (F - ((A * i * 100 + B * j * 100) + C * k)) / D; for (int l = 0; l <= dCount; ++l) { if ((C * k + D * l) <= (i * A + j * B) * E) { var sugarWater = (A * i) * 100 + (B * j) * 100 + C * k + D * l; var sugar = C * k + D * l; var concentration = sugar == 0 ? 0 : sugar / sugarWater * 100; if (max < concentration) { max = concentration; maxSugarWater = sugarWater; maxSugar = sugar; } } } } } } Console.WriteLine($"{maxSugarWater} {maxSugar}"); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 17, 48], ["-", 0, 212, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 48], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
396
26
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; using Pair = System.Tuple<int, int>; using Edge = System.Tuple<int, int, long>; // using static System.Globalization.CultureInfo; class Program { static void Main(string[] args) { var atof = Input.ar; var d = (100 * (double)atof[4] / (100 + atof[4])); var max = 0d; var pa = new Pair(0, 0); var wat = new List<int>(); var sug = new List<int>(); for (var i = 0; i <= atof[5]; i++) for (var j = 0; j <= atof[5]; j++) { if (i == 0 && j == 0) continue; var val = 100 * i * atof[0] + 100 * j * atof[1]; if (val <= atof[5]) wat.Add(val); val = i * atof[2] + j * atof[3]; if (val <= atof[5]) sug.Add(val); } wat = wat.Distinct().ToList(); sug = sug.Distinct().ToList(); for (var i = 0; i < wat.Count; i++) for (var j = 0; j < sug.Count; j++) { if (wat[i] + sug[j] > atof[5]) continue; var val = 100 * (double)sug[j] / (wat[i] + sug[j]); if (val <= d && val > max) { max = val; pa = new Pair(wat[i], sug[j]); } } WriteLine($"{pa.Item1+pa.Item2} {pa.Item2}"); } } 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 static string[] gred(int h) => Enumerable.Repeat(0, h).Select(v => read).ToArray(); public static int[][] twodim(int num) => Enumerable.Repeat(0, num).Select(v => ar).ToArray(); public static long[][] twodimL(int num) => Enumerable.Repeat(0, num).Select(v => arL).ToArray(); public const long Inf = (long)1e18; public const double eps = 1e-11; 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 Pair = System.Tuple<int, int>; using Edge = System.Tuple<int, int, long>; // using static System.Globalization.CultureInfo; class Program { static void Main(string[] args) { var atof = Input.ar; var d = (100 * (double)atof[4] / (100 + atof[4])); var max = 0d; var pa = new Pair(0, 0); var wat = new List<int>(); var sug = new List<int>(); for (var i = 0; i <= atof[5]; i++) for (var j = 0; j <= atof[5]; j++) { if (i == 0 && j == 0) continue; var val = 100 * i * atof[0] + 100 * j * atof[1]; if (val <= atof[5]) wat.Add(val); val = i * atof[2] + j * atof[3]; if (val <= atof[5]) sug.Add(val); } wat = wat.Distinct().ToList(); sug = sug.Distinct().ToList(); for (var i = 0; i < wat.Count; i++) for (var j = 0; j < sug.Count; j++) { if (wat[i] + sug[j] > atof[5]) continue; var val = 100 * (double)sug[j] / (wat[i] + sug[j]); if (val <= d && val > max) { max = val; pa = new Pair(wat[i], sug[j]); } } if (pa.Item1 == 0) pa = new Pair(atof[0] * 100, pa.Item2); WriteLine($"{pa.Item1+pa.Item2} {pa.Item2}"); } } 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 static string[] gred(int h) => Enumerable.Repeat(0, h).Select(v => read).ToArray(); public static int[][] twodim(int num) => Enumerable.Repeat(0, num).Select(v => ar).ToArray(); public static long[][] twodimL(int num) => Enumerable.Repeat(0, num).Select(v => arL).ToArray(); public const long Inf = (long)1e18; public const double eps = 1e-11; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 230, 0, 228], ["+", 0, 57, 64, 1, 0, 11, 12, 230, 39, 22], ["+", 64, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 230, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 12, 230, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 1, 0, 11, 12, 230, 3, 4, 0, 21], ["+", 12, 230, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 12, 230, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 12, 230, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 64, 1, 0, 11, 12, 230, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
630
25
using System.Collections.Generic; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); var c = int.Parse(line[2]); var d = int.Parse(line[3]); var e = int.Parse(line[4]); var f = int.Parse(line[5]); var water = new List<int>(); for (int i = 1; 100 * i <= f; i++) if (canMake(100 * i, 100 * a, 100 * b)) water.Add(i); var sugar = new List<int>(); for (int i = 0; i <= f; i++) if (canMake(i, c, d)) sugar.Add(i); var ret = 0d; var retwater = 0; var retsugar = 0; foreach (var w in water) foreach (var s in sugar) if (s <= w * e && w * 100 + s <= f) { var t = (double)s / (w * 100d + s); if (t > ret) { ret = t; retwater = w; retsugar = s; } } Console.WriteLine("{0} {1}", retwater * 100 + retsugar, retsugar); } public static bool canMake(int t, int a, int b) { var imax = t / a; for (int i = 0; i <= imax; i++) if ((t - a * i) % b == 0) return true; return false; } }
using System.Collections.Generic; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); var c = int.Parse(line[2]); var d = int.Parse(line[3]); var e = int.Parse(line[4]); var f = int.Parse(line[5]); var water = new List<int>(); for (int i = 1; 100 * i <= f; i++) if (canMake(100 * i, 100 * a, 100 * b)) water.Add(i); var sugar = new List<int>(); for (int i = 0; i <= f; i++) if (canMake(i, c, d)) sugar.Add(i); var ret = 0d; var retwater = 0; var retsugar = 0; foreach (var w in water) foreach (var s in sugar) if (s <= w * e && w * 100 + s <= f) { var t = (double)s / (w * 100d + s); if (t > ret) { ret = t; retwater = w; retsugar = s; } } if (retwater == 0) retwater = a; Console.WriteLine("{0} {1}", retwater * 100 + retsugar, retsugar); } public static bool canMake(int t, int a, int b) { var imax = t / a; for (int i = 0; i <= imax; i++) if ((t - a * i) % b == 0) return true; return false; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
374
10
using System; using System.Linq;   class Program { static void Main(string[] args) { // 入力 var inputs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();   var A = inputs[0]; var B = inputs[1]; var C = inputs[2]; var D = inputs[3]; var E = inputs[4]; var F = inputs[5];   // 砂糖水の濃度、砂糖水の質量、砂糖の質量 var maxSWRatio = 0.0d; var SWRatio = 0.0d; var ansSugarWater = 0; var ansSugar = 0;     for (int a = 0; 100 * A * a <= F; a++) { for (int b = 0; 100 * A * a + 100 * B * b <= F; b++) { for (int c = 0; 100 * A * a + 100 * B * b + C * c <= F; c++) { for (int d = 0; 100 * A * a + 100 * B * b + C * c + D * d <= F; d++) { if (C * c + D * d <= E * (A * a + B * b)) { try { SWRatio = (double)(C * c + D * d) / (double)(100 * A * a + 100 * B * b + C * c + D * d); } catch (DivideByZeroException) {   SWRatio = 0.0d; } if (SWRatio > maxSWRatio) { maxSWRatio = SWRatio; ansSugarWater = 100 * A * a + 100 * B * b + C * c + D * d; ansSugar = C * c + D * d; } } } } } }     // 出力 Console.WriteLine("{0} {1}", ansSugarWater.ToString(), ansSugar.ToString());   } }
using System; using System.Linq; class Program { static void Main(string[] args) { // 入力 var inputs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var A = inputs[0]; var B = inputs[1]; var C = inputs[2]; var D = inputs[3]; var E = inputs[4]; var F = inputs[5]; // 砂糖水の濃度、砂糖水の質量、砂糖の質量 var maxSWRatio = 0.0d; var SWRatio = 0.0d; var ansSugarWater = 0; var ansSugar = 0; for (int a = 0; 100 * A * a <= F; a++) { for (int b = 0; 100 * A * a + 100 * B * b <= F; b++) { for (int c = 0; 100 * A * a + 100 * B * b + C * c <= F; c++) { for (int d = 0; 100 * A * a + 100 * B * b + C * c + D * d <= F; d++) { if (C * c + D * d <= E * (A * a + B * b)) { try { SWRatio = (double)(C * c + D * d) / (double)(100 * A * a + 100 * B * b + C * c + D * d); } catch (DivideByZeroException) { SWRatio = 0.0d; } if (SWRatio >= maxSWRatio) { maxSWRatio = SWRatio; ansSugarWater = 100 * A * a + 100 * B * b + C * c + D * d; ansSugar = C * c + D * d; } } } } } } // 出力 Console.WriteLine("{0} {1}", ansSugarWater.ToString(), ansSugar.ToString()); Console.ReadLine(); } }
[["-", 36, 36, 36, 36, 36, 36, 36, 36, 0, 208], ["-", 36, 36, 36, 36, 36, 36, 0, 208, 0, 231], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 141, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 22, 0, 231], ["-", 0, 208, 0, 231, 141, 22, 0, 231, 141, 232], ["-", 0, 231, 141, 22, 0, 231, 141, 232, 234, 22], ["-", 141, 22, 0, 231, 141, 232, 234, 22, 141, 22], ["-", 0, 231, 141, 232, 234, 22, 141, 22, 0, 235], ["-", 141, 232, 234, 22, 141, 22, 0, 235, 141, 22], ["-", 234, 22, 141, 22, 0, 235, 141, 22, 8, 201], ["-", 141, 22, 0, 235, 141, 22, 8, 201, 0, 195], ["-", 0, 208, 0, 235, 8, 201, 0, 195, 8, 196], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 169], ["-", 8, 201, 0, 195, 8, 196, 0, 169, 0, 197], ["-", 0, 195, 8, 196, 0, 169, 0, 197, 0, 198], ["-", 8, 196, 0, 169, 0, 197, 0, 198, 39, 216], ["-", 0, 169, 0, 197, 0, 198, 39, 216, 0, 200], ["-", 0, 197, 0, 198, 39, 216, 0, 200, 0, 197], ["-", 0, 198, 39, 216, 0, 200, 0, 197, 0, 198], ["-", 39, 216, 0, 200, 0, 197, 0, 198, 39, 216], ["-", 0, 200, 0, 197, 0, 198, 39, 216, 0, 200], ["-", 0, 197, 0, 198, 39, 216, 0, 200, 0, 169], ["-", 0, 198, 39, 216, 0, 200, 0, 169, 0, 197], ["-", 39, 216, 0, 200, 0, 169, 0, 197, 0, 198], ["-", 0, 200, 0, 169, 0, 197, 0, 198, 39, 216], ["-", 0, 197, 0, 198, 39, 216, 0, 200, 0, 7], ["-", 0, 198, 39, 216, 0, 200, 0, 7, 10, 198], ["-", 39, 216, 0, 200, 0, 7, 10, 198, 39, 199], ["-", 0, 200, 0, 7, 10, 198, 39, 199, 0, 200], ["-", 0, 7, 10, 198, 39, 199, 0, 200, 15, 16], ["-", 10, 198, 39, 199, 0, 200, 15, 16, 31, 16], ["-", 39, 199, 0, 200, 15, 16, 31, 16, 12, 22], ["-", 0, 200, 15, 16, 31, 16, 12, 22, 26, 223], ["-", 15, 16, 31, 16, 12, 22, 26, 223, 0, 22], ["-", 31, 16, 12, 22, 26, 223, 0, 22, 8, 196], ["-", 12, 22, 26, 223, 0, 22, 8, 196, 0, 7], ["-", 26, 223, 0, 22, 8, 196, 0, 7, 0, 169], ["-", 0, 22, 8, 196, 0, 7, 0, 169, 0, 1], ["-", 8, 196, 0, 7, 0, 169, 0, 1, 0, 213], ["-", 0, 7, 0, 169, 0, 1, 0, 213, 63, 214], ["-", 0, 169, 0, 1, 0, 213, 63, 214, 3, 4], ["-", 0, 57, 64, 196, 0, 246, 0, 248, 8, 196], ["-", 64, 196, 0, 246, 0, 248, 8, 196, 0, 1], ["-", 0, 246, 0, 248, 8, 196, 0, 1, 0, 11], ["-", 0, 248, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 31, 22, 0, 202], ["-", 0, 1, 0, 11, 31, 22, 0, 202, 12, 250], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
385
15
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; long[,] A; void Solve() { N = io.Int; A = new long[N, N]; N.REP(i => N.REP(j => A[i, j] = io.Long)); var wf = new WarshallFloyd(); wf.Init(N); N.REP(i => N.REP(j => wf.AddPath(i + 1, j + 1, A[i, j]))); wf.Run(); bool f = true; N.REP(i => N.REP(j => { if (wf.isMinPath(i + 1, j + 1, A[i, j])) { // } else { f = false; } })); long ans = 0; ans = wf.MinCost(); io.o(f ? ans : -1); } //////////////////////////////////////////////////////////// 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 = 0; i < E; ++i) for (int j = 0; j < E; ++j) for (int k = 0; 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) break; if (G[i, j] == G[i, k] + G[k, j]) { isOrig = false; break; } } if (isOrig) orig += BefG[i, j]; } return orig; } } class UnionFind { public long[] parent; public long[] depth; private int I; public void Init(int n) { I = n + 1; parent = new long[I]; depth = new long[I]; I.REP(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(int a, int b) { return Find(a) == Find(b); } public long Size(int x) { return depth[Find(x)]; } } 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.Same(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; long[,] A; void Solve() { N = io.Int; A = new long[N, N]; N.REP(i => N.REP(j => A[i, j] = io.Long)); var wf = new WarshallFloyd(); wf.Init(N); N.REP(i => N.REP(j => wf.AddPath(i + 1, j + 1, A[i, j]))); wf.Run(); bool f = true; N.REP(i => N.REP(j => { if (wf.isMinPath(i + 1, j + 1, A[i, j])) { // } else { f = false; } })); long ans = 0; ans = wf.MinCost(); io.o(f ? ans : -1); } //////////////////////////////////////////////////////////// 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 = i + 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 UnionFind { public long[] parent; public long[] depth; private int I; public void Init(int n) { I = n + 1; parent = new long[I]; depth = new long[I]; I.REP(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(int a, int b) { return Find(a) == Find(b); } public long Size(int x) { return depth[Find(x)]; } } 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.Same(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, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 57, 64, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 204, 205, 22]]
8
8,100
12
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; class Program { static void Main() { string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); int c = int.Parse(s[2]); int d = int.Parse(s[3]); int e = int.Parse(s[4]); int f = int.Parse(s[5]); double ans_concentration = 0.0; double max_concentration = 100.0 * ((double)e / (e + 100.0)); int ans_sugar = 0; int ans_total = 100 * a; Console.WriteLine("max : " + max_concentration); for (int i = 0; 100 * a * i <= f; i++) { for (int j = 0; 100 * b * j <= f; j++) { for (int k = 0; c * k <= f; k++) { for (int l = 0; d * l <= f; l++) { int water = 100 * a * i + 100 * b * j; int sugar = c * k + d * l; int total = water + sugar; if (i == 0 && j == 0) { continue; } if (total <= f && total >= 100 * a) { double concentration = 100.0 * (double)sugar / (double)total; if (concentration <= (max_concentration + 1e-7) && concentration >= ans_concentration) { ans_concentration = concentration; ans_sugar = sugar; ans_total = total; } } } } } } Console.WriteLine(ans_total + " " + ans_sugar); } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; class Program { static void Main() { string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); int c = int.Parse(s[2]); int d = int.Parse(s[3]); int e = int.Parse(s[4]); int f = int.Parse(s[5]); double ans_concentration = 0.0; double max_concentration = 100.0 * ((double)e / (e + 100.0)); int ans_sugar = 0; int ans_total = 100 * a; for (int i = 0; 100 * a * i <= f; i++) { for (int j = 0; 100 * b * j <= f; j++) { for (int k = 0; c * k <= f; k++) { for (int l = 0; d * l <= f; l++) { int water = 100 * a * i + 100 * b * j; int sugar = c * k + d * l; int total = water + sugar; if (i == 0 && j == 0) { continue; } if (total <= f && total >= 100 * a) { double concentration = 100.0 * (double)sugar / (double)total; if (concentration <= (max_concentration + 1e-7) && concentration >= ans_concentration) { ans_concentration = concentration; ans_sugar = sugar; ans_total = total; } } } } } } Console.WriteLine(ans_total + " " + ans_sugar); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
383
11
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using LayoutKind = System.Runtime.InteropServices.LayoutKind; using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute; using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { int n = int.Parse(Console.ReadLine()); var p = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); var X = Console.ReadLine().Split().Select(int.Parse).ToArray(); var childlen = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray(); for (int i = 0; i < p.Length; i++) childlen[p[i]].Add(i + 1); Stack<int> stack = new Stack<int>(); stack.Push(0); List<int> order = new List<int>(); while (stack.Count > 0) { int elem = stack.Pop(); order.Add(elem); foreach (var child in childlen[elem]) stack.Push(child); } Tuple<int, int>[] bw = new Tuple<int, int>[n]; foreach (var elem in order.Reverse<int>()) { // Xまで詰めたい List<bool> knapsack = new bool[X[elem] + 1].ToList(); knapsack[0] = true; int totalSum = 0; foreach (var child in childlen[elem]) { totalSum += bw[child].Item1; totalSum += bw[child].Item2; for (int i = knapsack.Count - 1; i >= 0; i--) { if (!knapsack[i]) continue; knapsack[i] = false; if (i + bw[child].Item1 < knapsack.Count) knapsack[i + bw[child].Item1] = true; if (i + bw[child].Item2 < knapsack.Count) knapsack[i + bw[child].Item2] = true; } } var count = knapsack.LastIndexOf(true); if (count == -1) { Console.WriteLine("IMPOSSIBLE"); return; } bw[elem] = new Tuple<int, int>(totalSum - count, X[elem]); } Console.WriteLine("POSSIBLE"); } }
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using LayoutKind = System.Runtime.InteropServices.LayoutKind; using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute; using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { int n = int.Parse(Console.ReadLine()); if (n == 1) { Console.WriteLine("POSSIBLE"); return; } var p = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); var X = Console.ReadLine().Split().Select(int.Parse).ToArray(); var childlen = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray(); for (int i = 0; i < p.Length; i++) childlen[p[i]].Add(i + 1); Stack<int> stack = new Stack<int>(); stack.Push(0); List<int> order = new List<int>(); while (stack.Count > 0) { int elem = stack.Pop(); order.Add(elem); foreach (var child in childlen[elem]) stack.Push(child); } Tuple<int, int>[] bw = new Tuple<int, int>[n]; foreach (var elem in order.Reverse<int>()) { // Xまで詰めたい List<bool> knapsack = new bool[X[elem] + 1].ToList(); knapsack[0] = true; int totalSum = 0; foreach (var child in childlen[elem]) { totalSum += bw[child].Item1; totalSum += bw[child].Item2; for (int i = knapsack.Count - 1; i >= 0; i--) { if (!knapsack[i]) continue; knapsack[i] = false; if (i + bw[child].Item1 < knapsack.Count) knapsack[i + bw[child].Item1] = true; if (i + bw[child].Item2 < knapsack.Count) knapsack[i + bw[child].Item2] = true; } } var count = knapsack.LastIndexOf(true); if (count == -1) { Console.WriteLine("IMPOSSIBLE"); return; } bw[elem] = new Tuple<int, int>(totalSum - count, X[elem]); } Console.WriteLine("POSSIBLE"); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
587
19
using System; namespace AtCoder { class program { static void Main(string[] args) { Console.WriteLine(Console.ReadLine().Contains("9")); } } }
using System; namespace AtCoder { class program { static void Main(string[] args) { Console.WriteLine(Console.ReadLine().Contains("9") ? "Yes" : "No"); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
40
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Numerics; class Myon { // chokudaiさんのコードをコピペ static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); return 0; } public void calc() { int n = cin.nextInt(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); int[] l = new int[n]; int[] r = new int[n]; for (int i = 0; i < n; i++) { l[i] = cin.nextInt(); r[i] = cin.nextInt(); } int ans = 0; for (int i = 0; i < n; i++) ans += (r[i] - l[i] + 1); showL(ans); sw.Stop(); showL($"処理時間: {sw.ElapsedMilliseconds} [msec]"); } public void backetSort(ref int[] a) { // max a << a.len に対して有効なソート //よってa = int[] とする long n = a.Length; var count = new int[n]; var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index] // = loc[i] for (long i = 0; i < n; i++) count[a[i]]++; loc[0] = count[0] - 1; for (long i = 0; i < n - 1; i++) loc[i + 1] = loc[i] + count[i + 1]; long index = 0; for (int i = 0; i < n; i++) { while (index <= loc[i]) a[index++] = i; // incex <= loc[i] == index < loc[i] + 1 } } public static void showL<T>(T s) { Console.WriteLine(s); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } class SMath { /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 12 なら 2,2,3 です。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> Factorization(long n) { if (n <= 0) return null; List<long> output = new List<long>(); int i = 2; long max = (long)Math.Sqrt(n); ; while (n > 1) { if (i > max) { output.Add(n); break; } while (n % i == 0) { output.Add(i); n /= i; } i++; } return output; } /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1  remainder = 1です。(打ち切られない) /// 13 = 0,0,...0 remainder = 2019 /// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) /// </summary> /// <param name="n"></param> /// <param name="remainder"></param> /// <returns></returns> public static List<long> Factorization(long n, out long remainder) { // output[i] が i-1番目の素数の数を示す //ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) remainder = 1; if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; long max = (long)Math.Sqrt(n); bool[] isNOTPrime = new bool[max + 1]; while (n > 1) { if (tempn > max) { remainder = n; break; } if (!isNOTPrime[tempn]) { output.Add(0); while (n % tempn == 0) { output[output.Count - 1]++; n /= tempn; } for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } /// <summary> /// i番目の素数をoutput[i-1]に返します。 /// ただしnより大きい素数については判定しません。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> GetPrimeNumbers(long n) { if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; bool[] isNOTPrime = new bool[n + 1]; while (n > 1) { if (tempn > n) { break; } if (!isNOTPrime[tempn]) { output.Add(tempn); for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } private static long[][] combMemo; private static int maxn_combination = -1; public static long Combination(int n, int k) { if (n < 0 || k > n) return 0; if (n == k || k == 0) return 1; if (k > n / 2) return Combination(n, n - k); if (maxn_combination < n) { maxn_combination = n; combMemo = new long [n + 1][]; } if (combMemo[n] == null) combMemo[n] = new long[n / 2 + 1]; if (combMemo[n][k] != 0) return combMemo[n][k]; else { combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1); return combMemo[n][k]; } } public static long Gcd(long a, long b) { if (a <= 0) return -1; // if (a > b) return gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Numerics; class Myon { // chokudaiさんのコードをコピペ static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); return 0; } public void calc() { int n = cin.nextInt(); // System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); // sw.Start(); int[] l = new int[n]; int[] r = new int[n]; for (int i = 0; i < n; i++) { l[i] = cin.nextInt(); r[i] = cin.nextInt(); } int ans = 0; for (int i = 0; i < n; i++) ans += (r[i] - l[i] + 1); showL(ans); // sw.Stop(); // showL($"処理時間: {sw.ElapsedMilliseconds} [msec]"); } public void backetSort(ref int[] a) { // max a << a.len に対して有効なソート //よってa = int[] とする long n = a.Length; var count = new int[n]; var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index] // = loc[i] for (long i = 0; i < n; i++) count[a[i]]++; loc[0] = count[0] - 1; for (long i = 0; i < n - 1; i++) loc[i + 1] = loc[i] + count[i + 1]; long index = 0; for (int i = 0; i < n; i++) { while (index <= loc[i]) a[index++] = i; // incex <= loc[i] == index < loc[i] + 1 } } public static void showL<T>(T s) { Console.WriteLine(s); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } class SMath { /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 12 なら 2,2,3 です。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> Factorization(long n) { if (n <= 0) return null; List<long> output = new List<long>(); int i = 2; long max = (long)Math.Sqrt(n); ; while (n > 1) { if (i > max) { output.Add(n); break; } while (n % i == 0) { output.Add(i); n /= i; } i++; } return output; } /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1  remainder = 1です。(打ち切られない) /// 13 = 0,0,...0 remainder = 2019 /// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) /// </summary> /// <param name="n"></param> /// <param name="remainder"></param> /// <returns></returns> public static List<long> Factorization(long n, out long remainder) { // output[i] が i-1番目の素数の数を示す //ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) remainder = 1; if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; long max = (long)Math.Sqrt(n); bool[] isNOTPrime = new bool[max + 1]; while (n > 1) { if (tempn > max) { remainder = n; break; } if (!isNOTPrime[tempn]) { output.Add(0); while (n % tempn == 0) { output[output.Count - 1]++; n /= tempn; } for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } /// <summary> /// i番目の素数をoutput[i-1]に返します。 /// ただしnより大きい素数については判定しません。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> GetPrimeNumbers(long n) { if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; bool[] isNOTPrime = new bool[n + 1]; while (n > 1) { if (tempn > n) { break; } if (!isNOTPrime[tempn]) { output.Add(tempn); for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } private static long[][] combMemo; private static int maxn_combination = -1; public static long Combination(int n, int k) { if (n < 0 || k > n) return 0; if (n == k || k == 0) return 1; if (k > n / 2) return Combination(n, n - k); if (maxn_combination < n) { maxn_combination = n; combMemo = new long [n + 1][]; } if (combMemo[n] == null) combMemo[n] = new long[n / 2 + 1]; if (combMemo[n][k] != 0) return combMemo[n][k]; else { combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1); return combMemo[n][k]; } } public static long Gcd(long a, long b) { if (a <= 0) return -1; // if (a > b) return gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } }
[["-", 0, 197, 0, 198, 39, 232, 234, 232, 234, 22], ["-", 0, 197, 0, 198, 39, 232, 234, 232, 0, 131], ["-", 0, 197, 0, 198, 39, 232, 234, 232, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 232, 0, 131], ["-", 8, 196, 0, 197, 0, 198, 39, 232, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 234, 22], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 0, 131], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 0, 131], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 205, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 0, 131], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62]]
8
1,306
41
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var n = IO.RInt; var paper = new bool[int.MaxValue]; for (int i = 0; i < n; i++) { var a = IO.RInt - 1; if (!paper[a]) { paper[a] = true; } else { paper[a] = false; } } WriteLine(paper.Where(f => f).Count()); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #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"); 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 } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var n = IO.RInt; var paper = new Dictionary<int, int>(); for (int i = 0; i < n; i++) { var tmp = IO.RInt - 1; if (!paper.ContainsKey(tmp)) { paper[tmp] = 1; } else { paper[tmp]++; } } WriteLine(paper.Values.Where(x => x % 2 == 1).Count()); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #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"); 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 } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["-", 0, 227, 39, 224, 225, 226, 0, 214, 0, 131], ["-", 0, 227, 39, 224, 225, 226, 0, 214, 141, 22], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 21], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 57, 15, 241, 0, 204, 206, 207, 0, 70], ["-", 15, 241, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 241, 0, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 241, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 241, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 241, 0, 213, 3, 4, 0, 24], ["+", 15, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 223, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 63, 214, 205, 213, 63, 214, 205, 214, 0, 131], ["+", 63, 214, 205, 213, 63, 214, 205, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 17, 109], ["+", 0, 28, 0, 218, 8, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203]]
8
550
41
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); Dictionary<int, int> dic = new Dictionary<int, int>(); for (int i = 0; i < N; i++) { var r = int.Parse(Console.ReadLine()); if (!dic.ContainsKey(r)) { dic[r] = 1; } else { dic[r]++; } } Console.WriteLine(dic.Values.Where(x => x % 2 != 0).Sum()); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); Dictionary<int, int> dic = new Dictionary<int, int>(); for (int i = 0; i < N; i++) { var r = int.Parse(Console.ReadLine()); if (!dic.ContainsKey(r)) { dic[r] = 1; } else { if (dic[r] == 1) { dic[r] = 2; } else { dic[r] = 1; } } } Console.WriteLine(dic.Values.Where(x => x % 2 != 0).Sum()); } } }
[["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 75, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
8
167
24
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Numerics; class Myon { // chokudaiさんのコードをコピペ static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); return 0; } public void calc() { int n = cin.nextInt(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); List<int> paper = new List<int>(); for (int i = 0; i < n; i++) { paper.Add(cin.nextInt()); } paper.Sort(); int count = 0; //対消滅した数の数 for (int i = 0; i < paper.Count - 1; i++) { if (paper[i] == paper[i + 1]) { count += 2; i++; } } showL(paper.Count - count); sw.Stop(); showL($"処理時間: {sw.ElapsedMilliseconds} [msec]"); } public void backetSort(ref int[] a) { // max a << a.len に対して有効なソート //よってa = int[] とする long n = a.Length; var count = new int[n]; var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index] // = loc[i] for (long i = 0; i < n; i++) count[a[i]]++; loc[0] = count[0] - 1; for (long i = 0; i < n - 1; i++) loc[i + 1] = loc[i] + count[i + 1]; long index = 0; for (int i = 0; i < n; i++) { while (index <= loc[i]) a[index++] = i; // incex <= loc[i] == index < loc[i] + 1 } } public static void showL<T>(T s) { Console.WriteLine(s); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } class SMath { /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 12 なら 2,2,3 です。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> Factorization(long n) { if (n <= 0) return null; List<long> output = new List<long>(); int i = 2; long max = (long)Math.Sqrt(n); ; while (n > 1) { if (i > max) { output.Add(n); break; } while (n % i == 0) { output.Add(i); n /= i; } i++; } return output; } /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1  remainder = 1です。(打ち切られない) /// 13 = 0,0,...0 remainder = 2019 /// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) /// </summary> /// <param name="n"></param> /// <param name="remainder"></param> /// <returns></returns> public static List<long> Factorization(long n, out long remainder) { // output[i] が i-1番目の素数の数を示す //ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) remainder = 1; if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; long max = (long)Math.Sqrt(n); bool[] isNOTPrime = new bool[max + 1]; while (n > 1) { if (tempn > max) { remainder = n; break; } if (!isNOTPrime[tempn]) { output.Add(0); while (n % tempn == 0) { output[output.Count - 1]++; n /= tempn; } for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } /// <summary> /// i番目の素数をoutput[i-1]に返します。 /// ただしnより大きい素数については判定しません。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> GetPrimeNumbers(long n) { if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; bool[] isNOTPrime = new bool[n + 1]; while (n > 1) { if (tempn > n) { break; } if (!isNOTPrime[tempn]) { output.Add(tempn); for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } private static long[][] combMemo; private static int maxn_combination = -1; public static long Combination(int n, int k) { if (n < 0 || k > n) return 0; if (n == k || k == 0) return 1; if (k > n / 2) return Combination(n, n - k); if (maxn_combination < n) { maxn_combination = n; combMemo = new long [n + 1][]; } if (combMemo[n] == null) combMemo[n] = new long[n / 2 + 1]; if (combMemo[n][k] != 0) return combMemo[n][k]; else { combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1); return combMemo[n][k]; } } public static long Gcd(long a, long b) { if (a <= 0) return -1; // if (a > b) return gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Globalization; using System.Numerics; class Myon { // chokudaiさんのコードをコピペ static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); return 0; } public void calc() { int n = cin.nextInt(); // System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); // sw.Start(); List<int> paper = new List<int>(); for (int i = 0; i < n; i++) { paper.Add(cin.nextInt()); } paper.Sort(); int count = 0; //対消滅した数の数 for (int i = 0; i < paper.Count - 1; i++) { if (paper[i] == paper[i + 1]) { count += 2; i++; } } showL(paper.Count - count); // sw.Stop(); // showL($"処理時間: {sw.ElapsedMilliseconds} [msec]"); } public void backetSort(ref int[] a) { // max a << a.len に対して有効なソート //よってa = int[] とする long n = a.Length; var count = new int[n]; var loc = new long[n]; // loc[i] は i が終わる 位置 max index where c[index] // = loc[i] for (long i = 0; i < n; i++) count[a[i]]++; loc[0] = count[0] - 1; for (long i = 0; i < n - 1; i++) loc[i + 1] = loc[i] + count[i + 1]; long index = 0; for (int i = 0; i < n; i++) { while (index <= loc[i]) a[index++] = i; // incex <= loc[i] == index < loc[i] + 1 } } public static void showL<T>(T s) { Console.WriteLine(s); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } class SMath { /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 12 なら 2,2,3 です。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> Factorization(long n) { if (n <= 0) return null; List<long> output = new List<long>(); int i = 2; long max = (long)Math.Sqrt(n); ; while (n > 1) { if (i > max) { output.Add(n); break; } while (n % i == 0) { output.Add(i); n /= i; } i++; } return output; } /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1  remainder = 1です。(打ち切られない) /// 13 = 0,0,...0 remainder = 2019 /// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) /// </summary> /// <param name="n"></param> /// <param name="remainder"></param> /// <returns></returns> public static List<long> Factorization(long n, out long remainder) { // output[i] が i-1番目の素数の数を示す //ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) remainder = 1; if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; long max = (long)Math.Sqrt(n); bool[] isNOTPrime = new bool[max + 1]; while (n > 1) { if (tempn > max) { remainder = n; break; } if (!isNOTPrime[tempn]) { output.Add(0); while (n % tempn == 0) { output[output.Count - 1]++; n /= tempn; } for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } /// <summary> /// i番目の素数をoutput[i-1]に返します。 /// ただしnより大きい素数については判定しません。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> GetPrimeNumbers(long n) { if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; bool[] isNOTPrime = new bool[n + 1]; while (n > 1) { if (tempn > n) { break; } if (!isNOTPrime[tempn]) { output.Add(tempn); for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } private static long[][] combMemo; private static int maxn_combination = -1; public static long Combination(int n, int k) { if (n < 0 || k > n) return 0; if (n == k || k == 0) return 1; if (k > n / 2) return Combination(n, n - k); if (maxn_combination < n) { maxn_combination = n; combMemo = new long [n + 1][]; } if (combMemo[n] == null) combMemo[n] = new long[n / 2 + 1]; if (combMemo[n][k] != 0) return combMemo[n][k]; else { combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1); return combMemo[n][k]; } } public static long Gcd(long a, long b) { if (a <= 0) return -1; // if (a > b) return gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } }
[["-", 0, 197, 0, 198, 39, 232, 234, 232, 234, 22], ["-", 0, 197, 0, 198, 39, 232, 234, 232, 0, 131], ["-", 0, 197, 0, 198, 39, 232, 234, 232, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 232, 0, 131], ["-", 8, 196, 0, 197, 0, 198, 39, 232, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 234, 22], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 0, 131], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 0, 131], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 205, 22], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 0, 131], ["-", 0, 28, 0, 283, 0, 284, 0, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62]]
8
1,311
41
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var list = new List<int>(); for (int i = 0; i < N; i++) { list.Add(int.Parse(Console.ReadLine())); } list.Sort(); int u = list.First(); int cnt = 0; int ans = 0; for (int i = 0; i < N; i++) { if (list[i] != u) { if (cnt % 2 != 0) { ans++; } u = list[i]; cnt = 1; } else { cnt++; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharpSample01 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var list = new List<int>(); for (int i = 0; i < N; i++) { list.Add(int.Parse(Console.ReadLine())); } list.Sort(); int u = list.First(); int cnt = 0; int ans = 0; for (int i = 0; i < N; i++) { if (list[i] != u) { if (cnt % 2 != 0) { ans++; } u = list[i]; cnt = 1; } else { cnt++; } } if (cnt % 2 != 0) { ans++; } Console.WriteLine(ans); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
180
13
using System; using System.Linq; using System.Collections.Generic; class Cmondai { static void Main() { var N = Int32.Parse(Console.ReadLine()); var A = new long[N]; var ans = 0; var currentNum = 0L; var currentNumCount = 0; for (int i = 0; i < N; ++i) A[i] = Int64.Parse(Console.ReadLine()); A = A.OrderBy(x => x).ToArray(); for (int i = 0; i < N; ++i) { if (A[i] == currentNum) { currentNumCount++; if (i == N - 1) if (currentNumCount % 2 != 0) ans++; } else { if (currentNumCount % 2 != 0) ans++; currentNum = A[i]; currentNumCount = 1; } } 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 = new long[N]; var ans = 0; var currentNum = 0L; var currentNumCount = 0; for (int i = 0; i < N; ++i) A[i] = Int64.Parse(Console.ReadLine()); A = A.OrderBy(x => x).ToArray(); for (int i = 0; i < N; ++i) { if (A[i] == currentNum) { currentNumCount++; if (i == N - 1) if (currentNumCount % 2 != 0) ans++; } else { if (currentNumCount % 2 != 0) ans++; currentNum = A[i]; currentNumCount = 1; if (i == N - 1) if (currentNumCount % 2 != 0) ans++; } } Console.WriteLine(ans); } }
[["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 57, 0, 121], ["+", 0, 57, 75, 196, 0, 57, 64, 57, 0, 24], ["+", 0, 57, 64, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 64, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 64, 57, 15, 16, 31, 16, 12, 203], ["+", 75, 196, 0, 57, 64, 57, 15, 16, 17, 79], ["+", 75, 196, 0, 57, 64, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 64, 57, 0, 25], ["+", 0, 57, 64, 57, 64, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 57, 64, 1, 0, 223, 0, 29], ["+", 75, 196, 0, 57, 64, 57, 64, 1, 0, 35]]
8
190
19
using System; using System.Collections.Generic; using System.Linq; namespace ABC073_C_Write_and_Erase { internal class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List<int> aList = new List<int>(); for (int i = 0; i < n; i++) aList.Add(int.Parse(Console.ReadLine())); aList.Sort(); //解説スライドを見て書いたコード int count = 1; int result = 0; for (int i = 0; i < n - 1; i++) { if (aList[i] == aList[i + 1]) { count++; } else { if (count % 2 == 1) result++; if (i == n - 2) result++; count = 1; } } Console.WriteLine(result); //自分で書いたコード /*int count = aList.Count; for (int i = 0; i < n;) { int countNumbers = aList.Count(x => x == aList[i]); if (countNumbers % 2 == 1) count -= countNumbers - 1; else count -= countNumbers; i += countNumbers; } Console.WriteLine(count);*/ } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC073_C_Write_and_Erase { internal class Program { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List<int> aList = new List<int>(); for (int i = 0; i < n; i++) aList.Add(int.Parse(Console.ReadLine())); aList.Sort(); //解説スライドを見て書いたコード int count = 1; int result = 0; for (int i = 0; i < n - 1; i++) { if (aList[i] == aList[i + 1]) { count++; } else { if (count % 2 == 1) result++; count = 1; } if (i == n - 2 && count % 2 == 1) result++; } Console.WriteLine(result); //自分で書いたコード /*int count = aList.Count; for (int i = 0; i < n;) { int countNumbers = aList.Count(x => x == aList[i]); if (countNumbers % 2 == 1) count -= countNumbers - 1; else count -= countNumbers; i += countNumbers; } Console.WriteLine(count);*/ } } }
[["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
186
16
using System; using System.Collections.Generic; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); List<int> list = new List<int>(); for (int i = 0; i < n; i++) list.Add(int.Parse(Console.ReadLine())); list.Sort(); if (n == 1) { Console.WriteLine(1); } else { int ans = 0; int tmp = list[0]; bool even = false; for (int i = 1; i < n; i++) { if (i == n - 1) { if (tmp == list[i]) { if (even) ans++; } else ans++; } else { if (tmp == list[i]) { even = !even; } else { if (even) even = false; else ans++; tmp = list[i]; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); List<int> list = new List<int>(); for (int i = 0; i < n; i++) list.Add(int.Parse(Console.ReadLine())); list.Sort(); if (n == 1) { Console.WriteLine(1); } else { int ans = 0; int tmp = list[0]; bool even = false; for (int i = 1; i < n; i++) { if (i == n - 1) { if (tmp == list[i]) { if (even) ans++; } else if (even) ans++; else ans += 2; } else { if (tmp == list[i]) { even = !even; } else { if (even) even = false; else ans++; tmp = list[i]; } } } Console.WriteLine(ans); } } }
[["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 15, 22], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 25], ["+", 64, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 57, 0, 95], ["+", 0, 57, 75, 57, 75, 1, 0, 11, 31, 22], ["+", 75, 57, 75, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 75, 57, 75, 1, 0, 11, 12, 203]]
8
217
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // 入力 string sS = Console.ReadLine().Trim(); int iN = int.Parse(sS); List<int> lstsS = new List<int>(); for (int i = 0; i < iN; i++) { lstsS.Add(int.Parse(Console.ReadLine().Trim())); } //// debug // int iN = 100000; // 10万件で検証 // List<int> lstsS = new List<int>(); // for (int i = 1; i <= iN; i++) //{ // lstsS.Add(i); //} // 解析 lstsS.Sort(); // 昇順 int iOut = 0; // 存在奇数数 int iBak = lstsS[0]; // 比較元 int iDup = 0; // 重複数 for (int i = 1; i < lstsS.Count; i++) { if (lstsS[i] == iBak) { iDup += 1; } else { if (iDup % 2 == 0) { iOut += 1; } // 存在奇数のみ加算 iDup = 0; iBak = lstsS[i]; } } //出力 Console.WriteLine("{0}", iOut.ToString().Trim()); sw.Stop(); #if DEBUG Console.WriteLine(); Console.WriteLine("{0}", sw.Elapsed.ToString()); Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // 入力 string sS = Console.ReadLine().Trim(); int iN = int.Parse(sS); List<int> lstsS = new List<int>(); for (int i = 0; i < iN; i++) { lstsS.Add(int.Parse(Console.ReadLine().Trim())); } //// debug // int iN = 100000; // 10万件で検証 // List<int> lstsS = new List<int>(); // for (int i = 1; i <= iN; i++) //{ // lstsS.Add(i); //} // 解析 lstsS.Sort(); // 昇順 int iOut = 0; // 存在奇数数 int iBak = lstsS[0]; // 比較元 int iDup = 0; // 重複数 for (int i = 1; i < lstsS.Count; i++) { if (lstsS[i] == iBak) { iDup += 1; } else { if (iDup % 2 == 0) { iOut += 1; } // 存在奇数のみ加算 iDup = 0; iBak = lstsS[i]; } } if (iDup % 2 == 0) { iOut += 1; } // 存在奇数のみ加算 //出力 Console.WriteLine("{0}", iOut.ToString().Trim()); sw.Stop(); #if DEBUG Console.WriteLine(); Console.WriteLine("{0}", sw.Elapsed.ToString()); Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
298
14
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int n; n = int.Parse(Console.ReadLine()); int[] list = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { int a = int.Parse(Console.ReadLine()); list[i] = a; } Array.Sort(list); for (int i = 0; i < n; i++) { int cc = list[i]; int f = 0; while (i < n && list[i] == cc) { f++; i++; } sum += f % 2; } Console.WriteLine(sum); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int n; n = int.Parse(Console.ReadLine()); int[] list = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { int a = int.Parse(Console.ReadLine()); list[i] = a; } Array.Sort(list); int j = 0; while (j < n) { int cc = list[j]; int f = 0; while (j < n && list[j] == cc) { f++; j++; } sum += f % 2; } Console.WriteLine(sum); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22]]
8
164
19
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static void AssertEquals<T>(T expected, T actual, [CallerLineNumber] int lno = 0) where T : IComparable { if (expected.CompareTo(actual) != 0) { WriteLine($"Assertion Error at line {lno}:"); WriteLine($"\texpected: {expected}"); WriteLine($"\t actual: {actual}"); Environment.Exit(1); } } public static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { var r = a % b; a = b; b = r; } return a; } public static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void WarshallFloyd(int[,] d, int v) { for (int k = 0; k < v; k++) for (int i = 0; i < v; i++) for (int j = 0; j < v; j++) d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]); } public static bool NextPermutation<T>(T[] a) where T : IComparable { if (a.Length <= 1) return false; for (int i = a.Length - 1; i > 0; i--) { int k = i - 1; if (a[k].CompareTo(a[i]) < 0) { int j = a.Length - 1; while (a[k].CompareTo(a[j]) >= 0) { j--; } Swap(ref a[k], ref a[j]); Array.Reverse(a, i, a.Length - i); return true; } } Array.Reverse(a); return false; } public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } public static long[] ReadLongArray() { return ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } } class Program { public static void Main() { int inf = 2000000000; var tmp = ReadIntArray(); int n = tmp[0], m = tmp[1], r = tmp[2]; int[] rs = ReadIntArray(); for (int i = 0; i < r; i++) rs[i]--; Array.Sort(rs); int[,] d = new int[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) d[i, j] = inf; } } for (int i = 0; i < m; i++) { tmp = ReadIntArray(); int a = tmp[0], b = tmp[1], c = tmp[2]; d[a - 1, b - 1] = c; d[b - 1, a - 1] = c; } WarshallFloyd(d, n); long ans = inf * 1000; do { int dist = 0; for (int i = 0; i < rs.Length - 1; i++) { dist += d[rs[i], rs[i + 1]]; } ans = Math.Min(ans, dist); } while (NextPermutation(rs)); WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static void AssertEquals<T>(T expected, T actual, [CallerLineNumber] int lno = 0) where T : IComparable { if (expected.CompareTo(actual) != 0) { WriteLine($"Assertion Error at line {lno}:"); WriteLine($"\texpected: {expected}"); WriteLine($"\t actual: {actual}"); Environment.Exit(1); } } public static int Gcd(int a, int b) { if (a < b) { return Gcd(b, a); } while (b != 0) { var r = a % b; a = b; b = r; } return a; } public static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void WarshallFloyd(int[,] d, int v) { for (int k = 0; k < v; k++) for (int i = 0; i < v; i++) for (int j = 0; j < v; j++) d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]); } public static bool NextPermutation<T>(T[] a) where T : IComparable { if (a.Length <= 1) return false; for (int i = a.Length - 1; i > 0; i--) { int k = i - 1; if (a[k].CompareTo(a[i]) < 0) { int j = a.Length - 1; while (a[k].CompareTo(a[j]) >= 0) { j--; } Swap(ref a[k], ref a[j]); Array.Reverse(a, i, a.Length - i); return true; } } Array.Reverse(a); return false; } public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } public static long[] ReadLongArray() { return ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } } class Program { public static void Main() { int inf = (1 << 29); var tmp = ReadIntArray(); int n = tmp[0], m = tmp[1], r = tmp[2]; int[] rs = ReadIntArray(); for (int i = 0; i < r; i++) rs[i]--; Array.Sort(rs); int[,] d = new int[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) d[i, j] = inf; } } for (int i = 0; i < m; i++) { tmp = ReadIntArray(); int a = tmp[0], b = tmp[1], c = tmp[2]; a--; b--; d[a, b] = c; d[b, a] = c; } WarshallFloyd(d, n); int ans = inf; do { int dist = 0; for (int i = 0; i < r - 1; i++) { dist += d[rs[i], rs[i + 1]]; } ans = Math.Min(ans, dist); } while (NextPermutation(rs)); WriteLine(ans); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 31, 203], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 17, 151], ["+", 0, 200, 0, 212, 0, 23, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 23, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 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, 16, 17, 48], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22]]
8
810
28
using System; using System.Collections; // After watching ediorial namespace ABC073D { class Program { static int INFTY = 0x30000000; static void Main(string[] args) { int N, M, R; int[,] cost; int[] r; string[] str = Console.ReadLine().Split(' '); N = int.Parse(str[0]); M = int.Parse(str[1]); R = int.Parse(str[2]); cost = new int[N, N]; r = new int[R]; for (int i = 0; i < N; ++i) { cost[i, i] = 0; for (int j = i + 1; j < N; ++j) { cost[i, j] = cost[j, i] = INFTY; } } str = Console.ReadLine().Split(' '); for (int i = 0; i < R; ++i) { r[i] = int.Parse(str[i]) - 1; } for (int k = 0; k < M; ++k) { int i, j; str = Console.ReadLine().Split(' '); i = int.Parse(str[0]) - 1; j = int.Parse(str[1]) - 1; cost[i, j] = cost[j, i] = int.Parse(str[2]); } // Set connected costs for (int k = 0; k < N; ++k) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { int wc = cost[i, k] + cost[k, j]; if (wc < cost[i, j]) { cost[i, j] = wc; } } } } // Salesman's Problem /* int[,] costR = new int[R, R]; int ir = 0; for (int i = 0; i < N && ir < R; i++) { bool hit = false; int jr = 0; for (int j = 0; j < N && jr < R; j++) { if (i == r[ir] && j == r[jr]) { hit = true; costR[ir, jr] = cost[i, j]; jr++; } } if (hit) { ir++; } } */ Stack stack = new Stack(R); int pushNum = 0; int sum = 0; int res = INFTY; do { if (pushNum >= R) { pushNum = (int)stack.Pop(); if (stack.Count > 0) { sum -= cost[(int)stack.Peek(), r[pushNum]]; } pushNum++; } else if (stack.Count == R) { if (res > sum) { res = sum; } pushNum = (int)stack.Pop(); sum -= cost[(int)stack.Peek(), r[pushNum]]; pushNum++; } else if (!stack.Contains(pushNum)) { if (stack.Count > 0) { sum += cost[(int)stack.Peek(), r[pushNum]]; } stack.Push(pushNum); pushNum = 0; } else { pushNum++; } } while (stack.Count > 0 || pushNum < R); Console.WriteLine(res); } } }
using System; using System.Collections; namespace ABC073D { class Program { static int INFTY = 0x30000000; static void Main(string[] args) { int N, M, R; int[,] cost; int[] r; string[] str = Console.ReadLine().Split(' '); N = int.Parse(str[0]); M = int.Parse(str[1]); R = int.Parse(str[2]); cost = new int[N, N]; r = new int[R]; for (int i = 0; i < N; ++i) { cost[i, i] = 0; for (int j = i + 1; j < N; ++j) { cost[i, j] = cost[j, i] = INFTY; } } str = Console.ReadLine().Split(' '); for (int i = 0; i < R; ++i) { r[i] = int.Parse(str[i]) - 1; } for (int k = 0; k < M; ++k) { int i, j; str = Console.ReadLine().Split(' '); i = int.Parse(str[0]) - 1; j = int.Parse(str[1]) - 1; cost[i, j] = cost[j, i] = int.Parse(str[2]); } // Set connected costs for (int k = 0; k < N; ++k) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { int wc = cost[i, k] + cost[k, j]; if (wc < cost[i, j]) { cost[i, j] = wc; } } } } // Salesman's Problem /* int[,] costR = new int[R, R]; int ir = 0; for (int i = 0; i < N && ir < R; i++) { bool hit = false; int jr = 0; for (int j = 0; j < N && jr < R; j++) { if (i == r[ir] && j == r[jr]) { hit = true; costR[ir, jr] = cost[i, j]; jr++; } } if (hit) { ir++; } } */ Stack stack = new Stack(R); int pushNum = 0; int sum = 0; int res = INFTY; do { if (pushNum >= R) { pushNum = (int)stack.Pop(); if (stack.Count > 0) { sum -= cost[r[(int)stack.Peek()], r[pushNum]]; } pushNum++; } else if (stack.Count == R) { if (res > sum) { res = sum; } pushNum = (int)stack.Pop(); sum -= cost[r[(int)stack.Peek()], r[pushNum]]; pushNum++; } else if (!stack.Contains(pushNum)) { if (stack.Count > 0) { sum += cost[r[(int)stack.Peek()], r[pushNum]]; } stack.Push(pushNum); pushNum = 0; } else { pushNum++; } } while (stack.Count > 0 || pushNum < R); Console.WriteLine(res); } } }
[["+", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70]]
8
622
9
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(); int M = re.i(); int R = re.i(); int[] r = re.ia(); long[,] cost = new long[N, N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cost[i, j] = 100000000000000; } } for (int i = 0; i < M; i++) { int f = re.i() - 1; int t = re.i() - 1; int C = re.i(); cost[f, t] = Math.Min(cost[f, t], C); cost[t, f] = Math.Min(cost[t, f], C); } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { cost[i, k] = Math.Min(cost[i, j] + cost[j, k], cost[i, k]); } } } int P = 1; for (int i = 1; i <= R; i++) { P *= i; } long count = 10000000000000; for (int i = 0; i < P; i++) { bool[] b = new bool[R]; int K = i; long C = 0; int[] order = new int[R]; for (int j = 0; j < R; j++) { int o = K % (R - j); K /= (R - j); int p = 0; while (b[p] || o > 0) { if (!b[p]) { o--; } p++; } b[p] = true; order[j] = p; } for (int j = 0; j < R - 1; j++) { C += cost[r[order[j]] - 1, r[order[j + 1]] - 1]; } count = Math.Min(count, C); } sb.Append(count + "\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() { int N = re.i(); int M = re.i(); int R = re.i(); int[] r = re.ia(); long[,] cost = new long[N, N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cost[i, j] = 100000000000000; } } for (int i = 0; i < M; i++) { int f = re.i() - 1; int t = re.i() - 1; int C = re.i(); cost[f, t] = Math.Min(cost[f, t], C); cost[t, f] = Math.Min(cost[t, f], C); } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { cost[j, k] = Math.Min(cost[j, i] + cost[i, k], cost[j, k]); } } } int P = 1; for (int i = 1; i <= R; i++) { P *= i; } long count = 10000000000000; for (int i = 0; i < P; i++) { bool[] b = new bool[R]; int K = i; long C = 0; int[] order = new int[R]; for (int j = 0; j < R; j++) { int o = K % (R - j); K /= (R - j); int p = 0; while (b[p] || o > 0) { if (!b[p]) { o--; } p++; } b[p] = true; order[j] = p; } for (int j = 0; j < R - 1; j++) { C += cost[r[order[j]] - 1, r[order[j + 1]] - 1]; } count = Math.Min(count, C); } sb.Append(count + "\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, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 21], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 21], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22]]
8
2,156
10
using System; namespace abc072A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); long A = long.Parse(str[0]); long B = long.Parse(str[1]); Console.WriteLine(A - B); } } }
using System; namespace abc072A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); long A = long.Parse(str[0]); long B = long.Parse(str[1]); if (A >= B) Console.WriteLine(A - B); else Console.WriteLine(0); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
73
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Convert; using static System.Console; using static System.Math; class MainClass { static void Main(string[] args) { Answer(); } public static void Answer() { var str = Console.ReadLine(); var ans3 = ""; for (int i = 1; i < str.Length; i += 2) { ans3 += str[i - 1]; } Console.WriteLine(ans3); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Convert; using static System.Console; using static System.Math; class MainClass { static void Main(string[] args) { Answer(); } public static void Answer() { var str = Console.ReadLine(); var ans5 = new StringBuilder(); for (int i = 0; i < str.Length; i += 2) { ans5.Append(str[i]); } Console.WriteLine(ans5); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
115
2
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramC { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(" ").Select(x => int.Parse(x) + 1).ToList(); var xList = new int[(int)1e6]; for (var i = 0; i < n; i++) { xList[a[i]]++; xList[a[i] + 1]++; xList[a[i] - 1]++; } Console.WriteLine( string.Join(", ", xList[99999], xList[99999 - 1], xList[99999 + 1])); Console.WriteLine(xList.Max()); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramC { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); var a = Console.ReadLine().Split(" ").Select(x => int.Parse(x) + 1).ToList(); var xList = new int[(int)1e6]; for (var i = 0; i < n; i++) { xList[a[i]]++; xList[a[i] + 1]++; xList[a[i] - 1]++; } Console.WriteLine(xList.Max()); } } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 203], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22]]
8
185
33
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class Atcoder_nA { public static void Main() { int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; int[] b = new int[100010]; var input = Console.ReadLine().Split(); for (int i = 1; i < n; i++) { a[i] = int.Parse(input[i]); b[a[i]]++; } int m = 0; int index = 0; for (int i = 1; i < 100010; i++) { if (b[i - 1] + b[i] + b[i + 1] > m) { m = b[i - 1] + b[i] + b[i + 1]; index = i; } } Console.WriteLine(index); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class Atcoder_nA { public static void Main() { int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; int[] b = new int[100010]; var input = Console.ReadLine().Split(); for (int i = 0; i < n; i++) { a[i] = int.Parse(input[i]); b[a[i]]++; } int m = 0; // int index = 0; for (int i = 1; i < 100005; i++) { if (b[i - 1] + b[i] + b[i + 1] > m) { m = b[i - 1] + b[i] + b[i + 1]; // index = i; } } Console.WriteLine(m); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
205
15
using System; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a_distinct = a.Distinct().ToArray(); //それぞれの数を数えておく var counter = new int[a.Max() + 2]; for (int i = 0; i < a_distinct.Count(); i++) { if (a_distinct[i] > 0) { counter[a_distinct[i] - 1]++; } counter[a_distinct[i]]++; counter[a_distinct[i] + 1]++; } Console.WriteLine(counter.Max()); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); //それぞれの数を数えておく var counter = new int[a.Max() + 2]; for (int i = 0; i < a.Count(); i++) { if (a[i] > 0) { counter[a[i] - 1]++; } counter[a[i]]++; counter[a[i] + 1]++; } Console.WriteLine(counter.Max()); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22]]
8
163
23
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC_practice { public class Program { #region templete private static void WL(string s) { WriteLine(s); } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } /// <summary> /// 最小公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } static void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } static void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } public static bool Inside(int x, int a, int b) { return (a <= x && x <= b) ? true : false; } public static void Main(string[] args) { new Program().Solve(); ReadLine(); } #endregion static Dictionary<int, int> dic; public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var a = cin.ArrayInt(n); var cntMax = 100010; var num = new int[cntMax]; var ans = 0; foreach (var i in a) { num[i]++; } for (int i = 1; i < n; i++) { ans = Max(ans, num[i] + num[i - 1] + num[i + 1]); } WL($"{ans}"); } } } #region console in 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; } } #endregion
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace ABC_practice { public class Program { #region templete private static void WL(string s) { WriteLine(s); } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> static long Gcd(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } /// <summary> /// 最小公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } static void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } static void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } public static bool Inside(int x, int a, int b) { return (a <= x && x <= b) ? true : false; } public static void Main(string[] args) { new Program().Solve(); ReadLine(); } #endregion static Dictionary<int, int> dic; public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var a = cin.ArrayInt(n); var cntMax = 100010; var num = new int[cntMax]; foreach (var i in a) { num[i]++; } var ans = 0; for (int i = 1; i < cntMax - 1; i++) { ans = Max(ans, num[i] + num[i - 1] + num[i + 1]); } WL($"{ans}"); } } } #region console in 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; } } #endregion
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
780
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static System.Array; class Program { public static void Main() { var n = int.Parse(ReadLine()); var a = ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); var b = new bool [n].Select((x, i) => a[i] == i).ToArray(); var count = 0; for (int i = 0; i < n - 1; i++) { if (b[i]) { count++; a[i + 1] = a[i]; b[i + 1] = i + 1 == a[i + 1]; } } WriteLine(count); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static System.Array; class Program { public static void Main() { var n = int.Parse(ReadLine()); var a = ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); var b = new bool [n].Select((x, i) => a[i] == i).ToArray(); var count = 0; for (int i = 0; i < n; i++) { if (b[i]) { count++; if (i < n - 1) { a[i + 1] = a[i]; b[i + 1] = i + 1 == a[i + 1]; } } } WriteLine(count); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
190
12
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; using static Atcoder.IO; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); Out.Flush(); } } } public class Solve { public static void Answer() { var N = RInt; var p = RSInt; var ans = 0; for (int i = 0; i < N; i += 2) { if (i == N - 1) { if (p[i] == i + 1) { ans++; } break; } if (p[i] == i + 1 || p[i + 1] == i + 2) { ans++; } } WriteLine(ans); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #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"); 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 } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; using static Atcoder.IO; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); Out.Flush(); } } } public class Solve { public static void Answer() { var N = RInt; var p = RSInt; var ans = 0; for (int i = 0; i < N; i++) { if (p[i] == i + 1) { ans++; if (i != N - 1 && p[i + 1] == i + 2) { i++; } } } WriteLine(ans); } } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #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"); 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 } }
[["-", 8, 196, 0, 7, 26, 11, 0, 202, 0, 107], ["-", 0, 195, 8, 196, 0, 7, 26, 11, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 72], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
568
30
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_D.Lib_IO; using static Contest_D.Lib_Minifunc; public static class Contest_D { public static void Main() { checked{ long n; Lib_IO.rm(out n); ll[] p; ra(out p); long ans = 0; for (int i = 0; i < n-1; i++) { if(p[i]==i+1){ if(p[i+1]==i+2){ i++; ans++; }else{ i++; ans++; } } } Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; // using System.Numerics; using System.Runtime.CompilerServices; using System.Diagnostics; using ll=System.Int64; using static Contest_D.Lib_IO; using static Contest_D.Lib_Minifunc; public static class Contest_D { public static void Main() { checked{ long n; Lib_IO.rm(out n); ll[] p; ra(out p); long ans = 0; for (int i = 0; i < n; i++) { if(p[i]==i+1){ if(i==n-1){ ans++; }else{ if(p[i+1]==i+2){ i++; ans++; }else{ i++; ans++; } } } } Lib_IO.wm(ans); } } #region BaseModule public static class Lib_Minifunc{ [MethodImpl(256)] public static void swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } [MethodImpl(256)] public static void swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b)==1) swap1(ref a, ref b); } // b の方が小さければ交換 [MethodImpl(256)] public static bool chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)== 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 [MethodImpl(256)] public static bool chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b)==-1) { a = b; return true; } return false; } // b の方が大きければ a を更新 [MethodImpl(256)] public static bool inside(long i, long n) => (0<=i&&i<n); [MethodImpl(256)] public static bool inside(long x, long y, long w, long h) => (inside(x,w)&&inside(y,h)); [MethodImpl(256)] public static T min<T>(params T[] a) where T : IComparable => a.Min(); [MethodImpl(256)] public static T max<T>(params T[] a) where T : IComparable => a.Max(); [MethodImpl(256)] public static long mod(long a, long m=MOD1) { var v = a%m; return (v<0?v+m:v); } [MethodImpl(256)] public static long ceiling(long a, long b) => (a%b==0?a/b:a/b+1); // 整数商の切り上げ [MethodImpl(256)] public static P<T,U> initp<T,U>(T a,U b) => new P<T,U>(a,b); [MethodImpl(256)] public static P<T,U,V> initp<T,U,V>(T a,U b,V c) => new P<T,U,V>(a,b,c); [MethodImpl(256)] public static P<T,U,V,W> initp<T,U,V,W>(T a,U b,V c,W d) => new P<T,U,V,W>(a,b,c,d); [MethodImpl(256)] public static bool initd<T,U>(Dictionary<T,U> d, T k) { if(d.ContainsKey(k)) { return false; } else { d[k] = default(U); return true; } } public static T[] inita<T>(long len1) where T : new() { var m = new T[len1]; for (int i=0;i<m.Length;i++) m[i] = new T(); return m; } public static T[][] initm<T>(long len1,long len2,T val) where T : struct { var m = new T[len1][]; for (int i=0;i<m.Length;i++) m[i] = Enumerable.Repeat(val,(int)len2).ToArray(); return m; } public static T[][][] initm<T>(long len1,long len2,long len3,T val) where T : struct { var m = new T[len1][][]; for (int i=0;i<m.Length;i++) m[i] = initm(len2,len3,val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public const long INF1 = 1000000000000000; // 10^15 } public struct P<T,U> { public T A; public U B; public P(T a,U b) { A = a; B = b; } public static implicit operator KeyValuePair<T,U>(P<T,U> a) => new KeyValuePair<T,U>(a.A,a.B); public static implicit operator P<T,U>(KeyValuePair<T,U> a) => new P<T,U>(a.Key,a.Value); } public struct P<T,U,V> { public T A; public U B; public V C; public P(T a,U b,V c) { A = a; B = b; C = c; } } public struct P<T,U,V,W> { public T A; public U B; public V C; public W D; public P(T a,U b,V c,W d) { A = a; B = b; C = c; D = d; } } public static class Lib_IO { class Prt : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Prt(System.IO.Stream s) : base(s,new UTF8Encoding(false,true)) {} public Prt(System.IO.Stream s,Encoding e) : base(s,e) {} } static Prt sw = new Prt(Console.OpenStandardOutput()); static char[] sp = new char[] {' '}; [MethodImpl(256)] static bool eq<T,U>() => typeof(T).Equals(typeof(U)); [MethodImpl(256)] static T ct<T,U>(U a) => (T)Convert.ChangeType(a,typeof(T)); [MethodImpl(256)] static T cv<T>(string s) => eq<T,int>() ? ct<T,int>(int.Parse(s)) : eq<T,long>() ? ct<T,long>(long.Parse(s)) : eq<T,double>() ? ct<T,double>(double.Parse(s,System.Globalization.CultureInfo.InvariantCulture)) : eq<T,char>() ? ct<T,char>(s[0]) : ct<T,string>(s); public static string[] rm<T>(out T a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = cv<T>(z[0]); return z; } public static string[] rm<T,U>(out T a,out U b) { var z = rm<T>(out a); b = cv<U>(z[1]); return z; } public static string[] rm<T,U,V>(out T a,out U b,out V c) { var z = rm<T,U>(out a,out b); c = cv<V>(z[2]); return z; } public static string[] rm<T,U,V,W>(out T a,out U b,out V c,out W d) { var z = rm<T,U,V>(out a,out b,out c); d = cv<W>(z[3]); return z; } public static string[] rm<T,U,V,W,X>(out T a,out U b,out V c,out W d,out X e) { var z = rm<T,U,V,W>(out a,out b,out c,out d); e = cv<X>(z[4]); return z; } public static string[] rm<T,U,V,W,X,Y>(out T a,out U b,out V c,out W d,out X e,out Y f) { var z = rm<T,U,V,W,X>(out a,out b,out c,out d,out e); f = cv<Y>(z[5]); return z; } public static string[] ra<T>(out T[] a) { var z = Console.ReadLine().Split(sp,StringSplitOptions.RemoveEmptyEntries); a = z.Select(cv<T>).ToArray(); return z; } public static string[][] rl<T>(long n,out T[] a) { a = new T[n]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = rm(out a[i]); return y; } public static string[][] rl<T,U>(long n,out P<T,U>[] a) { a = new P<T,U>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; y[i] = rm(out o,out p); a[i] = new P<T,U>(o,p); } return y; } public static string[][] rl<T,U,V>(long n,out P<T,U,V>[] a) { a = new P<T,U,V>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; y[i] = rm(out o,out p,out q); a[i] = new P<T,U,V>(o,p,q); } return y; } public static string[][] rl<T,U,V,W>(long n,out P<T,U,V,W>[] a) { a = new P<T,U,V,W>[n]; var y = new string[n][]; for(int i=0;i<n;i++) { T o; U p; V q; W r; y[i] = rm(out o,out p,out q,out r); a[i] = new P<T,U,V,W>(o,p,q,r); } return y; } public static string[][] rx<T>(long n,out T[][] a) { a = new T[n][]; var y = new string[n][]; for(int i=0;i<n;i++) y[i] = ra(out a[i]); return y; } static void wwp(Action act){ sw.AutoFlush = false; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } [MethodImpl(256)] static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void wm(params object[] a) { wwp(()=>{ for(int i=0;i<a.Length-1;i++) Console.Write(wfm(a[i].GetType())+" ",a[i]); Console.WriteLine(wfm(a[a.Length-1].GetType()),a[a.Length-1]); }); } public static void wa<T>(IList<T> a) { wxa(new IList<T>[]{a}, " "); } public static void wl<T>(IList<T> a) { wwp(()=>{ var f = wfm(typeof(T)); foreach(T x in a) Console.WriteLine(f,x); }); } static void wxa<T>(IList<IList<T>> a, string s) { wwp(()=>{ var f = wfm(typeof(T)); var g = f + s; foreach(var b in a) { for(int i=0;i<b.Count-1;i++) Console.Write(g,b[i]); Console.WriteLine(f,b[b.Count-1]); } }); } public static void wx<T>(IList<IList<T>> a) { wxa(a, " "); } public static void wg<T>(IList<IList<T>> a) { wxa(a, ""); } } #endregion }
[["-", 0, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 0, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
8
2,968
18
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { static class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); // var N = GetInt(); var P = GetIntArray(); var ans = 0; for (int i = 0; i < N - 1; i++) { if (P[i] == i + 1) { Swap(ref P[i], ref P[i + 1]); ans++; } } Console.WriteLine(ans); // Console.Out.Flush(); Console.ReadKey(); } static void Solve() {} static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public string GetStr() { return Console.ReadLine().Trim(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } 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>(out T a, out U b, out V c, out V d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { static class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); // var N = GetInt(); var P = GetIntArray(); var ans = 0; for (int i = 0; i < N - 1; i++) { if (P[i] == i + 1) { Swap(ref P[i], ref P[i + 1]); ans++; } } if (P.Last() == P.Length) { Swap(ref P[N - 1], ref P[N - 2]); ans++; } Console.WriteLine(ans); // Console.Out.Flush(); Console.ReadKey(); } static void Solve() {} static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public string GetStr() { return Console.ReadLine().Trim(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public string[] GetStrArray() { return Console.ReadLine().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } static string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } 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>(out T a, out U b, out V c, out V d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 275], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
923
36
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class15 { static void Main() { int N = int.Parse(Console.ReadLine()); var p = Console.ReadLine().Split().Select(int.Parse).ToArray(); bool[] frag = new bool[N]; for (int i = 0; i < N; i++) frag[i] = p[i] == i + 1 ? true : false; int count = 0; for (int i = 0; i < N - 1; i++) { if (frag[i]) { frag[i] = false; frag[i + 1] = false; count++; } } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class15 { static void Main() { int N = int.Parse(Console.ReadLine()); var p = Console.ReadLine().Split().Select(int.Parse).ToArray(); bool[] frag = new bool[N]; for (int i = 0; i < N; i++) frag[i] = p[i] == i + 1 ? true : false; int count = 0; for (int i = 0; i < N; i++) { if (frag[i]) { frag[i] = false; if (i + 1 < N) frag[i + 1] = false; count++; } } Console.WriteLine(count); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25]]
8
181
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var a = Input().ToInt(); int cnt = 0; for (int i = 0; i < n - 1; i++) { if (i + 1 == a[i]) { var k = a[i + 1]; a[i + 1] = a[i]; a[i] = k; cnt++; } } Console.WriteLine(cnt); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var a = Input().ToInt(); int cnt = 0; for (int i = 0; i < n; i++) { if (i + 1 == a[i] && i + 1 < n) { var k = a[i + 1]; a[i + 1] = a[i]; a[i] = k; cnt++; } else if (i + 1 == a[i]) { cnt++; break; } } Console.WriteLine(cnt); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 72], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 75, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 57, 64, 196, 0, 93, 0, 94]]
8
337
27
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC072D { class Program { static void Solve(Input input) { var n = input.NextInt(); var p = input.NextInt(n); var count = 0; for (int i = 0; i < n; i++) { if (p[i] == i + 1) { Utils.Swap(p, i, i + 1); count++; } } Console.WriteLine(count); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC072D { class Program { static void Solve(Input input) { var n = input.NextInt(); var p = input.NextInt(n); var count = 0; for (int i = 0; i < n - 1; i++) { if (p[i] == i + 1) { Utils.Swap(p, i, i + 1); count++; } } if (p[p.Length - 1] == p.Length) { count++; } Console.WriteLine(count); } #region Competitive Template static readonly int MOD = (int)1e9 + 7; public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; Queue<string> q { get; set; } StreamReader sr; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> /// <param name="path"></param> public Input(string path = "") { q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { return ""; } } return q.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> /// <param name="n"></param> /// <returns></returns> bool accumulate(int n) { while (q.Count() < n) { if (!read()) return false; } return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="n"></param> /// <param name="offset"></param> /// <param name="parse"></param> /// <param name="add"></param> /// <returns></returns> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(q.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="v"></param> /// <returns></returns> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="v"></param> /// <returns></returns> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 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], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 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,190
22
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int n = int.Parse(Console.ReadLine()); int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int count = 0; bool last = false; for (int i = 0; i < x.Length; i++) { if (x[i] == i + 1) { if (last) { count++; last = false; } else { last = true; } } else if (last) { count++; last = false; } } Console.WriteLine(count); } }
using System; using System.Linq; using System.Collections.Generic; class P { static void Main() { int n = int.Parse(Console.ReadLine()); int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int count = 0; bool last = false; for (int i = 0; i < x.Length; i++) { if (x[i] == i + 1) { if (last) { count++; last = false; } else { last = true; } } else if (last) { count++; last = false; } } if (last) { count++; } Console.WriteLine(count); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
148
9
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; namespace ConsoleApplication { class Program { static void Main() { new Solution().answer(); } } class Solution { string N, M; int T = 0; public Solution() { N = Console.ReadLine(); M = Console.ReadLine(); int j = Convert.ToInt32(N); string[] M_split = new string[j]; // string temp1, temp2; M_split = M.Split(' '); int i; for (i = 0; i <= j - 1; i++) { if (i + 1 == Convert.ToInt32(M_split[i]) && i + 1 <= j - 1) { // M_split[i] = temp2; // M_split[i+1] = temp1; T++; i++; } } if (Convert.ToInt32(M_split[j - 1]) == j) { T++; } } public void answer() { Console.WriteLine(T.ToString()); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; namespace ConsoleApplication { class Program { static void Main() { new Solution().answer(); } } class Solution { string N, M; int T = 0; public Solution() { N = Console.ReadLine(); M = Console.ReadLine(); int j = Convert.ToInt32(N); string[] M_split = new string[j]; M_split = M.Split(' '); int i; for (i = 0; i < j; i++) { if (i + 1 == Convert.ToInt32(M_split[i])) { T++; i++; } } // if (j % 2 == 1 && Convert.ToInt32(M_split[j - 1]) == j) { T++; } } public void answer() { Console.WriteLine(T.ToString()); } } }
[["-", 0, 263, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 263, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 33], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["-", 0, 263, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 201, 0, 263, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 263, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 31, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 263, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 263, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 263, 8, 196, 0, 57, 0, 25], ["-", 0, 263, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
223
33
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 { static void Main(string[] args) { var num = Input.num; var ps = Input.ar; var res = 0; for (var i = 0; i < num - 1; i++) { if (ps[i] == i + 1) res++; if (ps[i] == i + 1 && ps[i + 1] == i + 2) i++; } WriteLine(res + ToInt32(ps[num - 1] == num)); } } 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 static int[][] twodim(int num) => Enumerable.Repeat(0, num).Select(v => ar).ToArray(); public static long[][] twodimL(int num) => Enumerable.Repeat(0, num).Select(v => arL).ToArray(); public const double eps = 1e-11; 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 { static void Main(string[] args) { var num = Input.num; var ps = Input.ar; var res = 0; for (var i = 0; i < num; i++) { if (ps[i] == i + 1) res++; if (i != num - 1 && ps[i] == i + 1 && ps[i + 1] == i + 2) i++; } WriteLine(res); } } 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 static int[][] twodim(int num) => Enumerable.Repeat(0, num).Select(v => ar).ToArray(); public static long[][] twodimL(int num) => Enumerable.Repeat(0, num).Select(v => arL).ToArray(); public const double eps = 1e-11; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 79], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 33], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 213, 63, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 60], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
8
315
20
using System; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { int S = Reader.Int(), N = Reader.Int(); var R = Reader.IntArray(N); int NQ = Reader.Int(); var Q = Reader.IntTable(NQ); var diff = new long[N + 1]; long[] min = new long[N + 1], max = new long[N + 1]; long[] lower = new long[N + 1], upper = new long[N + 1]; min[0] = 0; max[0] = S; upper[0] = S; for (int i = 0; i < N; i++) { int r = R[i] - (i == 0 ? 0 : R[i - 1]); diff[i + 1] = diff[i] + (i % 2 == 0 ? -r : r); if (i % 2 == 0) { min[i + 1] = Math.Max(min[i], r - diff[i]); max[i + 1] = max[i]; lower[i + 1] = Math.Max(0, lower[i] - r); upper[i + 1] = upper[i] - r; } else { min[i + 1] = min[i]; max[i + 1] = Math.Min(max[i], S - r - diff[i]); lower[i + 1] = lower[i] + r; upper[i + 1] = Math.Min(S, upper[i] + r); } } var ans = new List<long>(); foreach (var q in Q) { int time = q[0]; long x = q[1]; int i = UpperBound(R, time) - 1; if (i == -1) { ans.Add(Math.Max(0, x - time)); continue; } if (x >= min[i + 1] && x <= max[i + 1]) x += diff[i + 1]; else if (x < min[i + 1]) x = lower[i + 1]; else x = upper[i + 1]; if (i % 2 == 0) x = Math.Min(S, x + (time - R[i])); else x = Math.Max(0, x - (time - R[i])); ans.Add(x); } Console.WriteLine(string.Join("\n", ans)); } bool CheckMin(ref int a, int b) { if (b < a) { a = b; return true; } return false; } bool CheckMax(ref int a, int b) { if (b > a) { a = b; return true; } return false; } static int UpperBound(int[] A, int val, int L = 0, int R = -1) { if (R == -1) R = A.Length; while (R - L >= 1) { int mid = (L + R) / 2; if (A[mid] > val) R = mid; else L = mid + 1; } return R; } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { Dispose(); A = new string[0]; } public static void Set(TextReader r) { Init(); reader = r; } public static void Set(string file) { Init(); reader = new StreamReader(file); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } public static void Dispose() { reader.Dispose(); } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
using System; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { int S = Reader.Int(), N = Reader.Int(); var R = Reader.IntArray(N); int NQ = Reader.Int(); var Q = Reader.IntTable(NQ); var diff = new long[N + 1]; long[] min = new long[N + 1], max = new long[N + 1]; long[] lower = new long[N + 1], upper = new long[N + 1]; min[0] = 0; max[0] = S; upper[0] = S; for (int i = 0; i < N; i++) { int r = R[i] - (i == 0 ? 0 : R[i - 1]); diff[i + 1] = diff[i] + (i % 2 == 0 ? -r : r); if (i % 2 == 0) { min[i + 1] = Math.Max(min[i], r - diff[i]); max[i + 1] = max[i]; lower[i + 1] = Math.Max(0, lower[i] - r); upper[i + 1] = Math.Max(0, upper[i] - r); } else { min[i + 1] = min[i]; max[i + 1] = Math.Min(max[i], S - r - diff[i]); lower[i + 1] = Math.Min(S, lower[i] + r); upper[i + 1] = Math.Min(S, upper[i] + r); } } var ans = new List<long>(); foreach (var q in Q) { int time = q[0]; long x = q[1]; int i = UpperBound(R, time) - 1; if (i == -1) { ans.Add(Math.Max(0, x - time)); continue; } if (x >= min[i + 1] && x <= max[i + 1]) x += diff[i + 1]; else if (x < min[i + 1]) x = lower[i + 1]; else x = upper[i + 1]; if (i % 2 == 0) x = Math.Min(S, x + (time - R[i])); else x = Math.Max(0, x - (time - R[i])); ans.Add(x); } Console.WriteLine(string.Join("\n", ans)); } bool CheckMin(ref int a, int b) { if (b < a) { a = b; return true; } return false; } bool CheckMax(ref int a, int b) { if (b > a) { a = b; return true; } return false; } static int UpperBound(int[] A, int val, int L = 0, int R = -1) { if (R == -1) R = A.Length; while (R - L >= 1) { int mid = (L + R) / 2; if (A[mid] > val) R = mid; else L = mid + 1; } return R; } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { Dispose(); A = new string[0]; } public static void Set(TextReader r) { Init(); reader = r; } public static void Set(string file) { Init(); reader = new StreamReader(file); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } public static void Dispose() { reader.Dispose(); } static string[] Split(string s) { return s.Split(separator, op); } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
8
1,262
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int q = sc.NextInt(); int h = sc.NextInt(); int s = sc.NextInt(); int d = sc.NextInt(); int n = sc.NextInt(); int[] nums = new int[] { 4 * q, 2 * h, s }; int min = nums.Min(); int answer; if (min * 2 <= d) { answer = min * n; } else { answer = n / 2 * d + (n % 2) * min; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long q = sc.NextLong(); long h = sc.NextLong(); long s = sc.NextLong(); long d = sc.NextLong(); long n = sc.NextLong(); long[] nums = new long[] { 4 * q, 2 * h, s }; long min = nums.Min(); long answer; if (min * 2 <= d) { answer = min * n; } else { answer = n / 2 * d + (n % 2) * min; } 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, 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, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
454
28
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = longa(); var va = rlong(); long t1 = n[0] * 4; long t2 = n[1] * 2; long t3 = n[2]; long l1 = Min(t1, t2); l1 = Min(l1, t3); long l2 = n[3]; if (l1 * 2 <= l2) { WriteLine(l1 * va); } else { long temp = va / 2; WriteLine(l2 * temp + l1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = longa(); var va = rlong(); long t1 = n[0] * 4; long t2 = n[1] * 2; long t3 = n[2]; long l1 = Min(t1, t2); l1 = Min(l1, t3); long l2 = n[3]; if (l1 * 2 <= l2) { WriteLine(l1 * va); } else { long temp = va / 2; va -= temp * 2; WriteLine(l2 * temp + l1 * va); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
[["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22]]
8
1,282
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.IO; class _Class { void _Do() { // var a_ = _longArray(); var N_ = _longArray(); // long l = Math.Min(a_[0] * 4, a_[1] * 2); l = Math.Min(l, a_[2]); long l2 = a_[3]; long n = N_[0]; // { // 2l if (N_[0] % 2 == 0) { // guusuu var d = Math.Min(l * 2, l2); Console.WriteLine(d / 2); } else { // kisuu if (l2 > l * 2) { Console.WriteLine(n * l); } else { long d = n / 2; Console.WriteLine(d * l2 + 1 * l); } } } } static void Main(string[] args) { new _Class()._Do(); } // 1 string[] _stringArray() { return Console.ReadLine().Split(); } // 2.1 -2,147,483,648 ~ +2,147,483,647 int[] _intArray() { var _s = Console.ReadLine().Split(); var x = new int[_s.Length]; for (var i = 0; i < _s.Length; i++) x[i] = int.Parse(_s[i]); return x; } // 2.2 -9,223,372,036,854,775,808 ~ +9,223,372,036,854,775,807 long[] _longArray() { var _s = Console.ReadLine().Split(); var x = new long[_s.Length]; for (var i = 0; i < _s.Length; i++) x[i] = long.Parse(_s[i]); return x; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.IO; class _Class { void _Do() { // var a_ = _longArray(); var N_ = _longArray(); // long _l = Math.Min(a_[0] * 4, a_[1] * 2); _l = Math.Min(_l, a_[2]); long _2l = a_[3]; long _リットル = N_[0]; // { // 2l if (_リットル % 2 == 0) { // guusuu var yasui2l = Math.Min(_l * 2, _2l); Console.WriteLine(yasui2l * _リットル / 2); } else { // kisuu if (_2l > _l * 2) { // Console.WriteLine(_リットル * _l); } else { // long ダブル = _リットル / 2; Console.WriteLine(ダブル * _2l + 1 * _l); } } } } static void Main(string[] args) { new _Class()._Do(); } // 1 string[] _stringArray() { return Console.ReadLine().Split(); } // 2.1 -2,147,483,648 ~ +2,147,483,647 int[] _intArray() { var _s = Console.ReadLine().Split(); var x = new int[_s.Length]; for (var i = 0; i < _s.Length; i++) x[i] = int.Parse(_s[i]); return x; } // 2.2 -9,223,372,036,854,775,808 ~ +9,223,372,036,854,775,807 long[] _longArray() { var _s = Console.ReadLine().Split(); var x = new long[_s.Length]; for (var i = 0; i < _s.Length; i++) x[i] = long.Parse(_s[i]); return x; } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 16], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 16], ["+", 0, 28, 0, 16, 31, 16, 31, 22, 12, 22], ["+", 0, 16, 31, 16, 31, 22, 12, 22, 12, 16], ["+", 31, 16, 31, 22, 12, 22, 12, 16, 31, 203], ["+", 31, 22, 12, 22, 12, 16, 31, 203, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22]]
8
369
45
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 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 I = cins(); int Q = I[0], H = I[1], S = I[2], D = I[3]; var N = cin(); var G = new int[] { Q * 4, H * 2, S }; int OneL = G.Min(); int TwoL = Math.Min(OneL * 2, D); print(((long)N) / 2 * TwoL + OneL); read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 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 I = cins(); int Q = I[0], H = I[1], S = I[2], D = I[3]; var N = cin(); var G = new int[] { Q * 4, H * 2, S }; int OneL = G.Min(); int TwoL = Math.Min(OneL * 2, D); print(((long)N) / 2 * TwoL + (N % 2 == 1 ? OneL : 0)); read(); } } }
[["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 31, 22], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 17, 109], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 17, 60], ["+", 0, 16, 12, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 0, 102], ["+", 0, 28, 0, 16, 12, 23, 0, 41, 75, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
410
10
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int sx, sy, gx, gy; sc.Multi(out sx, out sy, out gx, out gy); int xl = Math.Min(sx, gx), xr = Math.Max(sx, gx), yl = Math.Min(sy, gy), yr = Math.Max(sy, gy); int n = sc.Int; var lis = new List<int[]>(); for (int i = 0; i < n; i++) { int x, y; sc.Multi(out x, out y); if (xl <= x && x <= xr && yl <= y && y <= yr) { if (sy <= gy) lis.Add(new int[] { x, y }); else lis.Add(new int[] { x, -y }); } } lis.Sort((x, y) => x[0].CompareTo(y[0])); var dp = new int[n]; for (int i = 0; i < n; i++) { dp[i] = M; } foreach (var item in lis) { dp[dp.UpperBound(item[1])] = item[1]; } int lc = n; for (int i = 0; i < n; i++) { if (dp[i] == M) { lc = i; break; } } double ans = (xr - xl + yr - yl) * 100.0 - lc * (20 - Math.PI * 5); if (lc == Math.Min(xr - xl, yr - yl) + 1) { ans = (xr - xl + yr - yl) * 100.0 - (lc - 1) * (20 - Math.PI * 5) + Math.PI * 10 - 20; } Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void Prt(string a) { sw.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ // static string Join<T>(string sep, IEnumerable<T> a) { return // string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void // DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params // object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { // Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", // a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } } static class Search { // nより大きいの項のindexのうち最小のものを返す // n以下の項のindexのうち最大のもの+1を返す // そこに挿入 public static int UpperBound<T>(this IList<T> a, T n) where T : IComparable<T> { if (a.Count == 0) return 0; int l = 0, r = a.Count - 1; while (l < r) { int m = (l + r) >> 1; if (a[m].CompareTo(n) <= 0) { if (a[m + 1].CompareTo(n) > 0) return m + 1; l = m + 1; } else r = m - 1; } if (a[l].CompareTo(n) <= 0) return l + 1; return l; } // n未満の項のindexのうち最大のもの+1を返す // n以上の項のindexのうち最小のものを返す // そこに挿入 public static int LowerBound<T>(this IList<T> a, T n) where T : IComparable<T> { if (a.Count == 0) return 0; int l = 0, r = a.Count - 1; while (l < r) { int m = (l + r) >> 1; if (a[m].CompareTo(n) < 0) { if (a[m + 1].CompareTo(n) >= 0) return m + 1; l = m + 1; } else r = m - 1; } if (a[l].CompareTo(n) < 0) return l + 1; return l; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int sx, sy, gx, gy; sc.Multi(out sx, out sy, out gx, out gy); int xl = Math.Min(sx, gx), xr = Math.Max(sx, gx), yl = Math.Min(sy, gy), yr = Math.Max(sy, gy); int n = sc.Int; var lis = new List<int[]>(); for (int i = 0; i < n; i++) { int x, y; sc.Multi(out x, out y); if (xl <= x && x <= xr && yl <= y && y <= yr) { if ((sx <= gx) == (sy <= gy)) lis.Add(new int[] { x, y }); else lis.Add(new int[] { x, -y }); } } lis.Sort((x, y) => x[0].CompareTo(y[0])); var dp = new int[n]; for (int i = 0; i < n; i++) { dp[i] = M; } foreach (var item in lis) { dp[dp.UpperBound(item[1])] = item[1]; } int lc = n; for (int i = 0; i < n; i++) { if (dp[i] == M) { lc = i; break; } } double ans = (xr - xl + yr - yl) * 100.0 - lc * (20 - Math.PI * 5); if (lc == Math.Min(xr - xl, yr - yl) + 1) { ans = (xr - xl + yr - yl) * 100.0 - (lc - 1) * (20 - Math.PI * 5) + Math.PI * 10 - 20; } Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void Prt(string a) { sw.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ // static string Join<T>(string sep, IEnumerable<T> a) { return // string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void // DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params // object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { // Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", // a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } } static class Search { // nより大きいの項のindexのうち最小のものを返す // n以下の項のindexのうち最大のもの+1を返す // そこに挿入 public static int UpperBound<T>(this IList<T> a, T n) where T : IComparable<T> { if (a.Count == 0) return 0; int l = 0, r = a.Count - 1; while (l < r) { int m = (l + r) >> 1; if (a[m].CompareTo(n) <= 0) { if (a[m + 1].CompareTo(n) > 0) return m + 1; l = m + 1; } else r = m - 1; } if (a[l].CompareTo(n) <= 0) return l + 1; return l; } // n未満の項のindexのうち最大のもの+1を返す // n以上の項のindexのうち最小のものを返す // そこに挿入 public static int LowerBound<T>(this IList<T> a, T n) where T : IComparable<T> { if (a.Count == 0) return 0; int l = 0, r = a.Count - 1; while (l < r) { int m = (l + r) >> 1; if (a[m].CompareTo(n) < 0) { if (a[m + 1].CompareTo(n) >= 0) return m + 1; l = m + 1; } else r = m - 1; } if (a[l].CompareTo(n) < 0) return l + 1; return l; } }
[["+", 64, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 12, 23, 0, 25]]
8
4,147
8
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var a = sc.Str; var b = sc.Str; if (!b.Contains('1') && a != b) { DBG(-1); return; } int n = a.Length; var lc = new int[n]; var rc = new int[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (b[(i + j) % n] == '1') { rc[i] = j; break; } } for (int j = 0; j < n; j++) { if (b[(i + n - j) % n] == '1') { lc[i] = j; break; } } } int ans = M; for (int i = 0; i < n; i++) { int mar = 0, mal = 0; var rlis = new List<int>[n]; var llis = new List<int>[n]; for (int j = 0; j < n; j++) { rlis[j] = new List<int>(); llis[j] = new List<int>(); } int rdc = 0, ldc = 0; for (int j = 0; j < n; j++) { if (a[j] != b[(j + i) % n]) { ++rdc; if (rc[j] > i) { mar = Math.Max(mar, lc[j]); rlis[lc[j]].Add(j); } } if (a[j] != b[(j + n - i) % n]) { ++ldc; if (lc[j] > i) { mal = Math.Max(mal, rc[j]); llis[rc[j]].Add(j); } } } ans = Math.Min(ans, i + rdc + mar * 2); int marr = 0; for (int j = n - 1; j >= 0; j--) { foreach (var item in rlis[j]) { marr = Math.Max(marr, rc[item] - i); } ans = Math.Min(ans, i + rdc + (mar + marr) * 2); } ans = Math.Min(ans, i + ldc + mal * 2); int mall = 0; for (int j = n - 1; j >= 0; j--) { foreach (var item in llis[j]) { mall = Math.Max(mall, lc[item] - i); } ans = Math.Min(ans, i + ldc + (mal + mall) * 2); } } Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void Prt(string a) { sw.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ // static string Join<T>(string sep, IEnumerable<T> a) { return // string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void // DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params // object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { // Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", // a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { var a = sc.Str; var b = sc.Str; if (!b.Contains('1') && a != b) { DBG(-1); return; } int n = a.Length; var lc = new int[n]; var rc = new int[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (b[(i + j) % n] == '1') { rc[i] = j; break; } } for (int j = 0; j < n; j++) { if (b[(i + n - j) % n] == '1') { lc[i] = j; break; } } } int ans = M; for (int i = 0; i < n; i++) { int mar = 0, mal = 0; var rlis = new List<int>[n]; var llis = new List<int>[n]; for (int j = 0; j < n; j++) { rlis[j] = new List<int>(); llis[j] = new List<int>(); } int rdc = 0, ldc = 0; for (int j = 0; j < n; j++) { if (a[j] != b[(j + i) % n]) { ++rdc; if (rc[j] > i) { mar = Math.Max(mar, lc[j]); rlis[lc[j]].Add(j); } } if (a[j] != b[(j + n - i) % n]) { ++ldc; if (lc[j] > i) { mal = Math.Max(mal, rc[j]); llis[rc[j]].Add(j); } } } ans = Math.Min(ans, i + rdc + mar * 2); int marr = 0; for (int j = n - 1; j > 0; j--) { foreach (var item in rlis[j]) { marr = Math.Max(marr, rc[item] - i); } ans = Math.Min(ans, i + rdc + (j - 1 + marr) * 2); } ans = Math.Min(ans, i + ldc + mal * 2); int mall = 0; for (int j = n - 1; j > 0; j--) { foreach (var item in llis[j]) { mall = Math.Max(mall, lc[item] - i); } ans = Math.Min(ans, i + ldc + (j - 1 + mall) * 2); } } Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void Prt(string a) { sw.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ // static string Join<T>(string sep, IEnumerable<T> a) { return // string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void // DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params // object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { // Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", // a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 47], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 203]]
8
4,058
12
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string alphabet = "abcdefghijklmnopqrstuvwxyz"; List<string> result = new List<string>(); for (int i = 0; i < S.Length; i++) { if (S.IndexOf(alphabet.Substring(i, 1)) == -1) { result.Add(alphabet.Substring(i, 1)); } } if (result.Count() == 0) { Console.WriteLine("None"); } else { Console.WriteLine(result[0]); } } } } // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // long n = long.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(ans);
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string alphabet = "abcdefghijklmnopqrstuvwxyz"; List<string> result = new List<string>(); for (int i = 0; i < alphabet.Length; i++) { string checkStr = alphabet.Substring(i, 1); if (S.IndexOf(checkStr) == -1) { result.Add(checkStr); } } if (result.Count() == 0) { Console.WriteLine("None"); } else { Console.WriteLine(result[0]); } } } } // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // long n = long.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(ans);
[["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
180
28
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp69 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); char[] charArray = new char[26] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; char[] s_ = S.ToCharArray(); Console.WriteLine(charArray.Except(s_).ToArray()[0]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp69 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); char[] charArray = new char[26] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; char[] s_ = S.ToCharArray().Distinct().ToArray(); char[] restArray = charArray.Except(s_).ToArray(); Console.WriteLine(restArray.Count() == 0 ? "None" : restArray[0].ToString()); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 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, 31, 213, 3, 4, 0, 24], ["+", 0, 41, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 41, 75, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 28, 0, 41, 75, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 41, 75, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 41, 75, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 41, 75, 213, 3, 4, 0, 25]]
8
201
37
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Linq.Expressions; using static System.Console; using static System.Math; class Simple { string S; void Solve() { // input S = io.String; // cal var alp = Enumerable.Range('a', 'z' - 'a' + 1).Select(c => (char)c); var containsDict = new Dictionary<char, int>(); foreach (var c in alp) containsDict[c] = 0; foreach (var c in S) containsDict[c] += 1; var ans = containsDict.Where(kp => kp.Value == 0).Select(kp => kp.Key).Min(); // ret WriteLine(ans); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); private void Stream() { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // SetIn(exStdIn); Solve(); io.Flush(); } } class SimpleIO { string[] _nextBuffer; int _bufferCnt; char[] cs = new char[] { ' ', '"', ',' }; StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { _nextBuffer = new string[0]; _bufferCnt = 0; SetOut(sw); } string Next() { if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++]; var st = ReadLine(); while (st == "") st = ReadLine(); if (st != null) _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); else st = ""; _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 Flush() => Out.Flush(); }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Linq.Expressions; using static System.Console; using static System.Math; class Simple { string S; void Solve() { // input S = io.String; // cal var alp = Enumerable.Range('a', 'z' - 'a' + 1).Select(c => (char)c); var containsDict = new Dictionary<char, int>(); foreach (var c in alp) containsDict[c] = 0; foreach (var c in S) containsDict[c] += 1; var t = containsDict.Where(kp => kp.Value == 0).Select(kp => kp.Key); var ans = t.Count() > 0 ? t.Min().ToString() : "None"; // ret WriteLine(ans); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); private void Stream() { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // SetIn(exStdIn); Solve(); io.Flush(); } } class SimpleIO { string[] _nextBuffer; int _bufferCnt; char[] cs = new char[] { ' ', '"', ',' }; StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { _nextBuffer = new string[0]; _bufferCnt = 0; SetOut(sw); } string Next() { if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++]; var st = ReadLine(); while (st == "") st = ReadLine(); if (st != null) _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); else st = ""; _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 Flush() => Out.Flush(); }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 41, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 41, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 41, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 41, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 47], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 64, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 64, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 41, 64, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 41, 64, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 41, 64, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 41, 64, 213, 3, 4, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 62], ["+", 0, 200, 0, 212, 0, 41, 75, 5, 0, 222]]
8
440
23
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder.Contest.C { static class Program { public static void Solve(Scanner cin) { var n = cin.ReadInt(); var a = cin.ReadLongArray(n); var p = new Dictionary<long, int>(); for (int i = 0; i < n; i++) { if (p.ContainsKey(a[i])) p[a[i]]++; else p.Add(a[i], 1); } var s = p.OrderByDescending(x => x.Key); long ans = 1; int cnt = 0; foreach (var e in s) { if (cnt >= 2) break; if (e.Value >= 4) { ans = e.Key * e.Key; cnt += 2; } else if (e.Value >= 2) { ans *= e.Key; cnt++; } } if (cnt < 2) ans = 0; Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); } static class Util { static string Join<T>(this IEnumerable<T> x, string separator = " ") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace AtCoder.Contest.C { static class Program { public static void Solve(Scanner cin) { var n = cin.ReadInt(); var a = cin.ReadLongArray(n); var p = new Dictionary<long, int>(); for (int i = 0; i < n; i++) { if (p.ContainsKey(a[i])) p[a[i]]++; else p.Add(a[i], 1); } var s = p.OrderByDescending(x => x.Key); long ans = 1; int cnt = 0; foreach (var e in s) { if (cnt >= 2) break; if (e.Value >= 4) { if (cnt == 1) { ans *= e.Key; cnt++; } else { ans = e.Key * e.Key; cnt += 2; } } else if (e.Value >= 2) { ans *= e.Key; cnt++; } } if (cnt < 2) ans = 0; Console.WriteLine(ans); } public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); Solve(cin); Console.Out.Flush(); } public static void YESNO(bool condition) => Console.WriteLine(condition ? "YES" : "NO"); public static void YesNo(bool condition) => Console.WriteLine(condition ? "Yes" : "No"); public static void yesno(bool condition) => Console.WriteLine(condition ? "yes" : "no"); } static class Util { static string Join<T>(this IEnumerable<T> x, string separator = " ") => string.Join(separator, x); } class Scanner { string[] s; int i; char[] separator = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Read() => ReadString(); public string ReadString() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return ReadString(); i = 0; return s[i++]; } public string[] ReadStringArray(int N) { string[] Array = new string[N]; for (int i = 0; i < N; i++) { Array[i] = ReadString(); } return Array; } public int ReadInt() { return int.Parse(ReadString()); } public int[] ReadIntArray(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = ReadInt() + add; } return Array; } public long ReadLong() { return long.Parse(ReadString()); } public long[] ReadLongArray(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = ReadLong() + add; } return Array; } public double ReadDouble() { return double.Parse(ReadString()); } public double[] ReadDoubleArray(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = ReadDouble() + add; } return Array; } public T1 ReadValue<T1>() => (T1)Convert.ChangeType(ReadString(), typeof(T1)); public (T1, T2) ReadValue<T1, T2>() { var inputs = ReadStringArray(2); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); return (v1, v2); } public (T1, T2, T3) ReadValue<T1, T2, T3>() { var inputs = ReadStringArray(3); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); return (v1, v2, v3); } public (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>() { var inputs = ReadStringArray(4); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); return (v1, v2, v3, v4); } public (T1, T2, T3, T4, T5) ReadValue<T1, T2, T3, T4, T5>() { var inputs = ReadStringArray(5); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); return (v1, v2, v3, v4, v5); } public (T1, T2, T3, T4, T5, T6) ReadValue<T1, T2, T3, T4, T5, T6>() { var inputs = ReadStringArray(6); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); return (v1, v2, v3, v4, v5, v6); } public (T1, T2, T3, T4, T5, T6, T7) ReadValue<T1, T2, T3, T4, T5, T6, T7>() { var inputs = ReadStringArray(7); var v1 = (T1)Convert.ChangeType(inputs[0], typeof(T1)); var v2 = (T2)Convert.ChangeType(inputs[1], typeof(T2)); var v3 = (T3)Convert.ChangeType(inputs[2], typeof(T3)); var v4 = (T4)Convert.ChangeType(inputs[3], typeof(T4)); var v5 = (T5)Convert.ChangeType(inputs[4], typeof(T5)); var v6 = (T6)Convert.ChangeType(inputs[5], typeof(T6)); var v7 = (T7)Convert.ChangeType(inputs[6], typeof(T7)); return (v1, v2, v3, v4, v5, v6, v7); } public T1[] ReadValueArray<T1>(int N) { var v1 = new T1[N]; for (int i = 0; i < N; i++) { v1[i] = ReadValue<T1>(); } return v1; } public (T1[], T2[]) ReadValueArray<T1, T2>(int N) { var (v1, v2) = (new T1[N], new T2[N]); for (int i = 0; i < N; i++) { var (t1, t2) = ReadValue<T1, T2>(); v1[i] = t1; v2[i] = t2; } return (v1, v2); } public (T1[], T2[], T3[]) ReadValueArray<T1, T2, T3>(int N) { var (v1, v2, v3) = (new T1[N], new T2[N], new T3[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3) = ReadValue<T1, T2, T3>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; } return (v1, v2, v3); } public (T1[], T2[], T3[], T4[]) ReadValueArray<T1, T2, T3, T4>(int N) { var (v1, v2, v3, v4) = (new T1[N], new T2[N], new T3[N], new T4[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4) = ReadValue<T1, T2, T3, T4>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; } return (v1, v2, v3, v4); } public (T1[], T2[], T3[], T4[], T5[]) ReadValueArray<T1, T2, T3, T4, T5>(int N) { var (v1, v2, v3, v4, v5) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5) = ReadValue<T1, T2, T3, T4, T5>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; } return (v1, v2, v3, v4, v5); } public (T1[], T2[], T3[], T4[], T5[], T6[]) ReadValueArray<T1, T2, T3, T4, T5, T6>(int N) { var (v1, v2, v3, v4, v5, v6) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6) = ReadValue<T1, T2, T3, T4, T5, T6>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; } return (v1, v2, v3, v4, v5, v6); } public (T1[], T2[], T3[], T4[], T5[], T6[], T7[]) ReadValueArray<T1, T2, T3, T4, T5, T6, T7>(int N) { var (v1, v2, v3, v4, v5, v6, v7) = (new T1[N], new T2[N], new T3[N], new T4[N], new T5[N], new T6[N], new T7[N]); for (int i = 0; i < N; i++) { var (t1, t2, t3, t4, t5, t6, t7) = ReadValue<T1, T2, T3, T4, T5, T6, T7>(); v1[i] = t1; v2[i] = t2; v3[i] = t3; v4[i] = t4; v5[i] = t5; v6[i] = t6; v7[i] = t7; } return (v1, v2, v3, v4, v5, v6, v7); } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
2,712
20
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 var n = long.Parse(Console.ReadLine()); long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); long h = 0; long w = 0; var dic = new Dictionary<long, long>() {}; for (int i = 0; i < n; i++) { if (!dic.ContainsKey(a[i])) { dic.Add(a[i], 1); } else { dic[a[i]]++; } if (dic[a[i]] == 2) { if (h == 0) { h = a[i]; dic[a[i]] = 0; } else if (w == 0) { w = a[i]; dic[a[i]] = 0; } else if (a[i] > h) { w = h; h = a[i]; dic[a[i]] = 0; } else if (a[i] > w) { w = a[i]; dic[a[i]] = 0; } } } long ans = h * w; 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 n = long.Parse(Console.ReadLine()); long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); long h = 0; long w = 0; var dic = new Dictionary<long, long>() {}; for (int i = 0; i < n; i++) { if (!dic.ContainsKey(a[i])) { dic.Add(a[i], 1); } else { dic[a[i]]++; } if (dic[a[i]] == 2) { if (h == 0) { h = a[i]; dic[a[i]] = 0; } else if (w == 0) { w = a[i]; dic[a[i]] = 0; } else if (a[i] > h) { if (h > w) { w = h; } h = a[i]; dic[a[i]] = 0; } else if (a[i] > w) { w = a[i]; dic[a[i]] = 0; } } } long ans = h * w; Console.WriteLine(ans); } }
[["+", 75, 57, 75, 57, 64, 196, 0, 57, 0, 121], ["+", 75, 57, 75, 57, 64, 196, 0, 57, 0, 24], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 75, 57, 75, 57, 64, 196, 0, 57, 0, 25], ["+", 75, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
302
8
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 A = GetLongArray(); var dic = new Dictionary<long, int>(); for (int i = 0; i < N; i++) { if (dic.ContainsKey(A[i]) == false) dic.Add(A[i], 0); dic[A[i]]++; } long ans = 0; var keys = dic.Where(d => d.Value >= 2) .Select(s => s.Key) .OrderByDescending(o => o) .ToArray(); if (dic[keys[0]] >= 4) ans = keys[0] * keys[0]; else if (keys.Length > 1) ans = keys[0] * keys[1]; 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 A = GetLongArray(); var dic = new Dictionary<long, int>(); for (int i = 0; i < N; i++) { if (dic.ContainsKey(A[i]) == false) dic.Add(A[i], 0); dic[A[i]]++; } long ans = 0; var keys = dic.Where(d => d.Value >= 2) .Select(s => s.Key) .OrderByDescending(o => o) .ToArray(); if (keys.Length != 0) { if (dic[keys[0]] >= 4) ans = keys[0] * keys[0]; else if (keys.Length > 1) ans = keys[0] * keys[1]; } 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]); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,296
10
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { class CountedHashSet { class InveerseCompare : IComparer<int> { public int Compare(int x, int y) { return y - x; } } public class Counter { public Counter() { count = 1; } public int count { get; set; } } public SortedDictionary<int, Counter> keySet; public CountedHashSet() { keySet = new SortedDictionary<int, Counter>(new InveerseCompare()); } public void Add(int key) { Counter c; if (keySet.TryGetValue(key, out c)) { c.count++; } else { keySet.Add(key, new Counter()); } } public int GetKeyCount(int key) { Counter c; if (keySet.TryGetValue(key, out c)) { return c.count; } return 0; } } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); CountedHashSet hs = new CountedHashSet(); string[] s = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { int v = int.Parse(s[i]); hs.Add(v); } int ans = 0; foreach (KeyValuePair<int, CountedHashSet.Counter> e in hs.keySet) { if (e.Value.count >= 2) { if (e.Value.count >= 4) { Console.WriteLine(Math.BigMul(e.Key, e.Key)); return; } if (0 == ans) { ans = e.Key; } else { Console.WriteLine(Math.BigMul(ans, e.Key)); return; } } } Console.WriteLine(0); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { class CountedHashSet { class InveerseCompare : IComparer<int> { public int Compare(int x, int y) { return y - x; } } public class Counter { public Counter() { count = 1; } public int count { get; set; } } public SortedDictionary<int, Counter> keySet; public CountedHashSet() { keySet = new SortedDictionary<int, Counter>(new InveerseCompare()); } public void Add(int key) { Counter c; if (keySet.TryGetValue(key, out c)) { c.count++; } else { keySet.Add(key, new Counter()); } } public int GetKeyCount(int key) { Counter c; if (keySet.TryGetValue(key, out c)) { return c.count; } return 0; } } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); CountedHashSet hs = new CountedHashSet(); string[] s = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { int v = int.Parse(s[i]); hs.Add(v); } int ans = 0; foreach (KeyValuePair<int, CountedHashSet.Counter> e in hs.keySet) { if (e.Value.count >= 2) { if (e.Value.count >= 4) { if (0 == ans) { Console.WriteLine(Math.BigMul(e.Key, e.Key)); } else { Console.WriteLine(Math.BigMul(ans, e.Key)); } return; } if (0 == ans) { ans = e.Key; } else { Console.WriteLine(Math.BigMul(ans, e.Key)); return; } } } Console.WriteLine(0); } } }
[["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
394
27
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() { int n = ReadAndParseInt(); var a = ReadAndParseIntArr(); var dic = new Dictionary<int, int>(); foreach (int len in a) { if (dic.ContainsKey(len)) { dic[len]++; } else { dic.Add(len, 1); } } var validBars = new List<long>(); foreach (var pair in dic) { if (pair.Value >= 2) { validBars.Add(pair.Key); } } if (validBars.Count <= 1) { Console.WriteLine(0); return; } validBars.Sort(); validBars.Reverse(); long ans = validBars[0] * validBars[1]; 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() { int n = ReadAndParseInt(); var a = ReadAndParseIntArr(); var dic = new Dictionary<int, int>(); foreach (int len in a) { if (dic.ContainsKey(len)) { dic[len]++; } else { dic.Add(len, 1); } } var validBars = new List<long>(); foreach (var pair in dic) { if (pair.Value >= 4) { validBars.Add(pair.Key); validBars.Add(pair.Key); } else if (pair.Value >= 2) { validBars.Add(pair.Key); } } if (validBars.Count <= 1) { Console.WriteLine(0); return; } validBars.Sort(); validBars.Reverse(); long ans = validBars[0] * validBars[1]; 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, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["+", 0, 210, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 210, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 214, 205, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 214, 0, 131], ["+", 0, 57, 75, 57, 15, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 20]]
8
516
29
using System; namespace ABC071C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] bufs = Console.ReadLine().Split(' '); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(bufs[i]); } Array.Sort(A); int cnt = 0; int width = 0; int height = 0; int idx = N - 1; int seq = 0; int cur = 0; while (cnt < 2 && idx >= 0) { if (seq > 0 && A[idx] == A[cur]) { seq++; if (seq == 2) { if (cnt == 0) { width = A[idx]; } else if (cnt == 1) { height = A[idx]; } cnt++; } } else { seq = 1; cur = idx; } idx--; } Console.WriteLine((long)width * height); } } }
using System; namespace ABC071C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] bufs = Console.ReadLine().Split(' '); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(bufs[i]); } Array.Sort(A); int cnt = 0; int width = 0; int height = 0; int idx = N - 1; int seq = 0; int cur = 0; while (cnt < 2 && idx >= 0) { if (seq > 0 && A[idx] == A[cur]) { if (cnt == 0) { width = A[idx]; } else if (cnt == 1) { height = A[idx]; } seq = 0; cnt++; } else { seq = 1; cur = idx; } idx--; } Console.WriteLine((long)width * height); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
236
15
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(long.Parse).ToArray(); var a_disinct = a.Distinct().ToArray(); var a_group = a.GroupBy(e => e); var ab = a_group.Select(e => new { e.Key, Count = e.Count() }) .Where(e => e.Count >= 2) .OrderByDescending(e => e.Key) .Take(2) .ToArray(); if (ab[0].Count >= 4) { long max = ab[0].Key; Console.WriteLine(max * max); return; } Console.WriteLine(ab.Count() >= 2 ? ab[0].Key * ab[1].Key : 0); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(long.Parse).ToArray(); var a_group = a.GroupBy(e => e); var ab = a_group.Select(e => new { e.Key, Count = e.Count() }) .Where(e => e.Count >= 2) .OrderByDescending(e => e.Key) .Take(2) .ToArray(); if (ab.Any()) { if (ab[0].Count >= 4) { long max = ab[0].Key; Console.WriteLine(max * max); return; } } Console.WriteLine(ab.Count() >= 2 ? ab[0].Key * ab[1].Key : 0); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 214, 205, 204, 205, 22], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
212
23
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm {     class Program     { const int Mod = 1000000007;         static void Main(string[] args)         {             var n = int.Parse(Console.ReadLine()); var s1 = Console.ReadLine(); var s2 = Console.ReadLine(); if (n == 1) { Console.WriteLine(3); return; } var total = 6L; var counter = 0; var tate = false; if (s1[0] == s2[0]) tate = true; for (var i = 2; i < n; i++) { if (tate) { total *= 2; if (s1[i] != s2[i]) { tate = false; i++; } } else { if (s1[i] == s2[i]) { tate = true; } else { total *= 3; i++; } } total %= Mod; } Console.WriteLine(total);         }     } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm {     class Program     { const int Mod = 1000000007;         static void Main(string[] args)         {             var n = int.Parse(Console.ReadLine()); var s1 = Console.ReadLine(); var s2 = Console.ReadLine(); if (n == 1) { Console.WriteLine(3); return; } var total = 6L; var start = 2; var counter = 0; var tate = false; if (s1[0] == s2[0]) { tate = true; start = 1; total = 3; } for (var i = start; i < n; i++) { if (tate) { total *= 2; if (s1[i] != s2[i]) { tate = false; i++; } } else { if (s1[i] == s2[i]) { tate = true; } else { total *= 3; i++; } } total %= Mod; } Console.WriteLine(total);         }     } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22]]
8
216
17
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に変換。 string sUp = Console.ReadLine(); string sDown = Console.ReadLine(); long answer = 1; long memo = 0; //前回が縦なら0横なら1 for (long i = 0; i < n; i++) { if (i == 0) { if (sUp[0] == sDown[0]) answer = 3; else { answer = 6; i++; memo = 1; } } else { if (sUp[0] == sDown[0]) { if (memo == 0) answer *= 2; memo = 0; } else { answer *= 2; i++; memo = 1; } } } Console.WriteLine(answer); } }
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に変換。 string sUp = Console.ReadLine(); string sDown = Console.ReadLine(); long answer = 1; long memo = 0; //前回が縦なら0横なら1 for (long i = 0; i < n; i++) { if (i == 0) { if (sUp[0] == sDown[0]) answer = 3; else { answer = 6; i++; memo = 1; } } else { if (sUp[(int)i] == sDown[(int)i]) { if (memo == 0) answer *= 2; memo = 0; } else { if (memo == 0) answer *= 2; else answer *= 3; i++; memo = 1; } } answer %= 1000000007; } Console.WriteLine(answer); } }
[["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 74, 0, 24], ["+", 31, 204, 206, 207, 0, 28, 0, 74, 39, 199], ["+", 31, 204, 206, 207, 0, 28, 0, 74, 0, 25], ["+", 31, 204, 206, 207, 0, 28, 0, 74, 51, 22], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 0, 24], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 39, 199], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 0, 25], ["+", 12, 204, 206, 207, 0, 28, 0, 74, 51, 22], ["+", 75, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 75, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 75, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["+", 75, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 75, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 108], ["+", 75, 196, 0, 57, 75, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
183
25
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Cout; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 3; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var th = new Thread(Run, 1 << 26); th.Start(); th.Join(); // Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; // Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { var A = Cin.Str; int N = A.Length; var nx = new int [N][]; for (var i = 0; i < N; i++) { nx[i] = new int[26]; Fill(nx[i], INF); } for (var i = N - 1; i >= 0; i--) { for (var j = 0; j < 26; j++) { if (i + 1 < N) nx[i][j] = nx[i + 1][j]; } nx[i][A[i] - 'a'] = i; } var dp = new int[N + 1]; var nxc = new int[N + 1]; Fill(dp, INF); Fill(nxc, INF); for (var i = N - 1; i >= 0; i--) { for (var c = 0; c < 26; c++) { if (nx[i][c] == INF) { if (dp[i] == 1) continue; dp[i] = 1; nxc[i] = c; } else { if (dp[i] > dp[nx[i][c] + 1] + 1) { dp[i] = dp[nx[i][c] + 1] + 1; nxc[i] = c; } } } } var ans = new StringBuilder(); var id = 0; for (var i = 0; i < dp[0]; i++) { ans.Append((char)('a' + nxc[id])); id = nx[id][nxc[id]] + 1; } OutL(string.Join("", ans.ToString().Reverse())); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Modpow(ModInt a, long n) { if (n < 0) return Modpow(Modpow(a, -n), MOD - 2); var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { if (n < 0 || r < 0) return 0; return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } public class Rolling_Hash { const ulong m30 = (1UL << 30) - 1; const ulong m31 = (1UL << 31) - 1; const ulong MOD = (1UL << 61) - 1; const ulong Pl = (MOD << 1) << 1; private uint B; private string S; ulong[] hash; ulong[] pw; public Rolling_Hash(string str) { S = str; B = (uint) new Random().Next(1 << 12 + 1, int.MaxValue); int L = S.Length; hash = new ulong[L + 1]; pw = new ulong[L + 1]; hash[0] = 0; pw[0] = 1; for (var i = 0; i < L; i++) { hash[i + 1] = CalcMod(Mul(hash[i], B) + S[i]); pw[i + 1] = CalcMod(Mul(pw[i], B)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong GetHashValue(int idx) => hash[idx]; [MethodImpl(MethodImplOptions.AggressiveInlining)] // segment [l,r] public ulong Hash_fold(int l, int r) => CalcMod(Pl + hash[r + 1] - Mul(hash[l], pw[r - l + 1])); [MethodImpl( MethodImplOptions.AggressiveInlining)] // segment[start,start+len-1] public ulong Hash_sub(int start, int len) => CalcMod(Pl + hash[start + len] - Mul(hash[start], pw[len])); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong[] GetHashArray() => hash; [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong Mul(ulong a, ulong b) { ulong au = a >> 31; ulong ad = a & m31; ulong bu = b >> 31; ulong bd = b & m31; ulong mid = ad * bu + au * bd; ulong midu = mid >> 30; ulong midd = mid & m30; return au * bu * 2 + midu + (midd << 31) + ad * bd; } [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong CalcMod(ulong x) { ulong xu = x >> 61; ulong xd = x & MOD; ulong res = xu + xd; if (res >= MOD) res -= MOD; return res; } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } public class SegmentTree<T> { // 1-indexed type int n; T[] Tree; Func<T, T, T> f; T ex; int L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { ex = exvalue; f = fun; n = 1; while (n < size) n <<= 1; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue, T[] initial) { ex = exvalue; n = 1; while (n < size) n <<= 1; f = fun; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = (n <= i && i <= n + initial.Length - 1) ? initial[i - n] : ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Set_All() { for (var i = n - 1; i >= 1; i--) Tree[i] = f(Tree[i << 1], Tree[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Assign(int idx, T nxt) => Tree[idx + n] = nxt; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int idx) { int now = idx + n; while (now > 1) { now >>= 1; Tree[now] = f(Tree[now << 1], Tree[now << 1 | 1]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update(int idx, T nxt) { Assign(idx, nxt); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update_func(int idx, T y) { Assign(idx, f(Peek(idx), y)); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query_Fold(int l, int r) { int L = n + l; int R = n + r; T vL = ex, vR = ex; while (L < R) { if (L % 2 == 1) { vL = f(vL, Tree[L]); L++; } if (R % 2 == 1) { vR = f(Tree[R - 1], vR); R--; } L >>= 1; R >>= 1; } return f(vL, vR); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Peek(int idx) => Tree[idx + n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Display(int len) { for (var i = 0; i < len; i++) Console.Write($"{Tree[i + n]} "); Console.WriteLine(); } } public class UnionFind { private int[] parent; private int[] rank; private int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } public int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); public static int[] ReadSplitInt => ConvertAll(ReadSplit, int.Parse); public static long[] ReadSplitLong => ConvertAll(ReadSplit, long.Parse); public static double[] ReadSplit_Double => ConvertAll(ReadSplit, double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Scanf<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Scanf<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Scanf<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Scanf<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Scanf<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } } static class Cout { public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Cout; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 3; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var th = new Thread(Run, 1 << 26); th.Start(); th.Join(); // Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; // Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { var A = Cin.Str; int N = A.Length; var nx = new int [N][]; for (var i = 0; i < N; i++) { nx[i] = new int[26]; Fill(nx[i], INF); } for (var i = N - 1; i >= 0; i--) { for (var j = 0; j < 26; j++) { if (i + 1 < N) nx[i][j] = nx[i + 1][j]; } nx[i][A[i] - 'a'] = i; } var dp = new int[N + 1]; var nxc = new int[N + 1]; Fill(dp, INF); Fill(nxc, INF); for (var i = N - 1; i >= 0; i--) { for (var c = 0; c < 26; c++) { if (nx[i][c] == INF) { if (dp[i] == 1) continue; dp[i] = 1; nxc[i] = c; } else { if (dp[i] > dp[nx[i][c] + 1] + 1) { dp[i] = dp[nx[i][c] + 1] + 1; nxc[i] = c; } } } } var ans = new StringBuilder(); var id = 0; for (var i = 0; i < dp[0]; i++) { ans.Append((char)('a' + nxc[id])); id = nx[id][nxc[id]] + 1; } OutL(ans); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Modpow(ModInt a, long n) { if (n < 0) return Modpow(Modpow(a, -n), MOD - 2); var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { if (n < 0 || r < 0) return 0; return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } public class Rolling_Hash { const ulong m30 = (1UL << 30) - 1; const ulong m31 = (1UL << 31) - 1; const ulong MOD = (1UL << 61) - 1; const ulong Pl = (MOD << 1) << 1; private uint B; private string S; ulong[] hash; ulong[] pw; public Rolling_Hash(string str) { S = str; B = (uint) new Random().Next(1 << 12 + 1, int.MaxValue); int L = S.Length; hash = new ulong[L + 1]; pw = new ulong[L + 1]; hash[0] = 0; pw[0] = 1; for (var i = 0; i < L; i++) { hash[i + 1] = CalcMod(Mul(hash[i], B) + S[i]); pw[i + 1] = CalcMod(Mul(pw[i], B)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong GetHashValue(int idx) => hash[idx]; [MethodImpl(MethodImplOptions.AggressiveInlining)] // segment [l,r] public ulong Hash_fold(int l, int r) => CalcMod(Pl + hash[r + 1] - Mul(hash[l], pw[r - l + 1])); [MethodImpl( MethodImplOptions.AggressiveInlining)] // segment[start,start+len-1] public ulong Hash_sub(int start, int len) => CalcMod(Pl + hash[start + len] - Mul(hash[start], pw[len])); [MethodImpl(MethodImplOptions.AggressiveInlining)] public ulong[] GetHashArray() => hash; [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong Mul(ulong a, ulong b) { ulong au = a >> 31; ulong ad = a & m31; ulong bu = b >> 31; ulong bd = b & m31; ulong mid = ad * bu + au * bd; ulong midu = mid >> 30; ulong midd = mid & m30; return au * bu * 2 + midu + (midd << 31) + ad * bd; } [MethodImpl(MethodImplOptions.AggressiveInlining)] ulong CalcMod(ulong x) { ulong xu = x >> 61; ulong xd = x & MOD; ulong res = xu + xd; if (res >= MOD) res -= MOD; return res; } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } public class SegmentTree<T> { // 1-indexed type int n; T[] Tree; Func<T, T, T> f; T ex; int L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { ex = exvalue; f = fun; n = 1; while (n < size) n <<= 1; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, Func<T, T, T> fun, T exvalue, T[] initial) { ex = exvalue; n = 1; while (n < size) n <<= 1; f = fun; Tree = new T[n << 1]; L = (n << 1) - 1; for (var i = 0; i <= L; i++) Tree[i] = (n <= i && i <= n + initial.Length - 1) ? initial[i - n] : ex; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Set_All() { for (var i = n - 1; i >= 1; i--) Tree[i] = f(Tree[i << 1], Tree[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Assign(int idx, T nxt) => Tree[idx + n] = nxt; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int idx) { int now = idx + n; while (now > 1) { now >>= 1; Tree[now] = f(Tree[now << 1], Tree[now << 1 | 1]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update(int idx, T nxt) { Assign(idx, nxt); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Query_Update_func(int idx, T y) { Assign(idx, f(Peek(idx), y)); Update(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query_Fold(int l, int r) { int L = n + l; int R = n + r; T vL = ex, vR = ex; while (L < R) { if (L % 2 == 1) { vL = f(vL, Tree[L]); L++; } if (R % 2 == 1) { vR = f(Tree[R - 1], vR); R--; } L >>= 1; R >>= 1; } return f(vL, vR); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Peek(int idx) => Tree[idx + n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Display(int len) { for (var i = 0; i < len; i++) Console.Write($"{Tree[i + n]} "); Console.WriteLine(); } } public class UnionFind { private int[] parent; private int[] rank; private int[] size; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; size = new int[n]; for (var i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; size[i] = 1; } } public int Root(int x) { return parent[x] == x ? x : parent[x] = Root(parent[x]); } public bool SameRoot(int x, int y) { return Root(x) == Root(y); } public void Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) { return; } if (rank[x] < rank[y]) { parent[x] = y; size[y] += size[x]; size[x] = 0; } else { parent[y] = x; if (rank[x] == rank[y]) { rank[x]++; } size[x] += size[y]; size[y] = 0; } } public int SizeOf(int x) { return size[Root(x)]; } } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); public static int[] ReadSplitInt => ConvertAll(ReadSplit, int.Parse); public static long[] ReadSplitLong => ConvertAll(ReadSplit, long.Parse); public static double[] ReadSplit_Double => ConvertAll(ReadSplit, double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Scanf<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Scanf<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Scanf<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Scanf<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Scanf<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } } static class Cout { public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
4,021
16
using System; using System.Collections.Generic; using System.Globalization; namespace cswork { class Program { public Program() {} Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); void Omame() { cin = new Scanner(); int a = cin.nextInt(); int b = cin.nextInt(); int c = cin.nextInt(); int d = cin.nextInt(); int count = 0; for (int i = 0; i <= 100; i++) { if (a <= i && i <= b) { if (c <= i && i <= d) { count++; } } } Console.WriteLine(count - 1); } static void Main(string[] args) { new Program().Omame(); } public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } }
using System; using System.Collections.Generic; using System.Globalization; namespace cswork { class Program { public Program() {} Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); void Omame() { cin = new Scanner(); int a = cin.nextInt(); int b = cin.nextInt(); int c = cin.nextInt(); int d = cin.nextInt(); int count = 0; for (int i = 0; i <= 100; i++) { if (a <= i && i <= b) { if (c <= i && i <= d) { count++; } } } count--; if (count < 0) { count = 0; } Console.WriteLine(count); } static void Main(string[] args) { new Program().Omame(); } public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
465
17
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class AtCoder_abcd { public static void Main() { var input = Console.ReadLine().Split(); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]); Console.WriteLine(Math.Min(b, d) - Math.Max(a, c)); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; class AtCoder_abcd { public static void Main() { var input = Console.ReadLine().Split(); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]); int t = Math.Min(b, d) - Math.Max(a, c); if (t < 0) t = 0; Console.WriteLine(t); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
121
23
using System; using System.Collections.Generic; using System.Linq; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var r = Console.ReadLine().Split().Select(int.Parse).ToArray(); Console.WriteLine(Math.Min(r[3], r[1]) - Math.Max(r[2], r[0])); } } }
using System; using System.Collections.Generic; using System.Linq; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var r = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ret = Math.Min(r[3], r[1]) - Math.Max(r[2], r[0]); Console.WriteLine(ret < 0 ? 0 : ret); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
8
100
19
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using System.IO; namespace ConsoleTest { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var t = Console.ReadLine().Split().Select(int.Parse).ToArray(); int d = Math.Max(t[0], t[2]) - Math.Min(t[1], t[3]); Console.WriteLine(d > 0 ? d : 0); Console.Out.Flush(); } } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using System.IO; namespace ConsoleTest { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var t = Console.ReadLine().Split().Select(int.Parse).ToArray(); int d = Math.Min(t[1], t[3]) - Math.Max(t[2], t[0]); Console.WriteLine(d > 0 ? d : 0); Console.Out.Flush(); } } }
[["-", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 16, 12, 213, 63, 214, 141, 22]]
8
159
12
using System; class Program { static void Main(String[] args) { var str = Console.ReadLine().Split(' '); int[] buttonPushSec = new int[4]; int bothPushSec = 0; int endSec = 0; int startSec = 0; buttonPushSec[0] = int.Parse(str[0]); buttonPushSec[1] = int.Parse(str[1]); buttonPushSec[2] = int.Parse(str[2]); buttonPushSec[3] = int.Parse(str[3]); if ((buttonPushSec[1] > buttonPushSec[2]) && (buttonPushSec[2] > buttonPushSec[0])) { endSec = ((buttonPushSec[1] > buttonPushSec[3]) ? buttonPushSec[3] : buttonPushSec[1]); startSec = ((buttonPushSec[0] > buttonPushSec[2]) ? buttonPushSec[0] : buttonPushSec[2]); bothPushSec = endSec - startSec; } Console.WriteLine(bothPushSec); } }
using System; class Program { static void Main(String[] args) { var str = Console.ReadLine().Split(' '); int[] buttonPushSec = new int[4]; int bothPushSec = 0; int endSec = 0; int startSec = 0; buttonPushSec[0] = int.Parse(str[0]); buttonPushSec[1] = int.Parse(str[1]); buttonPushSec[2] = int.Parse(str[2]); buttonPushSec[3] = int.Parse(str[3]); if ((buttonPushSec[1] > buttonPushSec[2]) && ((buttonPushSec[2] > buttonPushSec[0]) || (buttonPushSec[3] > buttonPushSec[0]))) { endSec = ((buttonPushSec[1] > buttonPushSec[3]) ? buttonPushSec[3] : buttonPushSec[1]); startSec = ((buttonPushSec[0] > buttonPushSec[2]) ? buttonPushSec[0] : buttonPushSec[2]); bothPushSec = endSec - startSec; } Console.WriteLine(bothPushSec); } }
[["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 47], ["+", 0, 16, 31, 23, 0, 16, 12, 204, 205, 22], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 15, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
8
213
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int[] nums = input.Split(' ').Select(x => int.Parse(x)).ToArray(); if (nums[1] <= nums[2]) { Console.WriteLine("0"); } else { Console.WriteLine( Math.Abs(Math.Min(nums[3], nums[1]) - Math.Max(nums[2], nums[0]))); } return; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int[] nums = input.Split(' ').Select(x => int.Parse(x)).ToArray(); if (nums[1] <= nums[2] || nums[3] <= nums[0]) { Console.WriteLine("0"); } else { Console.WriteLine(Math.Min(nums[3], nums[1]) - Math.Max(nums[2], nums[0])); } return; } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
8
158
15
using System; namespace AtCoderConsole { class Program { static void Main(string[] args) { // 標準入力から1行取得 string input = Console.ReadLine(); // 4つの変数を宣言 int a, b, c, d; // 代入 a = int.Parse(input.Split(' ')[0]); b = int.Parse(input.Split(' ')[1]); c = int.Parse(input.Split(' ')[2]); d = int.Parse(input.Split(' ')[3]); int count = 0; for (int i = 1; i <= 100; i++) { if (i >= a && i <= b && i > c && i <= d) { count++; } } // 標準出力に出力 Console.WriteLine(count); } } }
using System; namespace AtCoderConsole { class Program { static void Main(string[] args) { // 標準入力から1行取得 string input = Console.ReadLine(); // 4つの変数を宣言 int a, b, c, d; // 代入 a = int.Parse(input.Split(' ')[0]); b = int.Parse(input.Split(' ')[1]); c = int.Parse(input.Split(' ')[2]); d = int.Parse(input.Split(' ')[3]); int count = 0; for (int i = 1; i <= 100; i++) { if (a <= c) { if (i >= a && i <= b && i > c && i <= d) { count++; } } else { if (i > a && i <= b && i >= c && i <= d) { count++; } } } // 標準出力に出力 Console.WriteLine(count); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 20], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
8
171
34
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int[] s = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int A = s[0]; int B = s[1]; int C = s[2]; int D = s[3]; int ans = -1; if (D <= A || B <= C) ans = 0; else if ((C <= A && A <= D) && D <= B) ans = D - A; else if (A <= C && D <= B) ans = D - C; else if (C <= A && B <= D) ans = B - A; Console.WriteLine(ans); } }
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int[] s = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int A = s[0]; int B = s[1]; int C = s[2]; int D = s[3]; int ans = -1; if (D <= A || B <= C) ans = 0; else if ((C <= A && A <= D) && D <= B) ans = D - A; else if (A <= C && D <= B) ans = D - C; else if ((A <= C && C <= B) && B <= D) ans = B - C; else if (C <= A && B <= D) ans = B - A; Console.WriteLine(ans); } }
[["+", 75, 57, 75, 57, 15, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 19], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 17, 98], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 17, 19], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 75, 57, 75, 57, 15, 16, 31, 23, 0, 25], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 17, 19], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["+", 75, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 57, 64, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 75, 57, 64, 1, 0, 11, 12, 16, 12, 22], ["+", 75, 57, 75, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 57, 75, 57, 75, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 31, 22]]
8
172
23
using System; public class Hello { public static void Main() { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int C = int.Parse(input[2]); int D = int.Parse(input[3]); int bot = Math.Max(A, C); int top = Math.Min(B, D); Console.WriteLine(top - bot); } }
using System; public class Hello { public static void Main() { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int C = int.Parse(input[2]); int D = int.Parse(input[3]); int bot = Math.Max(A, C); int top = Math.Min(B, D); if (top > bot) { Console.WriteLine(top - bot); } else { Console.WriteLine(0); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
119
18
using System; using System.Linq; namespace ABC070 { class MainClass { public static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); if (input[2] > input[1]) { Console.WriteLine("0"); } else { input.Sort(); Console.WriteLine("{0}", input[2] - input[1]); } } } }
using System; using System.Linq; namespace ABC070 { class MainClass { public static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); if (input[2] > input[1] || input[0] > input[3]) { Console.WriteLine("0"); } else { input.Sort(); Console.WriteLine("{0}", input[2] - input[1]); } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
8
111
10
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(); } public static long GCM(long x, long y) { var s = x; var t = y; if (x < y) GCM(y, x); while (y != 0) { var z = x % y; x = y; y = z; } return s / x * t; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); var t = new long[n]; if (n > 1) { t[0] = Read(); t[1] = Read(); var gcm = GCM(t[0], t[1]); for (int i = 2; i < n; i++) { t[i] = Read(); gcm = GCM(gcm, t[i]); } Console.WriteLine(gcm); } else Console.WriteLine(t[0]); 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(); } public static long GCM(long x, long y) { var s = x; var t = y; if (x < y) GCM(y, x); while (y != 0) { var z = x % y; x = y; y = z; } return s / x * t; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var n = Read(); var t = new long[n]; t[0] = Read(); if (n > 1) { t[1] = Read(); var gcm = GCM(t[0], t[1]); for (int i = 2; i < n; i++) { t[i] = Read(); gcm = GCM(gcm, t[i]); } Console.WriteLine(gcm); } else Console.WriteLine(t[0]); Console.Out.Flush(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45]]
8
303
14
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var N = int.Parse(Console.ReadLine()); var T = new long [N].Select(x => x = long.Parse(Console.ReadLine())).ToArray(); var answer = 1L; for (var i = 0; i < N; i++) { answer = LCM(answer, T[i]); Console.WriteLine(answer); } Console.WriteLine(answer); } static long LCM(long a, long b) { var (min, max) = a >= b ? (a, b) : (b, a); return min * (max / GCD(min, max)); } static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b); } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var N = int.Parse(Console.ReadLine()); var T = new long [N].Select(x => x = long.Parse(Console.ReadLine())).ToArray(); var answer = 1L; for (var i = 0; i < N; i++) { answer = LCM(answer, T[i]); // Console.WriteLine(answer); } Console.WriteLine(answer); } static long LCM(long a, long b) { var (min, max) = a >= b ? (a, b) : (b, a); return min * (max / GCD(min, max)); } static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
257
7
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); List<ulong> clock = new List<ulong>(); for (int i = 0; i < N; i++) { ulong input = ulong.Parse(Console.ReadLine()); if (!clock.Contains(input)) { clock.Add(input); } } while (clock.Count > 1) { ulong multi = clock[0] * clock[1]; ulong small = (clock[0] > clock[1]) ? clock[1] : clock[0]; ulong big = (clock[0] < clock[1]) ? clock[1] : clock[0]; while (big % small != 0) { ulong rem = big % small; big = small; small = rem; } clock[0] = multi / small; clock.RemoveAt(1); } Console.WriteLine(clock[0]); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); List<long> clock = new List<long>(); for (int i = 0; i < N; i++) { long input = long.Parse(Console.ReadLine()); if (!clock.Contains(input)) { clock.Add(input); } } while (clock.Count > 1) { long small = (clock[0] > clock[1]) ? clock[1] : clock[0]; long big = (clock[0] < clock[1]) ? clock[1] : clock[0]; while (big % small != 0) { long rem = big % small; big = small; small = rem; } clock[0] = clock[0] * (clock[1] / small); clock.RemoveAt(1); } Console.WriteLine(clock[0]); } } }
[["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 52, 8, 196, 0, 197, 0, 35], ["+", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 12, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
8
235
39
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); long t1 = long.Parse(Console.ReadLine()); long ans = t1; for (var i = 1; i < n; ++i) { long t = long.Parse(Console.ReadLine()); long min = Math.Min(ans, t); long max = Math.Max(ans, t); if (max % min == 0) { ans = max; } else { while (true) { max *= 2; if (max % min == 0) { ans = max; break; } } } } Console.WriteLine(ans); //デバッグ実行での確認用。そのまま提出しても問題なし Console.ReadKey(); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); long t1 = long.Parse(Console.ReadLine()); long ans = t1; for (var i = 1; i < n; ++i) { long t = long.Parse(Console.ReadLine()); long min = Math.Min(ans, t); long max = Math.Max(ans, t); if (max % min == 0) { ans = max; } else { var now = max; while (true) { now += max; if (now % min == 0) { ans = now; break; } } } } Console.WriteLine(ans); //デバッグ実行での確認用。そのまま提出しても問題なし Console.ReadKey(); } }
[["+", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
8
170
13
using System; using System.Collections.Generic; using System.Linq; namespace abc070_c { class Program { static void Main(string[] args) { var N = GetInt(); var TL = new List<long>(); for (int i = 0; i < N; i++) TL.Add(GetLong()); var r = Lcm(TL[0], TL[1]); for (int i = 2; i < N; i++) r = Lcm(r, TL[i]); Console.WriteLine(r); } public static string GetStr() => Console.ReadLine(); public static int GetInt() => int.Parse(Console.ReadLine()); public static long GetLong() => long.Parse(Console.ReadLine()); public static double GetDouble() => double.Parse(Console.ReadLine()); public static decimal GetDecimal() => decimal.Parse(Console.ReadLine()); public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList(); public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList(); public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList(); /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } /// <summary> /// 互いに素 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static bool Coprime(long a, long b) { return Gcd(a, b) == 1; } /// <summary> /// 最小公約数:ユークリッドの互除法 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> 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; namespace abc070_c { class Program { static void Main(string[] args) { var N = GetInt(); var TL = new List<long>(); for (int i = 0; i < N; i++) TL.Add(GetLong()); if (N == 1) Console.WriteLine(TL[0]); else { var r = Lcm(TL[0], TL[1]); for (int i = 2; i < N; i++) r = Lcm(r, TL[i]); Console.WriteLine(r); } } public static string GetStr() => Console.ReadLine(); public static int GetInt() => int.Parse(Console.ReadLine()); public static long GetLong() => long.Parse(Console.ReadLine()); public static double GetDouble() => double.Parse(Console.ReadLine()); public static decimal GetDecimal() => decimal.Parse(Console.ReadLine()); public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList(); public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList(); public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList(); /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } /// <summary> /// 互いに素 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static bool Coprime(long a, long b) { return Gcd(a, b) == 1; } /// <summary> /// 最小公約数:ユークリッドの互除法 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> 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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
512
19
using System; namespace ABC070 { class C { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] T = new long[N]; for (int i = 0; i < N; i++) { T[i] = long.Parse(Console.ReadLine()); } long lcm = CalcLCM(T[0], T[1]); for (int i = 2; i < N; i++) { lcm = CalcLCM(lcm, T[i]); } Console.WriteLine(lcm); } public static long CalcGCD(long a, long b) { if (b == 0) { return a; } return CalcGCD(b, a % b); } public static long CalcLCM(long a, long b) { return a * (b / CalcGCD(a, b)); } } }
using System; namespace ABC070 { class C { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] T = new long[N]; for (int i = 0; i < N; i++) { T[i] = long.Parse(Console.ReadLine()); } if (N == 1) { Console.WriteLine(T[0]); return; } long lcm = CalcLCM(T[0], T[1]); for (int i = 2; i < N; i++) { lcm = CalcLCM(lcm, T[i]); } Console.WriteLine(lcm); } public static long CalcGCD(long a, long b) { if (b == 0) { return a; } return CalcGCD(b, a % b); } public static long CalcLCM(long a, long b) { return a * (b / CalcGCD(a, b)); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
191
20
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { //入力を受け取る var N = long.Parse(Console.ReadLine()); // var A = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); var AllLcm = long.Parse(Console.ReadLine()); for (int i = 1; i < N; i++) { var T = long.Parse(Console.ReadLine()); Console.WriteLine(T); AllLcm = Lcm(T, AllLcm); } // Console.WriteLine(AllLcm); } // 最小公倍数 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.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { //入力を受け取る var N = long.Parse(Console.ReadLine()); // var A = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); var AllLcm = long.Parse(Console.ReadLine()); for (int i = 1; i < N; i++) { var T = long.Parse(Console.ReadLine()); // Console.WriteLine(T); AllLcm = Lcm(T, AllLcm); } Console.WriteLine(AllLcm); } // 最小公倍数 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, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
205
14
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var lcm = 1L; for (var i = 0; i < N; i++) { var tmp = long.Parse(Console.ReadLine()); try { var check = checked(tmp * lcm); } catch (OverflowException se) { lcm = tmp; continue; } lcm = Lcm(tmp, lcm); } Console.WriteLine(lcm); } static long Gcd(long a, long b) { if (b > a) return Gcd(b, a); if (b == 0) return a; return Gcd(b, (a % b)); } static long Lcm(long a, long b) { return a * b / Gcd(a, b); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var lcm = 1L; for (var i = 0; i < N; i++) { var tmp = long.Parse(Console.ReadLine()); lcm = Lcm(tmp, lcm); } Console.WriteLine(lcm); } static long Gcd(long a, long b) { if (b > a) return Gcd(b, a); if (b == 0) return a; return Gcd(b, (a % b)); } static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["-", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 328, 0, 292], ["-", 0, 198, 0, 200, 0, 212, 0, 328, 0, 24], ["-", 0, 200, 0, 212, 0, 328, 0, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 328, 0, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 328, 0, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 328, 0, 25], ["-", 8, 196, 0, 246, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 141, 22], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 0, 25], ["-", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["-", 0, 248, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 248, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["-", 0, 246, 0, 248, 8, 196, 0, 116, 0, 117], ["-", 0, 246, 0, 248, 8, 196, 0, 116, 0, 35], ["-", 8, 196, 0, 246, 0, 248, 8, 196, 0, 46], ["-", 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
196
30
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var N = ReadInt(); var T = ReadLines(N); var lcm = Lcm(T[0], T[1]); for (int i = 2; i < N; i++) { if (lcm != T[i]) lcm = Lcm(lcm, T[i]); } Println(lcm); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a * b / Gcd(a, b); static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; namespace ConsoleApp1 { class Program { static void Main(string[] args) { A(); } static void A() { var N = ReadInt(); var T = ReadLines(N); if (N == 1) { Println(T[0]); return; } var lcm = Lcm(T[0], T[1]); for (int i = 2; i < N; i++) { lcm = Lcm(lcm, T[i]); } Println(lcm); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static IEnumerable<int> Range(int start, int stop) { if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0)) return new List<int>(); return Enumerable.Range(start, stop - start); } static bool IsDigit(string str) { var i = 0; return int.TryParse(str, out i); } static int SumDigits(long num) { return num.ToString().Select(x => x.ToString()).Sum(int.Parse); } static int[] ToIntArray(string str) { return str.Select(x => x.ToString()).Select(int.Parse).ToArray(); } static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b); static long Lcm(long a, long b) => a / Gcd(a, b) * b; static bool IsPrime(int x) { if (x <= 1 || (x != 2 && x % 2 == 0)) return false; if (x == 2) return true; for (int i = 3; i < x; i += 2) if (x % i == 0) return false; return true; } static string Read() => Console.ReadLine(); static int ReadInt() => int.Parse(Read()); static long ReadLong() => long.Parse(Read()); static List<string> ReadSplit() => Read().Split().ToList(); static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList(); static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList(); static void Print(object value) => Console.Write(value.ToString()); static void Println(object value) => Console.WriteLine(value.ToString()); static string Join<T>(IEnumerable<T> list) => string.Join("", list); } public static class MyExtensions { public static string Slice(this string str, int start = 0, int stop = 0) { if (start > str.Length || stop > str.Length || start < 0 || stop < 0) return ""; if (stop == 0) stop = str.Length; return str.Substring(start, stop - start); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 195, 8, 306, 0, 16, 31, 16, 17, 48], ["-", 0, 195, 8, 306, 0, 16, 31, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 306, 0, 16, 17, 48], ["+", 8, 201, 0, 195, 8, 306, 0, 16, 12, 22]]
8
704
31
using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { var n = uint.Parse(Console.ReadLine()); var gcd = ulong.Parse(Console.ReadLine()); ulong gcm = gcd; for (var i = 1; i < n; i++) { var x = ulong.Parse(Console.ReadLine()); var gcmx = gcm * x; var a = Math.Max(gcd, x); var b = Math.Min(gcd, x); while (b != 0) { var tmp = b; b = a % b; a = tmp; } gcd = a; gcm = gcmx / gcd; } Console.WriteLine(gcm.ToString()); } }
using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { var n = uint.Parse(Console.ReadLine()); var gcd = ulong.Parse(Console.ReadLine()); ulong gcm = gcd; for (var i = 1; i < n; i++) { var x = ulong.Parse(Console.ReadLine()); var a = Math.Max(gcm, x); var b = Math.Min(gcm, x); while (b != 0) { var tmp = b; b = a % b; a = tmp; } gcd = a; gcm = (x / gcd) * gcm; } Console.WriteLine(gcm.ToString()); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
166
17
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) { Scanner cin = new Scanner(); int N = cin.Int(); long[] t = new long[N]; for (int i = 0; i < N; i++) { t[i] = cin.Long(); } long ans = 1; for (int i = 0; i < N; i++) { ans = LCM(t[i], ans); } Console.WriteLine(ans); Console.ReadLine(); } static long GCD(long a, long b) // a,bの最大公約数を返す { if (a < b) // 引数を入替えて自分を呼び出す return GCD(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } static long LCM(long a, long b) // a,bの最小公倍数を返す { return a * b / GCD(a, b); } static int BinarySearch<T>(T[] array, T target) where T : IComparable<T> // 2分探索 { int min = 0; int max = array.Length - 1; while (true) { // 範囲内に見つからなかった if (max < min) return -1; // 範囲内の中央値と比較する int mid = min + (max - min) / 2; switch (target.CompareTo(array[mid])) { case -1: // 中央値より小さい max = mid - 1; break; case 1: // 中央値より大きい min = mid + 1; break; case 0: // 見つかった return mid; } } } static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { Scanner cin = new Scanner(); int N = cin.Int(); long[] t = new long[N]; for (int i = 0; i < N; i++) { t[i] = long.Parse(Console.ReadLine()); } long ans = 1; for (int i = 0; i < N; i++) { ans = LCM(t[i], ans); } Console.WriteLine(ans); Console.ReadLine(); } static long GCD(long a, long b) // a,bの最大公約数を返す { if (a < b) // 引数を入替えて自分を呼び出す return GCD(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } static long LCM(long a, long b) // a,bの最小公倍数を返す { return a / GCD(a, b) * b; } static int BinarySearch<T>(T[] array, T target) where T : IComparable<T> // 2分探索 { int min = 0; int max = array.Length - 1; while (true) { // 範囲内に見つからなかった if (max < min) return -1; // 範囲内の中央値と比較する int mid = min + (max - min) / 2; switch (target.CompareTo(array[mid])) { case -1: // 中央値より小さい max = mid - 1; break; case 1: // 中央値より大きい min = mid + 1; break; case 0: // 見つかった return mid; } } } static void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; } } class Scanner //標準入力 { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 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
723
13
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 n = ReadAndParseInt(); long[] t = new long[n]; for (int i = 0; i < n; ++i) { t[i] = ReadAndParseLong(); } long min = lcm(t[0], t[1]); for (int i = 2; i < n; ++i) { min = lcm(min, t[i]); } Console.WriteLine(min); } #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 n = ReadAndParseInt(); long[] t = new long[n]; for (int i = 0; i < n; ++i) { t[i] = ReadAndParseLong(); } if (n == 1) { Console.WriteLine(t[0]); return; } long min = lcm(t[0], t[1]); for (int i = 2; i < n; ++i) { min = lcm(min, t[i]); } Console.WriteLine(min); } #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 } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
455
20
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 long[] times = new long[n]; //ここに受け取る for (int i = 0; i < n; i++) times[i] = long.Parse(Console.ReadLine()); long answer = times[0]; for (int i = 1; i < n; i++) { answer = answer * times[i] / Gcd(answer, times[i]); } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } static long Gcd(long a, long b) { //引数a,bの最大公約数を返す if (a < b) return Gcd(b, a); //入れ替え while (b != 0) { long changeTo = a % b; a = b; b = changeTo; } return a; } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 long[] times = new long[n]; //ここに受け取る for (int i = 0; i < n; i++) times[i] = long.Parse(Console.ReadLine()); long answer = times[0]; for (int i = 1; i < n; i++) { answer = answer / Gcd(answer, times[i]) * times[i]; } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } static long Gcd(long a, long b) { //引数a,bの最大公約数を返す if (a < b) return Gcd(b, a); //入れ替え while (b != 0) { long changeTo = a % b; a = b; b = changeTo; } return a; } }
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 0, 11, 12, 16, 31, 16, 12, 204, 205, 22], ["-", 12, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73]]
8
189
10
using System; using System.Linq; using System.Collections.Generic; class Program { static int mainVertex; static int n = int.Parse(Console.ReadLine()); static int[] howlong = new int[n]; //頂点kからの距離 static List<int>[] nextList = new List<int>[n]; //隣接リスト(リストの入った配列) static void Main() { for (int i = 0; i < n; i++) howlong[i] = -1; for (int i = 0; i < n; i++) nextList[i] = new List<int>(); for (int i = 0; i < n - 1; i++) { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); //1行ごとに受け取る nextList[nums[0] - 1].Add(nums[1] - 1); //隣接リストへ追加。第2成分は距離。 nextList[nums[0] - 1].Add(nums[2]); nextList[nums[1] - 1].Add(nums[0] - 1); nextList[nums[1] - 1].Add(nums[2]); } string[] inputSub = Console.ReadLine().Split(' '); int q = int.Parse(inputSub[0]); int k = int.Parse(inputSub[1]); k--; mainVertex = k; howlong[k] = 0; Length(k, 0); //頂点kの、頂点kからの距離は0 for (int i = 0; i < q; i++) { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 int xx = int.Parse(input[0]); int yy = int.Parse(input[1]); Console.WriteLine(howlong[xx - 1] + howlong[yy - 1]); } } static void Length(int vertexNum, int length) //頂点番号と、頂点kからの距離 { for (int i = 0; i < nextList[vertexNum].Count(); i += 2) { int x = howlong[nextList[vertexNum][i]]; int y = nextList[vertexNum][i + 1]; if (x == -1) { howlong[nextList[vertexNum][i]] = y + length; Length(nextList[vertexNum][i], howlong[nextList[vertexNum][i]]); } } } }
using System; using System.Linq; using System.Collections.Generic; class Program { static long mainVertex; static long n = long.Parse(Console.ReadLine()); static long[] howlong = new long[n]; //頂点kからの距離 static List<long>[] nextList = new List<long>[n]; //隣接リスト(リストの入った配列) static void Main() { for (int i = 0; i < n; i++) howlong[i] = -1; for (int i = 0; i < n; i++) nextList[i] = new List<long>(); for (int i = 0; i < n - 1; i++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); //1行ごとに受け取る nextList[nums[0] - 1].Add(nums[1] - 1); //隣接リストへ追加。第2成分は距離。 nextList[nums[0] - 1].Add(nums[2]); nextList[nums[1] - 1].Add(nums[0] - 1); nextList[nums[1] - 1].Add(nums[2]); } string[] inputSub = Console.ReadLine().Split(' '); long q = long.Parse(inputSub[0]); long k = long.Parse(inputSub[1]); k--; mainVertex = k; howlong[k] = 0; Length(k, 0); //頂点kの、頂点kからの距離は0 for (int i = 0; i < q; i++) { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long xx = long.Parse(input[0]); long yy = long.Parse(input[1]); Console.WriteLine(howlong[xx - 1] + howlong[yy - 1]); } } static void Length(long vertexNum, long length) //頂点番号と、頂点kからの距離 { for (int i = 0; i < nextList[vertexNum].Count(); i += 2) { long x = howlong[nextList[vertexNum][i]]; long y = nextList[vertexNum][i + 1]; if (x == -1) { howlong[nextList[vertexNum][i]] = y + length; Length(nextList[vertexNum][i], howlong[nextList[vertexNum][i]]); } } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 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, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 198, 39, 224, 39, 236, 237, 238, 0, 199], ["+", 0, 198, 39, 224, 39, 236, 237, 238, 0, 199], ["-", 0, 227, 39, 224, 39, 236, 237, 238, 0, 199], ["+", 0, 227, 39, 224, 39, 236, 237, 238, 0, 199], ["-", 0, 11, 12, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199]]
8
505
44
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 Inf = (long)1e18; long[] min = new long[N]; for (int i = 0; i < N; i++) min[i] = Inf; min[K] = 0; var q = new Queue<int>(); q.Enqueue(K); while (q.Count > 0) { var now = q.Dequeue(); foreach (var nxt in E[now]) { if (min[nxt.Pos] != Inf) continue; min[nxt.Pos] = min[now] + nxt.Cost; } } var sb = new StringBuilder(); foreach (var query in Query) { int a = query[0], b = query[1]; sb.AppendLine(String.Format("{0}", min[a] + min[b])); } Console.Write(sb.ToString()); } int N; List<Pair>[] E; int Q, K; int[][] Query; public Sol() { N = ri(); E = new List<Pair>[N]; for (int i = 0; i < N; i++) E[i] = new List<Pair>(); for (int i = 0; i < N - 1; i++) { var d = ria(); E[d[0] - 1].Add(new Pair(d[1] - 1, d[2])); E[d[1] - 1].Add(new Pair(d[0] - 1, d[2])); } var dd = ria(); Q = dd[0]; K = dd[1] - 1; Query = new int [Q][]; for (int i = 0; i < Q; i++) { Query[i] = ria().Select(v => v - 1).ToArray(); } } class Pair { public int Pos; public long Cost; public Pair(int pos, long cost) { Pos = pos; Cost = cost; } } 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 Inf = (long)1e18; long[] min = new long[N]; for (int i = 0; i < N; i++) min[i] = Inf; min[K] = 0; var q = new Queue<int>(); q.Enqueue(K); while (q.Count > 0) { var now = q.Dequeue(); foreach (var nxt in E[now]) { if (min[nxt.Pos] != Inf) continue; min[nxt.Pos] = min[now] + nxt.Cost; q.Enqueue(nxt.Pos); } } var sb = new StringBuilder(); foreach (var query in Query) { int a = query[0], b = query[1]; sb.AppendLine(String.Format("{0}", min[a] + min[b])); } Console.Write(sb.ToString()); } int N; List<Pair>[] E; int Q, K; int[][] Query; public Sol() { N = ri(); E = new List<Pair>[N]; for (int i = 0; i < N; i++) E[i] = new List<Pair>(); for (int i = 0; i < N - 1; i++) { var d = ria(); E[d[0] - 1].Add(new Pair(d[1] - 1, d[2])); E[d[1] - 1].Add(new Pair(d[0] - 1, d[2])); } var dd = ria(); Q = dd[0]; K = dd[1] - 1; Query = new int [Q][]; for (int i = 0; i < Q; i++) { Query[i] = ria().Select(v => v - 1).ToArray(); } } class Pair { public int Pos; public long Cost; public Pair(int pos, long cost) { Pos = pos; Cost = cost; } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
732
9
using System; using System.Collections.Generic; using System.Linq; namespace ABC069A { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public string String() { return Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public string[] ArrayString(int rowNumber) { string[] s = new string[rowNumber]; for (int i = 0; i < rowNumber; i++) { s[i] = String(); } return s; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public int Int() { return int.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の配列</returns> public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <param name="rowNumber">行数</param> /// <returns>int型の配列</returns> public int[] ArrayInt(int rowNumber) { int[] ints = new int[rowNumber]; for (int i = 0; i < rowNumber; i++) { ints[i] = Int(); } return ints; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の値</returns> public long Long() { return long.Parse(String()); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> public void Longs(ref long A, ref long B) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> public void Longs(ref long A, ref long B, ref long C) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; C = longs[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> /// <param name="D"></param> public void Longs(ref long A, ref long B, ref long C, ref long D) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; C = longs[2]; D = longs[3]; } /// <summary> /// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="A"></param> /// <param name="B"></param> public void LongsArray(long rowNumber, ref long[] A, ref long[] B) { A = new long[rowNumber]; B = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { var l = ArrayLong(); A[i] = l[0]; B[i] = l[1]; } } /// <summary> /// 3つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> public void LongsArray(long rowNumber, ref long[] A, ref long[] B, ref long[] C) { A = new long[rowNumber]; B = new long[rowNumber]; C = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { var l = ArrayLong(); A[i] = l[0]; B[i] = l[1]; C[i] = l[2]; } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の配列</returns> public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); } public long[] ArrayLong(int rowNumber) { long[] longs = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { longs[i] = Long(); } return longs; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public double Double() { return double.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public double[] ArrayDouble() { return Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { return String().Split(' '); } } class Program { static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { public Solver() { Input input = new Input(); input.Longs(ref N, ref M); Console.WriteLine((N - 1) * (M - 1)); } private long N; private long M; public void Solve() { Console.WriteLine(0); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC069A { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public string String() { return Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public string[] ArrayString(int rowNumber) { string[] s = new string[rowNumber]; for (int i = 0; i < rowNumber; i++) { s[i] = String(); } return s; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public int Int() { return int.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の配列</returns> public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <param name="rowNumber">行数</param> /// <returns>int型の配列</returns> public int[] ArrayInt(int rowNumber) { int[] ints = new int[rowNumber]; for (int i = 0; i < rowNumber; i++) { ints[i] = Int(); } return ints; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の値</returns> public long Long() { return long.Parse(String()); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> public void Longs(ref long A, ref long B) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> public void Longs(ref long A, ref long B, ref long C) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; C = longs[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> /// <param name="D"></param> public void Longs(ref long A, ref long B, ref long C, ref long D) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; C = longs[2]; D = longs[3]; } /// <summary> /// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="A"></param> /// <param name="B"></param> public void LongsArray(long rowNumber, ref long[] A, ref long[] B) { A = new long[rowNumber]; B = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { var l = ArrayLong(); A[i] = l[0]; B[i] = l[1]; } } /// <summary> /// 3つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> public void LongsArray(long rowNumber, ref long[] A, ref long[] B, ref long[] C) { A = new long[rowNumber]; B = new long[rowNumber]; C = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { var l = ArrayLong(); A[i] = l[0]; B[i] = l[1]; C[i] = l[2]; } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の配列</returns> public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); } public long[] ArrayLong(int rowNumber) { long[] longs = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { longs[i] = Long(); } return longs; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public double Double() { return double.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public double[] ArrayDouble() { return Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { return String().Split(' '); } } class Program { static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { public Solver() { Input input = new Input(); input.Longs(ref N, ref M); } private long N; private long M; public void Solve() { Console.WriteLine((N - 1) * (M - 1)); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
822
29
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionD { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var s = Console.ReadLine(); Console.WriteLine(s.Substring(0, 1) + s.Length + s.Substring(s.Length - 1, s.Length)); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionD { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var s = Console.ReadLine(); Console.WriteLine(s.Substring(0, 1) + (s.Length - 2) + s.Substring(s.Length - 1, 1)); Console.Out.Flush(); } } }
[["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 25], ["-", 12, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 12, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
8
129
8
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { static class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var S = GetStr(); var ans = S.Substring(0, 1) + S.Length.ToString() + S.Substring(S.Length - 1, 1); Console.WriteLine(ans); Console.Out.Flush(); Console.ReadKey(); } 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 string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } 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 { static class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var S = GetStr(); var ans = S.Substring(0, 1) + (S.Count() - 2).ToString() + S.Substring(S.Length - 1, 1); Console.WriteLine(ans); Console.Out.Flush(); Console.ReadKey(); } 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 string yesno(this bool b) { return b ? "yes" : "no"; } static string YesNo(this bool b) { return b ? "Yes" : "No"; } static string YESNO(this bool b) { return b ? "YES" : "NO"; } 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]); } } }
[["+", 31, 16, 12, 213, 63, 214, 205, 23, 0, 24], ["-", 31, 16, 12, 213, 63, 214, 205, 214, 141, 22], ["+", 205, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 205, 23, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 205, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 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
1,076
8