buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC011Airport { class Program { static void Main(string[] args) { int N, C, K; string[] vals = Console.ReadLine().Split(' '); N = int.Parse(vals[0]); C = int.Parse(vals[1]); K = int.Parse(vals[2]); int[] T = new int[N]; for (int i = 0; i < N; i++) { T[i] = int.Parse(Console.ReadLine()); } Array.Sort(T); Queue<int> queue = new Queue<int>(); int t, u; int numBus = 0; for (int i = 0; i < N; i++) { queue.Enqueue(T[i]); t = queue.Peek(); if (t + K <= T[i]) { if (i < N - 1) { if (t + K == T[i] && T[i] == T[i + 1] && queue.Count < C) continue; } numBus++; for (int j = 0; j < C; j++) { u = queue.Peek(); if (u <= t + K) { queue.Dequeue(); } else { break; } } } else { if (queue.Count == C) { numBus++; queue.Clear(); } } } if (queue.Count > 0) numBus++; Console.WriteLine(numBus); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC011Airport { class Program { static void Main(string[] args) { int N, C, K; string[] vals = Console.ReadLine().Split(' '); N = int.Parse(vals[0]); C = int.Parse(vals[1]); K = int.Parse(vals[2]); int[] T = new int[N]; for (int i = 0; i < N; i++) { T[i] = int.Parse(Console.ReadLine()); } Array.Sort(T); Queue<int> queue = new Queue<int>(); int t, u; int numBus = 0; for (int i = 0; i < N; i++) { queue.Enqueue(T[i]); t = queue.Peek(); if (t + K <= T[i]) { if (i < N - 1) { if (t + K == T[i] && T[i] == T[i + 1] && queue.Count < C) continue; } numBus++; for (int j = 0; j < C; j++) { if (queue.Count == 0) break; u = queue.Peek(); if (u <= t + K) { queue.Dequeue(); } else { break; } } } else { if (queue.Count == C) { numBus++; queue.Clear(); } } } if (queue.Count > 0) numBus++; Console.WriteLine(numBus); } } }
[["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 64, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35]]
8
357
10
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long[] sums = new long[n]; // iまでの和 long answer = 1; sums[0] = nums[0]; for (long i = 1; i < n; i++) { sums[i] = sums[i - 1] + nums[i]; } for (long i = n - 1; i >= 0; i--) { if (sums[i] * 2 >= nums[i + 1]) answer++; else break; } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); Array.Sort(nums); //ソート long[] sums = new long[n]; // iまでの和 long answer = 1; sums[0] = nums[0]; for (long i = 1; i < n; i++) { sums[i] = sums[i - 1] + nums[i]; } for (long i = n - 2; i >= 0; i--) { if (sums[i] * 2 >= nums[i + 1]) answer++; else break; } Console.WriteLine(answer); // WriteLineをWriteとすると、改行なしで出力。 } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
176
9
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("3"); WillReturn.Add("3 1 4"); // 2 } else if (InputPattern == "Input2") { WillReturn.Add("5"); WillReturn.Add("1 1 1 1 1"); // 5 } else if (InputPattern == "Input3") { WillReturn.Add("6"); WillReturn.Add("40 1 30 2 7 20"); // 4 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); long[] AArr = InputList[1].Split(' ').Select(X => long.Parse(X)).ToArray(); Array.Sort(AArr); long Ruisekiwa = 0; bool HasBundan = false; int BundanInd = 0; for (int I = 0; I <= AArr.GetUpperBound(0) - 1; I++) { Ruisekiwa += AArr[I]; if (Ruisekiwa * 2 < AArr[I + 1]) { HasBundan = true; BundanInd = I; Console.WriteLine(AArr.Length - I - 1); return; } } if (HasBundan) Console.WriteLine(AArr.Length - BundanInd - 1); else Console.WriteLine(AArr.Length); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("3"); WillReturn.Add("3 1 4"); // 2 } else if (InputPattern == "Input2") { WillReturn.Add("5"); WillReturn.Add("1 1 1 1 1"); // 5 } else if (InputPattern == "Input3") { WillReturn.Add("6"); WillReturn.Add("40 1 30 2 7 20"); // 4 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); long[] AArr = InputList[1].Split(' ').Select(X => long.Parse(X)).ToArray(); Array.Sort(AArr); long Ruisekiwa = 0; bool HasBundan = false; int BundanInd = 0; for (int I = 0; I <= AArr.GetUpperBound(0) - 1; I++) { Ruisekiwa += AArr[I]; if (Ruisekiwa * 2 < AArr[I + 1]) { HasBundan = true; BundanInd = I; } } if (HasBundan) Console.WriteLine(AArr.Length - BundanInd - 1); else Console.WriteLine(AArr.Length); } }
[["-", 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, 28, 0, 16, 31, 16, 31, 214, 205, 22], ["-", 0, 28, 0, 16, 31, 16, 31, 214, 0, 131], ["-", 0, 28, 0, 16, 31, 16, 31, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 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]]
8
334
15
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} List<int>[] G; bool[] us; bool[] b; StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int M = int.Parse(str[1]); G = new List<int>[N]; for (int i = 0; i < N; i++) { G[i] = new List<int>(); } for (int i = 0; i < M; i++) { str = Console.ReadLine().Split(' '); int x = int.Parse(str[0]) - 1; int y = int.Parse(str[1]) - 1; G[x].Add(y); G[y].Add(x); } us = new bool[N]; long single = 0; long tw = 0; long no = 0; b = new bool[N]; for (int i = 0; i < N; i++) { if (!us[i]) { if (G[i].Count == 0) { single++; } else if (!dfs(i, true)) { no++; } else { tw++; } } } long count = 0; count += 2 * single * N - single * single; count += 2 * no * tw; count += no * no; count += tw * tw * 2; sb.Append(count + "\n"); } bool dfs(int v, bool c) { us[v] = true; b[v] = c; for (int i = 0; i < G[v].Count; i++) { int t = G[v][i]; if (!us[t]) { if (!dfs(t, !c)) { return false; } } else if (b[v] == b[t]) { return false; } } return true; } }
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} List<int>[] G; bool[] us; bool[] b; StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int M = int.Parse(str[1]); G = new List<int>[N]; for (int i = 0; i < N; i++) { G[i] = new List<int>(); } for (int i = 0; i < M; i++) { str = Console.ReadLine().Split(' '); int x = int.Parse(str[0]) - 1; int y = int.Parse(str[1]) - 1; G[x].Add(y); G[y].Add(x); } us = new bool[N]; long single = 0; long tw = 0; long no = 0; b = new bool[N]; for (int i = 0; i < N; i++) { if (!us[i]) { if (G[i].Count == 0) { single++; } else if (!dfs(i, true)) { no++; } else { tw++; } } } long count = 0; count += 2 * single * N - single * single; count += 2 * no * tw; count += no * no; count += tw * tw * 2; sb.Append(count + "\n"); } bool dfs(int v, bool c) { us[v] = true; b[v] = c; bool ans = true; for (int i = 0; i < G[v].Count; i++) { int t = G[v][i]; if (!us[t]) { if (!dfs(t, !c)) { ans = false; } } else if (b[v] == b[t]) { ans = false; } } return ans; } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 57, 64, 196, 0, 37, 0, 38], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 195, 8, 196, 0, 37, 0, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22]]
8
514
13
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using Number = System.Int64; namespace Program { public class Solver { public void Solve() { var n = sc.Integer(); var m = sc.Integer(); var a = new int[2 * m]; var b = new int[2 * m]; var G = Enumerate(n, x => new List<int>()); for (int i = 0; i < m; i++) { a[i] = sc.Integer() - 1; b[i] = sc.Integer() - 1; if (a[i] > b[i]) Swap(ref a[i], ref b[i]); a[i + m] = b[i]; b[i + m] = a[i]; G[a[i]].Add(b[i]); G[b[i]].Add(a[i]); } var s = new DisjointSet(n); for (int i = 0; i < m; i++) s.Unite(a[i], b[i]); var ans = 0L; long odd = 0; long even = 0; var vis = new int[n]; long X = 0; for (int i = 0; i < n; i++) vis[i] = -1; for (int i = 0; i < n; i++) { if (vis[i] != -1) continue; if (G[i].Count == 0) { X++; continue; } var f = true; Action<int, int> dfs = null; dfs = (cur, c) => { vis[cur] = c; foreach (var to in G[cur]) { var nc = c ^ 1; if (vis[to] == -1) dfs(to, nc); else if (vis[to] != nc) { f = false; } } }; dfs(i, 0); if (f) { even++; ans += 2; } else { odd++; ans += 1; } } ans += even * (even - 1) * 2; ans += odd * (odd - 1 + even) * 2; ans += Math.BigMul(n, n) - (n - X) * (n - X); /* var set = new DisjointSet(n * n); long otaku = 0; for (int i = 0; i < 2 * m; i++) for (int j = 0; j < 2 * m; j++) { var u = a[i] * n + a[j]; var v = b[i] * n + b[j]; set.Unite(u, v); } for (int i = 0; i < n * n; i++) if (set[i] == i) { //if (i / n == 6 || i % n == 6) continue; var res = new List<KeyValuePair<int, int>>(); for (int j = 0; j < n * n; j++) { if (set[j] == i) res.Add(new KeyValuePair<int, int>(j / n + 1, j % n + 1)); } IO.Printer.Out.WriteLine(res.AsJoinedString()); otaku++; } IO.Printer.Out.WriteLine(otaku); //*/ IO.Printer.Out.WriteLine(ans); } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public 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()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (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 = 0; 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 (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else 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; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public 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); } } } #endregion #region DisjointSet public class DisjointSet { int[] par; byte[] rank; public DisjointSet(int n) { par = new int[n]; for (int i = 0; i < n; i++) par[i] = -1; rank = new byte[n]; } public int this[int id] { get { if ((par[id] < 0)) return id; return par[id] = this[par[id]]; } } public bool Unite(int x, int y) { x = this[x]; y = this[y]; if (x == y) return false; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } return true; } public int Size(int x) { return -par[this[x]]; } public bool IsUnited(int x, int y) { return this[x] == this[y]; } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using Number = System.Int64; namespace Program { public class Solver { public void Solve() { var n = sc.Integer(); var m = sc.Integer(); var a = new int[2 * m]; var b = new int[2 * m]; var G = Enumerate(n, x => new List<int>()); for (int i = 0; i < m; i++) { a[i] = sc.Integer() - 1; b[i] = sc.Integer() - 1; if (a[i] > b[i]) Swap(ref a[i], ref b[i]); a[i + m] = b[i]; b[i + m] = a[i]; G[a[i]].Add(b[i]); G[b[i]].Add(a[i]); } var s = new DisjointSet(n); for (int i = 0; i < m; i++) s.Unite(a[i], b[i]); var ans = 0L; long odd = 0; long even = 0; var vis = new int[n]; long X = 0; for (int i = 0; i < n; i++) vis[i] = -1; for (int i = 0; i < n; i++) { if (vis[i] != -1) continue; if (G[i].Count == 0) { X++; continue; } var f = true; Action<int, int> dfs = null; dfs = (cur, c) => { vis[cur] = c; foreach (var to in G[cur]) { var nc = c ^ 1; if (vis[to] == -1) dfs(to, nc); else if (vis[to] != nc) { f = false; } } }; dfs(i, 0); if (f) { even++; } else { odd++; } } ans += even * (even * 2 + odd); ans += odd * (odd + even); ans += Math.BigMul(n, n) - (n - X) * (n - X); /* var set = new DisjointSet(n * n); long otaku = 0; for (int i = 0; i < 2 * m; i++) for (int j = 0; j < 2 * m; j++) { var u = a[i] * n + a[j]; var v = b[i] * n + b[j]; set.Unite(u, v); } for (int i = 0; i < n * n; i++) if (set[i] == i) { //if (i / n == 6 || i % n == 6) continue; var res = new List<KeyValuePair<int, int>>(); for (int j = 0; j < n * n; j++) { if (set[j] == i) res.Add(new KeyValuePair<int, int>(j / n + 1, j % n + 1)); } IO.Printer.Out.WriteLine(res.AsJoinedString()); IO.Printer.Out.WriteLine(); otaku++; } IO.Printer.Out.WriteLine(otaku); //*/ IO.Printer.Out.WriteLine(ans); } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public 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()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (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 = 0; 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 (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else 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; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public 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); } } } #endregion #region DisjointSet public class DisjointSet { int[] par; byte[] rank; public DisjointSet(int n) { par = new int[n]; for (int i = 0; i < n; i++) par[i] = -1; rank = new byte[n]; } public int this[int id] { get { if ((par[id] < 0)) return id; return par[id] = this[par[id]]; } } public bool Unite(int x, int y) { x = this[x]; y = this[y]; if (x == y) return false; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } return true; } public int Size(int x) { return -par[this[x]]; } public bool IsUnited(int x, int y) { return this[x] == this[y]; } } #endregion
[["-", 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, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["-", 31, 16, 12, 23, 0, 16, 31, 16, 17, 33], ["-", 31, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
1,860
18
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using Number = System.Int64; namespace Program { public class Solver { public void Solve() { var n = sc.Integer(); var k = sc.Integer(); var deq = new Deque<int>(); for (int i = 0; i < n; i++) deq.PushBack(sc.Char() - 'A'); var flip = 0; k %= 4 * n; for (int T = 0; T < k; T++) { var x = deq[0] ^ flip; if (x == 0) deq[0] ^= 1; else { deq.PopFront(); flip ^= 1; deq.PushBack(flip); } } var c = new char[n]; for (int i = 0; i < n; i++) c[i] = (char)((deq[i] ^ flip) + 'A'); IO.Printer.Out.WriteLine(c.AsString()); } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public 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()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (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 = 0; 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 (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else 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; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public 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); } } } #endregion #region Deque < T> public class Deque<T> { T[] buf; int offset; int count; int capacity; public int Count { get { return count; } } public Deque(int cap) { buf = new T[capacity = cap]; } public Deque() { buf = new T[capacity = 8]; } public T this[int index] { get { return buf[getIndex(index)]; } set { buf[getIndex(index)] = value; } } private int getIndex(int index) { if (index >= capacity) throw new IndexOutOfRangeException("out of range"); var ret = index + offset; if (ret >= capacity) ret -= capacity; return ret; } public void PushFront(T item) { if (count == capacity) Extend(); if (--offset < 0) offset += buf.Length; buf[offset] = item; ++count; } public T PopFront() { if (count == 0) throw new InvalidOperationException("collection is empty"); --count; var ret = buf[offset++]; if (offset >= capacity) offset -= capacity; return ret; } public void PushBack(T item) { if (count == capacity) Extend(); var id = count++ + offset; if (id >= capacity) id -= capacity; buf[id] = item; } public T PopBack() { if (count == 0) throw new InvalidOperationException("collection is empty"); return buf[getIndex(--count)]; } public void Insert(T item, int index) { if (index > count) throw new IndexOutOfRangeException(); this.PushFront(item); for (int i = 0; i < index; i++) this[i] = this[i + 1]; this[index] = item; } public T RemoveAt(int index) { if (index < 0 || index >= count) throw new IndexOutOfRangeException(); var ret = this[index]; for (int i = index; i > 0; i--) this[i] = this[i - 1]; this.PopFront(); return ret; } private void Extend() { T[] newBuffer = new T[capacity << 1]; if (offset > capacity - count) { var len = buf.Length - offset; Array.Copy(buf, offset, newBuffer, 0, len); Array.Copy(buf, 0, newBuffer, len, count - len); } else Array.Copy(buf, offset, newBuffer, 0, count); buf = newBuffer; offset = 0; capacity <<= 1; } public T[] Items { get { var a = new T[count]; for (int i = 0; i < count; i++) a[i] = this[i]; return a; } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Debug; using StringBuilder = System.Text.StringBuilder; using Number = System.Int64; namespace Program { public class Solver { public void Solve() { var n = sc.Integer(); var k = sc.Integer(); var deq = new Deque<int>(); for (int i = 0; i < n; i++) deq.PushBack(sc.Char() - 'A'); var flip = 0; k = Math.Min(k, 2 * n + (k % (4 * n))); for (int T = 0; T < k; T++) { var x = deq[0] ^ flip; if (x == 0) deq[0] ^= 1; else { deq.PopFront(); flip ^= 1; deq.PushBack(flip); } } var c = new char[n]; for (int i = 0; i < n; i++) c[i] = (char)((deq[i] ^ flip) + 'A'); IO.Printer.Out.WriteLine(c.AsString()); } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { var solver = new Program.Solver(); solver.Solve(); Program.IO.Printer.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} public 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()); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (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 = 0; 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 (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else 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; } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public 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); } } } #endregion #region Deque < T> public class Deque<T> { T[] buf; int offset; int count; int capacity; public int Count { get { return count; } } public Deque(int cap) { buf = new T[capacity = cap]; } public Deque() { buf = new T[capacity = 8]; } public T this[int index] { get { return buf[getIndex(index)]; } set { buf[getIndex(index)] = value; } } private int getIndex(int index) { if (index >= capacity) throw new IndexOutOfRangeException("out of range"); var ret = index + offset; if (ret >= capacity) ret -= capacity; return ret; } public void PushFront(T item) { if (count == capacity) Extend(); if (--offset < 0) offset += buf.Length; buf[offset] = item; ++count; } public T PopFront() { if (count == 0) throw new InvalidOperationException("collection is empty"); --count; var ret = buf[offset++]; if (offset >= capacity) offset -= capacity; return ret; } public void PushBack(T item) { if (count == capacity) Extend(); var id = count++ + offset; if (id >= capacity) id -= capacity; buf[id] = item; } public T PopBack() { if (count == 0) throw new InvalidOperationException("collection is empty"); return buf[getIndex(--count)]; } public void Insert(T item, int index) { if (index > count) throw new IndexOutOfRangeException(); this.PushFront(item); for (int i = 0; i < index; i++) this[i] = this[i + 1]; this[index] = item; } public T RemoveAt(int index) { if (index < 0 || index >= count) throw new IndexOutOfRangeException(); var ret = this[index]; for (int i = index; i > 0; i--) this[i] = this[i - 1]; this.PopFront(); return ret; } private void Extend() { T[] newBuffer = new T[capacity << 1]; if (offset > capacity - count) { var len = buf.Length - offset; Array.Copy(buf, offset, newBuffer, 0, len); Array.Copy(buf, 0, newBuffer, len, count - len); } else Array.Copy(buf, offset, newBuffer, 0, count); buf = newBuffer; offset = 0; capacity <<= 1; } public T[] Items { get { var a = new T[count]; for (int i = 0; i < count; i++) a[i] = this[i]; return a; } } } #endregion
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 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, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 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, 109], ["+", 0, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 12, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
1,892
19
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); long K = int.Parse(str[1]); long[] L = new long[N]; long[] R = new long[N]; int eN = 0; long sum = 0; { for (int i = 0; i < N; i++) { str = Console.ReadLine().Split(' '); long D = int.Parse(str[0]); bool b = int.Parse(str[1]) == 1; if (b && 2 * D > K) { sb.Append("-1\n"); return; } if (b) { L[eN] = K - (((sum + 2 * D) % K) == 0 ? K : ((sum + 2 * D) % K)); R[eN] = K - ((sum % K) == 0 ? K : sum % K); eN++; } sum += 2 * D; } } long[] DPL = new long[eN]; long[] DPR = new long[eN]; long[] Points = new long[2 * eN]; int[] A = new int[2 * eN]; for (int i = 0; i < eN; i++) { Points[2 * i] = L[i]; Points[2 * i + 1] = R[i]; A[2 * i] = 2 * i; A[2 * i + 1] = 2 * i + 1; } Array.Sort(Points, A); int[] B = new int[2 * eN]; for (int i = 0; i < 2 * eN; i++) { B[A[i]] = i; } SegTree Seg = new SegTree(2 * eN, this); for (int i = 4 * eN - 2; i >= 0; i--) { Seg.X[i] = eN; } for (int i = eN - 1; i >= 0; i--) { int lp = B[2 * i]; int rp = B[2 * i + 1]; int gL = Seg.Get(lp); DPL[i] = gL == eN ? 0 : DPR[gL] + (K + Points[B[2 * gL + 1]] - Points[lp]) % K; int gR = Seg.Get(rp); DPR[i] = gR == eN ? 0 : DPR[gR] + (K + Points[B[2 * gR + 1]] - Points[rp]) % K; int bf = 0; int bl = 2 * eN; long C = Points[B[2 * i]]; while (bf != bl) { int bc = (bf + bl) / 2; if (bc == 2 * eN || C < Points[bc]) { bl = bc; } else { bf = bc + 1; } } int l = bf; bf = -1; bl = 2 * eN - 1; C = Points[B[2 * i + 1]]; while (bf != bl) { int bc = (bf + bl + 1) / 2; if (bc == -1 || C > Points[bc]) { bf = bc; } else { bl = bc - 1; } } int r = bf; if (lp < rp) { if (l <= r) { Seg.Add(i, l, r); } } else { if (l != 2 * eN) { Seg.Add(i, l, 2 * eN - 1); } if (r != -1) { Seg.Add(i, 0, r); } } } for (int i = 4 * eN - 2; i >= 0; i--) { Seg.X[i] = eN; } long min = DPR[0]; for (int i = 0; i < eN; i++) { int lp = B[2 * i]; int rp = B[2 * i + 1]; int gL = Seg.Get(lp); if (gL == eN) { min = Math.Min(min, DPL[i]); } int gR = Seg.Get(rp); if (gR == eN) { min = Math.Min(min, DPR[i]); } int bf = 0; int bl = 2 * eN; long C = Points[B[2 * i]]; while (bf != bl) { int bc = (bf + bl) / 2; if (bc == 2 * eN || C < Points[bc]) { bl = bc; } else { bf = bc + 1; } } int l = bf; bf = -1; bl = 2 * eN - 1; C = Points[B[2 * i + 1]]; while (bf != bl) { int bc = (bf + bl + 1) / 2; if (bc == -1 || C > Points[bc]) { bf = bc; } else { bl = bc - 1; } } int r = bf; if (lp < rp) { if (l <= r) { Seg.Add(0, l, r); } } else { if (l != 2 * eN) { Seg.Add(0, l, 2 * eN - 1); } if (r != -1) { Seg.Add(0, 0, r); } } } sb.Append((min + sum) + "\n"); } } struct SegTree { Solve Sol; public int[] X; //葉の最初の場所 public int segf; // segfのbit public int segfb; //葉の深さの内浅い方 public int depth; //浅い葉の内座標が最大のもの public int borderP; //はみ出すものの数 public int border; public SegTree(int N, Solve So) { Sol = So; X = new int[2 * N - 1]; for (depth = 1; (1 << depth) <= N; depth++) { ; } segf = N - 1; borderP = (1 << depth) - 2; border = 2 * N - borderP - 2; segfb = border / 2; } public int ToBit(int p) { if (p >= border) { return segfb + p - border; } else { return p; } } //葉のある場所 public int ToLeaf(int p) { if (p >= border) { return segf + p - border; } else { return borderP + p + 1; } } //葉の示す頂点 public int ToPoint(int leaf) { if (leaf > borderP) { return leaf - borderP - 1; } else { return leaf - segf + border; } } public int Get(int p) { //葉の作業 int min = X[ToLeaf(p)]; //親の作業 for (int v = ToLeaf(p); v != 0; v = (v - 1) / 2) { int spa = (v - 1) / 2; int sl = (v - 1) / 2 * 2 + 1; int sr = (v - 1) / 2 * 2 + 2; min = Math.Min(min, X[spa]); } return min; } // vの子の内bより大きいものに(bは子孫,bはToBitしたもの) void More(int C, int b, int v, int depth) { if ((b & (1 << depth)) == 0) { //右の子は全てbより大きい if (((b + 1) % (1 << depth)) != 0) { More(C, b, v * 2 + 1, depth - 1); Act(C, v * 2 + 2); } else { Act(C, v * 2 + 2); } } else { //左の子は全てb未満 More(C, b, v * 2 + 2, depth - 1); } } // vの子の内bより小さなものに(bは子孫,bはToBitしたもの) void Less(int C, int b, int v, int depth) { if ((b & (1 << depth)) == 0) { //右の子は全てbより大きい Less(C, b, v * 2 + 1, depth - 1); } else { //左の子は全てb未満 if (b % (1 << depth) != 0) { Act(C, v * 2 + 1); Less(C, b, v * 2 + 2, depth - 1); } else { //右の子は全てb以上 Act(C, v * 2 + 1); } } } void Section(int C, int bl, int br, int v, int dl, int dr) { if (v >= segf) { //葉 Act(C, v); } else { if ((bl & (1 << dl)) == 0 && (br & (1 << dr)) == 0) { //両方左 Section(C, bl, br, v * 2 + 1, dl - 1, dr - 1); } else if ((bl & (1 << dl)) != 0 && (br & (1 << dr)) != 0) { //両方右 Section(C, bl, br, v * 2 + 2, dl - 1, dr - 1); } else { //左と右に分かれた if (bl % (1 << dl) != 0) { More(C, bl - 1, v * 2 + 1, dl - 1); } else { //左は全て含まれる Act(C, v * 2 + 1); } if ((br + 1) % (1 << dl) != 0) { Less(C, br + 1, v * 2 + 2, dr - 1); } else { //右は全て含まれる Act(C, v * 2 + 2); } } } } public void Add(int C, int l0, int r0) { int bl = ToBit(l0); int br = ToBit(r0); int dl = l0 >= border ? depth - 2 : depth - 1; int dr = r0 >= border ? depth - 2 : depth - 1; Section(C, bl, br, 0, dl, dr); } void Act(int C, int v) { X[v] = C; } }
using System; using System.Text; using System.Collections.Generic; class Solve { public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); long K = int.Parse(str[1]); long[] L = new long[N]; long[] R = new long[N]; int eN = 0; long sum = 0; { for (int i = 0; i < N; i++) { str = Console.ReadLine().Split(' '); long D = int.Parse(str[0]); bool b = int.Parse(str[1]) == 1; if (b && 2 * D > K) { sb.Append("-1\n"); return; } if (b) { L[eN] = K - (((sum + 2 * D) % K) == 0 ? K : ((sum + 2 * D) % K)); R[eN] = K - ((sum % K) == 0 ? K : sum % K); eN++; } sum += 2 * D; } } long[] DPL = new long[eN]; long[] DPR = new long[eN]; long[] Points = new long[2 * eN]; int[] A = new int[2 * eN]; for (int i = 0; i < eN; i++) { Points[2 * i] = L[i]; Points[2 * i + 1] = R[i]; A[2 * i] = 2 * i; A[2 * i + 1] = 2 * i + 1; } Array.Sort(Points, A); int[] B = new int[2 * eN]; for (int i = 0; i < 2 * eN; i++) { B[A[i]] = i; } SegTree Seg = new SegTree(2 * eN, this); for (int i = 4 * eN - 2; i >= 0; i--) { Seg.X[i] = eN; } for (int i = eN - 1; i >= 0; i--) { int lp = B[2 * i]; int rp = B[2 * i + 1]; int gL = Seg.Get(lp); DPL[i] = gL == eN ? 0 : DPR[gL] + (K + Points[B[2 * gL + 1]] - Points[lp]) % K; int gR = Seg.Get(rp); DPR[i] = gR == eN ? 0 : DPR[gR] + (K + Points[B[2 * gR + 1]] - Points[rp]) % K; int bf = 0; int bl = 2 * eN; long C = Points[B[2 * i]]; while (bf != bl) { int bc = (bf + bl) / 2; if (bc == 2 * eN || C < Points[bc]) { bl = bc; } else { bf = bc + 1; } } int l = bf; bf = -1; bl = 2 * eN - 1; C = Points[B[2 * i + 1]]; while (bf != bl) { int bc = (bf + bl + 1) / 2; if (bc == -1 || C > Points[bc]) { bf = bc; } else { bl = bc - 1; } } int r = bf; if (Points[lp] < Points[rp]) { if (l <= r) { Seg.Add(i, l, r); } } else { if (l != 2 * eN) { Seg.Add(i, l, 2 * eN - 1); } if (r != -1) { Seg.Add(i, 0, r); } } } for (int i = 4 * eN - 2; i >= 0; i--) { Seg.X[i] = eN; } long min = DPR[0]; for (int i = 0; i < eN; i++) { int lp = B[2 * i]; int rp = B[2 * i + 1]; int gL = Seg.Get(lp); if (gL == eN) { min = Math.Min(min, DPL[i]); } int gR = Seg.Get(rp); if (gR == eN) { min = Math.Min(min, DPR[i]); } int bf = 0; int bl = 2 * eN; long C = Points[B[2 * i]]; while (bf != bl) { int bc = (bf + bl) / 2; if (bc == 2 * eN || C < Points[bc]) { bl = bc; } else { bf = bc + 1; } } int l = bf; bf = -1; bl = 2 * eN - 1; C = Points[B[2 * i + 1]]; while (bf != bl) { int bc = (bf + bl + 1) / 2; if (bc == -1 || C > Points[bc]) { bf = bc; } else { bl = bc - 1; } } int r = bf; if (Points[lp] < Points[rp]) { if (l <= r) { Seg.Add(0, l, r); } } else { if (l != 2 * eN) { Seg.Add(0, l, 2 * eN - 1); } if (r != -1) { Seg.Add(0, 0, r); } } } sb.Append((min + sum) + "\n"); } } struct SegTree { Solve Sol; public int[] X; //葉の最初の場所 public int segf; // segfのbit public int segfb; //葉の深さの内浅い方 public int depth; //浅い葉の内座標が最大のもの public int borderP; //はみ出すものの数 public int border; public SegTree(int N, Solve So) { Sol = So; X = new int[2 * N - 1]; for (depth = 1; (1 << depth) <= N; depth++) { ; } segf = N - 1; borderP = (1 << depth) - 2; border = 2 * N - borderP - 2; segfb = border / 2; } public int ToBit(int p) { if (p >= border) { return segfb + p - border; } else { return p; } } //葉のある場所 public int ToLeaf(int p) { if (p >= border) { return segf + p - border; } else { return borderP + p + 1; } } //葉の示す頂点 public int ToPoint(int leaf) { if (leaf > borderP) { return leaf - borderP - 1; } else { return leaf - segf + border; } } public int Get(int p) { //葉の作業 int min = X[ToLeaf(p)]; //親の作業 for (int v = ToLeaf(p); v != 0; v = (v - 1) / 2) { int spa = (v - 1) / 2; int sl = (v - 1) / 2 * 2 + 1; int sr = (v - 1) / 2 * 2 + 2; min = Math.Min(min, X[spa]); } return min; } // vの子の内bより大きいものに(bは子孫,bはToBitしたもの) void More(int C, int b, int v, int depth) { if ((b & (1 << depth)) == 0) { //右の子は全てbより大きい if (((b + 1) % (1 << depth)) != 0) { More(C, b, v * 2 + 1, depth - 1); Act(C, v * 2 + 2); } else { Act(C, v * 2 + 2); } } else { //左の子は全てb未満 More(C, b, v * 2 + 2, depth - 1); } } // vの子の内bより小さなものに(bは子孫,bはToBitしたもの) void Less(int C, int b, int v, int depth) { if ((b & (1 << depth)) == 0) { //右の子は全てbより大きい Less(C, b, v * 2 + 1, depth - 1); } else { //左の子は全てb未満 if (b % (1 << depth) != 0) { Act(C, v * 2 + 1); Less(C, b, v * 2 + 2, depth - 1); } else { //右の子は全てb以上 Act(C, v * 2 + 1); } } } void Section(int C, int bl, int br, int v, int dl, int dr) { if (v >= segf) { //葉 Act(C, v); } else { if ((bl & (1 << dl)) == 0 && (br & (1 << dr)) == 0) { //両方左 Section(C, bl, br, v * 2 + 1, dl - 1, dr - 1); } else if ((bl & (1 << dl)) != 0 && (br & (1 << dr)) != 0) { //両方右 Section(C, bl, br, v * 2 + 2, dl - 1, dr - 1); } else { //左と右に分かれた if (bl % (1 << dl) != 0) { More(C, bl - 1, v * 2 + 1, dl - 1); } else { //左は全て含まれる Act(C, v * 2 + 1); } if ((br + 1) % (1 << dl) != 0) { Less(C, br + 1, v * 2 + 2, dr - 1); } else { //右は全て含まれる Act(C, v * 2 + 2); } } } } public void Add(int C, int l0, int r0) { int bl = ToBit(l0); int br = ToBit(r0); int dl = l0 >= border ? depth - 2 : depth - 1; int dr = r0 >= border ? depth - 2 : depth - 1; Section(C, bl, br, 0, dl, dr); } void Act(int C, int v) { X[v] = C; } }
[["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73]]
8
2,189
12
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string str = Console.ReadLine(); long N = long.Parse(str); string[] str2 = Console.ReadLine().Split(); long[] X = new long[N]; for (var i = 0; i < N; i++) { X[i] = long.Parse(str2[i]); } long ans = 1; long it = 1; long ct = 2 - X[0]; for (var h = N; h >= 1; h--) { long a = h; for (var i = it; i < h; i++) { ct += 2 - (X[i] - X[i - 1]); if (ct >= (N - h + 1) * 2) { a = a - (h - i - 1); it = i + 1; break; } } ans = ans * a % 1000000007; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string str = Console.ReadLine(); long N = long.Parse(str); string[] str2 = Console.ReadLine().Split(); long[] X = new long[N]; for (var i = 0; i < N; i++) { X[i] = long.Parse(str2[i]); } long ans = 1; long it = 1; long ct = 2 - X[0]; for (var h = N; h >= 1; h--) { long a = h; while (it < N) { ct += 2 - (X[it] - X[it - 1]); it += 1; if (ct >= (N - h + 1) * 2) { a = a - (N - it); break; } } ans = ans * a % 1000000007; } Console.WriteLine(ans); } }
[["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["-", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 12, 22], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 12, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 16, 12, 23, 0, 16, 31, 16, 17, 33], ["-", 12, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
8
227
32
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Mujin { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var x = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray(); long count = 1; var list = new List<int>(); var mod = (long)(10000000000 + 7); for (int i = 0; i < N; i++) { list.Add(x[i]); if (x[i] < 2 * list.Count - 1) { count *= list.Count; list.Remove(list.Count - 1); count %= mod; } } for (int i = 0; i < list.Count; i++) { count *= i + 1; count %= mod; } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Mujin { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var x = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray(); long count = 1; var list = new Stack<int>(); var mod = (long)(1000000007); for (int i = 0; i < N; i++) { list.Push(x[i]); if (x[i] < 2 * list.Count - 1) { count *= list.Count; list.Pop(); count %= mod; } } for (int i = 0; i < list.Count; i++) { count *= i + 1; count %= mod; } Console.WriteLine(count); } } }
[["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 31, 203], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 17, 72], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 74, 51, 23, 0, 203], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
219
15
using System; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 long pow = 1; for (int i = 1; i <= n; i++) { pow *= i; } //出力 Console.WriteLine(pow % 1000000007); // WriteLineをWriteとすると、改行なしで出力。 } }
using System; class Program { static void Main() { long n = long.Parse(Console.ReadLine()); // int.Parseは文字列を整数に変換。 long pow = 1; for (int i = 1; i <= n; i++) { pow *= i; while (pow > 1000000007) pow -= 1000000007; } //出力 Console.WriteLine(pow % 1000000007); // WriteLineをWriteとすると、改行なしで出力。 } }
[["+", 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, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 25], ["+", 8, 196, 0, 52, 8, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 52, 8, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 52, 8, 1, 0, 35]]
8
65
10
using System; // using System.Numerics; static class Program { static void Main(string[] args) { int a = Int32.Parse(Console.ReadLine()); ulong h = 1; for (int s = 1; s <= a; s++) { h *= (ulong)s % 1000000007; } //; s = s % 1000000007; } Console.WriteLine(h); // % 1000000007); Console.ReadLine(); } }
using System; class Program { static void Main(string[] args) { int a = Int32.Parse(Console.ReadLine()); ulong h = 1; for (int s = 1; s <= a; s++) { h = h * (ulong)s % 1000000007; } Console.WriteLine(h); } }
[["-", 36, 36, 0, 208, 0, 235, 0, 251, 0, 115], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 8, 196, 0, 1, 0, 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
79
11
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) { var N = int.Parse(Console.ReadLine()); double power = 1; for (int i = 1; i <= N; i++) { power *= i % (Math.Pow(10, 9) + 7); } Console.WriteLine(power); } } }
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) { var N = int.Parse(Console.ReadLine()); long power = 1; for (int i = 1; i <= N; i++) { power *= i; power %= (long)(Math.Pow(10, 9) + 7); } Console.WriteLine(power); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25]]
8
105
9
using System; using System.Collections.Generic; using System.Linq; namespace at { class Program { static void Main(string[] args) { var x = 0; var N = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); var a = new List<int>() { 0 }; for (int i = 0; i < N; i++) { Console.WriteLine(s[i]); if ((s[i]).ToString() == "I") a.Add(x = x + 1); if ((s[i]).ToString() == "D") a.Add(x = x - 1); } Console.WriteLine(a.Max()); } } }
using System; using System.Collections.Generic; using System.Linq; namespace at { class Program { static void Main(string[] args) { var x = 0; var N = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); var a = new List<int>() { 0 }; for (int i = 0; i < N; i++) { if ((s[i]).ToString() == "I") a.Add(x = x + 1); if ((s[i]).ToString() == "D") a.Add(x = x - 1); } Console.WriteLine(a.Max()); } } }
[["-", 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, 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], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
169
10
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; int x = 0; int ans = 0; string cmd = Reader.ReadLine(); foreach (char c in cmd) { if (c == 'D') { x--; } else { x++; } ans = Math.Max(x, ans); } Console.WriteLine(ans); } public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 3 5 2 7 "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Text; public class Program { public void Proc() { Reader.IsDebug = false; int x = 0; int ans = 0; int cnt = int.Parse(Reader.ReadLine()); string cmd = Reader.ReadLine(); foreach (char c in cmd) { if (c == 'D') { x--; } else { x++; } ans = Math.Max(x, ans); } Console.WriteLine(ans); } public class Reader { public static bool IsDebug = true; private static System.IO.StringReader SReader; private static string InitText = @" 3 5 2 7 "; public static string ReadLine() { if (IsDebug) { if (SReader == null) { SReader = new System.IO.StringReader(InitText.Trim()); } return SReader.ReadLine(); } else { return Console.ReadLine(); } } } public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 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], ["+", 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], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
8
219
14
using System; namespace abc_B { class Program { static void Main(string[] args) { int h = int.Parse(Console.ReadLine()); int[] j = new int[h]; string kl = Console.ReadLine(); string imaw; int imamade = 0; for (int q = 0; q < h; q++) { imaw = (kl.Substring(q, 1)); if (imaw == "D") { imamade -= 1; } else { imamade += 1; } j[q] = imamade; } Array.Sort(j); Console.WriteLine(j[h - 1]); } } }
using System; class Program { static void Main(string[] args) { int h = int.Parse(Console.ReadLine()); int[] j = new int[h]; string kl = Console.ReadLine(); string imaw; int imamade = 0; for (int q = 0; q < h; q++) { imaw = (kl.Substring(q, 1)); if (imaw == "D") { imamade -= 1; } else { imamade += 1; } j[q] = imamade; } Array.Sort(j); if (j[h - 1] > 0) { Console.WriteLine(j[h - 1]); } else { Console.WriteLine("0"); } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 0, 256], ["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 36, 36, 0, 208, 0, 209, 8, 201, 0, 45], ["+", 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], ["+", 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, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 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], ["+", 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
140
27
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication54 { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); string b = Console.ReadLine(); int[] e = new int[a + 1]; int d = 0; e[0] = 0; for (int c = 0; c < a; c++) { if (b[c] == 'I') d++; if (b[c] == 'D') d--; e[c + 1] = d; Console.WriteLine(d); } Array.Sort(e); Console.WriteLine(e[e.Length - 1]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication54 { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); string b = Console.ReadLine(); int[] e = new int[a + 1]; int d = 0; e[0] = 0; for (int c = 0; c < a; c++) { if (b[c] == 'I') d++; if (b[c] == 'D') d--; e[c + 1] = d; } Array.Sort(e); Console.WriteLine(e[e.Length - 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], ["-", 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
175
7
using System; using System.Collections.Generic; namespace kozaiyApp { public class FactorsOfFactorial { static void Main() { int N = int.Parse(Console.ReadLine()); Dictionary<int, int> count = new Dictionary<int, int>(); // 素数xが何個あるか int mod = 1000000007; for (int i = 1; i <= N; i++) // N!... 1*2*3*4*...N { List<int> factorList = PrimeFactor(i); // 素因数分解 foreach (var f in factorList) // 素数をカウント { // Dictionaryに記録 if (count.ContainsKey(f)) { count[f] += 1; } else { count.Add(f, 1); } } } int ans = 1; foreach (var c in count) { ans *= (c.Value + 1) % mod; ans %= mod; } Console.WriteLine(ans); } // 素因数分解 static List<int> PrimeFactor(int n) { List<int> result = new List<int>(); for (int i = 2; i * i <= n; i++) { while (n % i == 0) { result.Add(i); n /= i; } } result.Add(n); return result; } } }
using System; using System.Collections.Generic; namespace kozaiyApp { public class FactorsOfFactorial { static void Main() { long N = int.Parse(Console.ReadLine()); Dictionary<long, long> count = new Dictionary<long, long>(); // 素数xが何個あるか long mod = 1000000007; for (long i = 2; i <= N; i++) // N!... 1*2*3*4*...N { List<long> factorList = PrimeFactor(i); // 素因数分解 foreach (var f in factorList) // 素数をカウント { // Dictionaryに記録 if (count.ContainsKey(f)) { count[f] += 1; } else { count.Add(f, 1); } } } long ans = 1; foreach (var c in count) { ans *= (c.Value + 1) % mod; ans %= mod; } Console.WriteLine(ans); } // 素因数分解 static List<long> PrimeFactor(long n) { List<long> result = new List<long>(); for (long i = 2; i * i <= n; i++) { while (n % i == 0) { result.Add(i); n /= i; } } if (n != 1) result.Add(n); return result; } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 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, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 39, 236, 237, 238, 0, 199], ["+", 8, 201, 0, 195, 39, 236, 237, 238, 0, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
8
247
36
using System; using System.Collections.Generic; namespace ABC052 { class Program { const int N = 1000000000; static Dictionary<int, int> dic; static void Main(string[] args) { dic = new Dictionary<int, int>(); int n = int.Parse(Console.ReadLine()); ulong num = 1; for (int i = 1; i <= n; i++) { divNum(i); } foreach (KeyValuePair<int, int> item in dic) { Console.WriteLine(item.Key + " " + item.Value); num *= (ulong)(item.Value + 1); num = num % (N + 7); } Console.WriteLine(num % (N + 7)); } static void divNum(int n) { int div = 2; while (true) { if (n == 1) { break; } if (n % div == 0) { if (!dic.ContainsKey(div)) { dic[div] = 0; } dic[div]++; n /= div; } else { div++; } } } } }
using System; using System.Collections.Generic; namespace ABC052 { class Program { const int N = 1000000000; static Dictionary<int, int> dic; static void Main(string[] args) { dic = new Dictionary<int, int>(); int n = int.Parse(Console.ReadLine()); ulong num = 1; for (int i = 1; i <= n; i++) { divNum(i); } foreach (KeyValuePair<int, int> item in dic) { // Console.WriteLine(item.Key + " " + item.Value); num *= (ulong)(item.Value + 1); num = num % (N + 7); } Console.WriteLine(num % (N + 7)); } static void divNum(int n) { int div = 2; while (true) { if (n == 1) { break; } if (n % div == 0) { if (!dic.ContainsKey(div)) { dic[div] = 0; } dic[div]++; n /= div; } else { div++; } } } } }
[["-", 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, 28, 0, 16, 31, 16, 31, 214, 205, 22], ["-", 0, 28, 0, 16, 31, 16, 31, 214, 0, 131], ["-", 0, 28, 0, 16, 31, 16, 31, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 12, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 16, 12, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
238
17
using System; using System.Linq; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string ans = s.Replace('.', ' '); Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { string s = Console.ReadLine().Replace(',', ' '); Console.WriteLine(s); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
55
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var xx = ConsoleUtil.StrArrayReadLine(); Console.WriteLine(string.Join(",", xx)); } } static class ConsoleUtil { public static string[] StrArrayReadLine(char sepalator) { string str = Console.ReadLine(); return str.Split(sepalator).ToArray(); } public static string[] StrArrayReadLine() { string str = Console.ReadLine(); if (str.Contains(',')) { return StrArrayReadLine(','); } { return StrArrayReadLine(' '); } } public static int[] IntArrayReadLine() { return StrArrayReadLine().Select(s => int.Parse(s)).ToArray(); } public static int[] IntArrayReadLine(char sepalator) { return StrArrayReadLine(sepalator).Select(s => int.Parse(s)).ToArray(); } public static int IntReadLine() => int.Parse(Console.ReadLine()); }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var xx = ConsoleUtil.StrArrayReadLine(); Console.WriteLine(string.Join(" ", xx)); } } static class ConsoleUtil { public static string[] StrArrayReadLine(char sepalator) { string str = Console.ReadLine(); return str.Split(sepalator).ToArray(); } public static string[] StrArrayReadLine() { string str = Console.ReadLine(); if (str.Contains(',')) { return str.Split(',').ToArray(); } { return str.Split(' ').ToArray(); } } public static int[] IntArrayReadLine() { return StrArrayReadLine().Select(s => int.Parse(s)).ToArray(); } public static int[] IntArrayReadLine(char sepalator) { return StrArrayReadLine(sepalator).Select(s => int.Parse(s)).ToArray(); } public static int IntReadLine() => int.Parse(Console.ReadLine()); }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 57, 64, 196, 0, 37, 0, 213, 63, 22], ["+", 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, 25], ["+", 64, 196, 0, 37, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 37, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 37, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 196, 0, 37, 0, 213, 63, 22], ["+", 0, 196, 0, 37, 0, 213, 63, 214, 0, 131], ["+", 0, 196, 0, 37, 0, 213, 63, 214, 141, 22], ["+", 0, 196, 0, 37, 0, 213, 3, 4, 0, 24]]
8
238
18
using System; namespace Atcoder { class AtCoderContest { static void Main() { string input = Console.In.ReadToEnd(); string[] S = input.Split(','); int count = S.Length - 1; string answer = ""; while (count >= 0) { answer = answer + S[count] + " "; count--; } answer = answer.Remove(19); Console.Write(answer); } } }
using System; namespace Atcoder { class AtCoderContest { static void Main() { string input = Console.In.ReadToEnd(); string[] S = input.Split(','); int count = 0; string answer = ""; while (count <= (S.Length) - 1) { answer = answer + S[count] + " "; count++; } answer = answer.Remove(19); Console.Write(answer); } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 52, 15, 16, 12, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 16, 31, 23, 0, 214, 205, 22], ["+", 15, 16, 12, 16, 31, 23, 0, 214, 0, 131], ["+", 15, 16, 12, 16, 31, 23, 0, 214, 141, 22], ["+", 0, 52, 15, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 12, 203], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29]]
8
98
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var ks = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var k = ks[0]; var s = ks[1]; var count = 0; for (int x = 0; x <= k; x++) { for (int y = 0; y <= k; y++) { if (s - (x + y) >= 0) { count++; } } } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var ks = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var k = ks[0]; var s = ks[1]; var count = 0; for (int x = 0; x <= k; x++) { for (int y = 0; y <= k; y++) { if (s - (x + y) >= 0 && s - (x + y) <= k) { count++; } } } Console.WriteLine(count); } } }
[["+", 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, 33], ["+", 15, 16, 12, 16, 31, 16, 12, 23, 0, 24], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 15, 16, 12, 16, 31, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
148
10
using System; using System.IO; using System.Collections.Generic; using System.Linq; namespace AtCoder.Contest.C { static class Program { public static void Solve(Scanner cin) { long n = cin.ReadLong(); long m = cin.ReadLong(); Console.WriteLine((n * 2 + m) / 3); } 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(); } } 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; namespace AtCoder.Contest.C { static class Program { public static void Solve(Scanner cin) { long n = cin.ReadLong(); long m = cin.ReadLong(); Console.WriteLine(Math.Min((n * 2 + m) / 4, m / 2)); } 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(); } } 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); } } }
[["+", 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, 16, 31, 23, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
2,448
11
using System; using System.Collections.Generic; using System.Linq; namespace MyProgram { class AtCoder { static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long N = input[0]; long M = input[1]; long result = 0; if (2 * N < M) { result = N + (M - 2 * N) / 4; } else { result = N; } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; namespace MyProgram { class AtCoder { static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long N = input[0]; long M = input[1]; long result = 0; if (2 * N < M) { result = N + (M - 2 * N) / 4; } else { result = Math.Min(N, M / 2); } Console.WriteLine(result); } } }
[["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
114
9
using System; using System.Text; using System.Collections.Generic; using System.Linq; public class Remainder { static public void Main() { var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long N = NM[0]; long M = NM[1]; long ans = 0L; if (M - 2 * N >= 0) { ans = N + (M - 2 * N) / 4; } Console.WriteLine(ans); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; public class Remainder { static public void Main() { var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long N = NM[0]; long M = NM[1]; long ans = 0L; if (M - 2 * N >= 0) { ans = N + (M - 2 * N) / 4; } else { ans = M / 2; } Console.WriteLine(ans); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
119
9
using System; using System.Linq; using System.Collections.Generic; using static System.Math; using static System.Console; using System.Text; class Program { static void Main(string[] args) { solve(); } static Scanner cin; static long N, M; static void input() { cin = new Scanner(); N = cin.nextLong(); M = cin.nextLong(); } static void solve() { input(); long ans = 0; if (N >= 2 * M) { ans += M / 2; } else { ans += N; M -= 2 * N; ans += M / 4; } WriteLine(ans); } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDounble(int N, int add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Math; using static System.Console; using System.Text; class Program { static void Main(string[] args) { solve(); } static Scanner cin; static long N, M; static void input() { cin = new Scanner(); N = cin.nextLong(); M = cin.nextLong(); } static void solve() { input(); long ans = 0; if (M <= N * 2) { ans += M / 2; } else { ans += N; M -= 2 * N; ans += M / 4; } WriteLine(ans); } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDounble(int N, int add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
497
6
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Scc Puzzle var line = ReadLine(); int n = line[0]; //'s'型ピース int m = line[1]; //'c'型ピース if (m >= n * 2) { Console.WriteLine((m - n * 2) / 4 + n); } else { Console.WriteLine(n / 2); } } static List<int> ReadLine() { var line = Console.ReadLine(); var array = line.Split(' '); return array.Select(x => int.Parse(x)).ToList(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Scc Puzzle var line = ReadLine(); long s = line[0]; //'s'型ピース long c = line[1]; //'c'型ピース if (c >= s * 2) { Console.WriteLine((c - s * 2) / 4 + s); } else { Console.WriteLine(c / 2); } } static List<long> ReadLine() { var line = Console.ReadLine(); var array = line.Split(' '); return array.Select(x => long.Parse(x)).ToList(); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 31, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 31, 16, 31, 23, 0, 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], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 8, 201, 0, 195, 39, 236, 237, 238, 0, 199], ["+", 8, 201, 0, 195, 39, 236, 237, 238, 0, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199]]
8
149
24
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 NM = ReadSplitLong(); var N = NM[0]; var M = NM[1]; var ans = 0L; M -= (N * 2); ans += N; if (M >= 4) { ans += M / 4; } Println(ans); } static List<int> ReadLines(int n) { var l = new List<int>(); for (int i = 0; i < n; i++) { l.Add(ReadInt()); } 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 int Gcd(int a, int b) => b == 0 ? a : Gcd(b, 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 NM = ReadSplitLong(); var N = NM[0]; var M = NM[1]; var ans = 0L; if (N * 2 <= M) { M -= (N * 2); ans += N; } else { ans += M / 2; M = M % 2; } if (M >= 4) { ans += M / 4; } Println(ans); } static List<int> ReadLines(int n) { var l = new List<int>(); for (int i = 0; i < n; i++) { l.Add(ReadInt()); } 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 int Gcd(int a, int b) => b == 0 ? a : Gcd(b, 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); } } }
[["+", 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, 48], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
668
25
using System; namespace ABC055_C { class Program { static void Main(string[] args) { var nm = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var n = nm[0]; var m = nm[1]; if (2 * n >= m) { Console.WriteLine(n); } else { var c = m - 2 * n; Console.WriteLine(n + c / 4); } } } }
using System; namespace ABC055_C { class Program { static void Main(string[] args) { var nm = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var n = nm[0]; var m = nm[1]; if (m == 1) { Console.WriteLine(0); } else if (2 * n >= m) { Console.WriteLine(m / 2); } else { var c = m - 2 * n; Console.WriteLine(n + c / 4); } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
103
20
using System; using System.Collections; using System.Collections.Generic; using System.Text; using static MyIO; public class C { public static void Main() { long N = GetLong(); long M = GetLong(); Console.WriteLine((2 * N >= M) ? N : N + (M - 2 * N) / 4); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using static MyIO; public class C { public static void Main() { long N = GetLong(); long M = GetLong(); if (N >= M / 2) { Console.WriteLine(M / 2); } else { Console.WriteLine(N + (M - 2 * N) / 4); } } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() { return int.Parse(getArg()); } public static long GetLong() { return long.Parse(getArg()); } public static double GetDouble() { return double.Parse(getArg()); } public static string GetString() { return getArg(); } }
[["+", 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], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 3, 4, 0, 28, 0, 41, 15, 23, 0, 24], ["-", 0, 41, 15, 23, 0, 16, 31, 16, 31, 203], ["-", 0, 41, 15, 23, 0, 16, 31, 16, 17, 48], ["-", 0, 41, 15, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 28, 0, 41, 15, 23, 0, 16, 17, 20], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 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
224
28
#pragma warning disable using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Diagnostics; using System.Numerics; using System.Collections; static class MainClass { public static void Main() { var nm = Console.ReadLine() .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => long.Parse(x)) .ToList(); var n = nm[0]; var m = nm[1]; var k = n - m * 2; if (k >= 0) { Console.WriteLine(m / 2); } else { var count = n; var l = m - 2 * n; if (l < 0) { Console.WriteLine(0); return; } while (true) { if (l < 4) break; count++; l -= 4; } Console.WriteLine(count); } Console.ReadLine(); } #region ライブラリ #region 二分探索 public static int LowerBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(this IEnumerable<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } public static int UpperBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(this IEnumerable<T> arr, T value) { return UpperBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } #endregion #region bit全探索 /// <summary> /// Bit全探索用のライブラリ /// </summary> /// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param> /// <returns>できた配列</returns> public static List<List<bool>> CreateBits(int len) { return CreateBitsPri(new List<List<bool>>(), len, 0); } private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count) { if (count == 0) { var lss = new List<bool>(); lss.Add(true); bits.Add(lss); var lx = new List<bool>(); lx.Add(false); bits.Add(lx); count++; return CreateBitsPri(bits, len, count); } if (len - count == 0) return bits; count++; var ls = new List<List<bool>>(); foreach (var item in bits) { var x = item.ToList(); x.Add(true); item.Add(false); ls.Add(item); ls.Add(x); } return CreateBitsPri(ls, len, count); } #endregion #region 文字列処理 public static int ToInt32(this string str) { return int.Parse(str); } public static List<string> SplittedStringToList(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } public static List<int> SplittedStringToInt32List(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)) .ToList(); } #endregion #region エラトステネスの篩 /** * MIT License Copyright (c) 2018 gushwell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **/ public class BoundedBoolArray { private BitArray _array; private int _lower; public BoundedBoolArray(int lower, int upper) { _array = new BitArray(upper - lower + 1); _lower = lower; } public bool this[int index] { get { return _array[index - _lower]; } set { _array[index - _lower] = value; } } } public static IEnumerable<int> GeneratePrimes() { var primes = new List<int>() { 2, 3 }; foreach (var p in primes) yield return p; int ix = 0; while (true) { int prime1st = primes[ix]; int prime2nd = primes[++ix]; var lower = prime1st * prime1st; var upper = prime2nd * prime2nd - 1; var sieve = new BoundedBoolArray(lower, upper); foreach (var prime in primes.Take(ix)) { var start = (int)Math.Ceiling((double)lower / prime) * prime; for (int index = start; index <= upper; index += prime) sieve[index] = true; } for (int i = lower; i <= upper; i++) { if (sieve[i] == false) { primes.Add(i); yield return i; } } } } #endregion #region DeepClone public static T DeepClone<T>(this T src) { using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); memoryStream.Seek(0, SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); } } #endregion #region 順列を作るやつ public static List<List<int>> GeneratePermutations(int n) { if (n > 14) throw new ArgumentOutOfRangeException(); var ls = new List<List<int>>(); ls.Add(new List<int>() { 1 }); for (int i = 0; i < n - 1; i++) { var newls = new List<List<int>>(); ls.ForEach(x => { var len = x.Count; for (int j = 0; j <= len; j++) { var item = x.DeepClone(); item.Insert(j, i + 2); newls.Add(item); } }); ls = newls; } return ls; } #endregion #endregion }
#pragma warning disable using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Diagnostics; using System.Numerics; using System.Collections; static class MainClass { public static void Main() { var nm = Console.ReadLine() .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => long.Parse(x)) .ToList(); var n = nm[0]; var m = nm[1]; var k = n - m * 2; if (k >= 0) { Console.WriteLine(m / 2); } else { var count = n; var l = m - 2 * n; if (l < 0) { Console.WriteLine(m / 2); Console.ReadLine(); return; } count += l / 4; Console.WriteLine(count); } Console.ReadLine(); } #region ライブラリ #region 二分探索 public static int LowerBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } public static int LowerBound<T>(this IEnumerable<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } public static int UpperBound<T>(this IEnumerable<T> ar, int start, int end, T value, IComparer<T> comparer) { var arr = ar.ToArray(); int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } public static int UpperBound<T>(this IEnumerable<T> arr, T value) { return UpperBound(arr, 0, arr.Count(), value, Comparer<T>.Default); } #endregion #region bit全探索 /// <summary> /// Bit全探索用のライブラリ /// </summary> /// <param name="len">作る配列の長さ(lenが0以下だと(ry)</param> /// <returns>できた配列</returns> public static List<List<bool>> CreateBits(int len) { return CreateBitsPri(new List<List<bool>>(), len, 0); } private static List<List<bool>> CreateBitsPri(List<List<bool>> bits, int len, int count) { if (count == 0) { var lss = new List<bool>(); lss.Add(true); bits.Add(lss); var lx = new List<bool>(); lx.Add(false); bits.Add(lx); count++; return CreateBitsPri(bits, len, count); } if (len - count == 0) return bits; count++; var ls = new List<List<bool>>(); foreach (var item in bits) { var x = item.ToList(); x.Add(true); item.Add(false); ls.Add(item); ls.Add(x); } return CreateBitsPri(ls, len, count); } #endregion #region 文字列処理 public static int ToInt32(this string str) { return int.Parse(str); } public static List<string> SplittedStringToList(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } public static List<int> SplittedStringToInt32List(this string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x)) .ToList(); } #endregion #region エラトステネスの篩 /** * MIT License Copyright (c) 2018 gushwell Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **/ public class BoundedBoolArray { private BitArray _array; private int _lower; public BoundedBoolArray(int lower, int upper) { _array = new BitArray(upper - lower + 1); _lower = lower; } public bool this[int index] { get { return _array[index - _lower]; } set { _array[index - _lower] = value; } } } public static IEnumerable<int> GeneratePrimes() { var primes = new List<int>() { 2, 3 }; foreach (var p in primes) yield return p; int ix = 0; while (true) { int prime1st = primes[ix]; int prime2nd = primes[++ix]; var lower = prime1st * prime1st; var upper = prime2nd * prime2nd - 1; var sieve = new BoundedBoolArray(lower, upper); foreach (var prime in primes.Take(ix)) { var start = (int)Math.Ceiling((double)lower / prime) * prime; for (int index = start; index <= upper; index += prime) sieve[index] = true; } for (int i = lower; i <= upper; i++) { if (sieve[i] == false) { primes.Add(i); yield return i; } } } } #endregion #region DeepClone public static T DeepClone<T>(this T src) { using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, src); memoryStream.Seek(0, SeekOrigin.Begin); return (T)binaryFormatter.Deserialize(memoryStream); } } #endregion #region 順列を作るやつ public static List<List<int>> GeneratePermutations(int n) { if (n > 14) throw new ArgumentOutOfRangeException(); var ls = new List<List<int>>(); ls.Add(new List<int>() { 1 }); for (int i = 0; i < n - 1; i++) { var newls = new List<List<int>>(); ls.ForEach(x => { var len = x.Count; for (int j = 0; j <= len; j++) { var item = x.DeepClone(); item.Insert(j, i + 2); newls.Add(item); } }); ls = newls; } return ls; } #endregion #endregion }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 75, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 75, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 75, 196, 0, 52, 0, 89], ["-", 8, 196, 0, 57, 75, 196, 0, 52, 0, 24], ["-", 0, 57, 75, 196, 0, 52, 15, 211, 0, 146], ["-", 8, 196, 0, 57, 75, 196, 0, 52, 0, 25], ["-", 0, 57, 75, 196, 0, 52, 8, 196, 0, 45], ["-", 75, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 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], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 75, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 0, 57, 75, 196, 0, 52, 8, 196, 0, 46]]
8
1,367
29
using System; class Program { static void Main() { var nm = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long ans = 0; if (nm[0] <= nm[1] * 2) { ans = nm[0]; nm[1] -= nm[0] * 2; ans += nm[1] > 0 ? nm[1] / 4 : nm[1] / 2; } else ans = nm[1] / 2; Console.WriteLine(ans); } }
using System; class Program { static void Main() { var nm = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long ans = 0; if (nm[0] <= nm[1] * 2) { ans = nm[0]; nm[1] -= nm[0] * 2; ans += nm[1] > 0 ? nm[1] / 4 : (long)Math.Floor((double)nm[1] / 2); } else ans = nm[1] / 2; Console.WriteLine(ans); } }
[["+", 0, 1, 0, 11, 12, 41, 75, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 41, 75, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 41, 75, 74, 0, 25], ["+", 12, 41, 75, 74, 51, 213, 63, 214, 205, 22], ["+", 12, 41, 75, 74, 51, 213, 63, 214, 0, 131], ["+", 12, 41, 75, 74, 51, 213, 63, 214, 141, 22], ["+", 12, 41, 75, 74, 51, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["+", 12, 41, 75, 74, 51, 213, 3, 4, 0, 25]]
8
116
11
using System; using System.Linq; namespace abc_055_C { class Program { public static int a = 0; static void Main(string[] args) { int[] gf = Console.ReadLine().Split().Select(int.Parse).ToArray(); int s = gf[0], c = gf[1]; if (s * 2 < c) { Console.WriteLine(s); c -= s * 2; Console.WriteLine(s + c / 4); } else { Console.WriteLine(c / 2); } Console.ReadLine(); } } }
using System; using System.Linq; namespace abc_055_C { class Program { public static long a = 0; static void Main(string[] args) { long[] gf = Console.ReadLine().Split().Select(long.Parse).ToArray(); long s = gf[0], c = gf[1]; if (s * 2 < c) { c -= s * 2; Console.WriteLine(s + c / 4); } else { Console.WriteLine(c / 2); } Console.ReadLine(); } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
127
15
using System; using System.Linq; namespace arc069_a { class Program { static void Main(string[] args) { long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray(); if (x[0] * 2 > x[1]) { Console.WriteLine(x[1] / 2); } else { Console.WriteLine(x[0] / 2 + x[1] / 4); } } } }
using System; using System.Linq; namespace arc069_a { class Program { static void Main(string[] args) { long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray(); if (x[0] * 2 > x[1]) { Console.WriteLine(x[1] / 2); } else { Console.WriteLine((x[0] + x[1] / 2) / 2); } Console.ReadLine(); } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 85], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["+", 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, 203], ["+", 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
103
14
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public void Slove() { int n = int.Parse(Console.ReadLine()); bool[] testimony = Console.ReadLine().Select(x => x == 'o').ToArray(); foreach (int first in Enumerable.Range(0, 2)) foreach (int second in Enumerable.Range(0, 2)) { bool[] isSheep = new bool[n]; isSheep[0] = first == 0; isSheep[1] = second == 0; foreach (int i in Enumerable.Range(2, n - 2)) { isSheep[i] = (isSheep[i - 1] == testimony[i - 1]) ? isSheep[i - 2] : !isSheep[i - 2]; } if ((isSheep[n - 1] == testimony[n - 1]) == (isSheep[0] == isSheep[n - 2])) { System.Console.WriteLine( string.Join("", isSheep.Select(x => x ? 'S' : 'W'))); return; } } System.Console.WriteLine(-1); } static void Main(string[] args) { new Program().Slove(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public void Slove() { int n = int.Parse(Console.ReadLine()); bool[] testimony = Console.ReadLine().Select(x => x == 'o').ToArray(); foreach (int first in Enumerable.Range(0, 2)) foreach (int second in Enumerable.Range(0, 2)) { bool[] isSheep = new bool[n]; isSheep[0] = first == 0; isSheep[1] = second == 0; foreach (int i in Enumerable.Range(2, n - 2)) { isSheep[i] = (isSheep[i - 1] == testimony[i - 1]) ? isSheep[i - 2] : !isSheep[i - 2]; } if (((isSheep[n - 1] == testimony[n - 1]) == (isSheep[0] == isSheep[n - 2])) && ((isSheep[0] == testimony[0]) == (isSheep[1] == isSheep[n - 1]))) { System.Console.WriteLine( string.Join("", isSheep.Select(x => x ? 'S' : 'W'))); return; } } System.Console.WriteLine(-1); } static void Main(string[] args) { new Program().Slove(); } }
[["+", 15, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 8, 210, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 204, 205, 22], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 31, 23, 0, 16, 17, 60], ["+", 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, 60], ["+", 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], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 23, 0, 16, 12, 23, 0, 16, 17, 60], ["+", 0, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 15, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
8
282
30
using System; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); string[][] arr = new string[4][]; arr[0] = new string[n]; arr[1] = new string[n]; arr[2] = new string[n]; arr[3] = new string[n]; string ans = "-1"; arr[0][1] = "S"; arr[0][n - 1] = "S"; arr[1][1] = "W"; arr[1][n - 1] = "W"; arr[2][1] = "S"; arr[2][n - 1] = "W"; arr[3][1] = "W"; arr[3][n - 1] = "S"; if (s[0] == 'o') { arr[0][0] = "S"; arr[1][0] = "S"; arr[2][0] = "W"; arr[3][0] = "W"; } else { arr[0][0] = "W"; arr[1][0] = "W"; arr[2][0] = "S"; arr[3][0] = "S"; } for (int i = 1; i < n - 2; i++) { for (int j = 0; j < 4; j++) { if (s[i] == 'o' && arr[j][i] == "S") { arr[j][i + 1] = arr[j][i - 1]; } else if (s[i] == 'o' && arr[j][i] == "W") { arr[j][i + 1] = arr[j][i - 1] == "S" ? "W" : "S"; } else if (s[i] == 'x' && arr[j][i] == "S") { arr[j][i + 1] = arr[j][i - 1] == "S" ? "W" : "S"; } else if (s[i] == 'x' && arr[j][i] == "W") { arr[j][i + 1] = arr[j][i - 1]; } } } for (int j = 0; j < 4; j++) { if (fu(arr[j][n - 3], arr[j][n - 2], arr[j][n - 1], s[n - 2]) && fu(arr[j][n - 2], arr[j][n - 1], arr[j][0], s[n - 1])) { ans = String.Join("", arr[j]); } } } static bool fu(string a, string b, string c, char d) { if (d == 'o' && b == "S" && a == c) { return true; } else if (d == 'o' && b == "W" && a != c) { return true; } else if (d == 'x' && b == "S" && a != c) { return true; } else if (d == 'x' && b == "W" && a == c) { return true; } return false; } }
using System; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); string[][] arr = new string[4][]; arr[0] = new string[n]; arr[1] = new string[n]; arr[2] = new string[n]; arr[3] = new string[n]; string ans = "-1"; arr[0][1] = "S"; arr[0][n - 1] = "S"; arr[1][1] = "W"; arr[1][n - 1] = "W"; arr[2][1] = "S"; arr[2][n - 1] = "W"; arr[3][1] = "W"; arr[3][n - 1] = "S"; if (s[0] == 'o') { arr[0][0] = "S"; arr[1][0] = "S"; arr[2][0] = "W"; arr[3][0] = "W"; } else { arr[0][0] = "W"; arr[1][0] = "W"; arr[2][0] = "S"; arr[3][0] = "S"; } for (int i = 1; i < n - 2; i++) { for (int j = 0; j < 4; j++) { if (s[i] == 'o' && arr[j][i] == "S") { arr[j][i + 1] = arr[j][i - 1]; } else if (s[i] == 'o' && arr[j][i] == "W") { arr[j][i + 1] = arr[j][i - 1] == "S" ? "W" : "S"; } else if (s[i] == 'x' && arr[j][i] == "S") { arr[j][i + 1] = arr[j][i - 1] == "S" ? "W" : "S"; } else if (s[i] == 'x' && arr[j][i] == "W") { arr[j][i + 1] = arr[j][i - 1]; } } } for (int j = 0; j < 4; j++) { if (fu(arr[j][n - 3], arr[j][n - 2], arr[j][n - 1], s[n - 2]) && fu(arr[j][n - 2], arr[j][n - 1], arr[j][0], s[n - 1])) { ans = String.Join("", arr[j]); } } Console.WriteLine("{0}", ans); } static bool fu(string a, string b, string c, char d) { if (d == 'o' && b == "S" && a == c) { return true; } else if (d == 'o' && b == "W" && a != c) { return true; } else if (d == 'x' && b == "S" && a != c) { return true; } else if (d == 'x' && b == "W" && a == c) { return true; } return false; } }
[["+", 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, 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
789
11
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Runtime.InteropServices; using System.Runtime.Remoting.Messaging; using System.Security.Principal; using System.Text; class Simple { int N; string S; void Solve() { // input N = io.Int; S = io.String; // cal var sArr = S.Select(c => c.ToString()).ToArray(); var sw = new string[] { "S", "W" }; var ring = new string[0]; Func<string, string> rev = (a) => a == "S" ? "W" : "S"; Func<int, bool> isHonest = (index) => ring[index] == "S"; Func<int, bool> isSaySame = (index) => sArr[index] == "o"; Action<int> setSame = (index) => ring[index + 1] = ring[index - 1]; Action<int> setDiff = (index) => ring[index + 1] = rev(ring[index - 1]); Func<bool> isOK1 = () => ring[N - 2] == ring[0]; Func<bool> isOK2 = () => ring[N - 1] == ring[1]; Func<bool> isValid = () => { var f1 = false; var f2 = false; if (isHonest(N - 1)) if (isSaySame(N - 1)) f1 = isOK1(); else f1 = !isOK1(); else if (isSaySame(N - 1)) f1 = !isOK1(); else f1 = isOK1(); if (isHonest(0)) if (isSaySame(0)) f2 = isOK2(); else f2 = !isOK2(); else if (isSaySame(0)) f2 = !isOK2(); else f2 = isOK2(); return f1 && f2; }; for (int n0 = 0; n0 < sw.Length; ++n0) { for (int n1 = 0; n1 < sw.Length; ++n1) { ring = new string[N]; ring[0] = sw[n0]; ring[1] = sw[n1]; for (int i = 1; i < N - 1; ++i) { if (isHonest(i)) if (isSaySame(i)) setSame(i); else setDiff(i); else if (isSaySame(i)) setDiff(i); else setSame(i); } if (isValid()) { // ret Console.WriteLine(string.Join("", ring)); return; } } } // ret Console.WriteLine(-1); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); void Stream() { var exStdIn = new System.IO.StreamReader("stdin.txt"); System.Console.SetIn(exStdIn); Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Runtime.InteropServices; using System.Runtime.Remoting.Messaging; using System.Security.Principal; using System.Text; class Simple { int N; string S; void Solve() { // input N = io.Int; S = io.String; // cal var sArr = S.Select(c => c.ToString()).ToArray(); var sw = new string[] { "S", "W" }; var ring = new string[0]; Func<string, string> rev = (a) => a == "S" ? "W" : "S"; Func<int, bool> isHonest = (index) => ring[index] == "S"; Func<int, bool> isSaySame = (index) => sArr[index] == "o"; Action<int> setSame = (index) => ring[index + 1] = ring[index - 1]; Action<int> setDiff = (index) => ring[index + 1] = rev(ring[index - 1]); Func<bool> isOK1 = () => ring[N - 2] == ring[0]; Func<bool> isOK2 = () => ring[N - 1] == ring[1]; Func<bool> isValid = () => { var f1 = false; var f2 = false; if (isHonest(N - 1)) if (isSaySame(N - 1)) f1 = isOK1(); else f1 = !isOK1(); else if (isSaySame(N - 1)) f1 = !isOK1(); else f1 = isOK1(); if (isHonest(0)) if (isSaySame(0)) f2 = isOK2(); else f2 = !isOK2(); else if (isSaySame(0)) f2 = !isOK2(); else f2 = isOK2(); return f1 && f2; }; for (int n0 = 0; n0 < sw.Length; ++n0) { for (int n1 = 0; n1 < sw.Length; ++n1) { ring = new string[N]; ring[0] = sw[n0]; ring[1] = sw[n1]; for (int i = 1; i < N - 1; ++i) { if (isHonest(i)) if (isSaySame(i)) setSame(i); else setDiff(i); else if (isSaySame(i)) setDiff(i); else setSame(i); } if (isValid()) { // ret Console.WriteLine(string.Join("", ring)); return; } } } // ret Console.WriteLine(-1); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Simple().Stream(); void Stream() { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // System.Console.SetIn(exStdIn); Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
[["-", 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, 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, 230, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 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
871
24
// dryしたいがまず提出 using System; namespace AtCoder { class CircleList<T> { T[] circle_list; public int Length { get { return circle_list.Length; } } public CircleList(int length) { circle_list = new T[length]; } public CircleList(T[] char_array) { circle_list = char_array; } public T this[int index] { get { return circle_list[index % Length]; } set { circle_list[index % Length] = value; } } public void Print() { foreach (T t in circle_list) Console.Write(t); Console.WriteLine(); } } class Program { static void Main() { string input = Console.ReadLine(); int count = int.Parse(input); input = Console.ReadLine(); CircleList<char> declares = new CircleList<char>(input.ToCharArray()); CircleList<char> animals = new CircleList<char>(declares.Length); // 最初の2頭をSSと仮定 animals[0] = 'S'; animals[1] = 'S'; Solve(declares, animals); // 最初の2頭をSWと仮定 animals[0] = 'S'; animals[1] = 'W'; Solve(declares, animals); // 最初の2頭をWSと仮定 animals[0] = 'W'; animals[1] = 'S'; Solve(declares, animals); // 最初の2頭をWWと仮定 animals[0] = 'W'; animals[1] = 'W'; Solve(declares, animals); Console.WriteLine(-1); } static void Solve(CircleList<char> declares, CircleList<char> animals) { for (int i = 2; i < animals.Length * 2; i++) { animals[i] = GuessNextAnimal(animals[i - 1], declares[i - 1], animals[i - 2]); } if (CheckValidity(declares, animals)) { animals.Print(); return; } } static char GuessNextAnimal(char current_animal, char current_declare, char previous_animal) { switch (current_animal) { case 'S': switch (current_declare) { case 'o': switch (previous_animal) { case 'S': return 'S'; case 'W': return 'W'; } break; case 'x': switch (previous_animal) { case 'S': return 'W'; case 'W': return 'S'; } break; } break; case 'W': switch (current_declare) { case 'o': switch (previous_animal) { case 'S': return 'W'; case 'W': return 'S'; } break; case 'x': switch (previous_animal) { case 'S': return 'S'; case 'W': return 'W'; } break; } break; } return ' '; } static bool CheckValidity(CircleList<char> declares, CircleList<char> animals) { for (int i = 1; i <= declares.Length + 1; i++) { if (animals[i + 1] == GuessNextAnimal(animals[i], declares[i], animals[i - 1])) { // trueなら何もしない } else { return false; } } return true; } } }
using System; namespace AtCoder { class CircleList<T> { T[] circle_list; public int Length { get { return circle_list.Length; } } public CircleList(int length) { circle_list = new T[length]; } public CircleList(T[] char_array) { circle_list = char_array; } public T this[int index] { get { return circle_list[index % Length]; } set { circle_list[index % Length] = value; } } public void Print() { foreach (T t in circle_list) Console.Write(t); Console.WriteLine(); } } class Program { static void Main() { string input = Console.ReadLine(); int count = int.Parse(input); input = Console.ReadLine(); CircleList<char> declares = new CircleList<char>(input.ToCharArray()); CircleList<char> animals = new CircleList<char>(declares.Length); // 最初の2頭をSSと仮定 animals[0] = 'S'; animals[1] = 'S'; if (Solve(declares, animals)) return; // 最初の2頭をSWと仮定 animals[0] = 'S'; animals[1] = 'W'; if (Solve(declares, animals)) return; // 最初の2頭をWSと仮定 animals[0] = 'W'; animals[1] = 'S'; if (Solve(declares, animals)) return; // 最初の2頭をWWと仮定 animals[0] = 'W'; animals[1] = 'W'; if (Solve(declares, animals)) return; Console.WriteLine(-1); } static bool Solve(CircleList<char> declares, CircleList<char> animals) { for (int i = 2; i < animals.Length * 2; i++) { animals[i] = GuessNextAnimal(animals[i - 1], declares[i - 1], animals[i - 2]); } if (CheckValidity(declares, animals)) { animals.Print(); return true; } return false; } static char GuessNextAnimal(char current_animal, char current_declare, char previous_animal) { switch (current_animal) { case 'S': switch (current_declare) { case 'o': switch (previous_animal) { case 'S': return 'S'; case 'W': return 'W'; } break; case 'x': switch (previous_animal) { case 'S': return 'W'; case 'W': return 'S'; } break; } break; case 'W': switch (current_declare) { case 'o': switch (previous_animal) { case 'S': return 'W'; case 'W': return 'S'; } break; case 'x': switch (previous_animal) { case 'S': return 'S'; case 'W': return 'W'; } break; } break; } return ' '; } static bool CheckValidity(CircleList<char> declares, CircleList<char> animals) { for (int i = 1; i <= declares.Length + 1; i++) { if (animals[i + 1] == GuessNextAnimal(animals[i], declares[i], animals[i - 1])) { // trueなら何もしない } else { return false; } } return true; } } }
[["+", 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, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 57, 64, 196, 0, 37, 0, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 37, 0, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35]]
8
657
22
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using static CS_Contest.Utils; using System.Numerics; using System.Linq.Expressions; using Nakov.IO; using static Nakov.IO.Cin; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { int N = NextInt(), M = NextInt(); // default int cnt = 0; while (N > 0 && M > 1) { N--; M -= 2; cnt++; } cnt += M / 4; cnt.WL(); return; } } } public static class Utils { public static long ModValue = (long)1e9 + 7; public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li IntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Ll LongList() => ReadLine().Split().Select(long.Parse).ToList(); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static IEnumerable<int> ToImos(this IEnumerable<int> ie) { var s = 0; List<int> rt = new Li(); foreach (var item in ie) { s += item; rt.Add(s); } return rt; } public static void ForeachWithIndex<T>(IEnumerable<T> ie, Action<int, T> action) { int i = 0; foreach (var item in ie) { action(i, item); i++; } } public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Dictionary<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static int UpperBound<T>(this IEnumerable<T> list, T target) where T : IComparable { var idx = list.ToList().BinarySearch(target); idx = idx < 0 ? ~idx : (idx + 1); return Min(idx, list.Count()); } public static int LowerBound<T>(this IEnumerable<T> list, T target) where T : IComparable { var idx = list.ToList().BinarySearch(target); idx = idx < 0 ? ~idx : idx; return Max(0, idx - 1); } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using static System.Console; using static System.Math; using static CS_Contest.Utils; using System.Numerics; using System.Linq.Expressions; using Nakov.IO; using static Nakov.IO.Cin; // using static CS_Contest.Library; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { long N = NextLong(), M = NextLong(); // default long cnt = 0; cnt += Min(N, M / 2); M -= cnt * 2; cnt += M / 4; cnt.WL(); return; } } } public static class Utils { public static long ModValue = (long)1e9 + 7; public static long INF = long.MaxValue; public static long Mod(long x) => x % ModValue; public static long ModPow(long x, long n) { long tmp = 1; while (n != 0) { if (n % 2 == 1) { tmp = Mod(tmp * x); } x = Mod(x * x); n /= 2; } return tmp; } public static long DivMod(long x, long y) => Mod(x * ModPow(y, (long)(1e9 + 5))); public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li IntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Ll LongList() => ReadLine().Split().Select(long.Parse).ToList(); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static long GCD(long m, long n) { long tmp; if (m < n) { tmp = n; n = m; m = tmp; } while (m % n != 0) { tmp = n; n = m % n; m = tmp; } return n; } public static long LCM(long m, long n) => m * (n / GCD(m, n)); public static void REP(int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static IEnumerable<int> ToImos(this IEnumerable<int> ie) { var s = 0; List<int> rt = new Li(); foreach (var item in ie) { s += item; rt.Add(s); } return rt; } public static void ForeachWithIndex<T>(IEnumerable<T> ie, Action<int, T> action) { int i = 0; foreach (var item in ie) { action(i, item); i++; } } public static int ManhattanDistance(int x1, int y1, int x2, int y2) => Abs(x2 - x1) + Abs(y2 - y1); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static Dictionary<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Dictionary<TKey, int>(); foreach (var item in l) { if (dic.ContainsKey(item)) dic[item]++; else dic.Add(item, 1); } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static int UpperBound<T>(this IEnumerable<T> list, T target) where T : IComparable { var idx = list.ToList().BinarySearch(target); idx = idx < 0 ? ~idx : (idx + 1); return Min(idx, list.Count()); } public static int LowerBound<T>(this IEnumerable<T> list, T target) where T : IComparable { var idx = list.ToList().BinarySearch(target); idx = idx < 0 ? ~idx : idx; return Max(0, idx - 1); } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["-", 8, 196, 0, 52, 15, 16, 31, 16, 17, 47], ["-", 8, 196, 0, 52, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 98], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 17, 47], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
8
1,404
29
using System; using System.IO; using System.Collections.Generic; namespace ARC069C { public class Program { void Solve(StreamScanner ss, StreamWriter sw) { //--------------------------------- var N = ss.Next(long.Parse); var M = ss.Next(long.Parse); sw.WriteLine(N + Math.Max(0, M - N * 2) / 4); //--------------------------------- } static void Main() { var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput())); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; new Program().Solve(ss, sw); sw.Flush(); } static readonly Func<string, string> String = s => s; } public class StreamScanner { static readonly char[] Sep = { ' ' }; readonly Queue<string> buffer = new Queue<string>(); readonly TextReader textReader; public StreamScanner(TextReader textReader) { this.textReader = textReader; } public T Next<T>(Func<string, T> parser) { if (buffer.Count != 0) return parser(buffer.Dequeue()); var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries); foreach (var nextString in nextStrings) buffer.Enqueue(nextString); return Next(parser); } } }
using System; using System.IO; using System.Collections.Generic; namespace ARC069C { public class Program { void Solve(StreamScanner ss, StreamWriter sw) { //--------------------------------- var N = ss.Next(long.Parse); var M = ss.Next(long.Parse); sw.WriteLine(Math.Min(N, M / 2) + Math.Max(0, M - N * 2) / 4); //--------------------------------- } static void Main() { var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput())); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; new Program().Solve(ss, sw); sw.Flush(); } static readonly Func<string, string> String = s => s; } public class StreamScanner { static readonly char[] Sep = { ' ' }; readonly Queue<string> buffer = new Queue<string>(); readonly TextReader textReader; public StreamScanner(TextReader textReader) { this.textReader = textReader; } public T Next<T>(Func<string, T> parser) { if (buffer.Count != 0) return parser(buffer.Dequeue()); var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries); foreach (var nextString in nextStrings) buffer.Enqueue(nextString); return Next(parser); } } }
[["+", 0, 28, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 28, 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, 85], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25]]
8
281
9
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder20170211 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var s = Convert.ToDecimal(input[0]); var c = Convert.ToDecimal(input[1]); var scc = 0m; if (s * 2 <= c) { scc = s; scc += Math.Floor((c - s * 2) / 4); } else { scc = Math.Floor(c / 2); s -= scc; scc += Math.Floor(s / 2); } Console.WriteLine(scc); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder20170211 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var s = Convert.ToDecimal(input[0]); var c = Convert.ToDecimal(input[1]); var scc = 0m; if (s * 2 <= c) { scc = s; scc += Math.Floor((c - s * 2) / 4); } else { scc = Math.Floor(c / 2); // s -= scc; // scc += Math.Floor(s / 2); } Console.WriteLine(scc); // Console.ReadLine(); } } }
[["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
153
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ARC069 { public class C { private void Run() { var input = Console.ReadLine().Trim().Split(); var s = long.Parse(input[0]); var c = long.Parse(input[1]); Console.WriteLine((c + s * 2) / 4); } public static void Main() { var old = Console.Out; using (var writer = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }) { Console.SetOut(writer); new C().Run(); Console.Out.Flush(); Console.SetOut(old); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ARC069 { public class C { private void Run() { var input = Console.ReadLine().Trim().Split(); var s = long.Parse(input[0]); var c = long.Parse(input[1]); long t = Math.Min(s, c / 2); Console.WriteLine(t + (c - 2 * t) / 4); } public static void Main() { var old = Console.Out; using (var writer = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }) { Console.SetOut(writer); new C().Run(); Console.Out.Flush(); Console.SetOut(old); } } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["-", 0, 16, 31, 23, 0, 16, 12, 16, 17, 48], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 12, 22]]
8
166
22
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var n = ni(); var s = ns(); cout.WriteLine(Solve(s, true, true) ?? Solve(s, true, false) ?? Solve(s, false, true) ?? Solve(s, false, false) ?? "-1"); } private string Solve(string s, bool isSheep1, bool isSheep2) { var builder = new StringBuilder(); builder.Append(isSheep1 ? 'S' : 'W'); builder.Append(isSheep2 ? 'S' : 'W'); for (int i = 1; i < s.Length; i++) { if (s[i] == 'o' ^ builder[i] == 'W') { // same builder.Append(builder[i - 1]); } else { // diff builder.Append(builder[i - 1] == 'W' ? 'B' : 'W'); } } if (builder[0] != builder[builder.Length - 1]) return null; return builder.ToString().Substring(0, builder.Length - 1); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { [Conditional("DEBUG")] public static void Dump<T>(this T obj) { #if DEBUG LINQPad.Extensions.Dump(obj); #endif } } public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var n = ni(); var s = ns(); cout.WriteLine(Solve(s, true, true) ?? Solve(s, true, false) ?? Solve(s, false, true) ?? Solve(s, false, false) ?? "-1"); } private string Solve(string s, bool isSheep1, bool isSheep2) { var builder = new StringBuilder(); builder.Append(isSheep1 ? 'S' : 'W'); builder.Append(isSheep2 ? 'S' : 'W'); for (int i = 1; i < s.Length + 10; i++) { if (s[i % s.Length] == 'o' ^ builder[i] == 'W') { // same builder.Append(builder[i - 1]); } else { // diff builder.Append(builder[i - 1] == 'W' ? 'S' : 'W'); } } for (int i = 0; i + s.Length < builder.Length; i++) { if (builder[i] != builder[i + s.Length]) return null; } return builder.ToString().Substring(0, s.Length); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main() { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) { Console.SetIn(reader); new Solver(Console.In, Console.Out).Run(); } #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { [Conditional("DEBUG")] public static void Dump<T>(this T obj) { #if DEBUG LINQPad.Extensions.Dump(obj); #endif } } public class Scanner { private readonly TextReader Reader; private readonly CultureInfo ci = CultureInfo.InvariantCulture; private readonly char[] buffer = new char[2 * 1024]; private int cursor = 0, length = 0; private string Token; private readonly StringBuilder sb = new StringBuilder(1024); public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return checked((int)NextLong()); } public long NextLong() { var s = Next(); long r = 0; int i = 0; bool negative = false; if (s[i] == '-') { negative = true; i++; } for (; i < s.Length; i++) { r = r * 10 + (s[i] - '0'); #if DEBUG if (!char.IsDigit(s[i])) throw new FormatException(); #endif } return negative ? -r : r; } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (Token == null) { if (!StockToken()) { throw new Exception(); } } var token = Token; Token = null; return token; } public bool HasNext() { if (Token != null) { return true; } return StockToken(); } private bool StockToken() { while (true) { sb.Clear(); while (true) { if (cursor >= length) { cursor = 0; if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) { break; } } var c = buffer[cursor++]; if (33 <= c && c <= 126) { sb.Append(c); } else { if (sb.Length > 0) break; } } if (sb.Length > 0) { Token = sb.ToString(); return true; } return false; } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 109], ["+", 206, 207, 0, 28, 0, 16, 12, 214, 205, 22], ["+", 206, 207, 0, 28, 0, 16, 12, 214, 0, 131], ["+", 206, 207, 0, 28, 0, 16, 12, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 41, 64, 252, 0, 253], ["+", 3, 4, 0, 28, 0, 41, 64, 252, 0, 253], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 72], ["+", 0, 7, 15, 16, 31, 16, 12, 214, 205, 22], ["+", 0, 7, 15, 16, 31, 16, 12, 214, 0, 131], ["+", 0, 7, 15, 16, 31, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 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, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
1,298
42
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderRegularContest069 { public class Program { static void Main(string[] args) { Console.WriteLine( program1(new String[] { Console.ReadLine(), Console.ReadLine() })); } public static string program1(string[] args) { var n = int.Parse(args[0]); var s = args[1].ToCharArray(); var animalPattern = new List<char>[] { new List<char>() { 'S', 'S' }, new List<char> { 'S', 'W' }, new List<char> { 'W', 'W' }, new List<char> { 'W', 'S' } }; return string.Join( "", animalPattern .Where(animals => { return animals.First() == s.Skip(1).Aggregate(animals.First(), (ani, ans) => { var current = animals.Last(); if (ans == 'o' && current == 'S' || ans == 'x' && current == 'W') { animals.Add(ani); } else { animals.Add(ani == 'S' ? 'W' : 'S'); } return current; }); }) .Select(animals => animals.Take(n)) .FirstOrDefault(animals => { if (s.First() == 'o' && animals.First() == 'S' || s.First() == 'x' && animals.First() == 'W') { return animals.ElementAt(1) == animals.Last(); } else { return animals.ElementAt(1) != animals.Last(); } }) ?? new List<char>() { '-', '1' }); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderRegularContest069 { public class Program { static void Main(string[] args) { Console.WriteLine( program1(new String[] { Console.ReadLine(), Console.ReadLine() })); } public static string program1(string[] args) { var n = int.Parse(args[0]); var s = args[1].ToCharArray(); var animalPattern = new List<char>[] { new List<char>() { 'S', 'S' }, new List<char> { 'S', 'W' }, new List<char> { 'W', 'W' }, new List<char> { 'W', 'S' } }; return string.Join( "", animalPattern .Where(animals => { s.Skip(1).Aggregate(animals.First(), (ani, ans) => { var current = animals.Last(); if (ans == 'o' && current == 'S' || ans == 'x' && current == 'W') { animals.Add(ani); } else { animals.Add(ani == 'S' ? 'W' : 'S'); } return current; }); return animals.First() == animals.Last(); }) .Select(animals => animals.Take(n)) .FirstOrDefault(animals => { if (s.First() == 'o' && animals.First() == 'S' || s.First() == 'x' && animals.First() == 'W') { return animals.ElementAt(1) == animals.Last(); } else { return animals.ElementAt(1) != animals.Last(); } }) ?? new List<char>() { '-', '1' }); } } }
[["-", 0, 28, 0, 218, 8, 196, 0, 37, 0, 38], ["-", 0, 37, 0, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 37, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 37, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 37, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 37, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 218, 8, 196, 0, 37, 0, 16, 17, 60], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 218, 8, 196, 0, 1, 0, 35], ["+", 0, 28, 0, 218, 8, 196, 0, 37, 0, 38], ["+", 0, 37, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 37, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 37, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 37, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 37, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 218, 8, 196, 0, 37, 0, 16, 17, 60], ["+", 0, 37, 0, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 37, 0, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 37, 0, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 37, 0, 16, 12, 213, 3, 4, 0, 24]]
8
416
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { long N = GetLong(); var a = GetLongs(N); var list = new List<(long, long)>(); list.Add((-1, 0)); for (long i = 0; i < N; i++) list.Add((i, a[i])); var grps = list.GroupBy(x => x.Item2).ToList(); grps.Sort((x, y) => y.Key.CompareTo(x.Key)); var ans = new long[N]; long cnt = 0; for (int i = 0; i < grps.Count - 1; i++) { long idx = grps[i].Min(x => x.Item1); cnt += grps[i].Count(); ans[idx] += cnt * (grps[i].Key - grps[i + 1].Key); } WriteLine(string.Join("\n", ans)); } } public static class MyIO { private static string[] args = new string[0]; private static int cnt = 0; private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg()); private static string getArg() { if (cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; } return args[cnt++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray(); public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray(); public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray(); public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray(); public static string[] GetStrings(long N) => getArgs(N).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } public static long rightShift(long x, long y) => (x >> (int)y); public static long leftShift(long x, long y) => (x << (int)y); public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L; public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y); public static long lcm(long x, long y) => (x / gcd(x, y)) * y; public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count); public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal); }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { long N = GetLong(); var a = GetLongs(N); var list = new List<(long, long)>(); list.Add((-1, 0)); for (long i = 0; i < N; i++) list.Add((i, a[i])); var grps = list.GroupBy(x => x.Item2).ToList(); grps.Sort((x, y) => y.Key.CompareTo(x.Key)); var ans = new long[N]; long cnt = 0; long minIdx = long.MaxValue; for (int i = 0; i < grps.Count - 1; i++) { chmin(ref minIdx, grps[i].Min(x => x.Item1)); cnt += grps[i].Count(); ans[minIdx] += cnt * (grps[i].Key - grps[i + 1].Key); } WriteLine(string.Join("\n", ans)); } } public static class MyIO { private static string[] args = new string[0]; private static int cnt = 0; private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg()); private static string getArg() { if (cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; } return args[cnt++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray(); public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray(); public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray(); public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray(); public static string[] GetStrings(long N) => getArgs(N).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } public static long rightShift(long x, long y) => (x >> (int)y); public static long leftShift(long x, long y) => (x << (int)y); public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L; public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y); public static long lcm(long x, long y) => (x / gcd(x, y)) * y; public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count); public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal); }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 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, 7, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 275], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22]]
8
893
18
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ARC069.E(); } class ARC069 { public static void C() { var N = Read.Long(); var M = Read.Long(); long scc1 = Math.Min(N, M / 2); long scc2 = (M - scc1 * 2) / 4; Console.WriteLine(scc1 + scc2); } public static void D() { var N = Read.Int(); var S = Read.Str(); Func<bool, bool, bool[]> func = (S0, S1) => { var X = new bool[N]; X[0] = S0; X[1] = S1; for (int i = 2; i < N; ++i) { X[i] = S[i - 1] == 'o' ^ X[i - 1] ^ X[i - 2]; } if (X[0] != (S[N - 1] == 'o' ^ X[N - 1] ^ X[N - 2])) { return null; } if (X[1] != (S[0] == 'o' ^ X[0] ^ X[N - 1])) { return null; } return X; }; var res = func(true, true); if (res == null) { res = func(true, false); } if (res == null) { res = func(false, true); } if (res == null) { res = func(false, false); } if (res == null) { Console.WriteLine(-1); return; } Console.WriteLine(String.Join("", res.Select(x => x ? "S" : "W"))); } public static void E() { var N = Read.Int(); var A = Read.LongN(); List<long> list1 = new List<long>(); List<int> list2 = new List<int>(); long max = 0; for (int i = 0; i < N; ++i) { if (A[i] > max) { list1.Add(A[i]); list2.Add(i); max = A[i]; } } long[] ans = new long[list1.Count]; int[] count = new int[list1.Count]; for (int i = 0; i < N; ++i) { var a = A[i]; var idx = Bound.Lowerbound(list1, a); if (list1[idx] > a) { ans[idx] += a - list1[idx - 1]; count[idx - 1]++; } else { count[idx]++; } } int cum = 0; for (int i = list1.Count - 1; i >= 0; --i) { cum += count[i]; ans[i] += cum * (list1[i] - (i > 0 ? list1[i - 1] : 0)); } var dict = new Dictionary<int, int>(); for (int i = 0; i < list1.Count; ++i) { dict.Add(list2[i], i); } var sb = new System.Text.StringBuilder(); for (int i = 0; i < N; ++i) { sb.AppendLine((dict.ContainsKey(i) ? ans[dict[i]] : 0).ToString()); } Console.Write(sb.ToString()); } } class Util {} class Bound { public static int Lowerbound<T>(IList<T> list, T x) where T : IComparable<T> { int min = 0; int max = list.Count; while (min < max) { var mid = (min + max) / 2; if (list[mid].CompareTo(x) >= 0) { max = mid; } else { min = mid + 1; } } return max; } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); if (!isDirectional) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ARC069.E(); } class ARC069 { public static void C() { var N = Read.Long(); var M = Read.Long(); long scc1 = Math.Min(N, M / 2); long scc2 = (M - scc1 * 2) / 4; Console.WriteLine(scc1 + scc2); } public static void D() { var N = Read.Int(); var S = Read.Str(); Func<bool, bool, bool[]> func = (S0, S1) => { var X = new bool[N]; X[0] = S0; X[1] = S1; for (int i = 2; i < N; ++i) { X[i] = S[i - 1] == 'o' ^ X[i - 1] ^ X[i - 2]; } if (X[0] != (S[N - 1] == 'o' ^ X[N - 1] ^ X[N - 2])) { return null; } if (X[1] != (S[0] == 'o' ^ X[0] ^ X[N - 1])) { return null; } return X; }; var res = func(true, true); if (res == null) { res = func(true, false); } if (res == null) { res = func(false, true); } if (res == null) { res = func(false, false); } if (res == null) { Console.WriteLine(-1); return; } Console.WriteLine(String.Join("", res.Select(x => x ? "S" : "W"))); } public static void E() { var N = Read.Int(); var A = Read.LongN(); List<long> list1 = new List<long>(); List<int> list2 = new List<int>(); long max = 0; for (int i = 0; i < N; ++i) { if (A[i] > max) { list1.Add(A[i]); list2.Add(i); max = A[i]; } } long[] ans = new long[list1.Count]; int[] count = new int[list1.Count]; for (int i = 0; i < N; ++i) { var a = A[i]; var idx = Bound.Lowerbound(list1, a); if (list1[idx] > a) { ans[idx] += a - (idx > 0 ? list1[idx - 1] : 0); if (idx > 0) { count[idx - 1]++; } } else { count[idx]++; } } int cum = 0; for (int i = list1.Count - 1; i >= 0; --i) { cum += count[i]; ans[i] += cum * (list1[i] - (i > 0 ? list1[i - 1] : 0)); } var dict = new Dictionary<int, int>(); for (int i = 0; i < list1.Count; ++i) { dict.Add(list2[i], i); } var sb = new System.Text.StringBuilder(); for (int i = 0; i < N; ++i) { sb.AppendLine((dict.ContainsKey(i) ? ans[dict[i]] : 0).ToString()); } Console.Write(sb.ToString()); } } class Util {} class Bound { public static int Lowerbound<T>(IList<T> list, T x) where T : IComparable<T> { int min = 0; int max = list.Count; while (min < max) { var mid = (min + max) / 2; if (list[mid].CompareTo(x) >= 0) { max = mid; } else { min = mid + 1; } } return max; } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); if (!isDirectional) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 12, 16, 12, 23, 0, 41, 15, 16, 31, 22], ["+", 12, 16, 12, 23, 0, 41, 15, 16, 17, 47], ["+", 12, 16, 12, 23, 0, 41, 15, 16, 12, 203], ["+", 0, 11, 12, 16, 12, 23, 0, 41, 0, 101], ["+", 0, 11, 12, 16, 12, 23, 0, 41, 0, 102], ["+", 0, 11, 12, 16, 12, 23, 0, 41, 75, 203], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["+", 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, 47], ["+", 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, 57, 64, 196, 0, 46]]
8
1,963
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static void Main() { Sc sc = new Sc(); int n = sc.I; int[] a = sc.Ia; var hs = new SortedDictionary<int, int[]> { [0] = new int[] { 0, 0 } }; for (int i = 0; i < n; i++) { if (!hs.ContainsKey(a[i])) { hs.Add(a[i], new int[] { i, 1 }); } else { hs[a[i]][1]++; } } long k = 0, m = 0, p = 0; long[] ans = new long[n]; foreach (KeyValuePair<int, int[]> e in hs.Reverse()) { if (k != 0) { ans[m] = (k - e.Key) * p; } k = e.Key; m = e.Value[0]; p += e.Value[1]; } Console.WriteLine(String.Join("\n", ans)); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static void Main() { Sc sc = new Sc(); int n = sc.I; int[] a = sc.Ia; var hs = new SortedDictionary<int, int[]> { [0] = new int[] { -1, 0 } }; for (int i = 0; i < n; i++) { if (!hs.ContainsKey(a[i])) { hs.Add(a[i], new int[] { i, 1 }); } else { hs[a[i]][1]++; } } long k = 0, m = int.MaxValue, p = 0; long[] ans = new long[n]; foreach (KeyValuePair<int, int[]> e in hs.Reverse()) { if (k != 0) { ans[m] += (k - e.Key) * p; } k = e.Key; m = Math.Min(m, e.Value[0]); p += e.Value[1]; } Console.WriteLine(String.Join("\n", ans)); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
[["-", 10, 229, 0, 11, 12, 227, 0, 229, 0, 203], ["+", 0, 11, 12, 227, 0, 229, 0, 241, 0, 33], ["+", 0, 11, 12, 227, 0, 229, 0, 241, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
531
16
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); // static Scan sc = new ScanCHK(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n = sc.Int; var a = sc.LongArr; var cp = a.copy(); var indlis = new List<long>(); var lis = new List<long>(); long max = 0; for (int i = 0; i < n; i++) { if (max < a[i]) { max = a[i]; indlis.Add(i); lis.Add(a[i]); } } Array.Sort(cp); var sum = new long[n + 1]; for (int i = 0; i < n; i++) { sum[i + 1] = sum[i] + cp[i]; } var ans = new long[n]; for (int i = 0; i < lis.Count; i++) { if (i == 0 && i == lis.Count - 1) { ans[indlis[i]] = sum[n]; continue; } if (i == 0) { ans[indlis[i]] = lis[i] * n; continue; } int l = Search.LowerBound(cp, lis[i - 1]); int r = Search.LowerBound(cp, lis[i]); ans[indlis[i]] = sum[n] - sum[l] - (n - l) * lis[i - 1] - (sum[n] - sum[r] - (n - r) * lis[i]); } foreach (var item in ans) { Prt(item); } sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { Console.WriteLine(string.Join(" ", a)); } static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); } static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } } 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(); // static Scan sc = new ScanCHK(); const int M = 1000000007; const double eps = 1e-9; static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n = sc.Int; var a = sc.LongArr; var cp = a.copy(); var indlis = new List<long>(); var lis = new List<long>(); long max = 0; for (int i = 0; i < n; i++) { if (max < a[i]) { max = a[i]; indlis.Add(i); lis.Add(a[i]); } } Array.Sort(cp); var sum = new long[n + 1]; for (int i = 0; i < n; i++) { sum[i + 1] = sum[i] + cp[i]; } var ans = new long[n]; for (int i = 0; i < lis.Count; i++) { if (i == 0 && i == lis.Count - 1) { ans[indlis[i]] = sum[n]; continue; } if (i == 0) { int aa = Search.LowerBound(cp, lis[i]); ans[indlis[i]] = sum[aa] + (n - aa) * lis[i]; continue; } int l = Search.LowerBound(cp, lis[i - 1]); int r = Search.LowerBound(cp, lis[i]); ans[indlis[i]] = sum[n] - sum[l] - (n - l) * lis[i - 1] - (sum[n] - sum[r] - (n - r) * lis[i]); } foreach (var item in ans) { Prt(item); } sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } static void DBG<T>(IEnumerable<T> a) { Console.WriteLine(string.Join(" ", a)); } static void DBG(params object[] a) { Console.WriteLine(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } static void Prt<T>(IEnumerable<T> a) { sw.WriteLine(string.Join(" ", a)); } static void Prt(params object[] a) { sw.WriteLine(string.Join(" ", a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class ScanCHK : Scan { public new string Str { get { var s = Console.ReadLine(); if (s != s.Trim()) throw new Exception(); return s; } } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } } 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; } }
[["+", 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, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 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, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 11, 12, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 12, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
3,540
28
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Globalization; using System.Diagnostics; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().Solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; void Solve() { int N = cin.Nextint; var A = cin.Scanlong; var C = Enumerable.Range(0, N).ToArray(); var G = A.Select((x, y) => new { x, y }) .OrderByDescending(z => z.x) .ThenByDescending(z => z.y) .ToArray(); var ans = new long[N]; int min = G[0].y; for (int i = 1; i < N; i++) { ans[min] += i * (G[i - 1].x - G[i].x); min = Math.Min(min, G[i].y); } ans[0] = A.Sum() - ans.Sum(); foreach (var v in ans) { WriteLine(v); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] Scan { get { return ReadLine().Split(); } } public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } } public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } } public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } } public string Next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next; } } public int Nextint { get { return int.Parse(Next); } } public long Nextlong { get { return long.Parse(Next); } } public double Nextdouble { get { return double.Parse(Next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Globalization; using System.Diagnostics; using static System.Console; using Pair = System.Collections.Generic.KeyValuePair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().Solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; readonly int mod = 1000000007; readonly string alfa = "abcdefghijklmnopqrstuvwxyz"; void Solve() { int N = cin.Nextint; var A = cin.Scanlong; var C = Enumerable.Range(0, N).ToArray(); var G = A.Select((x, y) => new { x, y }) .OrderByDescending(z => z.x) .ThenByDescending(z => z.y) .ToArray(); var ans = new long[N]; int min = G[0].y; for (int i = 1; i < N; i++) { ans[min] += i * (G[i - 1].x - G[i].x); min = Math.Min(min, G[i].y); } ans[0] = A.Sum() - (ans.Sum() - ans[0]); foreach (var v in ans) { WriteLine(v); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] Scan { get { return ReadLine().Split(); } } public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } } public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } } public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } } public string Next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next; } } public int Nextint { get { return int.Parse(Next); } } public long Nextlong { get { return long.Parse(Next); } } public double Nextdouble { get { return double.Parse(Next); } } }
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73]]
8
562
7
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int n = sc.nextInt(); long[] ls = sc.nextLong(n); long[] ans = new long[n]; Dictionary<long, List<int>> dic = new Dictionary<long, List<int>>(); // val,no HashSet<long> set = new HashSet<long>(); // no for (int i = 0; i < n; i++) { set.Add(ls[i]); if (dic.ContainsKey(ls[i]) == false) { dic.Add(ls[i], new List<int>()); } dic[ls[i]].Add(i); } long[] valls = set.ToArray(); Array.Sort(valls); long cnt = 0; for (int i = valls.Length - 1; i >= 0; i--) { long val = valls[i]; int no = dic[val][0]; if (no == 0) { for (int j = 0; j < n; j++) { ans[0] -= ans[j]; ans[0] += ls[j]; } break; } else { long nextval = valls[i - 1]; cnt += dic[val].Count; ans[no] += cnt * (val - nextval); } } for (int i = 0; i < n; i++) { pr.WriteLine(ans[i]); } } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } } class HashMap<K, V> : Dictionary<K, V> { new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = default(V); } set { base[i] = value; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; // using System.Numerics; //comment out if AOJ using System.Text; using Problem = Tmp.Problem; using MyIO; #pragma warning disable // for AOJ namespace Tmp { class Problem : IDisposable { bool IsGCJ; int Repeat; Scanner sc; Printer pr; public Problem(bool isGCJ, Scanner scanner, Printer printer) { sc = scanner; pr = printer; IsGCJ = isGCJ; if (isGCJ) Repeat = sc.nextInt(); else Read(); } public Problem(bool isGCJ) : this(isGCJ, new Scanner(), new Printer()) {} public Problem(bool isGCJ, Scanner scanner) : this(isGCJ, scanner, new Printer()) {} public Problem(bool isGCJ, Printer printer) : this(isGCJ, new Scanner(), printer) {} public void Solve() { if (IsGCJ) for (var i = 0; i < Repeat; i++) { Read(); pr.Write("Case #" + (i + 1) + ": "); SolveOne(); } else SolveOne(); } public void Dispose() { sc.Dispose(); pr.Dispose(); } public int Size { get { return 1; } } public const long Mod = 1000000007; // 使用する変数をここに書く // string S; // int a; /// <summary> /// 読み込み処理をここに書く /// </summary> void Read() {} /// <summary> /// メイン処理をここに書く /// </summary> void SolveOne() { int n = sc.nextInt(); long[] ls = sc.nextLong(n); long[] ans = new long[n]; Dictionary<long, List<int>> dic = new Dictionary<long, List<int>>(); // val,no HashSet<long> set = new HashSet<long>(); // no for (int i = 0; i < n; i++) { set.Add(ls[i]); if (dic.ContainsKey(ls[i]) == false) { dic.Add(ls[i], new List<int>()); } dic[ls[i]].Add(i); } long[] valls = set.ToArray(); Array.Sort(valls); long cnt = 0; int no = n - 1; for (int i = valls.Length - 1; i >= 0; i--) { long val = valls[i]; no = Math.Min(no, dic[val][0]); if (no == 0) { for (int j = 0; j < n; j++) { ans[0] -= ans[j]; ans[0] += ls[j]; } break; } else { long nextval = valls[i - 1]; cnt += dic[val].Count; ans[no] += cnt * (val - nextval); } } for (int i = 0; i < n; i++) { pr.WriteLine(ans[i]); } } } } class Program { // public static RandomSFMT rand = new RandomSFMT(); public static bool IsJudgeMode = true; public static bool IsGCJMode = false; public static bool IsSolveCreated = true; static void Main() { if (IsJudgeMode) if (IsGCJMode) using (var problem = new Problem(true, new Scanner("C-large-practice.in.txt"), new Printer("output.txt"))) problem.Solve(); else using (var problem = new Problem(false, new Printer())) problem.Solve(); else { var num = 1; int size = 0; decimal time = 0; for (var tmp = 0; tmp < num; tmp++) { using (var P = IsSolveCreated ? new Problem(false, new Scanner("input.txt"), new Printer()) : new Problem(false)) { size = P.Size; // time += Func.MeasureTime(() => P.Solve()); } } Console.WriteLine("{0}, {1}ms", size, time / num); } } } /// <summary> /// カスタマイズしたIO /// </summary> namespace MyIO { class Printer : IDisposable { bool isConsole; TextWriter file; public Printer() { file = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; isConsole = true; } public Printer(string path) { file = new StreamWriter(path, false) { AutoFlush = false }; isConsole = false; } public void Write<T>(T value) { file.Write(value); } public void Write(bool b) { file.Write(b ? "YES" : "NO"); } public void Write(string str, params object[] args) { file.Write(str, args); } public void WriteLine() { file.WriteLine(); } public void WriteLine<T>(T value) { file.WriteLine(value); } public void WriteLine(bool b) { file.WriteLine(b ? "YES" : "NO"); } public void WriteLine<T>(IEnumerable<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(List<T> list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine<T>(T[] list) { foreach (var x in list) file.WriteLine(x); } public void WriteLine(string str, params object[] args) { file.WriteLine(str, args); } public void Dispose() { file.Flush(); if (!isConsole) file.Dispose(); } } class Scanner : IDisposable { bool isConsole; TextReader file; public Scanner() { file = Console.In; } public Scanner(string path) { file = new StreamReader(path); isConsole = false; } public void Dispose() { if (!isConsole) file.Dispose(); } #region next読み込み string[] nextBuffer = new string[0]; int BufferCnt = 0; char[] cs = new char[] { ' ' }; public string next() { while (BufferCnt >= nextBuffer.Length) { string st = file.ReadLine(); while (st == "") st = file.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; } return nextBuffer[BufferCnt++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } private T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public string[] next(int n) { return enumerate(n, next); } public double[] nextDouble(int n) { return enumerate(n, nextDouble); } public int[] nextInt(int n) { return enumerate(n, nextInt); } public long[] nextLong(int n) { return enumerate(n, nextLong); } #endregion } } class HashMap<K, V> : Dictionary<K, V> { new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = default(V); } set { base[i] = value; } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 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, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
1,541
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ARC069 { public class E { private void Run() { var N = int.Parse(Console.ReadLine().Trim()); var A = Console.ReadLine() .Trim() .Split() .Select((s, i) => new { index = i, value = long.Parse(s) }) .OrderByDescending(x => x.value) .ThenByDescending(x => x.index) .ToArray(); var results = new long[N]; int minIndex = A[0].index; int index = 0; while (index < A.Length && A[index].value == A[index + 1].value) { index++; } long count = index + 1; while (index + 1 < A.Length) { int prevMinIndex = minIndex; int sameValueLastIndex = index + 1; minIndex = Math.Min(minIndex, A[sameValueLastIndex].index); while (sameValueLastIndex + 1 < A.Length && A[sameValueLastIndex].value == A[sameValueLastIndex + 1].value) { sameValueLastIndex += 1; minIndex = Math.Min(minIndex, A[sameValueLastIndex].index); } long nextValue = A[sameValueLastIndex].value; results[prevMinIndex] += (A[index].value - nextValue) * count; count += sameValueLastIndex - index; index = sameValueLastIndex; } results[minIndex] += A.Last().value * count; foreach (var result in results) { Console.WriteLine(result); } } public static void Main() { var old = Console.Out; using (var writer = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }) { Console.SetOut(writer); new E().Run(); Console.Out.Flush(); Console.SetOut(old); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ARC069 { public class E { private void Run() { var N = int.Parse(Console.ReadLine().Trim()); var A = Console.ReadLine() .Trim() .Split() .Select((s, i) => new { index = i, value = long.Parse(s) }) .OrderByDescending(x => x.value) .ThenByDescending(x => x.index) .ToArray(); var results = new long[N]; int index = 0; while (index + 1 < A.Length && A[index].value == A[index + 1].value) { index++; } int minIndex = A[index].index; long count = index + 1; while (index + 1 < A.Length) { int prevMinIndex = minIndex; int sameValueLastIndex = index + 1; minIndex = Math.Min(minIndex, A[sameValueLastIndex].index); while (sameValueLastIndex + 1 < A.Length && A[sameValueLastIndex].value == A[sameValueLastIndex + 1].value) { sameValueLastIndex += 1; minIndex = Math.Min(minIndex, A[sameValueLastIndex].index); } long nextValue = A[sameValueLastIndex].value; results[prevMinIndex] += (A[index].value - nextValue) * count; count += sameValueLastIndex - index; index = sameValueLastIndex; } results[minIndex] += A.Last().value * count; foreach (var result in results) { Console.WriteLine(result); } } public static void Main() { var old = Console.Out; using (var writer = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }) { Console.SetOut(writer); new E().Run(); Console.Out.Flush(); Console.SetOut(old); } } } }
[["-", 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, 214, 205, 204, 205, 22], ["-", 0, 212, 0, 214, 205, 204, 206, 207, 0, 70], ["-", 0, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 214, 205, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 52, 15, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 52, 15, 16, 31, 16, 31, 16, 12, 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, 200, 0, 212, 0, 214, 205, 204, 205, 22], ["+", 0, 212, 0, 214, 205, 204, 206, 207, 0, 70], ["+", 0, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
8
407
22
using System; namespace abc054A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); int B = int.Parse(str[1]); if (A > B && B != 1) Console.WriteLine("Alice"); else if (A < B && A != 1) Console.WriteLine("Bob"); else if (A == 1) Console.WriteLine("Alice"); else if (B == 1) Console.WriteLine("Bob"); else if (A == B) Console.WriteLine("Draw"); } } }
using System; namespace abc054A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); int B = int.Parse(str[1]); if (A > B && B != 1) Console.WriteLine("Alice"); else if (A < B && A != 1) Console.WriteLine("Bob"); else if (A == B) Console.WriteLine("Draw"); else if (A == 1) Console.WriteLine("Alice"); else if (B == 1) Console.WriteLine("Bob"); } } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 75, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["-", 75, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 12, 203]]
8
151
14
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var AB = ReadIntArray(); if (AB[0] == AB[1]) { Console.WriteLine("Draw"); } else if (AB[0] == 1 || AB[0] > AB[1]) { Console.WriteLine("Alice"); } else { Console.WriteLine("Bob"); } } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var AB = ReadIntArray(); if (AB[0] == AB[1]) { Console.WriteLine("Draw"); } else if (AB[0] == 1 || (AB[0] > AB[1] && AB[1] != 1)) { Console.WriteLine("Alice"); } else { Console.WriteLine("Bob"); } } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
[["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 24], ["+", 75, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 12, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 79], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 57, 15, 16, 12, 23, 0, 25]]
8
300
9
using System; using System.Collections.Generic; using System.Linq; using static AtCoder.Io; namespace AtCoder { class Program { static void Main() { var ab = ReadIntArray(); var a = ab[0]; var b = ab[1]; Console.WriteLine(a == b ? "Draw" : a > b ? "Alice" : "Bob"); } } public static class Io { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static long ReadLong() => long.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse); public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse); } }
using System; using System.Collections.Generic; using System.Linq; using static AtCoder.Io; namespace AtCoder { class Program { static void Main() { var ab = ReadIntArray(); var a = ab[0]; var b = ab[1]; a = a == 1 ? 14 : a; b = b == 1 ? 14 : b; Console.WriteLine(a == b ? "Draw" : a > b ? "Alice" : "Bob"); } } public static class Io { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static long ReadLong() => long.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse); public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse); } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 75, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
247
20
using System; using System.Linq; class c { public static void Main() { int[] ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int a = ab[0]; int b = ab[1]; if ((a > b && b != 1) || (a == 1)) Console.WriteLine("Alice"); else Console.WriteLine("Bob"); } }
using System; using System.Linq; class c { public static void Main() { int[] ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int a = ab[0]; int b = ab[1]; if (a == b) Console.WriteLine("Draw"); else if ((a > b && b != 1) || (a == 1)) Console.WriteLine("Alice"); else Console.WriteLine("Bob"); } }
[["+", 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, 22], ["+", 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, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 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, 57, 0, 121], ["+", 0, 57, 75, 57, 15, 16, 31, 23, 0, 24]]
8
102
16
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 AB = ReadSplitInt(); if (AB[0] == 1) AB[0] = 14; if (AB[1] == 1) AB[1] = 14; if (AB[0] == AB[1]) Println("Draw"); else if (AB[0] < AB[1]) Println("Alice"); else Println("Bob"); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static void YESOrNO(bool e) => Println(e ? "YES" : "NO"); static void YesOrNo(bool e) => Println(e ? "Yes" : "No"); 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); } } }
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 AB = ReadSplitInt(); if (AB[0] == 1) AB[0] = 14; if (AB[1] == 1) AB[1] = 14; if (AB[0] == AB[1]) Println("Draw"); else if (AB[0] < AB[1]) Println("Bob"); else Println("Alice"); } static List<long> ReadLines(long n) { var l = new List<long>(); for (long i = 0; i < n; i++) { l.Add(ReadLong()); } return l; } static void YESOrNO(bool e) => Println(e ? "YES" : "NO"); static void YesOrNo(bool e) => Println(e ? "Yes" : "No"); 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); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
759
4
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; public class A { public static void Main() { int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); if (a == 1 || b == 1) { if (a == b) { Console.WriteLine("Draw"); } else if (a == 1) { Console.WriteLine("Alice"); } else if (b == 1) { Console.WriteLine("Bob"); } } else { if (a == b) { Console.WriteLine("Draw"); } else if (a > b) { Console.WriteLine("Alice"); } else if (b > a) { Console.WriteLine("Bob"); } } } }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; public class Program { public static void Main() { var x = Console.ReadLine().Split(); int a = int.Parse(x[0]); int b = int.Parse(x[1]); if (a == 1 || b == 1) { if (a == b) { Console.WriteLine("Draw"); } else if (a == 1) { Console.WriteLine("Alice"); } else if (b == 1) { Console.WriteLine("Bob"); } } else { if (a == b) { Console.WriteLine("Draw"); } else if (a > b) { Console.WriteLine("Alice"); } else if (b > a) { Console.WriteLine("Bob"); } } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 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, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 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, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
187
33
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B_007_54 { internal class Program { private static void Main(string[] args) { new Logic_A().Start(); // } public class Logic_A { public void Start() { var str = Console.ReadLine().Split(' '); var A = Convert.ToInt32(str[0]); var B = Convert.ToInt32(str[1]); if (A == B) { Console.WriteLine("Draw"); return; } if (A == 1 && B != 1) { Console.WriteLine("Alice"); } else if (A != 1 && B == 1) { Console.WriteLine("Bob"); } else { if (A > B) { Console.WriteLine(A > B ? "Alice" : "Bob"); } } } } } }
using System; namespace B_007_54 { internal class Program { private static void Main(string[] args) { new Logic_A().Start(); // } public class Logic_A { public void Start() { var str = Console.ReadLine().Split(' '); var A = Convert.ToInt32(str[0]); var B = Convert.ToInt32(str[1]); if (A == B) { Console.WriteLine("Draw"); return; } if (A == 1 && B != 1) { Console.WriteLine("Alice"); } else if (A != 1 && B == 1) { Console.WriteLine("Bob"); } else { Console.WriteLine(A > B ? "Alice" : "Bob"); } } } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 0, 57, 75, 57, 75, 196, 0, 57, 0, 121], ["-", 0, 57, 75, 57, 75, 196, 0, 57, 0, 24], ["-", 75, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["-", 75, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["-", 75, 57, 75, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 57, 75, 57, 75, 196, 0, 57, 0, 25], ["-", 75, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["-", 75, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
8
202
32
using System; public class Program { static void Main(string[] args) { args = Console.ReadLine().Split(' '); int b = int.Parse(args[0]); int a = int.Parse(args[1]); a += (a == 1 ? 13 : a); b += (b == 1 ? 13 : b); Console.WriteLine(a > b ? "Alice" : a < b ? "Bob" : "Draw"); } }
using System; class Program { static void Main(string[] args) { args = Console.ReadLine().Split(' '); int a = int.Parse(args[0]); int b = int.Parse(args[1]); a = (a == 1 ? 14 : a); b = (b == 1 ? 14 : b); Console.WriteLine(a > b ? "Alice" : a < b ? "Bob" : "Draw"); } }
[["-", 36, 36, 0, 208, 0, 235, 0, 251, 0, 259], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 23, 0, 41, 64, 203], ["+", 0, 1, 0, 11, 12, 23, 0, 41, 64, 203]]
8
109
13
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace ABC { public class Program { public static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var ab = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = ab[0]; int b = ab[1]; if (a > b) { Console.WriteLine("Alice"); } else if (a < b) { Console.WriteLine("Bob"); } else { Console.WriteLine("Draw"); } Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace ABC { public class Program { public static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var ab = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = ab[0]; int b = ab[1]; if (a == 1) a = 100; if (b == 1) b = 100; if (a > b) { Console.WriteLine("Alice"); } else if (a < b) { Console.WriteLine("Bob"); } else { Console.WriteLine("Draw"); } Console.Out.Flush(); } } }
[["+", 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, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 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]]
8
156
20
using System; using System.Collections.Generic; using System.Linq; using static AtCoder.Io; namespace AtCoder { class Program { static void Main() { var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var a = new List<string>(); var b = new List<string>(); for (var i = 0; i < n; i++) { a.Add(ReadString()); } for (var i = 0; i < m; i++) { b.Add(ReadString()); } for (var i = 0; i <= a.Count - b.Count; i++) { var index = a[i].IndexOf(b[0]); while (index >= 0) { if (Enumerable.Range(0, b.Count) .All(v => a[i + v].IndexOf(b[v]) == index)) { Console.WriteLine("Yes"); return; } index = a[i].IndexOf(b[0], index + 1); } } Console.WriteLine("No"); } } public static class Io { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static long ReadLong() => long.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse); public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse); } }
using System; using System.Collections.Generic; using System.Linq; using static AtCoder.Io; namespace AtCoder { class Program { static void Main() { var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var a = new List<string>(); var b = new List<string>(); for (var i = 0; i < n; i++) { a.Add(ReadString()); } for (var i = 0; i < m; i++) { b.Add(ReadString()); } for (var i = 0; i <= a.Count - b.Count; i++) { var from = 0; var index = a[i].IndexOf(b[0], from); while (index >= 0) { if (Enumerable.Range(0, b.Count) .All(v => a[i + v].IndexOf(b[v], from) == index)) { Console.WriteLine($"Yes"); return; } from = index + 1; index = a[i].IndexOf(b[0], from); } } Console.WriteLine("No"); } } public static class Io { public static string ReadString() => Console.ReadLine(); public static string[] ReadStringArray() => ReadString().Split(' '); public static int ReadInt() => int.Parse(ReadString()); public static long ReadLong() => long.Parse(ReadString()); public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray(); public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray(); public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse); public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse); } }
[["+", 0, 197, 0, 198, 0, 200, 141, 22, 0, 314], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 22, 0, 314], ["+", 0, 218, 8, 16, 31, 213, 3, 4, 0, 21], ["+", 31, 213, 3, 4, 0, 28, 0, 22, 0, 314], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["+", 8, 196, 0, 1, 0, 11, 31, 22, 0, 314], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 12, 213, 3, 4, 0, 28, 0, 22, 0, 314]]
8
416
21
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var p = Input().ToInt(); var n = p[0]; var m = p[1]; string[] a = new string[n]; string[] b = new string[m]; for (int i = 0; i < n; i++) { a[i] = Console.ReadLine(); } for (int i = 0; i < m; i++) { b[i] = Console.ReadLine(); } for (int i = 0; i < n; i++) { for (int k = 0; k < n; k++) { bool match = true; for (int j = 0; j < m; j++) { for (int l = 0; l < m; l++) { if (i + j >= n || k + l >= n) continue; if (a[i + j][k + l] != b[j][l]) { match = false; break; } } if (!match) break; } if (match) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static long Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } 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 static void Main(string[] args) { var p = Input().ToInt(); var n = p[0]; var m = p[1]; string[] a = new string[n]; string[] b = new string[m]; for (int i = 0; i < n; i++) { a[i] = Console.ReadLine(); } for (int i = 0; i < m; i++) { b[i] = Console.ReadLine(); } for (int i = 0; i < n; i++) { for (int k = 0; k < n; k++) { if (i + m - 1 >= n || k + m - 1 >= n) continue; bool match = true; for (int j = 0; j < m; j++) { for (int l = 0; l < m; l++) { if (a[i + j][k + l] != b[j][l]) { match = false; break; } } if (!match) break; } if (match) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static long Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } 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, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 72], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 17, 72], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 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], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 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, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 72], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["-", 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], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
520
36
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = l[0], M = l[1]; var A = new string[N]; var B = new string[M]; for (var i = 0; i < N; i++) A[i] = Console.ReadLine(); for (var i = 0; i < M; i++) B[i] = Console.ReadLine(); var count = 0; for (var i = 0; i < M; i++) { for (var j = 0; j < N; j++) { if (A[j].IndexOf(B[i]) >= 0) { count++; break; } else count = 0; } if (count == M) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = l[0], M = l[1]; var A = new string[N]; var B = new string[M]; for (var i = 0; i < N; i++) A[i] = Console.ReadLine(); for (var i = 0; i < M; i++) B[i] = Console.ReadLine(); var count = 0; var countJ = 0; for (var i = 0; i < M; i++) { for (var j = countJ; j < N; j++) { if (A[j].IndexOf(B[i]) >= 0) { count++; countJ++; break; } else { count = 0; countJ++; } } if (count == M) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
[["+", 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, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 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, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
235
15
using System; using System.Collections.Generic; public class Hello { public static void Main() { var array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var n = array[0]; var m = array[1]; var A = new string[n]; var B = new string[m]; var Hash = new HashSet<string>(); var target = ""; for (var i = 0; i < n; i++) { A[i] = Console.ReadLine(); } for (var i = 0; i < m; i++) { B[i] = Console.ReadLine(); target += B[i]; } for (var a = 0; a < n - m + 1; a++) { for (var b = 0; b < n - m + 1; b++) { var temp = ""; for (var y = 0; y < m; y++) { for (var x = 0; x < m; x++) { temp += A[a + y].Substring(b + x, m); } } Hash.Add(temp); } } if (Hash.Contains(target)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; public class Hello { public static void Main() { var array = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var n = array[0]; var m = array[1]; var A = new string[n]; var B = new string[m]; var Hash = new HashSet<string>(); var target = ""; for (var i = 0; i < n; i++) { A[i] = Console.ReadLine(); } for (var i = 0; i < m; i++) { B[i] = Console.ReadLine(); target += B[i]; } for (var a = 0; a < n - m + 1; a++) { for (var b = 0; b < n - m + 1; b++) { var temp = ""; for (var y = 0; y < m; y++) { temp += A[a + y].Substring(b, m); } Hash.Add(temp); } } if (Hash.Contains(target)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["-", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
8
295
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc54 { class Program { static void Main(string[] args) { bool res = false; var inp = ScanInt; int N = inp[0]; int M = inp[1]; string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } for (int i = 0; i < N - M + 1; i++) { for (int j = 0; j < N - M + 1; j++) { res = check(A, B, i, j); if (res) { break; } } } if (res) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } static bool check(string[] a, string[] b, int i, int j) { for (int i1 = 0; i1 < b[0].Length; i1++) { for (int j1 = 0; j1 < b[0].Length; j1++) { if (a[j + j1][i + i1] != b[j1][i1]) { return false; } } } // if(i==(a[0].Length-b[0].Length) // &&(j==(a[0].Length - b[0].Length))) //{ //} // else //{ return true; //} } static int[] ScanInt { get { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } } static string[] Scan { get { return Console.ReadLine().Split(' '); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc54 { class Program { static void Main(string[] args) { bool res = false; var inp = ScanInt; int N = inp[0]; int M = inp[1]; string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } for (int i = 0; i < N - M + 1; i++) { for (int j = 0; j < N - M + 1; j++) { // Console.WriteLine("@"); if (!res) res = check(A, B, i, j); } } if (res) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } static bool check(string[] a, string[] b, int i, int j) { for (int i1 = 0; i1 < b[0].Length; i1++) { for (int j1 = 0; j1 < b[0].Length; j1++) { // Console.WriteLine((i + i1) +" "+ (j + j1)); if (a[j + j1][i + i1] != b[j1][i1]) { return false; } } } return true; } static int[] ScanInt { get { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } } static string[] Scan { get { return Console.ReadLine().Split(' '); } } } }
[["+", 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, 241, 0, 111], ["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 15, 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, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
394
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B_007_54 { internal class Program { private static void Main(string[] args) { new Logic_B().Start(); // } public class Logic_B { public void Start() { var hw = Console.ReadLine().Split(' '); var ALength = Convert.ToInt32(hw[0]); var BLength = Convert.ToInt32(hw[1]); var AImage = new List<string>(); for (int i = 0; i < ALength; i++) { AImage.Add(Console.ReadLine()); } var BImage = new List<string>(); for (int i = 0; i < BLength; i++) { BImage.Add(Console.ReadLine()); } for (int i = 0; i < AImage.Count; i++) { for (int j = 0; j < AImage.Count; j++) { var valid = false; for (int m = 0; m < BImage.Count; m++) { for (int n = 0; n < BImage.Count; n++) { if (i + m >= AImage.Count || j + n >= AImage.Count) { valid = false; break; } if (AImage[i + m][j + n] == BImage[m][n]) { valid = true; } else { valid = false; } } } if (valid) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; namespace B_007_54 { internal class Program { private static void Main(string[] args) { new Logic_B().Start(); // } public class Logic_B { public void Start() { var hw = Console.ReadLine().Split(' '); var ALength = Convert.ToInt32(hw[0]); var BLength = Convert.ToInt32(hw[1]); var AImage = new List<string>(); for (int i = 0; i < ALength; i++) { AImage.Add(Console.ReadLine()); } var BImage = new List<string>(); for (int i = 0; i < BLength; i++) { BImage.Add(Console.ReadLine()); } for (int i = 0; i < AImage.Count; i++) { for (int j = 0; j < AImage.Count; j++) { var valid = false; for (int m = 0; m < BImage.Count; m++) { for (int n = 0; n < BImage.Count; n++) { if (i + m >= AImage.Count || j + n >= AImage.Count) { valid = false; break; } if (AImage[i + m][j + n] == BImage[m][n]) { valid = true; } else { valid = false; break; } } if (!valid) { break; } } if (valid) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 75, 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, 241, 0, 111], ["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 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, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35]]
8
352
28
using System; using System.Linq; public class Program { public static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse); int N = NM.First(), M = NM.Last(); var A = new string[N]; var B = new string[M]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } for (int i = 0; i + M < N; i++) { for (int j = 0; j + M < N; j++) { var flag = true; for (int k = 0; k < M; k++) { for (int l = 0; l < M; l++) { flag &= A[i + k][j + l] == B[k][l]; } } if (flag) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } }
using System; using System.Linq; public class Program { public static void Main() { var NM = Console.ReadLine().Split().Select(int.Parse); int N = NM.First(), M = NM.Last(); var A = new string[N]; var B = new string[M]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } for (int y = 0; y + M <= N; y++) { for (int x = 0; x + M <= N; x++) { var flag = true; for (int ly = 0; ly < M; ly++) { for (int lx = 0; lx < M; lx++) { flag &= A[y + ly][x + lx] == B[ly][lx]; } } if (flag) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } }
[["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 7, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 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, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["-", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
251
40
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace ConsoleApplication { public class main { static void Main() { string[] vals = Console.ReadLine().Split(' '); int N = int.Parse(vals[0]); int M = int.Parse(vals[1]); string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; i++) A[i] = Console.ReadLine(); for (int i = 0; i < M; i++) B[i] = Console.ReadLine(); for (int y = 0; y < N - M; y++) { for (int x = 0; x <= N - M; x++) { bool match = true; for (int j = 0; j < M; j++) { for (int i = 0; i < M; i++) { if (A[y + j][x + i] != B[j][i]) { match = false; } } } if (match) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
using System; class TempMatch { static public void Main(string[] args) { string[] vals = Console.ReadLine().Split(' '); int N = int.Parse(vals[0]); int M = int.Parse(vals[1]); string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; i++) A[i] = Console.ReadLine(); for (int i = 0; i < M; i++) B[i] = Console.ReadLine(); for (int y = 0; y <= N - M; y++) { for (int x = 0; x <= N - M; x++) { bool match = true; for (int j = 0; j < M; j++) { for (int i = 0; i < M; i++) { if (A[y + j][x + i] != B[j][i]) { match = false; break; } } } if (match) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 209, 0, 256], ["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 36, 36, 0, 208, 0, 209, 8, 201, 0, 45], ["-", 0, 209, 8, 201, 0, 235, 0, 251, 0, 259], ["-", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 235, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["+", 54, 55, 0, 220, 39, 224, 225, 226, 0, 70], ["+", 54, 55, 0, 220, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46]]
8
281
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc0211 { class Program { static void Main(string[] args) { bool judge = false; string[] tmp = Console.ReadLine().Split(' '); int A_square = int.Parse(tmp[0]); int B_square = int.Parse(tmp[1]); string[] Astr = new string[A_square]; string[] Bstr = new string[B_square]; for (int i = 0; i < A_square; i++) { Astr[i] = Console.ReadLine(); } for (int i = 0; i < B_square; i++) { Bstr[i] = Console.ReadLine(); } // Bの1行目をBが入りきる範囲で探す for (int i = 0; i < A_square - B_square + 1; i++) { if (Astr[i].Contains(Bstr[0]) == true) { int start = Astr[i].IndexOf(Bstr[0]); for (int j = 1; j < B_square; j++) { if (Astr[i + j].Substring(start, B_square) != Bstr[j]) { judge = false; break; } else { if (j == B_square - 1) { judge = true; Console.WriteLine("Yes"); return; } } } } } if (judge) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc0211 { class Program { static void Main(string[] args) { bool judge = false; string[] tmp = Console.ReadLine().Split(' '); int A_square = int.Parse(tmp[0]); int B_square = int.Parse(tmp[1]); string[] Astr = new string[A_square]; string[] Bstr = new string[B_square]; for (int i = 0; i < A_square; i++) { Astr[i] = Console.ReadLine(); } for (int i = 0; i < B_square; i++) { Bstr[i] = Console.ReadLine(); } // Bの1行目をBが入りきる範囲で探す for (int i = 0; i < A_square - B_square + 1; i++) { if (Astr[i].Contains(Bstr[0]) == true) { if (B_square == 1) { Console.WriteLine("Yes"); return; } int start = Astr[i].IndexOf(Bstr[0]); for (int j = 1; j < B_square; j++) { if (Astr[i + j].Substring(start, B_square) != Bstr[j]) { judge = false; break; } else { if (j == B_square - 1) { judge = true; Console.WriteLine("Yes"); return; } } } } } if (judge) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["+", 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], ["+", 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], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
323
19
using System; using System.Collections.Generic; using System.Text; struct coord { public int row; public int col; } class Program { public static int Main() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int M = int.Parse(str[1]); string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; ++i) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; ++i) { B[i] = Console.ReadLine(); } int offset = 0; System.Collections.Generic.Queue<coord> queue = new Queue<coord>(); for (int row = 0; row < N - M + 1; ++row) { while (offset < N - M + 1) { int col = A[row].IndexOf(B[0], offset); if (col != -1) { coord v; v.row = row; v.col = col; queue.Enqueue(v); offset = col + 1; } else { break; } } } bool exist = false; while (queue.Count > 0) { bool match = true; coord v = queue.Dequeue(); for (int i = 0; i < M; ++i) { if (A[v.row + i].IndexOf(B[i], v.col) != v.col) { match = false; break; } } if (match) { exist = true; break; } } if (exist) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } return 0; } }
using System; using System.Collections.Generic; using System.Text; struct coord { public int row; public int col; } class Program { public static int Main() { do { new Program().solve(); } while (false); return 0; } public void solve() { string[] str = Console.ReadLine().Split(' '); int N = int.Parse(str[0]); int M = int.Parse(str[1]); string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; ++i) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; ++i) { B[i] = Console.ReadLine(); } System.Collections.Generic.Queue<coord> queue = new Queue<coord>(); for (int row = 0; row < N - M + 1; ++row) { int offset = 0; while (offset < N - M + 1) { int col = A[row].IndexOf(B[0], offset); if (col != -1) { coord v; v.row = row; v.col = col; queue.Enqueue(v); offset = col + 1; } else { break; } } } bool exist = false; while (queue.Count > 0) { bool match = true; coord v = queue.Dequeue(); for (int i = 0; i < M; ++i) { if (A[v.row + i].IndexOf(B[i], v.col) != v.col) { match = false; break; } } if (match) { exist = true; break; } } if (exist) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 82, 0, 170], ["+", 0, 195, 8, 196, 0, 82, 8, 196, 0, 45], ["+", 0, 1, 0, 213, 63, 214, 205, 230, 0, 228], ["+", 0, 1, 0, 213, 63, 214, 205, 230, 39, 22], ["+", 0, 213, 63, 214, 205, 230, 3, 4, 0, 24], ["+", 0, 213, 63, 214, 205, 230, 3, 4, 0, 25], ["+", 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, 196, 0, 82, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 82, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 82, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 82, 0, 24], ["+", 0, 195, 8, 196, 0, 82, 15, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 82, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 82, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 259], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 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, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35]]
8
398
40
using System; using System.Collections.Generic; using System.Linq; class Method { bool[] seen; int sum; int count = 0; public Method(int s, int n) { seen = new bool[n]; for (int i = 0; i < n; i++) { seen[i] = false; } sum = s; } public int get() { return count; } public void dfs(int[,] pass, int v, int c) { seen[v - 1] = true; for (int i = 0; i < pass.Length / 2; i++) { int thisV = pass[i, 0]; if (thisV != v) continue; int nextV = pass[i, 1]; if (seen[nextV - 1]) continue; dfs(pass, nextV, c + nextV); } // Console.WriteLine(c); if (c == sum) count++; } } class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int s = 0; for (int i = 1; i <= n; i++) { s += i; } int[,] pass = new int[m * 2, 2]; for (int i = 0; i < m; i++) { string[] input2 = Console.ReadLine().Split(' '); pass[i, 0] = int.Parse(input2[0]); pass[i, 1] = int.Parse(input2[1]); pass[i + m, 0] = int.Parse(input2[1]); pass[i + m, 1] = int.Parse(input2[0]); } /*int start = 0; for(int i=0; i<m; i++){ if(pass[i,0] == 1) { start = pass[i,1]; break; } }*/ Method me = new Method(s, n); me.dfs(pass, 1, 1); Console.WriteLine(me.get()); } }
using System; using System.Collections.Generic; using System.Linq; class Method { bool[] seen; int sum; int count = 0; public Method(int s, int n) { seen = new bool[n]; for (int i = 0; i < n; i++) { seen[i] = false; } sum = s; } public int get() { return count; } public void dfs(int[,] pass, int v, int c) { seen[v - 1] = true; for (int i = 0; i < pass.Length / 2; i++) { int thisV = pass[i, 0]; if (thisV != v) continue; int nextV = pass[i, 1]; if (seen[nextV - 1]) continue; dfs(pass, nextV, c + nextV); } seen[v - 1] = false; if (c == sum) count++; } } class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int s = 0; for (int i = 1; i <= n; i++) { s += i; } int[,] pass = new int[m * 2, 2]; for (int i = 0; i < m; i++) { string[] input2 = Console.ReadLine().Split(' '); pass[i, 0] = int.Parse(input2[0]); pass[i, 1] = int.Parse(input2[1]); pass[i + m, 0] = int.Parse(input2[1]); pass[i + m, 1] = int.Parse(input2[0]); } /*int start = 0; for(int i=0; i<m; i++){ if(pass[i,0] == 1) { start = pass[i,1]; break; } }*/ Method me = new Method(s, n); me.dfs(pass, 1, 1); Console.WriteLine(me.get()); } }
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 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, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
435
9
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace CP { class Atria { //訪問済みかどうかを保存する配列 static bool[] vs; static long ans; static bool[,] graph; static void Main(string[] args) { int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = s[0]; int m = s[1]; //無向グラフを隣接行列を用いて受け取る graph = new bool[n, n]; for (int i = 0; i < m; i++) { int[] scan = ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray(); graph[scan[0], scan[1]] = true; // graph[scan[1], scan[0]] = true; } //訪問済みかどうかを保存する配列 vs = new bool[n]; ans = 0; DFS(0); WriteLine(ans); } static void DFS(int v) { if (vs.Distinct().Count(x => x == true) == 1) { ans++; return; } for (int i = 0; i < vs.Count(); i++) { if (graph[v, i] && vs[i] == false) { vs[i] = true; DFS(i); vs[i] = false; } } return; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace CP { class Atria { //訪問済みかどうかを保存する配列 static bool[] vs; static long ans; static bool[,] graph; static void Main(string[] args) { int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = s[0]; int m = s[1]; //無向グラフを隣接行列を用いて受け取る graph = new bool[n, n]; for (int i = 0; i < m; i++) { int[] scan = ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray(); graph[scan[0], scan[1]] = true; graph[scan[1], scan[0]] = true; } //訪問済みかどうかを保存する配列 vs = new bool[n]; vs[0] = true; ans = 0; DFS(0); WriteLine(ans); } static void DFS(int v) { if (vs.Count(x => x == true) == vs.Count()) { ans++; return; } for (int i = 0; i < vs.Count(); i++) { if (graph[v, i] && vs[i] == false) { vs[i] = true; DFS(i); vs[i] = false; } } return; } } }
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 31, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 31, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25]]
8
311
32
using System; namespace ABC054_C___One_Stroke_Path { class Program { static void Main(string[] args) { var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = NM[0]; var M = NM[1]; var joint = new bool[N, N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) joint[i, j] = false; for (int i = 0; i < M; i++) { var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); joint[ab[0] - 1, ab[1] - 1] = true; joint[ab[1] - 1, ab[0] - 1] = true; } var dp = new int[1 << N, N]; for (int i = 0; i < dp.GetLength(0); i++) for (int j = 0; j < dp.GetLength(1); j++) dp[i, j] = 0; for (int i = 0; i < N; i++) dp[1 << i, i] = 1; for (int bit = 1; bit < dp.GetLength(0); bit++) for (int last = 0; last < dp.GetLength(1); last++) { if ((bit & (1 << last)) == 0) continue; for (int prev = 0; prev < dp.GetLength(1); prev++) { if (((bit - (1 << last)) & (1 << prev)) > 0) if (joint[last, prev]) dp[bit, last] += dp[bit - (1 << last), prev]; } } int result = 0; for (int i = 0; i < dp.GetLength(1); i++) result = Math.Max(result, dp[dp.GetLength(0) - 1, i]); Console.WriteLine(result); } } }
using System; namespace ABC054_C___One_Stroke_Path { class Program { static void Main(string[] args) { var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = NM[0]; var M = NM[1]; var joint = new bool[N, N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) joint[i, j] = false; for (int i = 0; i < M; i++) { var ab = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); joint[ab[0] - 1, ab[1] - 1] = true; joint[ab[1] - 1, ab[0] - 1] = true; } var dp = new int[1 << N, N]; for (int i = 0; i < dp.GetLength(0); i++) for (int j = 0; j < dp.GetLength(1); j++) dp[i, j] = 0; for (int i = 0; i < N; i++) dp[1 << i, i] = 1; for (int bit = 1; bit < dp.GetLength(0); bit++) for (int last = 0; last < dp.GetLength(1); last++) { if ((bit & (1 << last)) == 0) continue; for (int prev = 0; prev < dp.GetLength(1); prev++) { if (((bit - (1 << last)) & (1 << prev)) > 0) if (joint[last, prev]) dp[bit, last] += dp[bit - (1 << last), prev]; } } Console.WriteLine(dp[dp.GetLength(0) - 1, 0]); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 8, 196, 0, 7, 8, 1, 0, 11, 31, 22], ["-", 0, 7, 8, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 8, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 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
457
41
using System; using System.Collections.Generic; using System.Linq; class Program { static Dictionary<int, List<int>> Nodes; static void Main(string[] args) { // C - One-stroke Path // https://atcoder.jp/contests/abc054/tasks/abc054_c var Array = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int N = Array[0]; int M = Array[1]; Nodes = new Dictionary<int, List<int>>(); for (int i = 1; i <= N; i++) { Nodes.Add(i, new List<int>()); } int Count = 0; while (Count < M) { Array = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); //無向グラフなのでどちらからでもいける Nodes[Array[0]].Add(Array[1]); Nodes[Array[1]].Add(Array[0]); Count++; } int Result = CheckPath(1, new List<int>()); } static int CheckPath(int CurrentNodeID, List<int> CheckedNum) { CheckedNum.Add(CurrentNodeID); //まだ調べていないものが次のNodeとなる var Next = Nodes[CurrentNodeID].Where(x => !CheckedNum.Exists(y => x == y)); //次のNodeがなく、調べたノード数と全ノード数一致 if (Next.Count() == 0 && (CheckedNum.Count == Nodes.Count())) { return 1; } //再起呼び出し var X = Next.Select(z => CheckPath(z, new List<int>(CheckedNum))); var Y = X.Sum(); return Y; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static Dictionary<int, List<int>> Nodes; static void Main(string[] args) { // C - One-stroke Path // https://atcoder.jp/contests/abc054/tasks/abc054_c var Array = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int N = Array[0]; int M = Array[1]; Nodes = new Dictionary<int, List<int>>(); for (int i = 1; i <= N; i++) { Nodes.Add(i, new List<int>()); } int Count = 0; while (Count < M) { Array = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); //無向グラフなのでどちらからでもいける Nodes[Array[0]].Add(Array[1]); Nodes[Array[1]].Add(Array[0]); Count++; } int Result = CheckPath(1, new List<int>()); Console.WriteLine(Result); } static int CheckPath(int CurrentNodeID, List<int> CheckedNum) { CheckedNum.Add(CurrentNodeID); //まだ調べていないものが次のNodeとなる var Next = Nodes[CurrentNodeID].Where(x => !CheckedNum.Exists(y => x == y)); //次のNodeがなく、調べたノード数と全ノード数一致 if (Next.Count() == 0 && (CheckedNum.Count == Nodes.Count())) { return 1; } //再起呼び出し var X = Next.Select(z => CheckPath(z, new List<int>(CheckedNum))); var Y = X.Sum(); return Y; } }
[["+", 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
341
7
using System; using System.Linq; using System.Collections.Generic; class Program { static string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 static int n = int.Parse(input[0]); //頂点数 static int m = int.Parse(input[1]); //辺数 static int[,] path = new int[n, n]; //隣接行列 static int answer = 0; static void Main() { for (int i = 0; i < m; i++) //隣接行列の完成 { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); if (nums[0] <= nums[1]) path[nums[0] - 1, nums[1] - 1]++; else path[nums[1] - 1, nums[0] - 1]++; } List<int> numListOriginal = Enumerable.Range(1, n - 1).ToList(); //順列 List<int> numListFinal = new List<int>() { 0 }; Permutation(numListOriginal, numListFinal); //順列の生成 Console.WriteLine(answer); } static void Permutation(List<int> numListOriginal, List<int> numListFinal) //順列の生成 { for (int i = 0; i < numListOriginal.Count(); i++) { int x = numListOriginal[i]; //移動する要素 numListFinal.Add(x); numListOriginal.RemoveAt(i); if (numListOriginal.Count() > 0) Permutation(numListOriginal, numListFinal); else CheckPath(numListFinal); numListOriginal.Insert(i, x); // listOriginalに戻す numListFinal.RemoveAt(numListFinal.Count() - 1); } } static void CheckPath(List<int> numListFinal) //引数startと繋がる頂点へ進む { for (int i = 0; i < numListFinal.Count() - 1; i++) { if (path[numListFinal[i], numListFinal[i + 1]] == 0) break; //辺でつながっていない時 if (i == numListFinal.Count() - 1) answer++; } } }
using System; using System.Linq; using System.Collections.Generic; class Program { static string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 static int n = int.Parse(input[0]); //頂点数 static int m = int.Parse(input[1]); //辺数 static int[,] path = new int[n, n]; //隣接行列 static int answer = 0; static void Main() { for (int i = 0; i < m; i++) //隣接行列の完成 { int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); path[nums[0] - 1, nums[1] - 1]++; path[nums[1] - 1, nums[0] - 1]++; } List<int> numListOriginal = Enumerable.Range(1, n - 1).ToList(); //順列 List<int> numListFinal = new List<int>() { 0 }; Permutation(numListOriginal, numListFinal); //順列の生成 Console.WriteLine(answer); } static void Permutation(List<int> numListOriginal, List<int> numListFinal) //順列の生成 { for (int i = 0; i < numListOriginal.Count(); i++) { int x = numListOriginal[i]; //移動する要素 numListFinal.Add(x); numListOriginal.RemoveAt(i); if (numListOriginal.Count() > 0) Permutation(numListOriginal, numListFinal); else CheckPath(numListFinal); numListOriginal.Insert(i, x); // listOriginalに戻す numListFinal.RemoveAt(numListFinal.Count() - 1); } } static void CheckPath(List<int> numListFinal) { for (int i = 0; i < numListFinal.Count() - 1; i++) { if (path[numListFinal[i], numListFinal[i + 1]] == 0) break; //辺でつながっていない時 if (i == numListFinal.Count() - 2) answer++; } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 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, 203], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
425
15
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { new Calc().calc(); } public class Calc { public Calc() {} public void calc() { var NM = ReadLine<int>(' '); nodes = new List<int>[NM[0]]; for (int i = 0; i < NM[0]; i++) { nodes[i] = new List<int>(); } for (int i = 0; i < NM[1]; i++) { var ab = ReadLine<int>(' '); nodes[ab[0] - 1].Add(ab[1] - 1); nodes[ab[1] - 1].Add(ab[0] - 1); } Search(0, "", NM[0]); return; } List<int>[] nodes; private int count = 0; public void Search(int node, string recent, int N) { foreach (var item in nodes[node]) { if (!recent.Contains(item + "")) Search(item, recent + node, N); } recent += node; if (recent.Length == N) { count++; return; } } } public static T ReadLine<T>() => (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); public static T[] ReadLine<T>(params char[] separators) => Console.ReadLine() .Split(separators) .Select(_ => (T)Convert.ChangeType(_, typeof(T))) .ToArray(); public static List<T> ReadLines<T>(int readCount) { List<T> rt = new List<T>(); for (int i = 0; i < readCount; i++) { rt.Add(ReadLine<T>()); } return rt; } } public static class Utils { public static string Docking<T>(this IEnumerable<T> s, int sequenceRange, Func<T, string> filter = null) { string str = ""; int c = 0; foreach (var item in s) { str += filter == null ? item.ToString() : filter(item); c++; if (c == sequenceRange) break; } return str; } public static string Docking<T>(this IEnumerable<T> s, Func<T, string> filter = null) { return s.Docking(s.Count(), filter); } public static string RangeDocking<T>(this IEnumerable<T> s, int start, int end, Func<T, string> filter = null) { string str = ""; end = end < s.Count() ? end : s.Count(); var items = s.ToArray(); for (int i = start; i < end; i++) { str += filter == null ? items[i].ToString() : filter(items[i]); } return str; } /// <summary> /// seqコマンドの代わり /// </summary> /// <param name="N"></param> /// <param name="start"></param> /// <returns></returns> public static List<int> Sequence(this int N, int start = 0) { List<int> rt = new List<int>(); for (int i = start; i < N; i++) { rt.Add(i); } return rt; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { new Calc().calc(); } public class Calc { public Calc() {} public void calc() { var NM = ReadLine<int>(' '); nodes = new List<int>[NM[0]]; for (int i = 0; i < NM[0]; i++) { nodes[i] = new List<int>(); } for (int i = 0; i < NM[1]; i++) { var ab = ReadLine<int>(' '); nodes[ab[0] - 1].Add(ab[1] - 1); nodes[ab[1] - 1].Add(ab[0] - 1); } Search(0, "", NM[0]); Console.WriteLine(count); return; } List<int>[] nodes; private int count = 0; public void Search(int node, string recent, int N) { foreach (var item in nodes[node]) { if (!recent.Contains(item + "")) Search(item, recent + node, N); } recent += node; if (recent.Length == N) { count++; return; } } } public static T ReadLine<T>() => (T)Convert.ChangeType(Console.ReadLine(), typeof(T)); public static T[] ReadLine<T>(params char[] separators) => Console.ReadLine() .Split(separators) .Select(_ => (T)Convert.ChangeType(_, typeof(T))) .ToArray(); public static List<T> ReadLines<T>(int readCount) { List<T> rt = new List<T>(); for (int i = 0; i < readCount; i++) { rt.Add(ReadLine<T>()); } return rt; } } public static class Utils { public static string Docking<T>(this IEnumerable<T> s, int sequenceRange, Func<T, string> filter = null) { string str = ""; int c = 0; foreach (var item in s) { str += filter == null ? item.ToString() : filter(item); c++; if (c == sequenceRange) break; } return str; } public static string Docking<T>(this IEnumerable<T> s, Func<T, string> filter = null) { return s.Docking(s.Count(), filter); } public static string RangeDocking<T>(this IEnumerable<T> s, int start, int end, Func<T, string> filter = null) { string str = ""; end = end < s.Count() ? end : s.Count(); var items = s.ToArray(); for (int i = start; i < end; i++) { str += filter == null ? items[i].ToString() : filter(items[i]); } return str; } /// <summary> /// seqコマンドの代わり /// </summary> /// <param name="N"></param> /// <param name="start"></param> /// <returns></returns> public static List<int> Sequence(this int N, int start = 0) { List<int> rt = new List<int>(); for (int i = start; i < N; i++) { rt.Add(i); } return rt; } }
[["+", 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
730
7
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC054.D(); } class ABC054 { public static void A() { var A = Read.Int(); var B = Read.Int(); if (A == 1) { A = 14; } if (B == 1) { B = 14; } Console.WriteLine(A == B ? "Draw" : A > B ? "Alice" : "Bob"); } public static void B() { var N = Read.Int(); var M = Read.Int(); var A = Enumerable.Range(0, N).Select(i => Read.Str()).ToArray(); var B = Enumerable.Range(0, M).Select(i => Read.Str()).ToArray(); for (int i = 0; i <= N - M; ++i) { for (int j = 0; j <= N - M; ++j) { bool ok = true; for (int k = 0; k < M; ++k) { for (int l = 0; l < M; ++l) { if (A[i + k][j + l] != B[k][l]) { ok = false; break; } } if (!ok) { break; } } if (ok) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } public static void C() { var N = Read.Int(); var M = Read.Int(); var Adj = Read.AdjacencyList(N, M); var dp = new long[N, 1 << N]; dp[0, 1] = 1; for (int i = 1; i < (1 << N) - 1; ++i) { for (int j = 0; j < N; ++j) { if (dp[j, i] == 0) { continue; } foreach (var v in Adj[j + 1]) { var k = v - 1; if ((i & (1 << k)) == 0) { dp[k, i + (1 << k)] += dp[j, i]; } } } } Console.WriteLine( Enumerable.Range(0, N).Select(x => dp[x, (1 << N) - 1]).Sum()); } public static void D() { var N = Read.Int(); var MA = Read.Int(); var MB = Read.Int(); var ABC = Enumerable.Range(0, N).Select(i => Read.IntN()).ToArray(); var dp = Util.Gen(401, 401, Int32.MaxValue); dp[0, 0] = 0; for (int i = 0; i < N; ++i) { var A = ABC[i][0]; var B = ABC[i][1]; var C = ABC[i][2]; for (int j = 0; j <= i * 10; ++j) { for (int k = 0; k <= i * 10; ++k) { if (dp[j, k] < Int32.MaxValue) { dp[j + A, k + B] = Math.Min(dp[j + A, k + B], dp[j, k] + C); } } } } int min = Int32.MaxValue; for (int x = 1;; ++x) { var A = MA * x; var B = MB * x; if (A > 400 || B > 400) { break; } min = Math.Min(min, dp[A, B]); } Console.WriteLine(min == Int32.MaxValue ? -1 : min); } } class Util { public static T[,] Gen<T>(int r, int c, T v) { var matrix = new T[r, c]; for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { matrix[i, j] = v; } } return matrix; } public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } public static long[,] ASum(long[,] matrix) { var N = matrix.GetLength(0); var M = matrix.GetLength(1); var res = new long[N + 1, M + 1]; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { res[i + 1, j + 1] = res[i, j + 1] + res[i + 1, j] - res[i, j] + matrix[i, j]; } } return res; } public static Dictionary<T, long> Frequency<T>(T[] array) { var dict = new Dictionary<T, long>(); foreach (var a in array) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } return dict; } public static long GCD(long a, long b) { while (b > 0) { var c = a % b; a = b; b = c; } return a; } public static HashSet<long> Divisor(long x) { var div = new HashSet<long>(); for (long p = 1; p * p <= x; ++p) { if (x % p == 0) { div.Add(p); } } foreach (var d in div.ToArray()) { if (!div.Contains(x / d)) { div.Add(x / d); } } return div; } public static Dictionary<long, int> Factorize(long x) { var dict = new Dictionary<long, int>(); long minp = 2; while (x > 1) { bool ok = false; for (long p = minp; p * p <= x; ++p) { if (x % p == 0) { if (!dict.ContainsKey(p)) { dict.Add(p, 0); } dict[p]++; minp = p; x /= p; ok = true; break; } } if (!ok) { if (!dict.ContainsKey(x)) { dict.Add(x, 0); } dict[x]++; break; } } return dict; } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC054.D(); } class ABC054 { public static void A() { var A = Read.Int(); var B = Read.Int(); if (A == 1) { A = 14; } if (B == 1) { B = 14; } Console.WriteLine(A == B ? "Draw" : A > B ? "Alice" : "Bob"); } public static void B() { var N = Read.Int(); var M = Read.Int(); var A = Enumerable.Range(0, N).Select(i => Read.Str()).ToArray(); var B = Enumerable.Range(0, M).Select(i => Read.Str()).ToArray(); for (int i = 0; i <= N - M; ++i) { for (int j = 0; j <= N - M; ++j) { bool ok = true; for (int k = 0; k < M; ++k) { for (int l = 0; l < M; ++l) { if (A[i + k][j + l] != B[k][l]) { ok = false; break; } } if (!ok) { break; } } if (ok) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } public static void C() { var N = Read.Int(); var M = Read.Int(); var Adj = Read.AdjacencyList(N, M); var dp = new long[N, 1 << N]; dp[0, 1] = 1; for (int i = 1; i < (1 << N) - 1; ++i) { for (int j = 0; j < N; ++j) { if (dp[j, i] == 0) { continue; } foreach (var v in Adj[j + 1]) { var k = v - 1; if ((i & (1 << k)) == 0) { dp[k, i + (1 << k)] += dp[j, i]; } } } } Console.WriteLine( Enumerable.Range(0, N).Select(x => dp[x, (1 << N) - 1]).Sum()); } public static void D() { var N = Read.Int(); var MA = Read.Int(); var MB = Read.Int(); var ABC = Enumerable.Range(0, N).Select(i => Read.IntN()).ToArray(); var dp = Util.Gen(401, 401, Int32.MaxValue); dp[0, 0] = 0; for (int i = 0; i < N; ++i) { var A = ABC[i][0]; var B = ABC[i][1]; var C = ABC[i][2]; for (int j = i * 10; j >= 0; --j) { for (int k = i * 10; k >= 0; --k) { if (dp[j, k] < Int32.MaxValue) { dp[j + A, k + B] = Math.Min(dp[j + A, k + B], dp[j, k] + C); } } } } int min = Int32.MaxValue; for (int x = 1;; ++x) { var A = MA * x; var B = MB * x; if (A > 400 || B > 400) { break; } min = Math.Min(min, dp[A, B]); } Console.WriteLine(min == Int32.MaxValue ? -1 : min); } } class Util { public static T[,] Gen<T>(int r, int c, T v) { var matrix = new T[r, c]; for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { matrix[i, j] = v; } } return matrix; } public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } public static long[,] ASum(long[,] matrix) { var N = matrix.GetLength(0); var M = matrix.GetLength(1); var res = new long[N + 1, M + 1]; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { res[i + 1, j + 1] = res[i, j + 1] + res[i + 1, j] - res[i, j] + matrix[i, j]; } } return res; } public static Dictionary<T, long> Frequency<T>(T[] array) { var dict = new Dictionary<T, long>(); foreach (var a in array) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } return dict; } public static long GCD(long a, long b) { while (b > 0) { var c = a % b; a = b; b = c; } return a; } public static HashSet<long> Divisor(long x) { var div = new HashSet<long>(); for (long p = 1; p * p <= x; ++p) { if (x % p == 0) { div.Add(p); } } foreach (var d in div.ToArray()) { if (!div.Contains(x / d)) { div.Add(x / d); } } return div; } public static Dictionary<long, int> Factorize(long x) { var dict = new Dictionary<long, int>(); long minp = 2; while (x > 1) { bool ok = false; for (long p = minp; p * p <= x; ++p) { if (x % p == 0) { if (!dict.ContainsKey(p)) { dict.Add(p, 0); } dict[p]++; minp = p; x /= p; ok = true; break; } } if (!ok) { if (!dict.ContainsKey(x)) { dict.Add(x, 0); } dict[x]++; break; } } return dict; } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 26, 241, 0, 29], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 26, 241, 0, 68]]
8
2,595
20
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); int ma = cin.Int(); int mb = cin.Int(); var val = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { int a = cin.Int(); int b = cin.Int(); int c = cin.Int(); int d = a * mb - b * ma; val[i] = new Tuple<int, int>(d, c); } int offset = 10000; int range = offset * 2 + 1; int max = 10000000; int[,] dp = new int[n + 1, range]; for (int i = 0; i <= n; i++) { for (int j = 0; j < range; j++) { dp[i, j] = max; } } for (int i = 0; i < n; i++) { for (int j = 0; j < range; j++) { if (dp[i, j] != max) { dp[i + 1, j + val[i].Item1] = Math.Min(dp[i, j + val[i].Item1], dp[i, j] + val[i].Item2); } } dp[i + 1, val[i].Item1 + offset] = Math.Min(dp[i, val[i].Item1 + offset], val[i].Item2); } if (dp[n, offset] == max) { Console.WriteLine(-1); return; } Console.WriteLine(dp[n, offset]); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); int ma = cin.Int(); int mb = cin.Int(); var val = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { int a = cin.Int(); int b = cin.Int(); int c = cin.Int(); int d = a * mb - b * ma; val[i] = new Tuple<int, int>(d, c); } int offset = 10000; int range = offset * 2 + 1; int max = 10000000; int[,] dp = new int[n + 1, range]; for (int i = 0; i <= n; i++) { for (int j = 0; j < range; j++) { dp[i, j] = max; } } for (int i = 0; i < n; i++) { for (int j = 0; j < range; j++) { if (dp[i, j] != max) { dp[i + 1, j + val[i].Item1] = Math.Min(dp[i, j + val[i].Item1], dp[i, j] + val[i].Item2); dp[i + 1, j] = Math.Min(dp[i + 1, j], dp[i, j]); } } dp[i + 1, val[i].Item1 + offset] = Math.Min(dp[i, val[i].Item1 + offset], val[i].Item2); } if (dp[n, offset] == max) { Console.WriteLine(-1); return; } Console.WriteLine(dp[n, offset]); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 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, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 21], ["+", 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, 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, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 21], ["+", 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, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
871
30
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Text; using System.Diagnostics; using static System.Math; using static System.Array; // 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 N, Ma, Mb; static int[] a, b, c; public static void Input() { var cin = new Scanner(); var input = cin.SplitReader(); N = input[0]; Ma = input[1]; Mb = input[2]; a = new int[N]; b = new int[N]; c = new int[N]; for (var i = 0; i < N; i++) { var p = cin.SplitReader(); a[i] = p[0]; b[i] = p[1]; c[i] = p[2]; } } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); int A = a.Sum(); int B = b.Sum(); long[,,] dp = new long[N + 1, A + 1, B + 1]; for (var i = 0; i <= N; i++) { for (var x = 0; x <= A; x++) { for (var y = 0; y <= B; y++) { if (i == 0 && x == 0 && y == 0) { dp[i, x, y] = 0; } else { dp[i, x, y] = INF; } } } } for (var i = 0; i < N; i++) { for (var x = 0; x <= A; x++) { for (var y = 0; y <= B; y++) { if (dp[i, x, y] == INF) { continue; } dp[i + 1, x, y] = dp[i, x, y]; if (x + a[i] <= A && y + b[i] <= B) { dp[i + 1, x + a[i], y + b[i]] = Min(dp[i, x + a[i], y + b[i]], dp[i, x, y] + c[i]); } } } } long ans = INF; for (var x = 1; x <= A; x++) { for (var y = 1; y <= B; y++) { if (x * Mb == y * Ma) { ans = Min(ans, dp[N, x, y]); } } } Console.WriteLine(ans == INF ? -1 : ans); // Console.Out.Flush(); } } public class Scanner { 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; } } public class Graph {} }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text.RegularExpressions; using System.Text; using System.Diagnostics; using static System.Math; using static System.Array; // 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 N, Ma, Mb; static int[] a, b, c; public static void Input() { var cin = new Scanner(); var input = cin.SplitReader(); N = input[0]; Ma = input[1]; Mb = input[2]; a = new int[N]; b = new int[N]; c = new int[N]; for (var i = 0; i < N; i++) { var p = cin.SplitReader(); a[i] = p[0]; b[i] = p[1]; c[i] = p[2]; } } static void Main(string[] args) { Input(); // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); int A = a.Sum(); int B = b.Sum(); long[,,] dp = new long[N + 1, A + 1, B + 1]; for (var i = 0; i <= N; i++) { for (var x = 0; x <= A; x++) { for (var y = 0; y <= B; y++) { if (i == 0 && x == 0 && y == 0) { dp[i, x, y] = 0; } else { dp[i, x, y] = INF; } } } } for (var i = 0; i < N; i++) { for (var x = 0; x <= A; x++) { for (var y = 0; y <= B; y++) { if (dp[i, x, y] == INF) { continue; } dp[i + 1, x, y] = Min(dp[i + 1, x, y], dp[i, x, y]); dp[i + 1, x + a[i], y + b[i]] = Min(dp[i + 1, x + a[i], y + b[i]], dp[i, x, y] + c[i]); } } } long ans = INF; for (var x = 1; x <= A; x++) { for (var y = 1; y <= B; y++) { if (x * Mb == y * Ma) { ans = Min(ans, dp[N, x, y]); } } } Console.WriteLine(ans == INF ? -1 : ans); // Console.Out.Flush(); } } public class Scanner { 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; } } public class Graph {} }
[["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 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, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 72], ["-", 15, 16, 31, 16, 31, 16, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 31, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 21], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["-", 15, 16, 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], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
696
30
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 nab = Input.ar; const int LI = 401; var abc = new int[nab[0]][]; for (var i = 0; i < nab[0]; i++) abc[i] = Input.ar; var dp = new int[nab[0] + 1, LI, LI]; for (var i = 0; i <= nab[0]; i++) for (var j = 0; j < LI; j++) for (var h = 0; h < LI; h++) dp[i, j, h] = int.MaxValue; dp[0, 0, 0] = 0; for (var i = 1; i <= nab[0]; i++) { for (var j = 1; j < LI; j++) { if (j - abc[i - 1][0] < 0) continue; for (var h = 1; h < LI; h++) { dp[i, j, h] = Min(dp[i, j, h], dp[i - 1, j, h]); if (h - abc[i - 1][1] < 0) continue; if (dp[i - 1, j - abc[i - 1][0], h - abc[i - 1][1]] != int.MaxValue) dp[i, j, h] = Min(dp[i, j, h], dp[i - 1, j - abc[i - 1][0], h - abc[i - 1][1]] + abc[i - 1][2]); } } } var min = int.MaxValue; for (var i = 1; i < LI; i++) for (var j = 1; j < LI; j++) if (i * nab[2] == j * nab[1]) min = Min(min, dp[nab[0], i, j]); WriteLine(min == int.MaxValue ? -1 : min); } } public class Input { public static string read => ReadLine(); public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse); public static int num => ToInt32(read); public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse); public static long numL => ToInt64(read); public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using static System.Globalization.CultureInfo; class Program { static void Main(string[] args) { var nab = Input.ar; const int LI = 401; var abc = new int[nab[0]][]; for (var i = 0; i < nab[0]; i++) abc[i] = Input.ar; var dp = new int[nab[0] + 1, LI, LI]; for (var i = 0; i <= nab[0]; i++) for (var j = 0; j < LI; j++) for (var h = 0; h < LI; h++) dp[i, j, h] = int.MaxValue; dp[0, 0, 0] = 0; for (var i = 1; i <= nab[0]; i++) { for (var j = 0; j < LI; j++) { for (var h = 0; h < LI; h++) { dp[i, j, h] = Min(dp[i, j, h], dp[i - 1, j, h]); if (j - abc[i - 1][0] < 0 || h - abc[i - 1][1] < 0) continue; if (dp[i - 1, j - abc[i - 1][0], h - abc[i - 1][1]] != int.MaxValue) dp[i, j, h] = Min(dp[i, j, h], dp[i - 1, j - abc[i - 1][0], h - abc[i - 1][1]] + abc[i - 1][2]); } } } var min = int.MaxValue; for (var i = 1; i < LI; i++) for (var j = 1; j < LI; j++) if (i * nab[2] == j * nab[1]) min = Min(min, dp[nab[0], i, j]); WriteLine(min == int.MaxValue ? -1 : min); } } public class Input { public static string read => ReadLine(); public static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse); public static int num => ToInt32(read); public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse); public static long numL => ToInt64(read); public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 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, 33], ["-", 15, 16, 31, 16, 12, 204, 205, 204, 205, 22], ["-", 31, 16, 12, 204, 205, 204, 206, 207, 0, 70], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 31, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["+", 31, 16, 31, 16, 12, 204, 205, 204, 205, 22], ["+", 31, 16, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 31, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106]]
8
591
36
using System; using System.Linq; class Program { static int N; static int Ma; static int Mb; static int[] a; static int[] b; static int[] c; static void Main() { /*入力を受け取る*/ int[] inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); N = inputs[0]; Ma = inputs[1]; Mb = inputs[2]; a = new int[N]; b = new int[N]; c = new int[N]; for (int i = 0; i < N; i++) { inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); a[i] = inputs[0]; b[i] = inputs[1]; c[i] = inputs[2]; } /* DP[i][p,q] : i番目までの商品で、Aをp(g),Bをq(g)買う最小金額(不可能なら∞) というDPを行う */ int[][,] DP = new int [N + 1][,]; int a_sum = a.Sum(); int b_sum = b.Sum(); for (int i = 0; i <= N; i++) DP[i] = new int[a_sum + 1, b_sum + 1]; for (int i = 0; i <= N; i++) for (int j = 0; j <= a_sum; j++) for (int k = 0; k <= b_sum; k++) DP[i][j, k] = (int)1e8; DP[0][0, 0] = 0; for (int i = 1; i <= N; i++) { int ai = a[i - 1]; int bi = b[i - 1]; int ci = c[i - 1]; for (int p = 0; p <= a_sum; p++) { for (int q = 0; q <= b_sum; q++) { try { DP[i][p, q] = Math.Min(DP[i - 1][p, q], DP[i - 1][p - ai, q - bi] + ci); } catch { continue; } } } } /*DP[N][Ma * i,Mb * i] (i = 1,2,3,...)の中の最小値が答え*/ int ans = int.MaxValue; for (int i = 1;; i++) { try { ans = Math.Min(ans, DP[N][Ma * i, Mb * i]); } catch { break; } } Console.WriteLine(ans >= (int)1e5 ? -1 : ans); } }
using System; using System.Linq; class Program { static int N; static int Ma; static int Mb; static int[] a; static int[] b; static int[] c; static void Main() { /*入力を受け取る*/ int[] inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); N = inputs[0]; Ma = inputs[1]; Mb = inputs[2]; a = new int[N]; b = new int[N]; c = new int[N]; for (int i = 0; i < N; i++) { inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); a[i] = inputs[0]; b[i] = inputs[1]; c[i] = inputs[2]; } /* DP[i][p,q] : i番目までの商品で、Aをp(g),Bをq(g)買う最小金額(不可能なら∞) というDPを行う */ int[][,] DP = new int [N + 1][,]; int a_sum = a.Sum(); int b_sum = b.Sum(); for (int i = 0; i <= N; i++) DP[i] = new int[a_sum + 1, b_sum + 1]; for (int i = 0; i <= N; i++) for (int j = 0; j <= a_sum; j++) for (int k = 0; k <= b_sum; k++) DP[i][j, k] = (int)1e8; DP[0][0, 0] = 0; for (int i = 1; i <= N; i++) { int ai = a[i - 1]; int bi = b[i - 1]; int ci = c[i - 1]; for (int p = 0; p <= a_sum; p++) { for (int q = 0; q <= b_sum; q++) { try { DP[i][p, q] = Math.Min(DP[i - 1][p, q], DP[i - 1][p - ai, q - bi] + ci); } catch { DP[i][p, q] = DP[i - 1][p, q]; } } } } /*DP[N][Ma * i,Mb * i] (i = 1,2,3,...)の中の最小値が答え*/ int ans = int.MaxValue; for (int i = 1;; i++) { try { ans = Math.Min(ans, DP[N][Ma * i, Mb * i]); } catch { break; } } Console.WriteLine(ans >= (int)1e5 ? -1 : ans); } }
[["-", 0, 246, 0, 248, 8, 196, 0, 116, 0, 117], ["+", 0, 1, 0, 11, 31, 204, 205, 204, 205, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 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, 21], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 204, 205, 204, 205, 22], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 21], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
8
528
22
using System; using System.Linq; namespace abc054_d { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[,] dp = new int[500, 500]; int inf = 100000000; for (int i = 0; i < 500; i++) { for (int j = 0; j < 500; j++) dp[i, j] = inf; } dp[0, 0] = 0; for (int i = 0; i < x[0]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int j = a[0]; j < 500; j++) { for (int k = a[1]; k < 500; k++) { dp[j, k] = Math.Min(dp[j - a[0], k - a[1]] + a[2], dp[j, k]); } } } int ret = inf; for (int i = 1; i < 500 / Math.Max(x[1], x[2]); i++) { ret = Math.Min(ret, dp[x[1] * i, x[2] * i]); } Console.WriteLine(ret != inf ? ret : -1); } } }
using System; using System.Linq; namespace abc054_d { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[,] dp = new int[500, 500]; int inf = 100000000; for (int i = 0; i < 500; i++) { for (int j = 0; j < 500; j++) dp[i, j] = inf; } dp[0, 0] = 0; for (int i = 0; i < x[0]; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int j = 499; j >= a[0]; j--) { for (int k = 499; k >= a[1]; k--) { dp[j, k] = Math.Min(dp[j - a[0], k - a[1]] + a[2], dp[j, k]); } } } int ret = inf; for (int i = 1; i < 500 / Math.Max(x[1], x[2]); i++) { ret = Math.Min(ret, dp[x[1] * i, x[2] * i]); } Console.WriteLine(ret != inf ? ret : -1); } } }
[["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 20], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 68], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22]]
8
320
20
using System; using System.Collections.Generic; using System.Linq; namespace ProgramingStudying2 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToList(); var even = 0; for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) { even++; } } var odd = n - even; if (odd % 2 != 0) { Console.WriteLine("NO"); return; } odd /= 2; if ((odd + even) % 2 != 0) { Console.WriteLine("NO"); return; } Console.WriteLine("YES"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ProgramingStudying2 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToList(); var even = 0; for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) { even++; } } var odd = n - even; if (odd % 2 != 0) { Console.WriteLine("NO"); return; } odd /= 2; Console.WriteLine("YES"); } } }
[["-", 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, 16, 31, 23, 0, 24], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 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], ["-", 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, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
8
175
25
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; namespace Sample { public class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { Solve(); } } public static void Solve() { int n = GetString().ToInt(); var input = IsEven(GetArray<int>()); var evenCount = input.Count(i => i); var oddCount = input.Count(i => !i); evenCount += oddCount / 2; oddCount %= 2; evenCount /= 2; if (evenCount % 2 == 0 && oddCount == 1) { CWrite("YES"); return; } if (evenCount % 2 == 1 && oddCount == 0) { CWrite("YES"); return; } CWrite("NO"); } public static bool[] IsEven(int[] array) { return array.Select(a => a % 2 == 0).ToArray(); } static void CWrite<T>(T str) => Console.WriteLine(str); static string GetString() => Console.ReadLine(); static T[] GetArray<T>() { var t = typeof(T); var str = Console.ReadLine(); if (t == typeof(string)) { return (T[])(object)str.Split(); } if (t == typeof(int)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(long)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(double)) { return (T[])(object)str.ToNumArray<T>(); } throw new NotSupportedException($"{t} is not supported."); } } class SetConsole : IDisposable { readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); public SetConsole() { sw.AutoFlush = false; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } } static class ExtentionsLibrary { public static T[] CopyArray<T>(this T[] array) { var newArray = new T[array.Length]; Array.Copy(array, newArray, array.Length); return newArray; } public static T[,] CopyArray<T>(this T[,] array) { var firstDimentionLength = array.GetLength(0); var secondDimentionLength = array.GetLength(1); var newDArray = new T[firstDimentionLength, secondDimentionLength]; Array.Copy(array, newDArray, firstDimentionLength * secondDimentionLength); return newDArray; } public static T[] ToNumArray<T>(this string str) { var t = typeof(T); if (t == typeof(int)) { return (T[])(object)str.Split().Select(int.Parse).ToArray(); } if (t == typeof(long)) { return (T[])(object)str.Split().Select(long.Parse).ToArray(); } if (t == typeof(double)) { return (T[])(object)str.Split().Select(double.Parse).ToArray(); } throw new NotSupportedException(); } public static int ToInt(this string str) => int.Parse(str); public static int ToInt(this char chr) => int.Parse(chr.ToString()); public static long ToLong(this string str) => long.Parse(str); public static DateTime ToDateTime(this string str) => DateTime.Parse(str); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; namespace Sample { public class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { Solve(); } } public static void Solve() { int n = GetString().ToInt(); var input = IsEven(GetArray<int>()); var evenCount = input.Count(i => i); var oddCount = input.Count(i => !i); evenCount += oddCount / 2; oddCount %= 2; evenCount /= 2; if (oddCount == 0) { CWrite("YES"); return; } CWrite("NO"); } public static bool[] IsEven(int[] array) { return array.Select(a => a % 2 == 0).ToArray(); } static void CWrite<T>(T str) => Console.WriteLine(str); static string GetString() => Console.ReadLine(); static T[] GetArray<T>() { var t = typeof(T); var str = Console.ReadLine(); if (t == typeof(string)) { return (T[])(object)str.Split(); } if (t == typeof(int)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(long)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(double)) { return (T[])(object)str.ToNumArray<T>(); } throw new NotSupportedException($"{t} is not supported."); } } class SetConsole : IDisposable { readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); public SetConsole() { sw.AutoFlush = false; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } } static class ExtentionsLibrary { public static T[] CopyArray<T>(this T[] array) { var newArray = new T[array.Length]; Array.Copy(array, newArray, array.Length); return newArray; } public static T[,] CopyArray<T>(this T[,] array) { var firstDimentionLength = array.GetLength(0); var secondDimentionLength = array.GetLength(1); var newDArray = new T[firstDimentionLength, secondDimentionLength]; Array.Copy(array, newDArray, firstDimentionLength * secondDimentionLength); return newDArray; } public static T[] ToNumArray<T>(this string str) { var t = typeof(T); if (t == typeof(int)) { return (T[])(object)str.Split().Select(int.Parse).ToArray(); } if (t == typeof(long)) { return (T[])(object)str.Split().Select(long.Parse).ToArray(); } if (t == typeof(double)) { return (T[])(object)str.Split().Select(double.Parse).ToArray(); } throw new NotSupportedException(); } public static int ToInt(this string str) => int.Parse(str); public static int ToInt(this char chr) => int.Parse(chr.ToString()); public static long ToLong(this string str) => long.Parse(str); public static DateTime ToDateTime(this string str) => DateTime.Parse(str); } }
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 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, 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, 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, 12, 16, 31, 22]]
8
800
29
using System; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const long mod = 1000000007; // public static int[] max; static void Main(string[] args) { char[] cs = new char[] { ' ', ',' }; int val = int.Parse(Console.ReadLine()); int[] vals = parseAry(Console.ReadLine().Split(cs)); // int val = int.Parse(Console.ReadLine()); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // int n = vals[0]; // string res=""; // int y = vals[0]; // int x = vals[1]; int guu = 0, ki = 0; for (int i = 0; i < val; i++) { if ((vals[i] & 1) == 1) { ki++; } else { guu++; } } string re = "NO"; if ((ki & 1) == 1) { // if (( (guu+(ki/2)) & 1 ) == 0) { re = "YES"; } } else { if (((guu + (ki / 2)) & 1) == 0) { re = "YES"; } } Console.WriteLine(re); return; } // String[] -----> int[] static int[] parseAry(string[] str) { int[] nums = new int[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } // String[] -----> long[] static long[] parseAryl(string[] str) { long[] nums = new long[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } //文字列を1文字ずつString[]に入れる static string[] strAry(String str) { string[] re = new string[str.Length]; for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); } return re; } }
using System; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const long mod = 1000000007; // public static int[] max; static void Main(string[] args) { char[] cs = new char[] { ' ', ',' }; int val = int.Parse(Console.ReadLine()); int[] vals = parseAry(Console.ReadLine().Split(cs)); // int val = int.Parse(Console.ReadLine()); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // int n = vals[0]; // string res=""; // int y = vals[0]; // int x = vals[1]; int guu = 0, ki = 0; for (int i = 0; i < val; i++) { if ((vals[i] & 1) == 1) { ki++; } else { guu++; } } string re = "NO"; if ((ki & 1) == 1) { // if (( (guu+(ki/2)) & 1 ) == 0) { re = "YES"; } } else { re = "YES"; } Console.WriteLine(re); return; } // String[] -----> int[] static int[] parseAry(string[] str) { int[] nums = new int[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } // String[] -----> long[] static long[] parseAryl(string[] str) { long[] nums = new long[str.Length]; for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); } return nums; } //文字列を1文字ずつString[]に入れる static string[] strAry(String str) { string[] re = new string[str.Length]; for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); } return re; } }
[["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["-", 75, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 15, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["-", 31, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 31, 23, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["-", 31, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 31, 23, 0, 16, 12, 23, 0, 16, 17, 85], ["-", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["-", 15, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 17, 67], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 12, 203], ["-", 75, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["-", 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], ["-", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
8
395
20
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 sum = 0; for (int i = 0; i < N; i++) sum += A[i]; long inc = (long)N * (long)(N + 1) / 2; if (sum % inc != 0) { Console.WriteLine("NO"); return; } long tot = sum / inc; long[] B = new long[N]; for (int i = 0; i < N; i++) { long diff = A[i] - A[(i - 1 + N) % N]; if ((tot - diff) % N != 0) { Console.WriteLine("NO"); return; } B[i] = (tot - diff) / N; } long cnt = 0; for (int i = 0; i < N; i++) cnt += B[i]; if (cnt != tot) { Console.WriteLine("NO"); return; } long a = 0; for (int i = 0; i < N; i++) { a += B[i] * (N - i); } Console.WriteLine(a == A[0] ? "YES" : "NO"); } int N; long[] A; public Sol() { N = ri(); A = rla(); } 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 sum = 0; for (int i = 0; i < N; i++) sum += A[i]; long inc = (long)N * (long)(N + 1) / 2; if (sum % inc != 0) { Console.WriteLine("NO"); return; } long tot = sum / inc; long[] B = new long[N]; for (int i = 0; i < N; i++) { long diff = A[i] - A[(i - 1 + N) % N]; if ((tot - diff) % N != 0) { Console.WriteLine("NO"); return; } B[i] = (tot - diff) / N; if (B[i] < 0) { Console.WriteLine("NO"); return; } } long cnt = 0; for (int i = 0; i < N; i++) cnt += B[i]; if (cnt != tot) { Console.WriteLine("NO"); return; } // Console.WriteLine(String.Join(" ",B)); long a = 0; for (int i = 0; i < N; i++) { a += B[i] * (N - i); } // Console.WriteLine(a); Console.WriteLine(a == A[N - 1] ? "YES" : "NO"); } int N; long[] A; public Sol() { N = ri(); A = rla(); } 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, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 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, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
566
26
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static List<int>[] li; static long[] h; static string ans = "YES"; static void Main() { Sc sc = new Sc(); int n = sc.I; h = sc.La2; li = new List<int>[n + 1]; for (int i = 1; i <= n; i++) { li[i] = new List<int>(); } for (int i = 1; i < n; i++) { int[] e = sc.Ia; li[e[0]].Add(e[1]); li[e[1]].Add(e[0]); } if (Fu(1, 0) != 0) { ans = "NO"; } Console.WriteLine("{0}", ans); } static long Fu(int a, int g) { long q = 0; for (int i = 0; i < li[a].Count; i++) { if (li[a][i] != g) { long p = Fu(li[a][i], a); if (h[a] < p) { ans = "NO"; } q += p; } } if (a == 1 && li[a].Count == 1) { q -= h[a]; } else if (a == 1) { q -= h[a] * 2; } else if (li[a].Count > 1 || a == 1) { q = h[a] * 2 - q; } else { q += h[a]; } if (h[a] < q) { ans = "NO"; } return q; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; static class Program { const int mod = 1000000007; static List<int>[] li; static long[] h; static string ans = "YES"; static void Main() { Sc sc = new Sc(); int n = sc.I; h = sc.La2; li = new List<int>[n + 1]; for (int i = 1; i <= n; i++) { li[i] = new List<int>(); } for (int i = 1; i < n; i++) { int[] e = sc.Ia; li[e[0]].Add(e[1]); li[e[1]].Add(e[0]); } if (Fu(1, 0) != 0) { ans = "NO"; } Console.WriteLine("{0}", ans); } static long Fu(int a, int g) { long q = 0; for (int i = 0; i < li[a].Count; i++) { if (li[a][i] != g) { long p = Fu(li[a][i], a); if (h[a] < p) { ans = "NO"; } q += p; } } if (a == 1 && li[a].Count == 1) { q -= h[a]; } else if (a == 1) { q -= h[a] * 2; } else if (li[a].Count > 1) { q = h[a] * 2 - q; } else { q += h[a]; } if (h[a] < q || q < 0) { ans = "NO"; } return q; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine()).Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } }
[["-", 0, 57, 75, 57, 75, 57, 15, 16, 17, 106], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
669
8
using System; using System.IO; class Program { static void Main(string[] args) { var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(writer); Console.WriteLine(Solve()); Console.Out.Flush(); } static object Solve() { var s = Console.ReadLine(); var len = s.Length; var isScanning = false; var start = 0; var result = 0; for (int i = 0; i < len; i++) { if (s[i] == 'A' && !isScanning) { isScanning = true; start = i; } if (s[i] != 'Z') continue; isScanning = false; result = Math.Max(result, i - start + 1); } return result; } }
using System; using System.IO; class Program { static void Main(string[] args) { var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(writer); Console.WriteLine(Solve()); Console.Out.Flush(); } static object Solve() { var s = Console.ReadLine(); var len = s.Length; var isScanning = false; var start = 0; var result = -1; for (int i = 0; i < len; i++) { if (s[i] == 'A' && !isScanning) { isScanning = true; start = i; } if (s[i] == 'Z' && start != -1) { result = Math.Max(result, i - start + 1); } } return result; } }
[["-", 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, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 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, 79], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 12, 16, 12, 241, 0, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
178
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC053 { class ProblemB { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); string s = Console.ReadLine(); int idxA = 0; int idxZ = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'A') idxA = i; if (s[i] == 'Z') idxZ = i; } string result = (idxZ - idxA + 1).ToString(); Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC053 { class ProblemB { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); string s = Console.ReadLine(); int idxA = 200001; int idxZ = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'A' & i < idxA) idxA = i; if (s[i] == 'Z' & i > idxZ) idxZ = i; } string result = (idxZ - idxA + 1).ToString(); Console.WriteLine(result); Console.Out.Flush(); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 67], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47]]
8
172
10
using System; class Program { static void Main(string[] args) { var S = Console.ReadLine(); var length = S.Substring(S.IndexOf('A'), S.LastIndexOf('Z')).Length; Console.WriteLine(length); } }
using System; class Program { static void Main(string[] args) { var S = Console.ReadLine(); var length = S.Substring(S.IndexOf('A'), S.LastIndexOf('Z') - S.IndexOf('A') + 1) .Length; Console.WriteLine(length); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["+", 12, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 212, 0, 214, 205, 213, 3, 4, 0, 25]]
8
62
11
using System; namespace abc_053_b { class Program { static void Main(string[] args) { int a1 = 0; string a = Console.ReadLine(); for (int i = 0; i < a.Length; i++) { if (a.Substring(i, 1) == "A") { a1 = i - 1; break; } } for (int i = a.Length; i > 0; i--) { if (a1 > 0 && a.Substring(i - 1, 1) == "Z") { Console.WriteLine(i - a1 - 1); break; } } Console.ReadLine(); } } }
using System; namespace abc_053_b { class Program { static void Main(string[] args) { long a1 = -123232; string a = Console.ReadLine(); for (long i = 0; i < a.Length; i++) { if (a.Substring((int)i, 1) == "A") { a1 = i - 1; break; } } for (long i = a.Length; i > 0; i--) { if (a1 >= -1 && a.Substring((int)i - 1, 1) == "Z") { Console.WriteLine(i - a1 - 1); break; } } Console.ReadLine(); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 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, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 31, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 12, 241, 0, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 241, 0, 203], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25]]
8
139
20
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.C { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var x = ReadLong(); var count = (x / 11) * 2; var amari = x % 11; if (amari <= 6) { return count + 1; } return count + 2; } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.C { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var x = ReadLong(); var count = (x / 11) * 2; var amari = x % 11; if (amari == 0) return count; if (amari <= 6) { return count + 1; } return count + 2; } #region Console.Read public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); } public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); } public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); } public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["+", 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, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22]]
8
391
9
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() { long x = GetLong(); var ans = x % 11 <= 6 ? x / 11 * 2 + 1 : x / 11 * 2 + 2; 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() { long x = GetLong(); var ans = (x - 1) % 11 <= 5 ? (x - 1) / 11 * 2 + 1 : (x - 1) / 11 * 2 + 2; Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } }
[["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 41, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 12, 203], ["+", 64, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 64, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 75, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 75, 16, 31, 16, 31, 16, 31, 23, 0, 25]]
8
1,164
14
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { long r = ReadLong(); var ret = r / 11; if (r <= 6) { Console.WriteLine(1); return; } else if (r <= 11) { Console.WriteLine(2); return; } if (r % 11 == 0) { Console.WriteLine(ret * 2); } else { Console.WriteLine(ret * 2 + 1); } } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { long r = ReadLong(); var ret = r / 11; if (r <= 6) { Console.WriteLine(1); return; } else if (r <= 11) { Console.WriteLine(2); return; } if (r % 11 == 0) { Console.WriteLine(ret * 2); return; } if (r % 11 <= 6) { Console.WriteLine(ret * 2 + 1); } else { Console.WriteLine(ret * 2 + 2); } } private static readonly Func<string> Read = () => Console.ReadLine(); private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split(); private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine()); private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine()); private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray(); private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray(); private static readonly Action<string> Cw = str => Console.WriteLine(str); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 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, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 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, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
309
25
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace kyoupuro { class MainClass { public static void Main() { var x = Input.NextLong(); Console.WriteLine((x / 11) * 2 + Convert.ToInt64(x % 11 > 6) + 1L); } } class Input { static IEnumerator<string> enumerator; public static string Line() { return Console.ReadLine(); } public static int NextInt() { if (enumerator == null || !enumerator.MoveNext()) { enumerator = StrArr().AsEnumerable().GetEnumerator(); enumerator.MoveNext(); } return int.Parse(enumerator.Current); } public static long NextLong() { if (enumerator == null || !enumerator.MoveNext()) { enumerator = StrArr().AsEnumerable().GetEnumerator(); enumerator.MoveNext(); } return long.Parse(enumerator.Current); } public static string[] StrArr() { return Line().Split(' '); } public static List<int> IntList() { return StrArr().Select(int.Parse).ToList(); } public static List<long> LongList() { return StrArr().Select(long.Parse).ToList(); } public static void Skip(int line = 1) { enumerator.Reset(); for (int i = 0; i < line; i++) Console.ReadLine(); } public static void Reset() { enumerator.Reset(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace kyoupuro { class MainClass { public static void Main() { var x = Input.NextLong(); Console.WriteLine(((x - 1) / 11 + 1) * 2 - Convert.ToInt64(x % 11 <= 6 && x % 11 > 0)); } } class Input { static IEnumerator<string> enumerator; public static string Line() { return Console.ReadLine(); } public static int NextInt() { if (enumerator == null || !enumerator.MoveNext()) { enumerator = StrArr().AsEnumerable().GetEnumerator(); enumerator.MoveNext(); } return int.Parse(enumerator.Current); } public static long NextLong() { if (enumerator == null || !enumerator.MoveNext()) { enumerator = StrArr().AsEnumerable().GetEnumerator(); enumerator.MoveNext(); } return long.Parse(enumerator.Current); } public static string[] StrArr() { return Line().Split(' '); } public static List<int> IntList() { return StrArr().Select(int.Parse).ToList(); } public static List<long> LongList() { return StrArr().Select(long.Parse).ToList(); } public static void Skip(int line = 1) { enumerator.Reset(); for (int i = 0; i < line; i++) Console.ReadLine(); } public static void Reset() { enumerator.Reset(); } } }
[["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 31, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 19], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 98], ["+", 0, 28, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 28, 0, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 28, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
333
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); long n = cin.nextLong(); long ans = 1; if (n < 6) Console.WriteLine(ans); else { ans += (n / 11) * 2; if (n % 11 > 6) ans++; Console.WriteLine(ans); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } public void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); long n = cin.nextLong(); long ans = 1; if (n < 7) Console.WriteLine(ans); else { ans = (n / 11) * 2; if (n % 11 > 0 && n % 11 < 7) ans++; else if (n % 11 > 0) ans += 2; Console.WriteLine(ans); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } public void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 57, 75, 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, 109], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 75, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 75, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["+", 75, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 12, 203]]
8
741
25
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var x = long.Parse(Console.ReadLine()); var ope = 0L; if (x >= 11) { var tmp = x % 11; ope = (x / 11) * 2; if (tmp > 6) ope += 2; else ope += 1; } else { if (x > 6) ope += 2; else ope += 1; } Console.WriteLine(ope); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var x = long.Parse(Console.ReadLine()); var ope = 0L; if (x >= 11) { var tmp = x % 11; ope = (x / 11) * 2; if (tmp == 0) ope--; if (tmp > 6) ope += 2; else ope += 1; } else { if (x > 6) ope += 2; else ope += 1; } Console.WriteLine(ope); } } }
[["+", 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], ["+", 64, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 64, 196, 0, 57, 64, 1, 0, 223, 0, 68], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 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]]
8
118
9
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Program { static void Main(string[] args) { solve(); } static Scanner cin; static long x; static void input() { cin = new Scanner(); x = cin.nextLong(); } static void solve() { input(); long ans = x / 11 * 2; ans += x % 11 > 6 ? 2 : 1; WriteLine(ans); } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDounble(int N, int add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Program { static void Main(string[] args) { solve(); } static Scanner cin; static long x; static void input() { cin = new Scanner(); x = cin.nextLong(); } static void solve() { input(); long ans = x / 11 * 2; ans += x % 11 == 0 ? 0 : x % 11 > 6 ? 2 : 1; WriteLine(ans); } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDounble(int N, int add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
[["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 60], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 12, 41, 75, 41, 15, 16, 31, 16, 31, 22], ["+", 12, 41, 75, 41, 15, 16, 31, 16, 17, 109], ["+", 12, 41, 75, 41, 15, 16, 31, 16, 12, 203]]
8
457
8
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; class Program { const int mod = 1000000007; static void Main(string[] args) { long ans = 0; long x = long.Parse(Console.ReadLine()); ans += (x / 11) * 2; if (x % 11 <= 6) { ans++; } else { ans += 2; } Console.WriteLine(ans); } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Threading.Tasks; class Program { const int mod = 1000000007; static void Main(string[] args) { long ans = 0; long x = long.Parse(Console.ReadLine()); ans += (x / 11) * 2; if (x % 11 != 0) { if (x % 11 <= 6) { ans++; } else { ans += 2; } } Console.WriteLine(ans); } }
[["+", 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], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
109
10
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { new Program().Sol(); } public void Sol() { long x = long.Parse(Console.ReadLine()); long a = x / 11; long ans = a * 2; long b = x % 11; if (b > 6) { ans += 2; } else { ans += 1; } Console.WriteLine(ans); } } }
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { new Program().Sol(); } public void Sol() { long x = long.Parse(Console.ReadLine()); long a = x / 11; long ans = a * 2; long b = x % 11; if (b == 0) { } else if (b > 6) { ans += 2; } else { ans += 1; } Console.WriteLine(ans); } } }
[["+", 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, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22]]
8
99
9