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; public class Test { public static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); if (n % 2 != 0) { Console.WriteLine("No"); return; } var a = s.Substring(0, n / 2); var b = s.Substring(n / 2 + 1); if (a == b) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
using System; public class Test { public static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); if (n % 2 != 0) { Console.WriteLine("No"); return; } var a = s.Substring(0, n / 2); var b = s.Substring(n / 2); if (a == b) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
121
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProCon { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); char[] inputs = Console.ReadLine().ToArray(); string retStr = "Yes"; if (N == 1) { retStr = "No"; } else { int i = 0; int j = N / 2; while (true) { if (inputs[i] != inputs[j]) { retStr = "No"; break; } i++; j++; if (j >= N) { break; } } } Console.WriteLine(retStr); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProCon { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); char[] inputs = Console.ReadLine().ToArray(); string retStr = "Yes"; if (N == 1 || N % 2 == 1) { retStr = "No"; } else { int i = 0; int j = N / 2; while (true) { if (inputs[i] != inputs[j]) { retStr = "No"; break; } i++; j++; if (j >= N) { break; } } } Console.WriteLine(retStr); Console.ReadKey(); } } }
[["+", 0, 195, 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, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
168
6
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); if (n % 2 != 0) { Console.WriteLine("NO"); return; } var m = n / 2; for (int i = 0; i < m; i++) { if (s[i] != s[i + m]) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); if (n % 2 != 0) { Console.WriteLine("No"); return; } var m = n / 2; for (int i = 0; i < m; i++) { if (s[i] != s[i + m]) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
129
6
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); int b = a / 2; string input = Console.ReadLine(); string Lword = input.Substring(0, b); string Rword = input.Substring(b - 1, b); if (a % 2 != 0) { Console.WriteLine("No"); } else { if (Lword == Rword) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } } }
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); int b = a / 2; string input = Console.ReadLine(); string Lword = input.Substring(0, b); string Rword = input.Substring(b, b); if (a % 2 != 0) { Console.WriteLine("No"); } else { if (Lword == Rword) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
129
2
using System; namespace CSharp { class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); if (N % 2 > 0) { Console.WriteLine("No"); return; } Console.WriteLine( S.Substring(0, N / 2) == S.Substring(N / 2, N / 2 - 1) ? "Yes" : "No"); } } }
using System; namespace CSharp { class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); if (N % 2 > 0) { Console.WriteLine("No"); return; } Console.WriteLine( S.Substring(0, N / 2) == S.Substring(N / 2, N / 2) ? "Yes" : "No"); } } }
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
102
2
using System; namespace B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); if (N % 2 != 0) { Console.WriteLine("No"); return; } string T1 = S.Substring(0, (N / 2)); string T2 = S.Substring(N / 2, N / 2); for (int i = 0; i < N; i++) { if (T1[i] != T2[i]) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); return; } } }
using System; namespace B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); if (N % 2 != 0) { Console.WriteLine("No"); return; } string T1 = S.Substring(0, N / 2); string T2 = S.Substring(N / 2, N / 2); for (int i = 0; i < N / 2; i++) { if (T1[i] != T2[i]) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); return; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 23, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 23, 0, 25], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
150
4
using System; class Program { static void Main(string[] args) { string str = Console.ReadLine(); // string[] str = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string str = "<>>><<><<<<<>>><"; int N = Int32.Parse(str); string S = Console.ReadLine(); // string[] strA = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string[] strB = // Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得 // long[] A = new long[N]; // long[] B = new long[N]; if (N % 2 != 0) { Console.WriteLine("No"); return; } int half = N / 2; for (int i = 0; i < half; i++) { if (S[i] != S[half + i]) { Console.WriteLine("No"); } } Console.WriteLine("Yes"); } }
using System; class Program { static void Main(string[] args) { string str = Console.ReadLine(); // string[] str = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string str = "<>>><<><<<<<>>><"; int N = Int32.Parse(str); string S = Console.ReadLine(); // string[] strA = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string[] strB = // Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得 // long[] A = new long[N]; // long[] B = new long[N]; if (N % 2 != 0) { Console.WriteLine("No"); return; } int half = N / 2; for (int i = 0; i < half; i++) { if (S[i] != S[half + i]) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
8
131
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var S = cin.Read; var chars = S.ToCharArray(); var ans = true; if (N % 2 != 0) { ans = false; } else { for (int i = 0; i < N / 2; i++) { if (chars[i] != chars[i + N / 2]) { ans = false; break; } } } if (ans) { Console.WriteLine("Yes"); } else { Console.WriteLine("NO"); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var S = cin.Read; var chars = S.ToCharArray(); var ans = true; if (N % 2 != 0) { ans = false; } else { for (int i = 0; i < N / 2; i++) { if (chars[i] != chars[i + N / 2]) { ans = false; break; } } } if (ans) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
538
2
using System; namespace abc145 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); if (N != 1 && S.Substring(0, N / 2) == S.Substring(N / 2, N / 2)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; namespace abc145 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); if (N != 1 && N % 2 == 0 && S.Substring(0, N / 2) == S.Substring(N / 2, N / 2)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
8
98
6
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) { int N = int.Parse(Console.ReadLine()); String S = Console.ReadLine(); if (N % 2 != 0) { Console.WriteLine("No"); } String s1 = S.Substring(0, N / 2); String s2 = S.Substring(N / 2, N / 2); if (s1 == s2) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
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) { int N = int.Parse(Console.ReadLine()); String S = Console.ReadLine(); if (N % 2 != 0) { Console.WriteLine("No"); return; } String s1 = S.Substring(0, N / 2); String s2 = S.Substring(N / 2, N / 2); if (s1 == s2) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
8
147
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { int N = cin.ReadInt; string S = cin.ReadLine; if (N == 1) { WriteLine("No"); return; } for (int i = 0; i < N / 2; i++) { if (S[i] != S[N / 2 + i]) { WriteLine("No"); return; } } WriteLine("Yes"); } static long GcdArray(long[] array) { var ans = array[0]; for (var i = 1; i < array.Length; i++) { ans = Gcd(ans, array[i]); } return ans; } 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]; } static List<long> GetDivisor(long n) { List<long> divisor = new List<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { divisor.Add(i); if (i != n / i) divisor.Add(n / i); } } divisor.Sort(); return divisor; } // 互いに素 static bool coprime(long a, long b) { return (Gcd(a, b) == 1); } static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } static bool ChMin<Type>(ref Type a, Type b) where Type : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } static bool ChMax<Type>(ref Type a, Type b) where Type : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } // From // http://visualstudiomagazine.com/articles/2012/11/01/priority-queues-with-c.aspx public class PriorityQueue<T> where T : IComparable<T> { private List<T> data; public PriorityQueue() { this.data = new List<T>(); } public void Enqueue(T item) { data.Add(item); int ci = data.Count - 1; // child index; start at end while (ci > 0) { int pi = (ci - 1) / 2; // parent index if (data[ci].CompareTo(data[pi]) >= 0) break; // child item is larger than (or equal) parent so we're done T tmp = data[ci]; data[ci] = data[pi]; data[pi] = tmp; ci = pi; } } public T Dequeue() { // assumes pq is not empty; up to calling code int li = data.Count - 1; // last index (before removal) T frontItem = data[0]; // fetch the front data[0] = data[li]; data.RemoveAt(li); --li; // last index (after removal) int pi = 0; // parent index. start at front of pq while (true) { int ci = pi * 2 + 1; // left child index of parent if (ci > li) break; // no children so done int rc = ci + 1; // right child if (rc <= li && data[rc].CompareTo(data[ci]) < 0) // if there is a rc (ci + 1), and it is smaller // than left child, use the rc instead ci = rc; if (data[pi].CompareTo(data[ci]) <= 0) break; // parent is smaller than (or equal to) smallest child so done T tmp = data[pi]; data[pi] = data[ci]; data[ci] = tmp; // swap parent and child pi = ci; } return frontItem; } public T Peek() { T frontItem = data[0]; return frontItem; } public int Count() { return data.Count; } public override string ToString() { string s = ""; for (int i = 0; i < data.Count; ++i) s += data[i].ToString() + " "; s += "count = " + data.Count; return s; } public bool IsConsistent() { // is the heap property true for all data? if (data.Count == 0) return true; int li = data.Count - 1; // last index for (int pi = 0; pi < data.Count; ++pi) { // each parent index int lci = 2 * pi + 1; // left child index int rci = 2 * pi + 2; // right child index if (lci <= li && data[pi].CompareTo(data[lci]) > 0) return false; // if lc exists and it's greater than parent then bad. if (rci <= li && data[pi].CompareTo(data[rci]) > 0) return false; // check the right child too. } return true; // passed all checks } // IsConsistent } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { int N = cin.ReadInt; string S = cin.ReadLine; if (N % 2 == 1) { WriteLine("No"); return; } for (int i = 0; i < N / 2; i++) { if (S[i] != S[N / 2 + i]) { WriteLine("No"); return; } } WriteLine("Yes"); } static long GcdArray(long[] array) { var ans = array[0]; for (var i = 1; i < array.Length; i++) { ans = Gcd(ans, array[i]); } return ans; } 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]; } static List<long> GetDivisor(long n) { List<long> divisor = new List<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { divisor.Add(i); if (i != n / i) divisor.Add(n / i); } } divisor.Sort(); return divisor; } // 互いに素 static bool coprime(long a, long b) { return (Gcd(a, b) == 1); } static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } static bool ChMin<Type>(ref Type a, Type b) where Type : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } static bool ChMax<Type>(ref Type a, Type b) where Type : IComparable { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } // From // http://visualstudiomagazine.com/articles/2012/11/01/priority-queues-with-c.aspx public class PriorityQueue<T> where T : IComparable<T> { private List<T> data; public PriorityQueue() { this.data = new List<T>(); } public void Enqueue(T item) { data.Add(item); int ci = data.Count - 1; // child index; start at end while (ci > 0) { int pi = (ci - 1) / 2; // parent index if (data[ci].CompareTo(data[pi]) >= 0) break; // child item is larger than (or equal) parent so we're done T tmp = data[ci]; data[ci] = data[pi]; data[pi] = tmp; ci = pi; } } public T Dequeue() { // assumes pq is not empty; up to calling code int li = data.Count - 1; // last index (before removal) T frontItem = data[0]; // fetch the front data[0] = data[li]; data.RemoveAt(li); --li; // last index (after removal) int pi = 0; // parent index. start at front of pq while (true) { int ci = pi * 2 + 1; // left child index of parent if (ci > li) break; // no children so done int rc = ci + 1; // right child if (rc <= li && data[rc].CompareTo(data[ci]) < 0) // if there is a rc (ci + 1), and it is smaller // than left child, use the rc instead ci = rc; if (data[pi].CompareTo(data[ci]) <= 0) break; // parent is smaller than (or equal to) smallest child so done T tmp = data[pi]; data[pi] = data[ci]; data[ci] = tmp; // swap parent and child pi = ci; } return frontItem; } public T Peek() { T frontItem = data[0]; return frontItem; } public int Count() { return data.Count; } public override string ToString() { string s = ""; for (int i = 0; i < data.Count; ++i) s += data[i].ToString() + " "; s += "count = " + data.Count; return s; } public bool IsConsistent() { // is the heap property true for all data? if (data.Count == 0) return true; int li = data.Count - 1; // last index for (int pi = 0; pi < data.Count; ++pi) { // each parent index int lci = 2 * pi + 1; // left child index int rci = 2 * pi + 2; // right child index if (lci <= li && data[pi].CompareTo(data[lci]) > 0) return false; // if lc exists and it's greater than parent then bad. if (rci <= li && data[pi].CompareTo(data[rci]) > 0) return false; // check the right child too. } return true; // passed all checks } // IsConsistent } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
1,359
2
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200411.abc145_c.Cin; using static _20200411.abc145_c.Util; using Pair = _20200411.abc145_c.VTuple<long, long>; /// <summary> /// abc145 /// C - Average Length /// https://atcoder.jp/contests/abc145/tasks/abc145_c /// </summary> namespace _20200411.abc145_c { public class Program { public static void Main(string[] args) { int N = ri; long[] X, Y; ReadCols(out X, out Y, N); double sum = 0; for (int i = 0; i < N - 1; i++) { for (int j = 1; j < N; j++) { sum += Math.Sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])); } } double ans = sum * 2 / N; Console.WriteLine(ans); } } /// <summary> /// 競プロライブラリ /// https://github.com/ha2ne2/ABC/tree/master/Lib /// </summary> public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long val) { Value = val % MOD; if (Value < 0) Value += MOD; } private static Mint Ctor(long val) { return new Mint() { Value = val }; } public static Mint operator +(Mint a, Mint b) { long res = a.Value + b.Value; if (res > MOD) res -= MOD; return Ctor(res); } public static Mint operator -(Mint a, Mint b) { long res = a.Value - b.Value; if (res < 0) res += MOD; return Ctor(res); } public static Mint operator *(Mint a, Mint b) { long res = a.Value * b.Value; if (res > MOD) res %= MOD; return Ctor(res); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object obj) { return obj is Mint && Value == ((Mint)obj).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public override string ToString() { return Value.ToString(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long n) { if (n == 0) return new Mint(1); Mint b = Pow(a, n >> 1); b *= b; if ((n & 1) == 1) b *= a; return b; } public static Mint Inv(Mint n) { long a = n.Value; long b = MOD; long x = 1; long u = 0; while (b != 0) { long k = a / b; long _x = u; u = x - k * u; x = _x; long _a = a; a = b; b = _a - (k * b); } return new Mint(x); } public bool Equals(Mint other) { return Value == other.Value; } public int CompareTo(Mint other) { return Comparer<long>.Default.Compare(Value, other.Value); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { private V DefaultValue; private static Func<V> CreateInstance = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V defaultValue) { DefaultValue = defaultValue; } new public V this[K i] { get { V v; if (TryGetValue(i, out v)) { return v; } else { return base[i] = DefaultValue != null ? DefaultValue : CreateInstance(); } } set { base[i] = value; } } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; } public override bool Equals(object obj) { return obj is VTuple<T1, T2> && Equals((VTuple<T1, T2>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ")"; } public bool Equals(VTuple<T1, T2> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2); } public int CompareTo(VTuple<T1, T2> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; return Comparer<T2>.Default.Compare(Item2, other.Item2); } } public struct VTuple3<T1, T2, T3> : System.IComparable<VTuple3<T1, T2, T3>>, System.IEquatable<VTuple3<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple3(T1 item1, T2 item2, T3 item3) { Item1 = item1; Item2 = item2; Item3 = item3; } public override bool Equals(object obj) { return obj is VTuple3<T1, T2, T3> && Equals((VTuple3<T1, T2, T3>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")"; } public bool Equals(VTuple3<T1, T2, T3> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3); } public int CompareTo(VTuple3<T1, T2, T3> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; return Comparer<T3>.Default.Compare(Item3, other.Item3); } } public struct VTuple4<T1, T2, T3, T4> : System.IComparable<VTuple4<T1, T2, T3, T4>>, System.IEquatable<VTuple4<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple4(T1 item1, T2 item2, T3 item3, T4 item4) { Item1 = item1; Item2 = item2; Item3 = item3; Item4 = item4; } public override bool Equals(object obj) { return obj is VTuple4<T1, T2, T3, T4> && Equals((VTuple4<T1, T2, T3, T4>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; int h4 = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3, h4); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")"; } public bool Equals(VTuple4<T1, T2, T3, T4> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3) && EqualityComparer<T4>.Default.Equals(Item4, other.Item4); } public int CompareTo(VTuple4<T1, T2, T3, T4> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; c = Comparer<T3>.Default.Compare(Item3, other.Item3); if (c != 0) return c; return Comparer<T4>.Default.Compare(Item4, other.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int h1, int h2) { uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27); return ((int)rol5 + h1) ^ h2; } public static int CombineHashCodes(int h1, int h2) { return Combine(Combine(RandomSeed, h1), h2); } public static int CombineHashCodes(int h1, int h2, int h3) { return Combine(CombineHashCodes(h1, h2), h3); } public static int CombineHashCodes(int h1, int h2, int h3, int h4) { return Combine(CombineHashCodes(h1, h2, h3), h4); } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static string ReadString() { return Next(); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { Tokens = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long N) { a = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[,] ReadIntTable(int h, int w) { Tokens = null; int[,] ret = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadInt(); } } return ret; } public static long[,] ReadLongTable(long h, long w) { Tokens = null; long[,] ret = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadLong(); } } return ret; } public static char[,] ReadCharTable(int h, int w) { Tokens = null; char[,] res = new char[h, w]; for (int i = 0; i < h; i++) { string s = ReadString(); for (int j = 0; j < w; j++) { res[i, j] = s[j]; } } return res; } private static string[] Tokens; private static int Pointer; private static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { if (Console.IsOutputRedirected) return; var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } public static long GCD(long a, long b) { while (b != 0) { long _a = a; a = b; b = _a % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } public static long[] Accumulate(long[] array) { long[] acc = new long[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } public static double[] Accumulate(double[] array) { double[] acc = new double[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200411.abc145_c.Cin; using static _20200411.abc145_c.Util; using Pair = _20200411.abc145_c.VTuple<long, long>; /// <summary> /// abc145 /// C - Average Length /// https://atcoder.jp/contests/abc145/tasks/abc145_c /// </summary> namespace _20200411.abc145_c { public class Program { public static void Main(string[] args) { int N = ri; long[] X, Y; ReadCols(out X, out Y, N); double sum = 0; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { sum += Math.Sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])); } } double ans = sum * 2 / N; Console.WriteLine(ans); } } /// <summary> /// 競プロライブラリ /// https://github.com/ha2ne2/ABC/tree/master/Lib /// </summary> public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long val) { Value = val % MOD; if (Value < 0) Value += MOD; } private static Mint Ctor(long val) { return new Mint() { Value = val }; } public static Mint operator +(Mint a, Mint b) { long res = a.Value + b.Value; if (res > MOD) res -= MOD; return Ctor(res); } public static Mint operator -(Mint a, Mint b) { long res = a.Value - b.Value; if (res < 0) res += MOD; return Ctor(res); } public static Mint operator *(Mint a, Mint b) { long res = a.Value * b.Value; if (res > MOD) res %= MOD; return Ctor(res); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object obj) { return obj is Mint && Value == ((Mint)obj).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public override string ToString() { return Value.ToString(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long n) { if (n == 0) return new Mint(1); Mint b = Pow(a, n >> 1); b *= b; if ((n & 1) == 1) b *= a; return b; } public static Mint Inv(Mint n) { long a = n.Value; long b = MOD; long x = 1; long u = 0; while (b != 0) { long k = a / b; long _x = u; u = x - k * u; x = _x; long _a = a; a = b; b = _a - (k * b); } return new Mint(x); } public bool Equals(Mint other) { return Value == other.Value; } public int CompareTo(Mint other) { return Comparer<long>.Default.Compare(Value, other.Value); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { private V DefaultValue; private static Func<V> CreateInstance = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V defaultValue) { DefaultValue = defaultValue; } new public V this[K i] { get { V v; if (TryGetValue(i, out v)) { return v; } else { return base[i] = DefaultValue != null ? DefaultValue : CreateInstance(); } } set { base[i] = value; } } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; } public override bool Equals(object obj) { return obj is VTuple<T1, T2> && Equals((VTuple<T1, T2>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ")"; } public bool Equals(VTuple<T1, T2> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2); } public int CompareTo(VTuple<T1, T2> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; return Comparer<T2>.Default.Compare(Item2, other.Item2); } } public struct VTuple3<T1, T2, T3> : System.IComparable<VTuple3<T1, T2, T3>>, System.IEquatable<VTuple3<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple3(T1 item1, T2 item2, T3 item3) { Item1 = item1; Item2 = item2; Item3 = item3; } public override bool Equals(object obj) { return obj is VTuple3<T1, T2, T3> && Equals((VTuple3<T1, T2, T3>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")"; } public bool Equals(VTuple3<T1, T2, T3> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3); } public int CompareTo(VTuple3<T1, T2, T3> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; return Comparer<T3>.Default.Compare(Item3, other.Item3); } } public struct VTuple4<T1, T2, T3, T4> : System.IComparable<VTuple4<T1, T2, T3, T4>>, System.IEquatable<VTuple4<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple4(T1 item1, T2 item2, T3 item3, T4 item4) { Item1 = item1; Item2 = item2; Item3 = item3; Item4 = item4; } public override bool Equals(object obj) { return obj is VTuple4<T1, T2, T3, T4> && Equals((VTuple4<T1, T2, T3, T4>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; int h4 = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3, h4); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")"; } public bool Equals(VTuple4<T1, T2, T3, T4> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3) && EqualityComparer<T4>.Default.Equals(Item4, other.Item4); } public int CompareTo(VTuple4<T1, T2, T3, T4> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; c = Comparer<T3>.Default.Compare(Item3, other.Item3); if (c != 0) return c; return Comparer<T4>.Default.Compare(Item4, other.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int h1, int h2) { uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27); return ((int)rol5 + h1) ^ h2; } public static int CombineHashCodes(int h1, int h2) { return Combine(Combine(RandomSeed, h1), h2); } public static int CombineHashCodes(int h1, int h2, int h3) { return Combine(CombineHashCodes(h1, h2), h3); } public static int CombineHashCodes(int h1, int h2, int h3, int h4) { return Combine(CombineHashCodes(h1, h2, h3), h4); } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static string ReadString() { return Next(); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { Tokens = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long N) { a = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[,] ReadIntTable(int h, int w) { Tokens = null; int[,] ret = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadInt(); } } return ret; } public static long[,] ReadLongTable(long h, long w) { Tokens = null; long[,] ret = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadLong(); } } return ret; } public static char[,] ReadCharTable(int h, int w) { Tokens = null; char[,] res = new char[h, w]; for (int i = 0; i < h; i++) { string s = ReadString(); for (int j = 0; j < w; j++) { res[i, j] = s[j]; } } return res; } private static string[] Tokens; private static int Pointer; private static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { if (Console.IsOutputRedirected) return; var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } public static long GCD(long a, long b) { while (b != 0) { long _a = a; a = b; b = _a % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } public static long[] Accumulate(long[] array) { long[] acc = new long[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } public static double[] Accumulate(double[] array) { double[] acc = new double[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } } }
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72]]
8
3,838
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] x = new int[N], y = new int[N]; double total = 0, result; for (int i = 0; i < N; i++) { var p = Console.ReadLine().Split( ' '); // positionストラクトにxPos,yPosを入れ込む x[i] = int.Parse(p[0]); y[i] = int.Parse(p[1]); } for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { total += Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(x[i] - y[j], 2)); } } // totalは各地点間の距離の和 result = total * 2 / N; Console.Write(result); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] x = new int[N], y = new int[N]; double total = 0, result; for (int i = 0; i < N; i++) { var p = Console.ReadLine().Split( ' '); // positionストラクトにxPos,yPosを入れ込む x[i] = int.Parse(p[0]); y[i] = int.Parse(p[1]); } for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { total += Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(y[i] - y[j], 2)); } } // totalは各地点間の距離の和 result = total * 2 / N; Console.Write(result); } }
[["-", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22]]
8
238
2
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x = new int[n]; int[] y = new int[n]; for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); x[i] = int.Parse(input[0]); y[i] = int.Parse(input[1]); } double kyori = 0; double sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { kyori = Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(y[i] - y[j], 2)); sum += kyori; } } //出力 Console.WriteLine(sum * (n - 1) / n); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] x = new int[n]; int[] y = new int[n]; for (int i = 0; i < n; i++) { string[] input = Console.ReadLine().Split(' '); x[i] = int.Parse(input[0]); y[i] = int.Parse(input[1]); } double kyori = 0; double sum = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { kyori = Math.Sqrt(Math.Pow(x[i] - x[j], 2) + Math.Pow(y[i] - y[j], 2)); sum += kyori; } } //出力 Console.WriteLine(sum * 2 / n); } }
[["-", 0, 28, 0, 16, 31, 16, 12, 23, 0, 24], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203]]
8
228
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC145D { class Program { static void Main(string[] args) { string[] XY = Console.ReadLine().Split(' '); long X = long.Parse(XY[0]); long Y = long.Parse(XY[1]); long ans = 1; if (Y < 2 * X && 2 * Y > X) { if ((X + Y) % 3 == 0) { long N = (X + Y) / 3; long x = 0; long y = 0; for (long i = 0; i <= N; i++) { if ((2 * i + (N - i)) == X && (i + 2 * (N - i)) == Y) { x = i; y = N - i; } } // Console.WriteLine(x); // Console.WriteLine(y); if (x > y) { long temp = x; x = y; y = temp; } List<long> gyakugen = new List<long>(); long mod = 1000000007; string smod = Convert.ToString(mod - 2, 2); int l = smod.Length; for (long i = 1; i <= x; i++) { long p = i; long g = 1; for (int j = l - 1; j >= 0; j--) { if (smod[j].ToString() == "1") { g *= p; } p *= p; p %= mod; g %= mod; // Console.WriteLine(p); } gyakugen.Add(g); } long m = x + y; for (long i = m; i > m - x; i--) { ans *= i; ans %= mod; } // Console.WriteLine(smod); // Console.WriteLine(gyakugen[1]); int L = gyakugen.Count; for (int i = 0; i < L; i++) { ans *= gyakugen[i]; ans %= mod; } Console.WriteLine(ans); } else Console.WriteLine(0); } else Console.WriteLine(0); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC145D { class Program { static void Main(string[] args) { string[] XY = Console.ReadLine().Split(' '); long X = long.Parse(XY[0]); long Y = long.Parse(XY[1]); long ans = 1; if (Y <= 2 * X && 2 * Y >= X) { if ((X + Y) % 3 == 0) { long N = (X + Y) / 3; long x = 0; long y = 0; for (long i = 0; i <= N; i++) { if ((2 * i + (N - i)) == X && (i + 2 * (N - i)) == Y) { x = i; y = N - i; } } // Console.WriteLine(x); // Console.WriteLine(y); if (x > y) { long temp = x; x = y; y = temp; } List<long> gyakugen = new List<long>(); long mod = 1000000007; string smod = Convert.ToString(mod - 2, 2); int l = smod.Length; for (long i = 1; i <= x; i++) { long p = i; long g = 1; for (int j = l - 1; j >= 0; j--) { if (smod[j].ToString() == "1") { g *= p; } p *= p; p %= mod; g %= mod; // Console.WriteLine(p); } gyakugen.Add(g); } long m = x + y; for (long i = m; i > m - x; i--) { ans *= i; ans %= mod; } // Console.WriteLine(smod); // Console.WriteLine(gyakugen[1]); int L = gyakugen.Count; for (int i = 0; i < L; i++) { ans *= gyakugen[i]; ans %= mod; } Console.WriteLine(ans); } else Console.WriteLine(0); } else Console.WriteLine(0); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20]]
8
444
4
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static List<List<int>> l = new List<List<int>>(); static void Main(string[] args) { var r = ReadSplit(); var x = r[0].Long(); var y = r[1].Long(); var a = (2 * x - y) / 3; var n = (x + y) / 3; long ans = 0; if ((x + y) % 3 != 0 || 2 * x > y || 2 * y > x) { ans = 0; } else { ans = Combination(n, a); } WriteRead(ans); } private static long mod = 1000000007; public static long ModPow(long x, long n) { x = x % mod; if (n == 0) { return 1; } else if (n % 2 == 1) { return (x * ModPow(x, n - 1)) % mod; } else { return ModPow((x * x) % mod, n / 2) % mod; } } public static long Combination(long n, long k) { long x = 1; for (long i = n - k + 1; i <= n; i++) { x = x * i % mod; } long y = 1; for (int i = 1; i <= k; i++) { y = y * i % mod; } y = ModPow(y, mod - 2); return x * y % mod; } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static List<List<int>> l = new List<List<int>>(); static void Main(string[] args) { var r = ReadSplit(); var x = r[0].Long(); var y = r[1].Long(); var a = (2 * x - y) / 3; var n = (x + y) / 3; long ans = 0; if ((x + y) % 3 != 0 || 2 * x < y || 2 * y < x) { ans = 0; } else { ans = Combination(n, a); } WriteRead(ans); } private static long mod = 1000000007; public static long ModPow(long x, long n) { x = x % mod; if (n == 0) { return 1; } else if (n % 2 == 1) { return (x * ModPow(x, n - 1)) % mod; } else { return ModPow((x * x) % mod, n / 2) % mod; } } public static long Combination(long n, long k) { long x = 1; for (long i = n - k + 1; i <= n; i++) { x = x * i % mod; } long y = 1; for (int i = 1; i <= k; i++) { y = y * i % mod; } y = ModPow(y, mod - 2); return x * y % mod; } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18]]
8
739
4
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200331.Abc145_D.Cin; using static _20200331.Abc145_D.Util; using Pair = _20200331.Abc145_D.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200331 { public class Abc145_D { public static void Main(string[] args) { int X = ri; int Y = ri; COMinit(); Mint ans = 0; for (int a = 0; a < X; a++) { if ((X - a) % 2 == 0) { var b = (X - a) / 2; if (2 * a + b == Y) { ans += nCk(a + b, a); } } } Console.WriteLine((long)ans); } static int MAX = 1000000; static int MOD = 1000000007; static long[] fac, finv, inv; static void COMinit() { fac = new long[MAX]; finv = new long[MAX]; inv = new long[MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long a) { Value = a % MOD; if (Value < 0) Value += MOD; } static Mint i(long a) { return new Mint() { Value = a }; } public static Mint operator +(Mint a, Mint b) { long c = a.Value + b.Value; if (c > MOD) c -= MOD; return i(c); } public static Mint operator -(Mint a, Mint b) { long c = a.Value - b.Value; if (c < 0) c += MOD; return i(c); } public static Mint operator *(Mint a, Mint b) { long c = a.Value * b.Value; if (c > MOD) c %= MOD; return i(c); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object a) { return a is Mint && Value == ((Mint)a).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long b) { if (b == 0) return new Mint(1); Mint c = Pow(a, b >> 1); c *= c; if ((b & 1) == 1) c *= a; return c; } public static Mint Inv(Mint a) { long b = a.Value; long c = MOD; long d = 1; long e = 0; while (c != 0) { long f = b / c; long g = e; e = d - f * e; d = g; long h = b; b = c; c = h - (f * c); } return new Mint(d); } public bool Equals(Mint a) { return Value == a.Value; } public int CompareTo(Mint a) { return Comparer<long>.Default.Compare(Value, a.Value); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 a, T2 b) { Item1 = a; Item2 = b; } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2); } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; return Comparer<T2>.Default.Compare(Item2, a.Item2); } } public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>, System.IEquatable<VTuple<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple(T1 a, T2 b, T3 c) { Item1 = a; Item2 = b; Item3 = c; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c); } public bool Equals(VTuple<T1, T2, T3> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3); } public int CompareTo(VTuple<T1, T2, T3> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; return Comparer<T3>.Default.Compare(Item3, a.Item3); } } public struct VTuple<T1, T2, T3, T4> : System.IComparable<VTuple<T1, T2, T3, T4>>, System.IEquatable<VTuple<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple(T1 a, T2 b, T3 c, T4 d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; int d = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c, d); } public bool Equals(VTuple<T1, T2, T3, T4> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3) && EqualityComparer<T4>.Default.Equals(Item4, a.Item4); } public int CompareTo(VTuple<T1, T2, T3, T4> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; b = Comparer<T3>.Default.Compare(Item3, a.Item3); if (b != 0) return b; return Comparer<T4>.Default.Compare(Item4, a.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int a, int b) { uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } public static int CombineHashCodes(int a, int b) { return Combine(Combine(RandomSeed, a), b); } public static int CombineHashCodes(int a, int b, int c) { return Combine(CombineHashCodes(a, b), c); } public static int CombineHashCodes(int a, int b, int c, int d) { return Combine(CombineHashCodes(a, b, c), d); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static long GCD(long a, long b) { while (b != 0) { long c = a; a = b; b = c % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200331.Abc145_D.Cin; using static _20200331.Abc145_D.Util; using Pair = _20200331.Abc145_D.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200331 { public class Abc145_D { public static void Main(string[] args) { int X = ri; int Y = ri; COMinit(); Mint ans = 0; for (int a = 0; a <= X; a++) { if ((X - a) % 2 == 0) { var b = (X - a) / 2; if (2 * a + b == Y) { ans += nCk(a + b, a); } } } Console.WriteLine((long)ans); } static int MAX = 1000001; static int MOD = 1000000007; static long[] fac, finv, inv; static void COMinit() { fac = new long[MAX]; finv = new long[MAX]; inv = new long[MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long a) { Value = a % MOD; if (Value < 0) Value += MOD; } static Mint i(long a) { return new Mint() { Value = a }; } public static Mint operator +(Mint a, Mint b) { long c = a.Value + b.Value; if (c > MOD) c -= MOD; return i(c); } public static Mint operator -(Mint a, Mint b) { long c = a.Value - b.Value; if (c < 0) c += MOD; return i(c); } public static Mint operator *(Mint a, Mint b) { long c = a.Value * b.Value; if (c > MOD) c %= MOD; return i(c); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object a) { return a is Mint && Value == ((Mint)a).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long b) { if (b == 0) return new Mint(1); Mint c = Pow(a, b >> 1); c *= c; if ((b & 1) == 1) c *= a; return c; } public static Mint Inv(Mint a) { long b = a.Value; long c = MOD; long d = 1; long e = 0; while (c != 0) { long f = b / c; long g = e; e = d - f * e; d = g; long h = b; b = c; c = h - (f * c); } return new Mint(d); } public bool Equals(Mint a) { return Value == a.Value; } public int CompareTo(Mint a) { return Comparer<long>.Default.Compare(Value, a.Value); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 a, T2 b) { Item1 = a; Item2 = b; } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2); } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; return Comparer<T2>.Default.Compare(Item2, a.Item2); } } public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>, System.IEquatable<VTuple<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple(T1 a, T2 b, T3 c) { Item1 = a; Item2 = b; Item3 = c; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c); } public bool Equals(VTuple<T1, T2, T3> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3); } public int CompareTo(VTuple<T1, T2, T3> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; return Comparer<T3>.Default.Compare(Item3, a.Item3); } } public struct VTuple<T1, T2, T3, T4> : System.IComparable<VTuple<T1, T2, T3, T4>>, System.IEquatable<VTuple<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple(T1 a, T2 b, T3 c, T4 d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; int d = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c, d); } public bool Equals(VTuple<T1, T2, T3, T4> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3) && EqualityComparer<T4>.Default.Equals(Item4, a.Item4); } public int CompareTo(VTuple<T1, T2, T3, T4> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; b = Comparer<T3>.Default.Compare(Item3, a.Item3); if (b != 0) return b; return Comparer<T4>.Default.Compare(Item4, a.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int a, int b) { uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } public static int CombineHashCodes(int a, int b) { return Combine(Combine(RandomSeed, a), b); } public static int CombineHashCodes(int a, int b, int c) { return Combine(CombineHashCodes(a, b), c); } public static int CombineHashCodes(int a, int b, int c, int d) { return Combine(CombineHashCodes(a, b, c), d); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static long GCD(long a, long b) { while (b != 0) { long c = a; a = b; b = c % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203]]
8
3,842
4
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { //入力を受け取る var XY = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long X = XY[0]; long Y = XY[1]; if (((2 * X - Y) % 3 == 0) && ((2 * Y - X) % 3 == 0) && ((2 * Y - X) / 3 > 0) && ((2 * X - Y) / 3 > 0)) { // long N = (X+Y)/3; long N = (2 * X - Y) / 3 + (2 * Y - X) / 3; long R = (long)Math.Min((2 * X - Y) / 3, (2 * Y - X) / 3); // N個のものからR個選ぶ組み合わせ var kaijo = new long[1000000]; //階乗のモジュラー逆数 var Ikaijo = new long[1000000]; kaijo[0] = 1; Ikaijo[0] = 1; for (long i = 1; i < 1000000; i++) { kaijo[i] = (kaijo[i - 1] * i) % 1000000007; Ikaijo[i] = RepeatSquaring(kaijo[i]); } long mo = 1000000007; long ans = (((kaijo[N] % mo) * (Ikaijo[R] % mo) % mo) * Ikaijo[N - R]) % mo; Console.WriteLine(ans); } else { Console.WriteLine(0); } } //繰り返し2乗法 static long RepeatSquaring(long N, long M = 1000000005, long mod = 1000000007) { if (M == 0) { return 1; } else if (M % 2 == 0) { long t = RepeatSquaring(N, (M / 2), mod) % mod; return (t * t) % mod; } else { return ((N % mod) * RepeatSquaring(N, M - 1, mod)) % mod; } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static void Main(string[] args) { //入力を受け取る var XY = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long X = XY[0]; long Y = XY[1]; if (((2 * X - Y) % 3 == 0) && ((2 * Y - X) % 3 == 0) && ((2 * Y - X) / 3 >= 0) && ((2 * X - Y) / 3 >= 0)) { // long N = (X+Y)/3; long N = (2 * X - Y) / 3 + (2 * Y - X) / 3; long R = (long)Math.Min((2 * X - Y) / 3, (2 * Y - X) / 3); // N個のものからR個選ぶ組み合わせ var kaijo = new long[1000000]; //階乗のモジュラー逆数 var Ikaijo = new long[1000000]; kaijo[0] = 1; Ikaijo[0] = 1; for (long i = 1; i < 1000000; i++) { kaijo[i] = (kaijo[i - 1] * i) % 1000000007; Ikaijo[i] = RepeatSquaring(kaijo[i]); } long mo = 1000000007; long ans = (((kaijo[N] % mo) * (Ikaijo[R] % mo) % mo) * Ikaijo[N - R]) % mo; Console.WriteLine(ans); } else { Console.WriteLine(0); } } //繰り返し2乗法 static long RepeatSquaring(long N, long M = 1000000005, long mod = 1000000007) { if (M == 0) { return 1; } else if (M % 2 == 0) { long t = RepeatSquaring(N, (M / 2), mod) % mod; return (t * t) % mod; } else { return ((N % mod) * RepeatSquaring(N, M - 1, mod)) % mod; } } }
[["-", 15, 16, 31, 16, 12, 23, 0, 16, 17, 47], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 20], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 47], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 20]]
8
441
4
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG // MyDebugger.MakeTestCase("../TextFile2.txt"); return; MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static long mod = 1000000000 + 7; static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var x = int.Parse(spl[0]); var y = int.Parse(spl[1]); if ((x + y) % 3 != 0) return 0; // n+2m=x // 2n+m=y var n = (2 * y - x) / 3; var m = y - 2 * n; if (n <= 0 || m <= 0) return 0; return CombinationMod(n + m, n); } static long CombinationMod(long m, long n) { Func<long, long, long> ModPow = (x1, x2) => { long ans = 1; while (x2 > 0) { if (x2 % 2 == 1) { ans = (ans * x1) % mod; } x1 = (x1 * x1) % mod; x2 /= 2; } return ans % mod; }; Func<long, long> ModFact = (x1) => { long ans = 1; for (long i = x1; i > 0; i--) ans = (ans * i) % mod; return ans; }; var a = ModFact(m); var b = (ModFact(n) * ModFact(m - n)) % mod; long bb = ModPow(b, mod - 2); return (a * bb) % mod; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG // MyDebugger.MakeTestCase("../TextFile2.txt"); return; MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static long mod = 1000000000 + 7; static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var x = int.Parse(spl[0]); var y = int.Parse(spl[1]); if ((x + y) % 3 != 0) return 0; // n+2m=x // 2n+m=y var n = (2 * y - x) / 3; var m = y - 2 * n; if (n < 0 || m < 0) return 0; return CombinationMod(n + m, n); } static long CombinationMod(long m, long n) { Func<long, long, long> ModPow = (x1, x2) => { long ans = 1; while (x2 > 0) { if (x2 % 2 == 1) { ans = (ans * x1) % mod; } x1 = (x1 * x1) % mod; x2 /= 2; } return ans % mod; }; Func<long, long> ModFact = (x1) => { long ans = 1; for (long i = x1; i > 0; i--) ans = (ans * i) % mod; return ans; }; var a = ModFact(m); var b = (ModFact(n) * ModFact(m - n)) % mod; long bb = ModPow(b, mod - 2); return (a * bb) % mod; } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18]]
8
386
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC145D { class Program { public static void Solve(Input input) { var x = input.NextInt(); var y = input.NextInt(); if ((x + y) % 3 != 0) { Console.WriteLine(0); return; } var m = (2 * x - y) / 3; var n = x - 2 * m; if (x < 0 || y < 0) { Console.WriteLine(0); return; } var mc = new ModCom(); var count = mc.Ncr(n + m, n); Console.WriteLine(count); } /// <summary> /// Mを法とする数値によるCombinationなど /// Mは素数 /// </summary> public class ModCom { public readonly int M; // 階乗テーブル private int[] factorials; // 逆元テーブル private int[] invs; // 階乗の逆元テーブル private int[] finvs; private const int maxTableSize = (int)1e5; public ModCom(int mod = (int)1e9 + 7) { M = mod; factorials = Enumerable.Repeat(1, 2).ToArray(); invs = Enumerable.Repeat(1, 2).ToArray(); finvs = Enumerable.Repeat(1, 2).ToArray(); } [System.Runtime.CompilerServices.MethodImpl( System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] int Mul(int a, int b) => (int)(((long)(a % M) * (b % M)) % M); /// <summary> a/b </summary> [System.Runtime.CompilerServices.MethodImpl( System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] int Div(int a, int b) => Mul(a, Inverse(b)); /// <summary> /// aの逆元(a^-1) /// (厳密には違うが)Mは素数とする /// </summary> int Inverse(int a) { int b = M; int u = 1, v = 0; while (b > 0) { int t = a / b; a -= t * b; Swap(ref a, ref b); u -= t * v; Swap(ref u, ref v); } u %= M; if (u < 0) u += M; return u; } static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } /// <summary> /// n以下の各テーブルを作成する /// </summary> void MakeTable(int n) { int begin = factorials.Length; if (n < begin) return; if (n > maxTableSize) { throw new ArgumentOutOfRangeException(); } Array.Resize(ref factorials, n + 1); Array.Resize(ref invs, n + 1); Array.Resize(ref finvs, n + 1); for (int i = begin; i <= n; i++) { factorials[i] = Mul(factorials[i - 1], i); invs[i] = M - Mul(invs[M % i], M / i); finvs[i] = Mul(finvs[i - 1], invs[i]); } } /// <summary> /// 順列(nPr) /// </summary> public int Npr(int n, int r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; if (n <= maxTableSize) { MakeTable(n); return Mul(factorials[n], finvs[n - r]); } else { int npr = 1; for (int i = n; i > n - r; i--) { npr *= n; npr %= M; } return npr; } } /// <summary> /// 組み合わせ(nCr) /// </summary> public int Ncr(int n, int r) { r = Math.Min(r, n - r); if (n <= maxTableSize) { return Mul(Npr(n, r), finvs[r]); } else { int npr = 1, fact = 1; for (int i = 0; i < r; i++) { npr = Mul(npr, n - i); fact = Mul(fact, i + 1); } return Div(npr, fact); } } /// <summary> /// 重複組み合わせ(nHr) /// n個から重複を許してr個取り出す /// </summary> public int Nhr(int n, int r) => Ncr(n + r - 1, r); } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // そのときにTLEするのはアルゴリズムが悪いせいだし、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // テスト入力したまま提出することがままあるので…… #if DEBUG input.SetText(""); #endif Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) SetText(item); } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (string.IsNullOrEmpty(s)) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) queue.Enqueue(elem); return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) return ""; return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) if (!Read()) return false; return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC145D { class Program { public static void Solve(Input input) { var x = input.NextInt(); var y = input.NextInt(); if ((x + y) % 3 != 0) { Console.WriteLine(0); return; } var m = (2 * x - y) / 3; var n = x - 2 * m; if (m < 0 || n < 0) { Console.WriteLine(0); return; } var mc = new ModCom(); var count = mc.Ncr(n + m, n); Console.WriteLine(count); } /// <summary> /// Mを法とする数値によるCombinationなど /// Mは素数 /// </summary> public class ModCom { public readonly int M; // 階乗テーブル private int[] factorials; // 逆元テーブル private int[] invs; // 階乗の逆元テーブル private int[] finvs; private const int maxTableSize = (int)1e5; public ModCom(int mod = (int)1e9 + 7) { M = mod; factorials = Enumerable.Repeat(1, 2).ToArray(); invs = Enumerable.Repeat(1, 2).ToArray(); finvs = Enumerable.Repeat(1, 2).ToArray(); } [System.Runtime.CompilerServices.MethodImpl( System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] int Mul(int a, int b) => (int)(((long)(a % M) * (b % M)) % M); /// <summary> a/b </summary> [System.Runtime.CompilerServices.MethodImpl( System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] int Div(int a, int b) => Mul(a, Inverse(b)); /// <summary> /// aの逆元(a^-1) /// (厳密には違うが)Mは素数とする /// </summary> int Inverse(int a) { int b = M; int u = 1, v = 0; while (b > 0) { int t = a / b; a -= t * b; Swap(ref a, ref b); u -= t * v; Swap(ref u, ref v); } u %= M; if (u < 0) u += M; return u; } static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } /// <summary> /// n以下の各テーブルを作成する /// </summary> void MakeTable(int n) { int begin = factorials.Length; if (n < begin) return; if (n > maxTableSize) { throw new ArgumentOutOfRangeException(); } Array.Resize(ref factorials, n + 1); Array.Resize(ref invs, n + 1); Array.Resize(ref finvs, n + 1); for (int i = begin; i <= n; i++) { factorials[i] = Mul(factorials[i - 1], i); invs[i] = M - Mul(invs[M % i], M / i); finvs[i] = Mul(finvs[i - 1], invs[i]); } } /// <summary> /// 順列(nPr) /// </summary> public int Npr(int n, int r) { if (n < r) return 0; if (n < 0 || r < 0) return 0; if (n <= maxTableSize) { MakeTable(n); return Mul(factorials[n], finvs[n - r]); } else { int npr = 1; for (int i = n; i > n - r; i--) { npr *= n; npr %= M; } return npr; } } /// <summary> /// 組み合わせ(nCr) /// </summary> public int Ncr(int n, int r) { r = Math.Min(r, n - r); if (n <= maxTableSize) { return Mul(Npr(n, r), finvs[r]); } else { int npr = 1, fact = 1; for (int i = 0; i < r; i++) { npr = Mul(npr, n - i); fact = Mul(fact, i + 1); } return Div(npr, fact); } } /// <summary> /// 重複組み合わせ(nHr) /// n個から重複を許してr個取り出す /// </summary> public int Nhr(int n, int r) => Ncr(n + r - 1, r); } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // そのときにTLEするのはアルゴリズムが悪いせいだし、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // テスト入力したまま提出することがままあるので…… #if DEBUG input.SetText(""); #endif Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) SetText(item); } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (string.IsNullOrEmpty(s)) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) queue.Enqueue(elem); return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) return ""; return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) if (!Read()) return false; return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
1,832
4
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC145E { class Program { static void Main(string[] args) { var N = RInt; var T = RInt; int[] A = new int[N]; int[] B = new int[N]; for (int i = 0; i < N; i++) { A[i] = RInt; B[i] = RInt; } int[,] dp1 = new int[N, 110]; int[,] dp2 = new int[N, 110]; for (int i = 0; i < N - 1; i++) { int i_ = N - 1 - i; for (int j = 0; j <= T; j++) { if (j < A[i]) dp1[i + 1, j] = dp1[i, j]; else dp1[i + 1, j] = Math.Max(dp1[i, j], dp1[i, j - A[i]] + B[i]); if (j < A[i_]) dp2[i_ - 1, j] = dp2[i_, j]; else dp2[i_ - 1, j] = Math.Max(dp2[i_, j], dp2[i_, j - A[i_]] + B[i_]); } } Draw2D(dp1); Draw2D(dp2); int max = 0; for (int i = 0; i < N; i++) { //料理i以外をT-1以内に食べきれる合計 for (int j = 0; j < T; j++) { int cand = B[i]; if (i >= 0) cand += dp1[i, j]; if (i < N) cand += dp2[i, T - 1 - j]; max = Math.Max(max, cand); } } Console.WriteLine(max); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } static class Debug { static public void Draw2D(int[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j] % 10); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D(int[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC145E { class Program { static void Main(string[] args) { var N = RInt; var T = RInt; int[] A = new int[N]; int[] B = new int[N]; for (int i = 0; i < N; i++) { A[i] = RInt; B[i] = RInt; } int[,] dp1 = new int[N, 6001]; int[,] dp2 = new int[N, 6001]; for (int i = 0; i < N - 1; i++) { int i_ = N - 1 - i; for (int j = 0; j <= T; j++) { if (j < A[i]) dp1[i + 1, j] = dp1[i, j]; else dp1[i + 1, j] = Math.Max(dp1[i, j], dp1[i, j - A[i]] + B[i]); if (j < A[i_]) dp2[i_ - 1, j] = dp2[i_, j]; else dp2[i_ - 1, j] = Math.Max(dp2[i_, j], dp2[i_, j - A[i_]] + B[i_]); } } Draw2D(dp1); Draw2D(dp2); int max = 0; for (int i = 0; i < N; i++) { //料理i以外をT-1以内に食べきれる合計 for (int j = 0; j < T; j++) { int cand = B[i]; if (i >= 0) cand += dp1[i, j]; if (i < N) cand += dp2[i, T - 1 - j]; max = Math.Max(max, cand); } } Console.WriteLine(max); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } static class Debug { static public void Draw2D(int[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); int[,] map2 = new int[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0; else if (i == 0) map2[i, j] = j - 1; else if (j == 0) map2[i, j] = i - 1; else map2[i, j] = map[i - 1, j - 1]; } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j] % 10); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D(int[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
8
1,000
4
using System; public class Program { private int N, T; private Pair[] AB; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); T = sc.NextInt(); AB = new Pair[N]; for (int i = 0; i < N; i++) { AB[i] = new Pair(sc.NextInt(), sc.NextInt()); } Array.Sort(AB, (a, b) => a.A.CompareTo(b.B)); var dp = new int[T]; for (int i = 0; i < T; i++) { dp[i] = -1; } dp[0] = 0; int ans = 0; for (int i = 0; i < N; i++) { for (int j = T - 1; j >= 0; j--) { if (dp[j] == -1) continue; ans = Math.Max(ans, dp[j] + AB[i].B); if (j + AB[i].A < T) { dp[j + AB[i].A] = Math.Max(dp[j + AB[i].A], dp[j] + AB[i].B); } } } Console.WriteLine(ans); } public static void Main(string[] args) { new Program().Solve(); } } struct Pair { public int A, B; public Pair(int a, int b) { A = a; B = b; } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; public class Program { private int N, T; private Pair[] AB; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); T = sc.NextInt(); AB = new Pair[N]; for (int i = 0; i < N; i++) { AB[i] = new Pair(sc.NextInt(), sc.NextInt()); } Array.Sort(AB, (a, b) => a.A.CompareTo(b.A)); var dp = new int[T]; for (int i = 0; i < T; i++) { dp[i] = -1; } dp[0] = 0; int ans = 0; for (int i = 0; i < N; i++) { for (int j = T - 1; j >= 0; j--) { if (dp[j] == -1) continue; ans = Math.Max(ans, dp[j] + AB[i].B); if (j + AB[i].A < T) { dp[j + AB[i].A] = Math.Max(dp[j + AB[i].A], dp[j] + AB[i].B); } } } Console.WriteLine(ans); } public static void Main(string[] args) { new Program().Solve(); } } struct Pair { public int A, B; public Pair(int a, int b) { A = a; B = b; } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["-", 8, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 8, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
8
762
2
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; namespace UtakaApp { public partial class Program { //========================================================================================= // Answer //========================================================================================= public const string SiteName = "AtCoder"; public const string ContestName = "abc145"; public const string ProblemName = "E"; public void Solve() { int N = cin.ReadInt; int T = cin.ReadInt; int[][] abs = new int [N][]; for (int i = 0; i < N; i++) { abs[i] = cin.ReadIntArray(2); } // // 時間の昇順でソート // Array.Sort(abs, (x, y) => x[0] - y[0]); // dp1[i][j] : 1始まりのi番目までの料理で // j分以内に完食できる料理の美味しさの最大値 jはT-1まで dp2[i][j] : // 0始まりのi番目以降の料理で j分以内に完食できる料理の美味しさの最大値 // jはT-1まで int[][] dpF = JagArray2D<int>(N + 1, T, int.MinValue); int[][] dpB = JagArray2D<int>(N + 1, T, int.MinValue); dpF[0][0] = 0; dpB[N][0] = 0; for (int i = 0; i < N; i++) { dpF[i + 1] = dpF[i].Copy(); for (int j = abs[i][0]; j < T; j++) { dpF[i + 1][j] = Math.Max(dpF[i][j], dpF[i][j - abs[i][0]] + abs[i][1]); } // for (int j = 0; j < T; j++) // { // if (j - abs[i][0] >= 0) // { // dpF[i + 1][j] = Math.Max(dpF[i][j], dpF[i][j - // abs[i][0]] + abs[i][1]); // } // else // { // dpF[i + 1][j] = dpF[i][j]; // } // } } for (int i = N - 1; i >= 0; i--) { dpB[i] = dpB[i + 1].Copy(); for (int j = abs[i][0]; j < T; j++) { dpB[i][j] = Math.Max(dpB[i + 1][j], dpB[i + 1][j - abs[i][0]] + abs[i][1]); } // for (int j = abs[i][0]; j < T; j++) // { // if (j - abs[i][0] >= 0) // { // dpB[i][j] = Math.Max(dpB[i + 1][j], dpB[i + 1][j // - abs[i][0]] + abs[i][1]); // } // else // { // dpB[i][j] = dpB[i + 1][j]; // } // } } int max = dpF[N][T - 1]; for (int i = 0; i < N; i++) { int lastVal = abs[i][1]; for (int j = 0; j < T; j++) { int val1 = dpF[i][j]; int val2 = dpB[i + 1][T - 1 - j]; int total = lastVal + val1 + val2; max = Math.Max(max, total); } } cou.WriteLine(max); } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } //========================================================================================= // Library //========================================================================================= /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[,] Array2D<T>(int a, int b) where T : struct { var ret = new T[a, b]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// 配列をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL public static class Dbg { public static void WriteLine(string str) { Console.WriteLine(str); } public static void Write(string str) { Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; namespace UtakaApp { public partial class Program { //========================================================================================= // Answer //========================================================================================= public const string SiteName = "AtCoder"; public const string ContestName = "abc145"; public const string ProblemName = "E"; public void Solve() { int N = cin.ReadInt; int T = cin.ReadInt; int[][] abs = new int [N][]; for (int i = 0; i < N; i++) { abs[i] = cin.ReadIntArray(2); } // // 時間の昇順でソート // Array.Sort(abs, (x, y) => x[0] - y[0]); // dp1[i][j] : 1始まりのi番目までの料理で // j分以内に完食できる料理の美味しさの最大値 jはT-1まで dp2[i][j] : // 0始まりのi番目以降の料理で j分以内に完食できる料理の美味しさの最大値 // jはT-1まで int[][] dpF = JagArray2D<int>(N + 1, T, 0); int[][] dpB = JagArray2D<int>(N + 1, T, 0); dpF[0][0] = 0; dpB[N][0] = 0; for (int i = 0; i < N; i++) { // まず、1始まりでi-1番目の状態をコピー dpF[i + 1] = dpF[i].Copy(); for (int j = abs[i][0]; j < T; j++) { dpF[i + 1][j] = Math.Max(dpF[i][j], dpF[i][j - abs[i][0]] + abs[i][1]); } // for (int j = 0; j < T; j++) // { // if (j - abs[i][0] >= 0) // { // dpF[i + 1][j] = Math.Max(dpF[i][j], dpF[i][j - // abs[i][0]] + abs[i][1]); // } // else // { // dpF[i + 1][j] = dpF[i][j]; // } // } } for (int i = N - 1; i >= 0; i--) { // まず0始まりでi+1番目の状態をコピー dpB[i] = dpB[i + 1].Copy(); for (int j = abs[i][0]; j < T; j++) { dpB[i][j] = Math.Max(dpB[i + 1][j], dpB[i + 1][j - abs[i][0]] + abs[i][1]); } // for (int j = abs[i][0]; j < T; j++) // { // if (j - abs[i][0] >= 0) // { // dpB[i][j] = Math.Max(dpB[i + 1][j], dpB[i + 1][j // - abs[i][0]] + abs[i][1]); // } // else // { // dpB[i][j] = dpB[i + 1][j]; // } // } } int max = dpF[N][T - 1]; for (int i = 0; i < N; i++) { int lastVal = abs[i][1]; for (int j = 0; j < T; j++) { int val1 = dpF[i][j]; int val2 = dpB[i + 1][T - 1 - j]; int total = lastVal + val1 + val2; max = Math.Max(max, total); } } cou.WriteLine(max); } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } //========================================================================================= // Library //========================================================================================= /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[,] Array2D<T>(int a, int b) where T : struct { var ret = new T[a, b]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = Enumerable.Repeat(defaultValue, b).ToArray(); } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// 配列をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL public static class Dbg { public static void WriteLine(string str) { Console.WriteLine(str); } public static void Write(string str) { Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203]]
8
2,281
8
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var n = ni(); var t = ni(); var a = new int[n]; var b = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); b[i] = ni(); } var p = E.Range(0, n).ToArray(); Array.Sort(p, (p1, p2) => b[p1].CompareTo(b[p2])); var dp = new int[t + 3100]; foreach (var i in p) { for (int j = dp.Length - 1; j >= 0; j--) { var before = j - a[i]; if (0 <= before && before < t) { dp[j] = Math.Max(dp[j], dp[before] + b[i]); } } } cout.WriteLine(dp.Max()); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)); 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 { public static T Dump<T>(this T obj) { #if LOCAL return LINQPad.Extensions.Dump(obj); #else return obj; #endif } } public class Scanner { private readonly TextReader Reader; private readonly Queue<string> TokenQueue = new Queue<string>(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return int.Parse(Next(), ci); } public long NextLong() { return long.Parse(Next(), ci); } 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 (TokenQueue.Count == 0) { if (!StockTokens()) { throw new InvalidOperationException(); } } return TokenQueue.Dequeue(); } public bool HasNext() { if (TokenQueue.Count > 0) { return true; } return StockTokens(); } private static readonly char[] _separator = new[] { ' ', '\t' }; private bool StockTokens() { while (true) { string line = Reader.ReadLine(); if (line == null) { return false; } string[] tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { continue; } foreach (string token in tokens) { TokenQueue.Enqueue(token); } return true; } } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var n = ni(); var t = ni(); var a = new int[n]; var b = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); b[i] = ni(); } var p = E.Range(0, n).ToArray(); Array.Sort(p, (p1, p2) => a[p1].CompareTo(a[p2])); var dp = new int[t + 3100]; foreach (var i in p) { for (int j = dp.Length - 1; j >= 0; j--) { var before = j - a[i]; if (0 <= before && before < t) { dp[j] = Math.Max(dp[j], dp[before] + b[i]); } } } cout.WriteLine(dp.Max()); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)); 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 { public static T Dump<T>(this T obj) { #if LOCAL return LINQPad.Extensions.Dump(obj); #else return obj; #endif } } public class Scanner { private readonly TextReader Reader; private readonly Queue<string> TokenQueue = new Queue<string>(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return int.Parse(Next(), ci); } public long NextLong() { return long.Parse(Next(), ci); } 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 (TokenQueue.Count == 0) { if (!StockTokens()) { throw new InvalidOperationException(); } } return TokenQueue.Dequeue(); } public bool HasNext() { if (TokenQueue.Count > 0) { return true; } return StockTokens(); } private static readonly char[] _separator = new[] { ' ', '\t' }; private bool StockTokens() { while (true) { string line = Reader.ReadLine(); if (line == null) { return false; } string[] tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { continue; } foreach (string token in tokens) { TokenQueue.Enqueue(token); } return true; } } }
[["-", 0, 218, 8, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 218, 8, 213, 63, 214, 205, 204, 205, 22], ["-", 8, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 8, 213, 3, 4, 0, 28, 0, 204, 205, 22]]
8
1,109
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long answer = n / 2; Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long answer = (n + 1) / 2 - 1; Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
357
6
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; class Program { static void Main(string[] args) { string str = Console.ReadLine(); // string[] str = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string str = "<>>><<><<<<<>>><"; decimal A = Int64.Parse(str); // int B = int.Parse(str[1]); // string[] strHeight = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string[] results = new string[N]; // long[] result = new long[str.Length+1]; // result[0] = 0; // long min = 0; // long minpoint = 0; if (A % 2 == 0) { Console.WriteLine(A / 2); } else { Console.WriteLine(Math.Floor(A / 2)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; class Program { static void Main(string[] args) { string str = Console.ReadLine(); // string[] str = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string str = "<>>><<><<<<<>>><"; decimal A = Int64.Parse(str); // int B = int.Parse(str[1]); // string[] strHeight = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string[] results = new string[N]; // long[] result = new long[str.Length+1]; // result[0] = 0; // long min = 0; // long minpoint = 0; if (A % 2 == 0) { Console.WriteLine((A / 2) - 1); } else { Console.WriteLine(Math.Floor(A / 2)); } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
101
4
using System; class test { static void Main() { Int64 num1 = Int64.Parse(Console.ReadLine()); if ((num1 % 2) == 1) { Console.Write(((num1 - 1) / 2)); } else { Console.Write((num1 / 2)); } } }
using System; class test { static void Main() { Int64 num1 = Int64.Parse(Console.ReadLine()) - 1; if ((num1 % 2) == 1) { Console.Write(((num1 - 1) / 2)); } else { Console.Write((num1 / 2)); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
69
2
using System; using System.Linq; using System.Collections.Generic; using System.Collections; namespace Algorithm { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); n /= 2; if (n % 2 == 0) n--; Console.WriteLine(n); } } }
using System; using System.Linq; using System.Collections.Generic; using System.Collections; namespace Algorithm { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var ans = n / 2; if (n % 2 == 0) ans--; Console.WriteLine(ans); } } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 90], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
75
9
using System; namespace AtCoderWorkspace { public class Class142_1 { public static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); int n = 0; int.TryParse(inputs[0], out n); bool isGusu = n % 2 == 0; int split = n / 2; if (!isGusu) { split++; } float result = split / n; Console.WriteLine(result.ToString()); } } }
using System; namespace AtCoderWorkspace { public class Class142_1 { public static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); int n = 0; int.TryParse(inputs[0], out n); bool isGusu = n % 2 == 0; int split = n / 2; if (!isGusu) { split++; } float result = (float)split / n; Console.WriteLine(result.ToString()); } } }
[["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25]]
8
102
3
using System; class p { static void Main() { int N = int.Parse(Console.ReadLine()); double d = double.Parse(N.ToString()); Console.WriteLine((N % 2 == 0) ? ((d / 2) / d) : (((d / 2) + 1) / d)); } }
using System; class p { static void Main() { int N = int.Parse(Console.ReadLine()); double d = double.Parse(N.ToString()); Console.WriteLine((N % 2 == 0) ? ((N / 2) / d) : (((N / 2) + 1) / d)); } }
[["-", 64, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 64, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 31, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 23, 0, 16, 31, 22]]
8
79
4
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { static long mod = 1000000007; // static long mod =998244353; static int[] ans; static void Main(string[] args) { char[] cs = new char[] { ' ' }; // char[] cs = new char[] { ' ', ',' }; // int n = int.Parse(Console.ReadLine()); // int val = int.Parse(Console.ReadLine()); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); // string res = ""; double res = 0; int n = int.Parse(Console.ReadLine()); res = 1.0 * ((n / 2) + 1) / n; if (n == 1) { res = 1; } if (res % 2 == 0) { res = 0.5; } Console.WriteLine(res); return; } // int配列をスペース区切りの文字列に変換 static string stringBuilderArrayInt(int[] a) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < a.Length; i++) { if (a[i] == 1) { sb.Append(i + " "); } } if (sb.Length > 1) { sb = sb.Remove(sb.Length - 1, 1); } return sb.ToString(); ; } // 文字列strをindex番目からdで上書き static string strOverWrite(string str, int i, string s) { return str.Remove(i, s.Length).Insert(i, s); } // 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] = long.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; using System.Collections.Generic; class Program { static long mod = 1000000007; // static long mod =998244353; static int[] ans; static void Main(string[] args) { char[] cs = new char[] { ' ' }; // char[] cs = new char[] { ' ', ',' }; // int n = int.Parse(Console.ReadLine()); // int val = int.Parse(Console.ReadLine()); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); // string res = ""; double res = 0; int n = int.Parse(Console.ReadLine()); res = 1.0 * ((n / 2) + 1) / n; if (n == 1) { res = 1; } if (n % 2 == 0) { res = 0.5; } Console.WriteLine(res); return; } // int配列をスペース区切りの文字列に変換 static string stringBuilderArrayInt(int[] a) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < a.Length; i++) { if (a[i] == 1) { sb.Append(i + " "); } } if (sb.Length > 1) { sb = sb.Remove(sb.Length - 1, 1); } return sb.ToString(); ; } // 文字列strをindex番目からdで上書き static string strOverWrite(string str, int i, string s) { return str.Remove(i, s.Length).Insert(i, s); } // 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] = long.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, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22]]
8
459
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static void INPUT() { N = NextInt(); } static void OUT() { var a = N / 2; Console.WriteLine((float)(a) / N); } static void Main(string[] args) { #if DEBUG TESTINPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() { N = 11; } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static void INPUT() { N = NextInt(); } static void OUT() { var a = N / 2 + N % 2; Console.WriteLine((float)(a) / N); } static void Main(string[] args) { #if DEBUG TESTINPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() { N = 3; } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 109], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203]]
8
434
6
using System; class ProgramA { static void Main(string[] args) { string input = Console.ReadLine(); int a = int.Parse(input); double b = (double)((a / 2 + 1) / a); if (a % 2 == 0) Console.WriteLine("0.5"); else Console.WriteLine(b); } }
using System; class ProgramA { static void Main(string[] args) { string input = Console.ReadLine(); int a = int.Parse(input); double b = (double)(a / 2 + 1) / (double)a; if (a % 2 == 0) Console.WriteLine("0.5"); else Console.WriteLine(b); } }
[["-", 0, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 0, 24], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 12, 74, 51, 22]]
8
80
5
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); int N = int.Parse(str1[0]); int K = int.Parse(str1[1]); int ans = 0; string[] str2 = Console.ReadLine().Split(' '); int[] height = str2.Select(int.Parse).ToArray(); for (int i = 0; i < N; i++) { if (height[i] < K) { ans++; } } Console.WriteLine(ans); } } }
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); int N = int.Parse(str1[0]); int K = int.Parse(str1[1]); int ans = 0; string[] str2 = Console.ReadLine().Split(' '); int[] height = str2.Select(int.Parse).ToArray(); for (int i = 0; i < N; i++) { if (height[i] >= K) { ans++; } } Console.WriteLine(ans); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
149
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner cin = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var o = cin.IntM; int N = o[0]; int K = o[1]; var h = cin.IntM; int ans = 0; for (int i = 0; i < N; ++i) { if (h[i] > K) ans++; } wr.wri(ans); } } // b-aで降順 class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner cin = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var o = cin.IntM; int N = o[0]; int K = o[1]; var h = cin.IntM; int ans = 0; for (int i = 0; i < N; ++i) { if (h[i] >= K) ans++; } wr.wri(ans); } } // b-aで降順 class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
960
2
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class AtCoderC { static void Main() { int n = int.Parse(Console.ReadLine()); Tuple<int, int>[] students = new Tuple<int, int>[n]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { int num = int.Parse(words[i]); students[i] = Tuple.Create(i, num); } } students = students.OrderBy(t => t.Item1).ToArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.Append(" " + students[i].Item2); } Console.WriteLine(sb.ToString().Trim()); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class AtCoderC { static void Main() { int n = int.Parse(Console.ReadLine()); Tuple<int, int>[] students = new Tuple<int, int>[n]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { int num = int.Parse(words[i]); students[i] = Tuple.Create(i, num); } } students = students.OrderBy(t => t.Item2).ToArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.Append(" " + (students[i].Item1 + 1)); } Console.WriteLine(sb.ToString().Trim()); } }
[["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 12, 214, 141, 22], ["+", 0, 16, 12, 23, 0, 16, 31, 214, 141, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
205
8
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int32; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var a = Enumerate(n, x => ri); var id = Enumerate(n, x => x + 1).OrderBy(x => a[x]).ToArray(); Console.WriteLine(id.AsJoinedString()); } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); /* var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); //*/ solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int32; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var a = Enumerate(n, x => ri); var id = Enumerate(n, x => x + 1).OrderBy(x => a[x - 1]).ToArray(); Console.WriteLine(id.AsJoinedString()); } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); /* var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); //*/ solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion
[["+", 8, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 8, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
890
2
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp3 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var list = Console.ReadLine() .Split() .Select((order, index) => new { Order = order, Number = index + 1 }) .OrderBy(stu => stu.Order) .Select(stu => stu.Number); var str = string.Join(" ", list); Console.WriteLine(str); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp3 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var list = Console.ReadLine() .Split() .Select((order, index) => new { Order = int.Parse(order), Number = index + 1 }) .OrderBy(stu => stu.Order) .Select(stu => stu.Number); var str = string.Join(" ", list); Console.WriteLine(str); } } }
[["+", 0, 218, 8, 312, 0, 213, 63, 214, 205, 199], ["+", 0, 218, 8, 312, 0, 213, 63, 214, 0, 131], ["+", 0, 218, 8, 312, 0, 213, 63, 214, 141, 22], ["+", 0, 218, 8, 312, 0, 213, 3, 4, 0, 24], ["+", 0, 218, 8, 312, 0, 213, 3, 4, 0, 25]]
8
122
5
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderWorkspace { public static class Class142_3 { private struct Hi { public int Order; public int Number; } private static List<Hi> _hos = new List<Hi>(); public static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); int n = 0; int.TryParse(inputs[0], out n); var orders = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { int temp; int.TryParse(orders[i], out temp); var hi = new Hi(); hi.Number = i; hi.Order = temp; _hos.Add(hi); } var ordered = _hos.OrderBy(h => h.Order).ToList(); for (int i = 0; i < ordered.Count; i++) { var hi = ordered[i]; Console.Write(hi.Number); if (i != ordered.Count - 1) { Console.Write(" "); } } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderWorkspace { public static class Class142_3 { private struct Hi { public int Order; public int Number; } private static List<Hi> _hos = new List<Hi>(); public static void Main(string[] args) { var inputs = Console.ReadLine().Split(' '); int n = 0; int.TryParse(inputs[0], out n); var orders = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { int temp; int.TryParse(orders[i], out temp); var hi = new Hi(); hi.Number = i + 1; hi.Order = temp; _hos.Add(hi); } var ordered = _hos.OrderBy(h => h.Order).ToList(); for (int i = 0; i < ordered.Count; i++) { var hi = ordered[i]; Console.Write(hi.Number); if (i != ordered.Count - 1) { Console.Write(" "); } } } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
249
2
using System; using System.Linq; using System.Collections.Generic; // Gluttony namespace E { class Program { static long Solve(int n, long k, List<long> a, List<long> f) { a.Sort(); f.Sort(); f.Reverse(); var scores = a.Zip(f, (ai, fi) => new { ai, fi }); var max = scores.Select(s => s.ai * s.fi).Max(); Func<long, bool> pred = x => { return scores.Select(score => Math.Max(0, score.ai - x / score.fi)) .Sum() <= k; }; // Func<long, long, long> binarySearch = null; // binarySearch = (start, end) => { // if (start + 1 >= end) // { // return pred(start) // ? start // : end; // } // var m = (start + end) / 2; // return pred(m) // ? binarySearch(start, m) // : binarySearch(m, end); //}; // return binarySearch(0, max); // another version of binary search long start = 0; long end = max; while (Math.Abs(start - end) > 1) { long m = (start + end) / 2; if (pred(m)) { end = m; } else { start = m; } } return end; } static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int n = Convert.ToInt32(line[0]); long k = Convert.ToInt64(line[1]); var a = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x)); var f = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x)); Console.Write(Solve(n, k, a.ToList(), f.ToList())); } } }
using System; using System.Linq; using System.Collections.Generic; // Gluttony namespace E { class Program { static long Solve(int n, long k, List<long> a, List<long> f) { a.Sort(); f.Sort(); f.Reverse(); var scores = a.Zip(f, (ai, fi) => new { ai, fi }); var max = scores.Select(s => s.ai * s.fi).Max(); Func<long, bool> pred = x => { return scores.Select(score => Math.Max(0, score.ai - x / score.fi)) .Sum() <= k; }; // Func<long, long, long> binarySearch = null; // binarySearch = (start, end) => { // if (start + 1 >= end) // { // return pred(start) // ? start // : end; // } // var m = (start + end) / 2; // return pred(m) // ? binarySearch(start, m) // : binarySearch(m, end); //}; // return binarySearch(0, max); // another version of binary search long start = -1; long end = max; while (Math.Abs(start - end) > 1) { long m = (start + end) / 2; if (pred(m)) { end = m; } else { start = m; } } return end; } static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int n = Convert.ToInt32(line[0]); long k = Convert.ToInt64(line[1]); var a = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x)); var f = Console.ReadLine().Split(' ').Select(x => Convert.ToInt64(x)); Console.Write(Solve(n, k, a.ToList(), f.ToList())); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203]]
8
364
3
using System; using System.Linq; using System.Collections.Generic; class ProgramE { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int n = int.Parse(input[0]); long k = long.Parse(input[1]); long[] eat = new long[n]; long[] food = new long[n]; long[] sec = new long[n]; string[] input_a = Console.ReadLine().Split(); for (int i = 0; i < n; i++) eat[i] = long.Parse(input_a[i]); string[] input_f = Console.ReadLine().Split(); for (int i = 0; i < n; i++) food[i] = long.Parse(input_f[i]); long check = 0; for (int i = 0; i < n; i++) check += eat[i]; if (k >= check) { Console.WriteLine("0"); return; } Array.Sort(eat); Array.Sort(food); Array.Reverse(food); for (int i = 0; i < n; i++) sec[i] = food[i] * eat[i]; long max = sec.Max(); long min = 0; while (max != min + 1) { long x = (max + min) / 2; long count = 0; for (int i = 0; i < n; i++) { if (sec[i] > x) { if ((sec[i] - x) % food[i] == 0) count += (sec[i] - x) / food[i]; else count += (sec[i] - x) / food[i] + 1; } } if (count < k) max = x; else min = x; } Console.WriteLine(max); } }
using System; using System.Linq; using System.Collections.Generic; class ProgramE { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int n = int.Parse(input[0]); long k = long.Parse(input[1]); long[] eat = new long[n]; long[] food = new long[n]; long[] sec = new long[n]; string[] input_a = Console.ReadLine().Split(); for (int i = 0; i < n; i++) eat[i] = long.Parse(input_a[i]); string[] input_f = Console.ReadLine().Split(); for (int i = 0; i < n; i++) food[i] = long.Parse(input_f[i]); long check = 0; for (int i = 0; i < n; i++) check += eat[i]; if (k >= check) { Console.WriteLine("0"); return; } Array.Sort(eat); Array.Sort(food); Array.Reverse(food); for (int i = 0; i < n; i++) sec[i] = food[i] * eat[i]; long max = sec.Max(); long min = 0; while (max != min + 1) { long x = (max + min) / 2; long count = 0; for (int i = 0; i < n; i++) { if (sec[i] > x) { if ((sec[i] - x) % food[i] == 0) count += (sec[i] - x) / food[i]; else count += (sec[i] - x) / food[i] + 1; } } if (count <= k) max = x; else min = x; } Console.WriteLine(max); } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19]]
8
429
2
using System; using System.Linq; namespace E { class Program { static long[] A; static long[] F; static long K; static void Main(string[] args) { var NK = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = (int)NK[0]; K = NK[1]; A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); F = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); A = A.OrderBy(n => n).ToArray(); F = F.OrderByDescending(n => n).ToArray(); var result = lower_bound(1000000000000, judge); Console.WriteLine(result); } static bool judge(long key) { var target = F.Select(x => (long)(key / x)).ToArray(); long count = 0; for (int i = 0; i < A.Length; i++) { count += Math.Max(0, A[i] - target[i]); } return count <= K; } static long lower_bound(long length, Func<long, bool> pred) { long ng = 0; long ok = length; while (Math.Abs(ng - ok) > 1) { long mid = (ok + ng) / 2; if (pred(mid)) ok = mid; else ng = mid; } return ok; } } }
using System; using System.Linq; namespace E { class Program { static long[] A; static long[] F; static long K; static void Main(string[] args) { var NK = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = (int)NK[0]; K = NK[1]; A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); F = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); A = A.OrderBy(n => n).ToArray(); F = F.OrderByDescending(n => n).ToArray(); var result = lower_bound(1000000000000, judge); Console.WriteLine(result); } static bool judge(long key) { var target = F.Select(x => (long)(key / x)).ToArray(); long count = 0; for (int i = 0; i < A.Length; i++) { count += Math.Max(0, A[i] - target[i]); } return count <= K; } static long lower_bound(long length, Func<long, bool> pred) { long ng = -1; long ok = length; while (Math.Abs(ng - ok) > 1) { long mid = (ok + ng) / 2; if (pred(mid)) ok = mid; else ng = mid; } return ok; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203]]
8
332
3
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int32; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var m = ri; var f = new int[m]; var t = new int[m]; var G = Enumerate(n, x => new List<int>()); for (int i = 0; i < m; i++) { f[i] = ri - 1; t[i] = ri - 1; G[f[i]].Add(t[i]); } var dp = new double[n]; var prob = new double[n]; prob[0] = 1; for (int i = n - 2; i >= 0; i--) { var p = G[i].Count; var u = 0.0; foreach (var x in G[i]) { u += dp[x]; } dp[i] = 1 + u / p; } for (int i = 0; i < n - 1; i++) { foreach (var x in G[i]) prob[x] += prob[i] / G[i].Count; } var max = 0.0; for (int i = 0; i < m; i++) { var u = f[i]; var v = t[i]; if (G[u].Count == 1) continue; var p = prob[u]; var val = (dp[u] - 1) * G[u].Count; val -= dp[v]; val /= G[u].Count - 1; val += 1; max = Max(max, prob[u] * (dp[u] - val)); } Debug.WriteLine(dp[0] - max); } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); /* var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); //*/ solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion #region Binomial Coefficient public class BinomialCoefficient { public ModInt[] fact, ifact; public BinomialCoefficient(int n) { fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } #endregion
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int32; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var m = ri; var f = new int[m]; var t = new int[m]; var G = Enumerate(n, x => new List<int>()); for (int i = 0; i < m; i++) { f[i] = ri - 1; t[i] = ri - 1; G[f[i]].Add(t[i]); } var dp = new double[n]; var prob = new double[n]; prob[0] = 1; for (int i = n - 2; i >= 0; i--) { var p = G[i].Count; var u = 0.0; foreach (var x in G[i]) { u += dp[x]; } dp[i] = 1 + u / p; } for (int i = 0; i < n - 1; i++) { foreach (var x in G[i]) prob[x] += prob[i] / G[i].Count; } var max = 0.0; for (int i = 0; i < m; i++) { var u = f[i]; var v = t[i]; if (G[u].Count == 1) continue; var p = prob[u]; var val = (dp[u] - 1) * G[u].Count; val -= dp[v]; val /= G[u].Count - 1; val += 1; max = Max(max, prob[u] * (dp[u] - val)); } Console.WriteLine(dp[0] - max); } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); /* var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); //*/ solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion #region Binomial Coefficient public class BinomialCoefficient { public ModInt[] fact, ifact; public BinomialCoefficient(int n) { fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } #endregion
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22]]
8
1,766
2
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static List<int>[] li; static bool[] b; static double[] h; static void Main() { Sc sc = new Sc(); int[] s = sc.Ia; int n = s[0], m = s[1]; li = new List<int>[n + 1]; b = new bool[n + 1]; h = new double[n + 1]; for (int i = 1; i <= n; i++) { li[i] = new List<int>(); } for (int i = 0; i < s[1]; i++) { int[] e = sc.Ia; li[e[0]].Add(e[1]); } var li2 = new List<Tuple<int, double>>(); for (int i = n - 1; i > 0; i--) { if (li[i].Count == 1) { h[i] = h[li[i][0]] + 1; } else { double d = 0, p = 0; for (int j = 0; j < li[i].Count; j++) { d += h[li[i][j]] + 1; p = Max(p, h[li[i][j]] + 1); } li2.Add(Tuple.Create(i, p)); h[i] = d / (li[i].Count); } } double ans = double.MaxValue; for (int k = 0; k < li2.Count; k++) { h = new double[n + 1]; for (int i = n - 1; i > 0; i--) { if (li[i].Count == 1) { h[i] = h[li[i][0]] + 1; } else { double d = 0; for (int j = 0; j < li[i].Count; j++) { d += h[li[i][j]] + 1; } if (i == li2[k].Item1) { d -= li2[k].Item2; h[i] = d / (li[i].Count - 1); } else { h[i] = d / (li[i].Count); } } } ans = Min(ans, h[1]); } Console.WriteLine("{0}", 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 long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static List<int>[] li; static bool[] b; static double[] h; static void Main() { Sc sc = new Sc(); int[] s = sc.Ia; int n = s[0], m = s[1]; li = new List<int>[n + 1]; b = new bool[n + 1]; h = new double[n + 1]; for (int i = 1; i <= n; i++) { li[i] = new List<int>(); } for (int i = 0; i < s[1]; i++) { int[] e = sc.Ia; li[e[0]].Add(e[1]); } var li2 = new List<Tuple<int, double>>(); for (int i = n - 1; i > 0; i--) { if (li[i].Count == 1) { h[i] = h[li[i][0]] + 1; } else { double d = 0, p = 0; for (int j = 0; j < li[i].Count; j++) { d += h[li[i][j]] + 1; p = Max(p, h[li[i][j]] + 1); } li2.Add(Tuple.Create(i, p)); h[i] = d / (li[i].Count); } } double ans = h[1]; for (int k = 0; k < li2.Count; k++) { h = new double[n + 1]; for (int i = n - 1; i > 0; i--) { if (li[i].Count == 1) { h[i] = h[li[i][0]] + 1; } else { double d = 0; for (int j = 0; j < li[i].Count; j++) { d += h[li[i][j]] + 1; } if (i == li2[k].Item1) { d -= li2[k].Item2; h[i] = d / (li[i].Count - 1); } else { h[i] = d / (li[i].Count); } } } ans = Min(ans, h[1]); } Console.WriteLine("{0}", 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 long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73]]
8
1,399
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 2; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long A = inputArray[0]; long B = inputArray[1]; //答えの出力 var ans = A - B * 2 >= 0 ? A - B * 2 : -1; Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } /// <summary> /// 2組みずつの入力データ(数値)からTuppleListを作成する /// </summary> /// <param name="N"></param> /// <returns></returns> private static List<Tuple<long, long>> createLongTuppleList(long N) { var inpList = new List<Tuple<long, long>>(); for (int i = 0; i < N; i++) { var inp = retreiveLongArray(); var item1 = inp[0]; var item2 = inp[1]; inpList.Add(new Tuple<long, long>(item1, item2)); } return inpList; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 2; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long A = inputArray[0]; long B = inputArray[1]; //答えの出力 var ans = A - B * 2 >= 0 ? A - B * 2 : 0; Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } /// <summary> /// 2組みずつの入力データ(数値)からTuppleListを作成する /// </summary> /// <param name="N"></param> /// <returns></returns> private static List<Tuple<long, long>> createLongTuppleList(long N) { var inpList = new List<Tuple<long, long>>(); for (int i = 0; i < N; i++) { var inp = retreiveLongArray(); var item1 = inp[0]; var item2 = inp[1]; inpList.Add(new Tuple<long, long>(item1, item2)); } return inpList; } } }
[["-", 0, 200, 0, 212, 0, 41, 75, 241, 0, 33], ["-", 0, 200, 0, 212, 0, 41, 75, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 75, 203]]
8
310
3
using System; using System.Collections.Generic; using System.Dynamic; using System.Linq; using System.Security.Cryptography.X509Certificates; namespace atcorder { class Program { static void Main(string[] args) { int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int A = intArray[0]; int B = intArray[1]; if (A / 2 <= B) { Console.WriteLine(0); } else { Console.WriteLine(A - B * 2); } } } } //文字配列の取得 // string[] strArray = Console.ReadLine().Split(' ').ToArray(); // string S = strArray[0]; // string T = strArray[1]; //文字列の取得 // string s = Console.ReadLine(); //数字配列の取得 // int[] intArray = Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray(); int H = intArray[0]; int W = intArray[1]; //数字の取得 // int N = int.Parse(Console.ReadLine()); //リスト型(int)の取得 // List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray()); //出力 // Console.WriteLine(ans); // Console.WriteLine("Yes"); // Console.WriteLine("No"); // Console.WriteLine(cnt);
using System; using System.Collections.Generic; using System.Dynamic; using System.Linq; using System.Security.Cryptography.X509Certificates; namespace atcorder { class Program { static void Main(string[] args) { int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int A = intArray[0]; int B = intArray[1] * 2; if (A <= B) { Console.WriteLine(0); } else { Console.WriteLine(A - B); } } } } //文字配列の取得 // string[] strArray = Console.ReadLine().Split(' ').ToArray(); // string S = strArray[0]; // string T = strArray[1]; //文字列の取得 // string s = Console.ReadLine(); //数字配列の取得 // int[] intArray = Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray(); int H = intArray[0]; int W = intArray[1]; //数字の取得 // int N = int.Parse(Console.ReadLine()); //リスト型(int)の取得 // List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray()); //出力 // Console.WriteLine(ans); // Console.WriteLine("Yes"); // Console.WriteLine("No"); // Console.WriteLine(cnt);
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203]]
8
148
6
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.A { class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Scanner cin = new Scanner(); int a = cin.nextInt(); int b = cin.nextInt(); Console.WriteLine(Math.Min(0, a - 2 * b)); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.A { class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Scanner cin = new Scanner(); int a = cin.nextInt(); int b = cin.nextInt(); Console.WriteLine(Math.Max(0, a - 2 * b)); Console.Out.Flush(); } } 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; } } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
8
483
2
using System; namespace ABC143A { public class EmptyClass { public static void Main(string[] args) { int[] inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int x = inp[1] * 2; Console.WriteLine(x >= inp[0] ? 0 : x); } } }
using System; namespace ABC143A { public class EmptyClass { public static void Main(string[] args) { int[] inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int x = inp[1] * 2; Console.WriteLine(x >= inp[0] ? 0 : inp[0] - x); } } }
[["+", 0, 28, 0, 41, 75, 16, 31, 204, 205, 22], ["+", 0, 41, 75, 16, 31, 204, 206, 207, 0, 70], ["+", 75, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 41, 75, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 17, 33]]
8
77
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC143A { class Program { static void Main(string[] args) { int A, B; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); if (A < B * 2) { Console.WriteLine(0); } else if (A > B * 2) { Console.WriteLine(A - B * 2); } Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC143A { class Program { static void Main(string[] args) { int A, B; var word = Console.ReadLine().Split(' '); A = int.Parse(word[0]); B = int.Parse(word[1]); if (A <= B * 2) { Console.WriteLine(0); } else if (A > B * 2) { Console.WriteLine(A - B * 2); } Console.ReadKey(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
136
2
using System; using System.Linq; namespace A { class Program { static void Main(string[] args) { int[] input = new int[2]; input = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray(); int ans = input[0] - (2 * input[1]); if (ans <= 0) { Console.WriteLine(ans); } else { Console.WriteLine(ans); } } } }
using System; using System.Linq; namespace A { class Program { static void Main(string[] args) { int[] input = new int[2]; input = Console.ReadLine().Split().Select(i => Convert.ToInt32(i)).ToArray(); int ans = input[0] - (2 * input[1]); if (ans >= 0) { Console.WriteLine(ans); } else { Console.WriteLine(0); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
108
4
using System; class p { static void Main() { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); Console.WriteLine(Math.Min(0, A - (B * 2))); } }
using System; class p { static void Main() { string[] input = Console.ReadLine().Split(' '); int A = int.Parse(input[0]); int B = int.Parse(input[1]); Console.WriteLine(Math.Max(0, A - (B * 2))); } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22]]
8
78
2
using System; using System.Collections.Generic; using System.Linq; public class AtCoderB { static void Main() { int n = int.Parse(Console.ReadLine()); int[] ds = new int[n]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { ds[i] = int.Parse(words[i]); } } int answer = 0; for (int i = 0; i < n - 1; i++) { for (int j = i; j < n; j++) { answer += ds[i] * ds[j]; } } Console.WriteLine(answer); } }
using System; using System.Collections.Generic; using System.Linq; public class AtCoderB { static void Main() { int n = int.Parse(Console.ReadLine()); int[] ds = new int[n]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { ds[i] = int.Parse(words[i]); } } int answer = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { answer += ds[i] * ds[j]; } } Console.WriteLine(answer); } }
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
164
2
using System; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] d = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int sum = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { sum = sum + d[i] + d[j]; } } Console.WriteLine(sum.ToString()); } } }
using System; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] d = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int sum = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { sum = sum + d[i] * d[j]; } } Console.WriteLine(sum.ToString()); } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 17, 48]]
8
136
2
using System; using System.Linq; namespace CSharp { class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); var d = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var result = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { result += d[i] * d[j]; } } Console.WriteLine(result); } } }
using System; using System.Linq; namespace CSharp { class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); var d = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var result = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { result += d[i] * d[j]; } } Console.WriteLine(result); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
121
4
using System; using System.Collections.Generic; using System.Linq; namespace Contest { class ABC { static void Main() { Solve(); } private static void Solve() { int N = int.Parse(Console.ReadLine()); int[] INPUT = Console.ReadLine().Split().Select(int.Parse).ToArray(); int res = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (i == j) continue; res += INPUT[i] * INPUT[j]; } } Console.WriteLine(res); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Contest { class ABC { static void Main() { Solve(); } private static void Solve() { int N = int.Parse(Console.ReadLine()); int[] INPUT = Console.ReadLine().Split().Select(int.Parse).ToArray(); int res = 0; for (int i = 0; i < N; ++i) { for (int j = i; j < N; ++j) { if (i == j) continue; res += INPUT[i] * INPUT[j]; } } Console.WriteLine(res); Console.ReadLine(); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22]]
8
152
2
using System; namespace B___TAKOYAKI_FESTIVAL_2019 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] D = Console.ReadLine().Split(' '); int energy = 0; for (int i = 0; i < D.Length; i++) { for (int j = i + 1; j < D.Length; j++) { energy += int.Parse(D[i]) + int.Parse(D[j]); } } Console.WriteLine(energy); } } }
using System; namespace B___TAKOYAKI_FESTIVAL_2019 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] D = Console.ReadLine().Split(' '); int energy = 0; for (int i = 0; i < D.Length; i++) { for (int j = i + 1; j < D.Length; j++) { energy += int.Parse(D[i]) * int.Parse(D[j]); } } Console.WriteLine(energy); } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48]]
8
126
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder.Abc { internal class QuestionB { public static void Main(string[] args) { // 整数の入力 int n = int.Parse(Console.ReadLine()); // 整数配列の入力 var dArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)); if (dArray.ElementAt(0) != 0) { Console.WriteLine(0); return; } Dictionary<int, int> dic = new Dictionary<int, int>(); int max = -1; foreach (var d in dArray) { if (dic.ContainsKey(d)) { dic[d]++; } else { dic.Add(d, 1); } if (max < d) { max = d; } } if (dic[0] != 1) { Console.WriteLine(0); return; } long result = 1; for (int i = 1; i <= max; i++) { if (dic.ContainsKey(i) == false) { Console.WriteLine(0); return; } for (int j = 0; j < dic[i]; j++) { result = dic[i - 1]; if (result >= 998244353) { result %= 998244353; } } } Console.WriteLine(result %= 998244353); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder.Abc { internal class QuestionB { public static void Main(string[] args) { // 整数の入力 int n = int.Parse(Console.ReadLine()); // 整数配列の入力 var dArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)); if (dArray.ElementAt(0) != 0) { Console.WriteLine(0); return; } Dictionary<int, int> dic = new Dictionary<int, int>(); int max = -1; foreach (var d in dArray) { if (dic.ContainsKey(d)) { dic[d]++; } else { dic.Add(d, 1); } if (max < d) { max = d; } } if (dic[0] != 1) { Console.WriteLine(0); return; } long result = 1; for (int i = 1; i <= max; i++) { if (dic.ContainsKey(i) == false) { Console.WriteLine(0); return; } for (int j = 0; j < dic[i]; j++) { result *= dic[i - 1]; if (result >= 998244353) { result %= 998244353; } } } Console.WriteLine(result %= 998244353); } } }
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108]]
8
290
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { // static long mod = 1000000007; static long mod = 998244353; static void Main(string[] args) { char[] cs = new char[] { ' ' }; // char[] cs = new char[] { ' ', ',' }; // int n = int.Parse(Console.ReadLine()); // int val = int.Parse(Console.ReadLine()); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); // string res = ""; long res = 0; int n = int.Parse(Console.ReadLine()); // int[] vals = new int[n]; int[] vals = parseAry(Console.ReadLine().Split(cs)); /* for ( int i = 1; i < n/2; i++ ) { vals[i] = i; vals[i+(n/2)] = i; }*/ if (vals[0] != 0) { Console.WriteLine(0); return; } long[] num = new long[n]; for (int i = 1; i < n; i++) { if (vals[i] == 0) { res = 0; Console.WriteLine(res); break; } num[vals[i]]++; } res = 1; for (int i = 2; i < n; i++) { if (num[i] == 0) { for (int k = i; i < n; i++) { if (num[i] != 0) { res = 0; break; } } break; } long p = (long)mod_pow(num[i - 1], num[i]) % mod; res = (res * p) % mod; } Console.WriteLine(res); return; } static public long mod_pow(long x, long n) { long res = 1; while (n > 0) { if ((n & 1) == 1) { res = res * x % mod; } x = (x * x) % mod; n >>= 1; } return res; } // int配列をスペース区切りの文字列に変換 static string stringBuilderArrayInt(int[] a) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < a.Length; i++) { sb.Append(a[i] + " "); } if (sb.Length > 1) { sb = sb.Remove(sb.Length - 1, 1); } return sb.ToString(); ; } // 文字列strをindex番目からdで上書き static string strOverWrite(string str, int i, string s) { return str.Remove(i, s.Length).Insert(i, s); } // 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] = long.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; using System.Collections.Generic; class Program { // static long mod = 1000000007; static long mod = 998244353; static void Main(string[] args) { char[] cs = new char[] { ' ' }; // char[] cs = new char[] { ' ', ',' }; // int n = int.Parse(Console.ReadLine()); // int val = int.Parse(Console.ReadLine()); // int[] vals = parseAry(Console.ReadLine().Split(cs)); // string str = Console.ReadLine(); // string[] strs = Console.ReadLine().Split(cs); // string res = ""; long res = 0; int n = int.Parse(Console.ReadLine()); // int[] vals = new int[n]; int[] vals = parseAry(Console.ReadLine().Split(cs)); /* for ( int i = 1; i < (n+2)/2; i++ ) { vals[i] = i; vals[i+(n/2)-1] = i; }*/ if (vals[0] != 0) { Console.WriteLine(0); return; } long[] num = new long[n]; for (int i = 1; i < n; i++) { if (vals[i] == 0) { res = 0; Console.WriteLine(res); return; } num[vals[i]]++; } res = 1; for (int i = 2; i < n; i++) { if (num[i] == 0) { for (int k = i; i < n; i++) { if (num[i] != 0) { res = 0; break; } } break; } long p = (long)mod_pow(num[i - 1], num[i]) % mod; res = (res * p) % mod; } Console.WriteLine(res); return; } static public long mod_pow(long x, long n) { long res = 1; while (n > 0) { if ((n & 1) == 1) { res = res * x % mod; } x = (x * x) % mod; n >>= 1; } return res; } // int配列をスペース区切りの文字列に変換 static string stringBuilderArrayInt(int[] a) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < a.Length; i++) { sb.Append(a[i] + " "); } if (sb.Length > 1) { sb = sb.Remove(sb.Length - 1, 1); } return sb.ToString(); ; } // 文字列strをindex番目からdで上書き static string strOverWrite(string str, int i, string s) { return str.Remove(i, s.Length).Insert(i, s); } // 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] = long.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, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
8
666
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var solver = new Solver(sw); // var t = new Thread(solver.solve, 1 << 26); // 64 MB // t.Start(); // t.Join(); solver.solve(); sw.Flush(); } } class Solver { StreamWriter sw; Scan sc; void Prt(string a) => sw.WriteLine(a); void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); void Prt(params object[] a) => Prt(string.Join(" ", a)); public Solver(StreamWriter sw) { this.sw = sw; this.sc = new Scan(); } public void solve() { int n = sc.Int; var d = sc.IntArr; var cnt = new int[n]; for (int i = 0; i < n; i++) { ++cnt[d[i]]; } if (d[0] != 0 || cnt[0] > 1) { Prt(0); return; } int ma = d.Max(); long ans = 1; for (int i = 0; i <= ma; i++) { ans = ans * MyMath.pow(cnt[i], cnt[i + 1]) % M; } Prt(ans); } } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { // public static readonly int M = 1000000007; public static readonly int M = 998244353; public static readonly long LM = 1L << 60; public static readonly double eps = 1e-11; public static void DBG(string a) => Console.Error.WriteLine(a); public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); public static void DBG(params object[] a) => DBG(string.Join(" ", a)); public static void Assert(bool cond) { if (!cond) throw new Exception(); } public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> { for (int i = 0; i < a.Count && i < b.Count; i++) if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]); return a.Count.CompareTo(b.Count); } public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; // static readonly string dstring = "RDLU"; public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static T[] inv<T>(this Dictionary<T, int> dic) { var res = new T[dic.Count]; foreach (var item in dic) res[item.Value] = item.Key; return res; } public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { 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; } } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); 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); 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]); } } static class MyMath { public static long Mod = util.M; // 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 bool[] segmentSieve(long l, long r) { int sqn = (int)Math.Sqrt(r + 9); var ps = getprimes(sqn); return segmentSieve(l, r, ps); } public static bool[] segmentSieve(long l, long r, List<int> ps) { var sieve = new bool[r - l + 1]; for (long i = l; i <= r; i++) sieve[i - l] = true; foreach (long p in ps) { if (p * p > r) break; for (long i = p >= l ? p * p : (l + p - 1) / p * p; i <= r; i += p) sieve[i - l] = false; } return sieve; } 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 pow(long a, long b, long mod) { a %= mod; // if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long pow(long a, long b) { a %= Mod; // 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) => 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; } // 中国剰余定理 // リターン値を (r, m) とすると解は x ≡ r (mod. m) // 解なしの場合は (0, -1) をリターン public static pair<long, long> chineserem(IList<long> b, IList<long> m) { long r = 0, M = 1; for (int i = 0; i < b.Count; ++i) { long p, q; long d = extgcd(M, m[i], out p, out q); // p is inv of M/d (mod. m[i]/d) if ((b[i] - r) % d != 0) return new pair<long, long>(0, -1); long tmp = (b[i] - r) / d * p % (m[i] / d); r += M * tmp; M *= m[i] / d; } return new pair<long, long>((r % M + M) % M, M); } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts, invs; public static void setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; i++) facts[i] = facts[i - 1] * i % Mod; invs = new long[n + 1]; invs[n] = inv(facts[n]); for (int i = n; i > 0; i--) invs[i - 1] = invs[i] * i % Mod; } public static long fact(long n) { if (n < 0) return 0; if (facts != null && facts.Length > n) return facts[n]; long numer = 1; for (long i = 1; i <= n; i++) numer = numer * (i % Mod) % Mod; return numer; } public static long perm(long n, long r) { if (n < 0 || r < 0 || r > n) return 0; if (facts != null && facts.Length > n) return facts[n] * invs[n - r] % Mod; long numer = 1; for (long i = 0; i < r; i++) numer = numer * ((n - i) % Mod) % Mod; return numer; } public static long comb(long n, long r) { if (n < 0 || r < 0 || r > n) return 0; if (facts != null && facts.Length > n) return facts[n] * invs[r] % Mod * invs[n - r] % Mod; if (n - r < r) r = n - r; long numer = 1, denom = 1; for (long i = 0; i < r; i++) { numer = numer * ((n - i) % Mod) % Mod; denom = denom * ((i + 1) % Mod) % Mod; } return numer * inv(denom) % Mod; } public static long multi_choose(long n, long r) => comb(n + r - 1, r); public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } public static class ModMatrix { 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 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 long[][] trans(long[][] A) { int n = A[0].Length, m = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; 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[][] A) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, 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; } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var solver = new Solver(sw); // var t = new Thread(solver.solve, 1 << 26); // 64 MB // t.Start(); // t.Join(); solver.solve(); sw.Flush(); } } class Solver { StreamWriter sw; Scan sc; void Prt(string a) => sw.WriteLine(a); void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); void Prt(params object[] a) => Prt(string.Join(" ", a)); public Solver(StreamWriter sw) { this.sw = sw; this.sc = new Scan(); } public void solve() { int n = sc.Int; var d = sc.IntArr; var cnt = new int[n]; for (int i = 0; i < n; i++) { ++cnt[d[i]]; } if (d[0] != 0 || cnt[0] > 1) { Prt(0); return; } int ma = d.Max(); long ans = 1; for (int i = 0; i < ma; i++) { ans = ans * MyMath.pow(cnt[i], cnt[i + 1]) % M; } Prt(ans); } } class pair<T, U> : IComparable<pair<T, U>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } } static class util { // public static readonly int M = 1000000007; public static readonly int M = 998244353; public static readonly long LM = 1L << 60; public static readonly double eps = 1e-11; public static void DBG(string a) => Console.Error.WriteLine(a); public static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); public static void DBG(params object[] a) => DBG(string.Join(" ", a)); public static void Assert(bool cond) { if (!cond) throw new Exception(); } public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static int CompareList<T>(IList<T> a, IList<T> b) where T : IComparable<T> { for (int i = 0; i < a.Count && i < b.Count; i++) if (a[i].CompareTo(b[i]) != 0) return a[i].CompareTo(b[i]); return a.Count.CompareTo(b.Count); } public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; static readonly int[] dd = { 0, 1, 0, -1 }; // static readonly string dstring = "RDLU"; public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static T[] inv<T>(this Dictionary<T, int> dic) { var res = new T[dic.Count]; foreach (var item in dic) res[item.Value] = item.Key; return res; } public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { 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; } } class Scan { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); 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); 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]); } } static class MyMath { public static long Mod = util.M; // 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 bool[] segmentSieve(long l, long r) { int sqn = (int)Math.Sqrt(r + 9); var ps = getprimes(sqn); return segmentSieve(l, r, ps); } public static bool[] segmentSieve(long l, long r, List<int> ps) { var sieve = new bool[r - l + 1]; for (long i = l; i <= r; i++) sieve[i - l] = true; foreach (long p in ps) { if (p * p > r) break; for (long i = p >= l ? p * p : (l + p - 1) / p * p; i <= r; i += p) sieve[i - l] = false; } return sieve; } 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 pow(long a, long b, long mod) { a %= mod; // if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long pow(long a, long b) { a %= Mod; // 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) => 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; } // 中国剰余定理 // リターン値を (r, m) とすると解は x ≡ r (mod. m) // 解なしの場合は (0, -1) をリターン public static pair<long, long> chineserem(IList<long> b, IList<long> m) { long r = 0, M = 1; for (int i = 0; i < b.Count; ++i) { long p, q; long d = extgcd(M, m[i], out p, out q); // p is inv of M/d (mod. m[i]/d) if ((b[i] - r) % d != 0) return new pair<long, long>(0, -1); long tmp = (b[i] - r) / d * p % (m[i] / d); r += M * tmp; M *= m[i] / d; } return new pair<long, long>((r % M + M) % M, M); } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts, invs; public static void setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; i++) facts[i] = facts[i - 1] * i % Mod; invs = new long[n + 1]; invs[n] = inv(facts[n]); for (int i = n; i > 0; i--) invs[i - 1] = invs[i] * i % Mod; } public static long fact(long n) { if (n < 0) return 0; if (facts != null && facts.Length > n) return facts[n]; long numer = 1; for (long i = 1; i <= n; i++) numer = numer * (i % Mod) % Mod; return numer; } public static long perm(long n, long r) { if (n < 0 || r < 0 || r > n) return 0; if (facts != null && facts.Length > n) return facts[n] * invs[n - r] % Mod; long numer = 1; for (long i = 0; i < r; i++) numer = numer * ((n - i) % Mod) % Mod; return numer; } public static long comb(long n, long r) { if (n < 0 || r < 0 || r > n) return 0; if (facts != null && facts.Length > n) return facts[n] * invs[r] % Mod * invs[n - r] % Mod; if (n - r < r) r = n - r; long numer = 1, denom = 1; for (long i = 0; i < r; i++) { numer = numer * ((n - i) % Mod) % Mod; denom = denom * ((i + 1) % Mod) % Mod; } return numer * inv(denom) % Mod; } public static long multi_choose(long n, long r) => comb(n + r - 1, r); public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } public static class ModMatrix { 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 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 long[][] trans(long[][] A) { int n = A[0].Length, m = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; 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[][] A) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, 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; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
8
4,139
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; using Number = System.Int64; class Solver { public void Solve() { int num, m; Input.Make(out num, out m); var lrc = Input.ar2D(m); Array.Sort(lrc, (a, b) => a[0].CompareTo(b[0])); var seg = new SegmentTree<long>(num, long.MaxValue, Min); seg.Update(0, 0); foreach (var ar in lrc) { int l = ar[0], r = ar[1]; long c = ar[2]; var min = seg.Query(l - 1, r - 1); if (min != int.MaxValue && seg.Query(r - 1, r) > c + min) seg.Update(r - 1, c + min); } var res = seg.Query(num - 1, num); WriteLine(res == long.MaxValue ? -1 : res); } } public class SegmentTree<T> { protected readonly T[] item; protected readonly int num; protected readonly Func<T, T, T> func; protected readonly Func<T, T, T> updateFunc; protected readonly T minT; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Parent(int index) => (index - 1) >> 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Left(int index) => (index << 1) + 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Right(int index) => (index + 1) << 1; public T this[int i] { get { return item[i + num - 1]; } set { item[i + num - 1] = value; } } public SegmentTree(int num, T minT, Func<T, T, T> func, Func<T, T, T> updateFunc = null) { this.func = func; this.num = 1; this.minT = minT; this.updateFunc = updateFunc ?? ((T val1, T val2) => val2); while (this.num <= num) this.num <<= 1; item = new T[2 * this.num - 1]; for (var i = 0; i < 2 * this.num - 1; i++) item[i] = minT; } public void Update(int index, T value) { index += num - 1; item[index] = updateFunc(item[index], value); while (index > 0) { index = Parent(index); item[index] = func(item[Left(index)], item[Right(index)]); } } public virtual void Update(int left, int right, T value) => Update(left, right, 0, 0, num, value); protected virtual void Update(int left, int right, int k, int l, int r, T value) { if (r <= left || right <= l) return; if (left <= l && r <= right) item[k] = updateFunc(item[k], value); else { Update(left, right, Left(k), l, (l + r) >> 1, value); Update(left, right, Right(k), (l + r) >> 1, r, value); } } public void All_Update() { for (int i = num - 2; i >= 0; i--) item[i] = func(item[Left(i)], item[Right(i)]); } public T Query(int index) { index += num - 1; var value = func(minT, item[index]); while (index > 0) { index = Parent(index); value = func(value, item[index]); } return value; } public virtual T Query(int left, int right) => Query(left, right, 0, 0, num); protected virtual T Query(int left, int right, int k, int l, int r) { if (r <= left || right <= l) return minT; if (left <= l && r <= right) return item[k]; else return func(Query(left, right, Left(k), l, (l + r) >> 1), Query(left, right, Right(k), (l + r) >> 1, r)); } /// <summary> /// check(func(item[st]...item[i]))がtrueとなる最小のi /// </summary> public int Find(int st, Func<T, bool> check) { var x = minT; return Find(st, check, ref x, 0, 0, num); } private int Find(int st, Func<T, bool> check, ref T x, int k, int l, int r) { if (l + 1 == r) { x = func(x, item[k]); return check(x) ? k - num + 1 : -1; } var m = (l + r) >> 1; if (m <= st) return Find(st, check, ref x, Right(k), m, r); if (st <= l && !check(func(x, item[k]))) { x = func(x, item[k]); return -1; } var xl = Find(st, check, ref x, Left(k), l, m); if (xl >= 0) return xl; return Find(st, check, ref x, Right(k), m, r); } } #region Template public class Template { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) => Enumerable.Repeat(0, n).Select(_ => f()).ToArray(); public static void Fail() => Fail("No"); public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var p = new Solver(); for (var i = 1; i > 0; --i) p.Solve(); Console.Out.Flush(); } } public class Input { public static string read => Console.ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => Convert.ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => Convert.ToInt64(read); public static char[][] grid(int h) => Create(h, () => read.ToCharArray()); public static int[] ar1D(int n) => Create(n, () => num); public static long[] arL1D(int n) => Create(n, () => numL); public static string[] strs(int n) => Create(n, () => read); public static int[][] ar2D(int n) => Create(n, () => ar); public static long[][] arL2D(int n) => Create(n, () => arL); public static List<T>[] edge<T>(int n) => Create(n, () => new List<T>()); public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } static Input() { sc = new Queue<string>(); dic = new Dictionary<Type, Func<string, object>>(); dic[typeof(int)] = s => int.Parse(s); dic[typeof(long)] = s => long.Parse(s); dic[typeof(char)] = s => char.Parse(s); dic[typeof(double)] = s => double.Parse(s); dic[typeof(uint)] = s => uint.Parse(s); dic[typeof(ulong)] = s => ulong.Parse(s); dic[typeof(string)] = s => s; } private static Dictionary<Type, Func<string, object>> dic; private static Queue<string> sc; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T Next<T>() { if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return (T)dic[typeof(T)](sc.Dequeue()); } public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() { v1 = default(T1); v2 = default(T2); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() { v3 = default(T3); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; using Number = System.Int64; class Solver { public void Solve() { int num, m; Input.Make(out num, out m); var lrc = Input.ar2D(m); Array.Sort(lrc, (a, b) => a[0].CompareTo(b[0])); var seg = new SegmentTree<long>(num, long.MaxValue, Min); seg.Update(0, 0); foreach (var ar in lrc) { int l = ar[0], r = ar[1]; long c = ar[2]; var min = seg.Query(l - 1, r - 1); if (min != long.MaxValue && seg.Query(r - 1, r) > c + min) seg.Update(r - 1, c + min); } var res = seg.Query(num - 1, num); WriteLine(res == long.MaxValue ? -1 : res); } } public class SegmentTree<T> { protected readonly T[] item; protected readonly int num; protected readonly Func<T, T, T> func; protected readonly Func<T, T, T> updateFunc; protected readonly T minT; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Parent(int index) => (index - 1) >> 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Left(int index) => (index << 1) + 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected int Right(int index) => (index + 1) << 1; public T this[int i] { get { return item[i + num - 1]; } set { item[i + num - 1] = value; } } public SegmentTree(int num, T minT, Func<T, T, T> func, Func<T, T, T> updateFunc = null) { this.func = func; this.num = 1; this.minT = minT; this.updateFunc = updateFunc ?? ((T val1, T val2) => val2); while (this.num <= num) this.num <<= 1; item = new T[2 * this.num - 1]; for (var i = 0; i < 2 * this.num - 1; i++) item[i] = minT; } public void Update(int index, T value) { index += num - 1; item[index] = updateFunc(item[index], value); while (index > 0) { index = Parent(index); item[index] = func(item[Left(index)], item[Right(index)]); } } public virtual void Update(int left, int right, T value) => Update(left, right, 0, 0, num, value); protected virtual void Update(int left, int right, int k, int l, int r, T value) { if (r <= left || right <= l) return; if (left <= l && r <= right) item[k] = updateFunc(item[k], value); else { Update(left, right, Left(k), l, (l + r) >> 1, value); Update(left, right, Right(k), (l + r) >> 1, r, value); } } public void All_Update() { for (int i = num - 2; i >= 0; i--) item[i] = func(item[Left(i)], item[Right(i)]); } public T Query(int index) { index += num - 1; var value = func(minT, item[index]); while (index > 0) { index = Parent(index); value = func(value, item[index]); } return value; } public virtual T Query(int left, int right) => Query(left, right, 0, 0, num); protected virtual T Query(int left, int right, int k, int l, int r) { if (r <= left || right <= l) return minT; if (left <= l && r <= right) return item[k]; else return func(Query(left, right, Left(k), l, (l + r) >> 1), Query(left, right, Right(k), (l + r) >> 1, r)); } /// <summary> /// check(func(item[st]...item[i]))がtrueとなる最小のi /// </summary> public int Find(int st, Func<T, bool> check) { var x = minT; return Find(st, check, ref x, 0, 0, num); } private int Find(int st, Func<T, bool> check, ref T x, int k, int l, int r) { if (l + 1 == r) { x = func(x, item[k]); return check(x) ? k - num + 1 : -1; } var m = (l + r) >> 1; if (m <= st) return Find(st, check, ref x, Right(k), m, r); if (st <= l && !check(func(x, item[k]))) { x = func(x, item[k]); return -1; } var xl = Find(st, check, ref x, Left(k), l, m); if (xl >= 0) return xl; return Find(st, check, ref x, Right(k), m, r); } } #region Template public class Template { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) => Enumerable.Repeat(0, n).Select(_ => f()).ToArray(); public static void Fail() => Fail("No"); public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var p = new Solver(); for (var i = 1; i > 0; --i) p.Solve(); Console.Out.Flush(); } } public class Input { public static string read => Console.ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => Convert.ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => Convert.ToInt64(read); public static char[][] grid(int h) => Create(h, () => read.ToCharArray()); public static int[] ar1D(int n) => Create(n, () => num); public static long[] arL1D(int n) => Create(n, () => numL); public static string[] strs(int n) => Create(n, () => read); public static int[][] ar2D(int n) => Create(n, () => ar); public static long[][] arL2D(int n) => Create(n, () => arL); public static List<T>[] edge<T>(int n) => Create(n, () => new List<T>()); public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } static Input() { sc = new Queue<string>(); dic = new Dictionary<Type, Func<string, object>>(); dic[typeof(int)] = s => int.Parse(s); dic[typeof(long)] = s => long.Parse(s); dic[typeof(char)] = s => char.Parse(s); dic[typeof(double)] = s => double.Parse(s); dic[typeof(uint)] = s => uint.Parse(s); dic[typeof(ulong)] = s => ulong.Parse(s); dic[typeof(string)] = s => s; } private static Dictionary<Type, Func<string, object>> dic; private static Queue<string> sc; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T Next<T>() { if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return (T)dic[typeof(T)](sc.Dequeue()); } public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() { v1 = default(T1); v2 = default(T2); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() { v3 = default(T3); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; } #endregion
[["-", 0, 57, 15, 16, 31, 16, 12, 214, 205, 199], ["+", 0, 57, 15, 16, 31, 16, 12, 214, 205, 199]]
8
2,673
2
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { var S = Console.ReadLine(); var ans = new long[S.Length + 1]; for (var i = 0; i < S.Length; i++) { if (S[i] == '<') { ans[i + 1] = ans[i] + 1; } } for (var i = S.Length - 1; i > 0; i--) { if (S[i] == '>' && ans[i] <= ans[i + 1] + 1) { ans[i] = ans[i + 1] + 1; } } Console.Write(ans.Sum()); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { var S = Console.ReadLine(); var ans = new long[S.Length + 1]; for (var i = 0; i < S.Length; i++) { if (S[i] == '<') { ans[i + 1] = ans[i] + 1; } } for (var i = S.Length - 1; i >= 0; i--) { if (S[i] == '>' && ans[i] <= ans[i + 1] + 1) { ans[i] = ans[i + 1] + 1; } } Console.Write(ans.Sum()); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20]]
8
174
2
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Runtime.ExceptionServices; using System.Security; using System.Threading; using System.Xml.Serialization; namespace AtCoderCs { class Program { const int mod = 1000000007; static void Main() { var str = Console.ReadLine(); var min = new List<int>(); var max = new List<int>(); var num = str.Length; var startIdx = 0; var count = 0; var result = 0L; for (int i = 0, l = str.Length; i + 1 < l; i++) { if (str[i] == '<' && str[i + 1] == '>') max.Add(i + 1); else if (str[i] == '>' && str[i + 1] == '<') min.Add(i + 1); } if (min.Count == 0 && max.Count == 0) { Console.WriteLine(Enumerable.Range(1, str.Length).Sum(x => (long)x)); return; } var buf = new long[num]; if (max.Count == 0) result += Enumerable.Range(1, min[0]).Sum(x => (long)x) + Enumerable.Range(1, num - min[0]).Sum(x => (long)x); else if (min.Count != 0 && min[0] < max[0]) result += Enumerable.Range(1, min[0]).Sum(x => (long)x); else { var right = ((min.Count != 0 ? min[0] : num) - max[0]); result += Enumerable.Range(1, max[0] - 1).Sum(x => (long)x) + Enumerable.Range(1, right - 1).Sum(x => (long)x) + (right < max[0] ? max[0] : right); startIdx = 1; } if (min.Count != 0 && max.Count != 0) { if (min[min.Count - 1] < max[max.Count - 1]) { var right = num - max[max.Count - 1]; var left = max[max.Count - 1] - min[min.Count - 1]; result += Enumerable.Range(1, right - 1).Sum(x => (long)x) + Enumerable.Range(1, left - 1).Sum(x => (long)x) + right < left ? left : right; count = max.Count - 1; } else { result += Enumerable.Range(1, num - min[min.Count - 1]).Sum(x => (long)x); count = max.Count; } for (int i = startIdx; i < count; i++) { var left = max[i] - min[i - startIdx]; var right = min[i + 1 - startIdx] - max[i]; result += Enumerable.Range(1, left - 1).Sum(x => (long)x) + Enumerable.Range(1, right - 1).Sum(x => (long)x) + (right < left ? left : right); } } Console.WriteLine(result); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Runtime.ExceptionServices; using System.Security; using System.Threading; using System.Xml.Serialization; namespace AtCoderCs { class Program { const int mod = 1000000007; static void Main() { var str = Console.ReadLine(); var min = new List<int>(); var max = new List<int>(); var num = str.Length; var startIdx = 0; var count = 0; var result = 0L; for (int i = 0, l = str.Length; i + 1 < l; i++) { if (str[i] == '<' && str[i + 1] == '>') max.Add(i + 1); else if (str[i] == '>' && str[i + 1] == '<') min.Add(i + 1); } if (min.Count == 0 && max.Count == 0) { Console.WriteLine(Enumerable.Range(1, str.Length).Sum(x => (long)x)); return; } var buf = new long[num]; if (max.Count == 0) result += Enumerable.Range(1, min[0]).Sum(x => (long)x) + Enumerable.Range(1, num - min[0]).Sum(x => (long)x); else if (min.Count != 0 && min[0] < max[0]) result += Enumerable.Range(1, min[0]).Sum(x => (long)x); else { var right = ((min.Count != 0 ? min[0] : num) - max[0]); result += Enumerable.Range(1, max[0] - 1).Sum(x => (long)x) + Enumerable.Range(1, right - 1).Sum(x => (long)x) + (right < max[0] ? max[0] : right); startIdx = 1; } if (min.Count != 0 && max.Count != 0) { if (min[min.Count - 1] < max[max.Count - 1]) { var right = num - max[max.Count - 1]; var left = max[max.Count - 1] - min[min.Count - 1]; result += Enumerable.Range(1, right - 1).Sum(x => (long)x) + Enumerable.Range(1, left - 1).Sum(x => (long)x) + (right < left ? left : right); count = max.Count - 1; } else { result += Enumerable.Range(1, num - min[min.Count - 1]).Sum(x => (long)x); count = max.Count; } for (int i = startIdx; i < count; i++) { var left = max[i] - min[i - startIdx]; var right = min[i + 1 - startIdx] - max[i]; result += Enumerable.Range(1, left - 1).Sum(x => (long)x) + Enumerable.Range(1, right - 1).Sum(x => (long)x) + (right < left ? left : right); } } Console.WriteLine(result); } } }
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
8
738
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var S = Str; var A = new long[S.Length]; for (int i = 0; i < S.Length; ++i) { if (S[i] == '<') { A[i + 1] = Max(A[i + 1], A[i] + 1); } } for (int i = S.Length - 1; i >= 0; --i) { if (S[i] == '>') { A[i] = Max(A[i], A[i + 1] + 1); } } Write(A.Sum()); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long i, long N, long MOD = 1000000007) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long Power2(long i, long N) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i; i = i * i; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var S = Str; var A = new long[S.Length + 1]; for (int i = 0; i < S.Length; ++i) { if (S[i] == '<') { A[i + 1] = Max(A[i + 1], A[i] + 1); } } for (int i = S.Length - 1; i >= 0; --i) { if (S[i] == '>') { A[i] = Max(A[i], A[i + 1] + 1); } } Write(A.Sum()); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long i, long N, long MOD = 1000000007) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i % MOD; i = i * i % MOD; N >>= 1; } return res; } public static long Power2(long i, long N) // i^N { long res = 1; while (N > 0) { if ((N & 1) != 0) res = res * i; i = i * i; N >>= 1; } return res; } public static long GCD(long i, long N) { if (i > N) Swap(ref i, ref N); if (i == 0) return N; while (N != 0) { var r = i % N; i = N; N = r; } return i; } public static long LCM(long i, long N) => i * N / GCD(i, N); public static long Comb(long N, long R, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = N; i >= N - R + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long N, long R) { long Nume = 1; long Deno = 1; if (R > N - R) Swap(ref N, ref R); for (long i = 1; i <= R; ++i) { Deno *= i; Nume *= N - i + 1; } return Deno / Nume; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
8
1,051
2
using System; namespace agc040a { class Program { static void Main(string[] args) { var S = Console.ReadLine(); long ans = 0; int[] A = new int[S.Length + 1]; int[] B = new int[S.Length + 1]; int countL = 0; int countR = 0; for (int i = 0; i < S.Length; i++) { if (S[i] == '<') { countL++; } else { countL = 0; } A[i + 1] = countL; } for (int i = S.Length - 1; i >= 0; i--) { if (S[i] == '>') { countR++; } else { countR = 0; } B[i] = countR; } for (int i = 1; i < A.Length; i++) { ans += Math.Max(A[i], B[i]); } Console.WriteLine(ans); } } }
using System; namespace agc040a { class Program { static void Main(string[] args) { string S = Console.ReadLine(); long ans = 0; int[] A = new int[S.Length + 1]; int[] B = new int[S.Length + 1]; int countL = 0; int countR = 0; for (int i = 0; i < S.Length; i++) { if (S[i] == '<') { countL++; } else { countL = 0; } A[i + 1] = countL; } for (int i = S.Length - 1; i >= 0; i--) { if (S[i] == '>') { countR++; } else { countR = 0; } B[i] = countR; } for (int i = 0; i < A.Length; i++) { ans += Math.Max(A[i], B[i]); } Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
218
4
using System; namespace agc040a { class Program { static void Main(string[] args) { string S = Console.ReadLine(); long ans = 0; int[] A = new int[S.Length + 1]; int[] B = new int[S.Length + 1]; int countL = 0; int countR = 0; for (int i = 0; i < S.Length; i++) { if (S.Substring(i, 1) == "<") { countL++; } else { countL = 0; } A[i + 1] = countL; } for (int i = S.Length - 1; i >= 0; i--) { if (S.Substring(i, 1) == ">") { countR++; } else { countR = 0; } B[i] = countR; } for (int i = 1; i < A.Length; i++) { ans += Math.Max(A[i], B[i]); } Console.WriteLine(ans); } } }
using System; namespace agc040a { class Program { static void Main(string[] args) { string S = Console.ReadLine(); long ans = 0; int[] A = new int[S.Length + 1]; int[] B = new int[S.Length + 1]; int countL = 0; int countR = 0; for (int i = 0; i < S.Length; i++) { if (S.Substring(i, 1) == "<") { countL++; } else { countL = 0; } A[i + 1] = countL; } for (int i = S.Length - 1; i >= 0; i--) { if (S.Substring(i, 1) == ">") { countR++; } else { countR = 0; } B[i] = countR; } for (int i = 0; i < A.Length; i++) { ans += Math.Max(A[i], B[i]); } Console.WriteLine(ans); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
226
2
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { string s = ReadLineStr(); int length = s.Length; long[] rtnArr = new long[length + 1]; string wk = ""; int cnt = 0; for (int i = 0; i < length; i++) { string chr = s.Substring(i, 1); if (wk != chr) { if (chr == "<") { for (int j = 0; j < cnt; j++) { rtnArr[i - j] = j; } if (i - cnt != 0 && rtnArr[i - (cnt)] < cnt) { rtnArr[i - (cnt)] = cnt; } } else { if (cnt == 0) { cnt++; } rtnArr[i] = cnt; } wk = chr; cnt = 1; } else { if (chr == "<") { rtnArr[i] = cnt; } cnt++; } } if (cnt != 0) { if (wk == "<") { rtnArr[length] = cnt; } else { for (int j = 0; j < cnt; j++) { rtnArr[length - j] = j; } if (rtnArr[length - cnt] < cnt) { rtnArr[length - cnt] = cnt; } } } Console.WriteLine(rtnArr.Sum()); } static string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static long[,] Combi = new long[2001, 2001]; static long div = 1000000007; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } static private long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } else if (Combi[n, r] == 0) { Combi[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return Combi[n, r]; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { string s = ReadLineStr(); int length = s.Length; long[] rtnArr = new long[length + 1]; string wk = ""; int cnt = 0; for (int i = 0; i < length; i++) { string chr = s.Substring(i, 1); if (wk != chr) { if (chr == "<") { for (int j = 0; j < cnt; j++) { rtnArr[i - j] = j; } if (rtnArr[i - (cnt)] < cnt) { rtnArr[i - (cnt)] = cnt; } } else { if (cnt == 0) { cnt++; } rtnArr[i] = cnt; } wk = chr; cnt = 1; } else { if (chr == "<") { rtnArr[i] = cnt; } cnt++; } } if (cnt != 0) { if (wk == "<") { rtnArr[length] = cnt; } else { for (int j = 0; j < cnt; j++) { rtnArr[length - j] = j; } if (rtnArr[length - cnt] < cnt) { rtnArr[length - cnt] = cnt; } } } Console.WriteLine(rtnArr.Sum()); } static string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static long[,] Combi = new long[2001, 2001]; static long div = 1000000007; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } static private long Combination(long n, long r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } else if (Combi[n, r] == 0) { Combi[n, r] = (Combination(n - 1, r - 1) + Combination(n - 1, r)) % div; } return Combi[n, r]; } }
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 33], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98]]
8
1,244
6
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class ABC { static long mod = 1000000007; // 10^9+7 static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); // int n = int.Parse(Console.ReadLine()); // int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); string s = Console.ReadLine(); int[] list = new int[s.Length + 1]; PriorityQueue<KeyValuePair<int, int>> queue = new PriorityQueue<KeyValuePair<int, int>>((x, y) => y.Key.CompareTo(x.Key)); for (int i = 0, j = 1; i < s.Length; i++, j++) { if (s[i] == '<') { list[j] = list[j - 1] + 1; if (i > 0 && s[i - 1] == '>') { queue.Enqueue(new KeyValuePair<int, int>(list[j - 1], j - 1)); } } if (s[i] == '>') { list[j] = list[j - 1] - 1; if (i == s.Length - 1) { queue.Enqueue(new KeyValuePair<int, int>(list[j], j)); } } } while (queue.Count > 0) { var item = queue.Dequeue(); int index = item.Value; int val = -item.Value; list[index] = 0; // 左 for (int i = index - 1; i >= 0; i--) { list[i] = list[i + 1] + 1; if (i > 0 && s[i - 1] == '<') { break; } } // 右 for (int i = index + 1; i < list.Length; i++) { list[i] = list[i - 1] + 1; if (i < s.Length && s[i] == '>') { break; } } // System.Diagnostics.Debug.WriteLine($"index={item.Value}, // value={item.Key} "); for (int i = 0; i < s.Length; i++) { // System.Diagnostics.Debug.Write($"{list[i]} {s[i]} "); //} // System.Diagnostics.Debug.WriteLine(list.Last()); } long ans = 0; foreach (var i in list) { ans += i; } Console.WriteLine(ans); Console.Out.Flush(); } } #region 優先度付きキュー PriorityQueue < T> public class PriorityQueue<T> // where T : IComparable { private readonly List<T> _Heap; private readonly Func<T, T, int> _Compare; public int Count { get { return _Heap.Count; } } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(bool reverse) : this((x, y) => Comparer<T>.Default.Compare(reverse ? y : x, reverse ? x : y)) {} public PriorityQueue(Comparer<T> comparer) : this(comparer.Compare) {} public PriorityQueue(Func<T, T, int> compare) { _Heap = new List<T>(); _Compare = compare; } public void Enqueue(T item) { _Heap.Add(item); int i = _Heap.Count - 1; while (i > 0) { int p = (i - 1) / 2; if (_Compare(_Heap[p], item) <= 0) { break; } _Heap[i] = _Heap[p]; i = p; } _Heap[i] = item; } public T Dequeue() { int size = _Heap.Count - 1; T ret = _Heap[0]; T x = _Heap[size]; int i = 0; while (i * 2 + 1 < size) { var a = i * 2 + 1; var b = i * 2 + 2; if (b < size && _Compare(_Heap[b], _Heap[a]) < 0) { a = b; } if (_Compare(_Heap[a], x) >= 0) { break; } _Heap[i] = _Heap[a]; i = a; } _Heap[i] = x; _Heap.RemoveAt(size); return ret; } public T Peek() { return _Heap[0]; } public void Clear() { _Heap.Clear(); } public List<T>.Enumerator GetEnumerator() { return _Heap.GetEnumerator(); } public override string ToString() { return string.Join(" ", _Heap); } } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace AtCoder { public class ABC { static long mod = 1000000007; // 10^9+7 static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); // int n = int.Parse(Console.ReadLine()); // int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); string s = Console.ReadLine(); int[] list = new int[s.Length + 1]; PriorityQueue<KeyValuePair<int, int>> queue = new PriorityQueue<KeyValuePair<int, int>>((x, y) => y.Key.CompareTo(x.Key)); for (int i = 0, j = 1; i < s.Length; i++, j++) { if (s[i] == '<') { list[j] = list[j - 1] + 1; if (i == 0 || s[i - 1] == '>') { queue.Enqueue(new KeyValuePair<int, int>(list[j - 1], j - 1)); } } if (s[i] == '>') { list[j] = list[j - 1] - 1; if (i == s.Length - 1) { queue.Enqueue(new KeyValuePair<int, int>(list[j], j)); } } } while (queue.Count > 0) { var item = queue.Dequeue(); int index = item.Value; int val = -item.Value; list[index] = 0; // 左 for (int i = index - 1; i >= 0; i--) { list[i] = list[i + 1] + 1; if (i > 0 && s[i - 1] == '<') { break; } } // 右 for (int i = index + 1; i < list.Length; i++) { list[i] = list[i - 1] + 1; if (i < s.Length && s[i] == '>') { break; } } // System.Diagnostics.Debug.WriteLine($"index={item.Value}, // value={item.Key} "); for (int i = 0; i < s.Length; i++) { // System.Diagnostics.Debug.Write($"{list[i]} {s[i]} "); //} // System.Diagnostics.Debug.WriteLine(list.Last()); } long ans = 0; foreach (var i in list) { ans += i; } Console.WriteLine(ans); Console.Out.Flush(); } } #region 優先度付きキュー PriorityQueue < T> public class PriorityQueue<T> // where T : IComparable { private readonly List<T> _Heap; private readonly Func<T, T, int> _Compare; public int Count { get { return _Heap.Count; } } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(bool reverse) : this((x, y) => Comparer<T>.Default.Compare(reverse ? y : x, reverse ? x : y)) {} public PriorityQueue(Comparer<T> comparer) : this(comparer.Compare) {} public PriorityQueue(Func<T, T, int> compare) { _Heap = new List<T>(); _Compare = compare; } public void Enqueue(T item) { _Heap.Add(item); int i = _Heap.Count - 1; while (i > 0) { int p = (i - 1) / 2; if (_Compare(_Heap[p], item) <= 0) { break; } _Heap[i] = _Heap[p]; i = p; } _Heap[i] = item; } public T Dequeue() { int size = _Heap.Count - 1; T ret = _Heap[0]; T x = _Heap[size]; int i = 0; while (i * 2 + 1 < size) { var a = i * 2 + 1; var b = i * 2 + 2; if (b < size && _Compare(_Heap[b], _Heap[a]) < 0) { a = b; } if (_Compare(_Heap[a], x) >= 0) { break; } _Heap[i] = _Heap[a]; i = a; } _Heap[i] = x; _Heap.RemoveAt(size); return ret; } public T Peek() { return _Heap[0]; } public void Clear() { _Heap.Clear(); } public List<T>.Enumerator GetEnumerator() { return _Heap.GetEnumerator(); } public override string ToString() { return string.Join(" ", _Heap); } } #endregion }
[["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 106]]
8
932
4
using System; using System.Linq; using System.Collections.Generic; using System.Collections; namespace Algorithm { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var counter = new List<int>(); var cur = S[0]; var count = 1; for (var i = 1; i < S.Length; i++) { if (cur == S[i]) count++; else { counter.Add(count); count = 1; cur = S[i]; } } counter.Add(count); if (counter.Count == 1) { Console.WriteLine(SumVal(counter[0])); return; } if (counter.Count == 2 && S[0] == '>' && S[S.Length - 1] == '<') { Console.WriteLine(SumVal(counter[0]) + SumVal(counter[1])); return; } var start = S[0] == '<' ? 1 : 2; decimal ans = 0; if (counter.Count % 2 == 1) ans = S[0] == '<' ? SumVal(counter[counter.Count - 1]) : SumVal(counter[0]); if (counter.Count % 2 == 0 && S[0] == '>' && S[S.Length - 1] == '<') ans = SumVal(counter[0]) + SumVal(counter[S.Length - 1]); for (var i = start; i < counter.Count; i += 2) { if (counter[i] >= counter[i - 1]) counter[i - 1]--; else counter[i]--; ans += SumVal(counter[i]); ans += SumVal(counter[i - 1]); } Console.WriteLine(ans); } static decimal SumVal(int a) { return (decimal)(a * 0.5 * (a + 1)); } } }
using System; using System.Linq; using System.Collections.Generic; using System.Collections; namespace Algorithm { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var counter = new List<int>(); var cur = S[0]; var count = 1; for (var i = 1; i < S.Length; i++) { if (cur == S[i]) count++; else { counter.Add(count); count = 1; cur = S[i]; } } counter.Add(count); if (counter.Count == 1) { Console.WriteLine(SumVal(counter[0])); return; } if (counter.Count == 2 && S[0] == '>' && S[S.Length - 1] == '<') { Console.WriteLine(SumVal(counter[0]) + SumVal(counter[1])); return; } var start = S[0] == '<' ? 1 : 2; decimal ans = 0; if (counter.Count % 2 == 1) ans = S[0] == '<' ? SumVal(counter[counter.Count - 1]) : SumVal(counter[0]); if (counter.Count % 2 == 0 && S[0] == '>' && S[S.Length - 1] == '<') ans = SumVal(counter[0]) + SumVal(counter[counter.Count - 1]); for (var i = start; i < counter.Count; i += 2) { if (counter[i] >= counter[i - 1]) counter[i - 1]--; else counter[i]--; ans += SumVal(counter[i]); ans += SumVal(counter[i - 1]); } Console.WriteLine(ans); } static decimal SumVal(int a) { return (decimal)(a * 0.5 * (a + 1)); } } }
[["-", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["-", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22]]
8
428
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class AGC040B { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var lrList = Repeat(0, N).Select(_ => new { L = NN, R = NN }).ToList(); var lrListHenka = lrList.Select(e => new { e.R, e.L, len = e.R - e.L + 1 }) .OrderByRand() .OrderByDescending(e => e.len) .ToList(); var maxValue = lrListHenka.First().len + lrListHenka.Skip(1).Min(e => e.R) - lrListHenka.Skip(1).Max(e => e.L) + 1; var minl = lrList.OrderByRand().OrderBy(e => e.L).First(); lrList.Remove(minl); var sorted = lrList.OrderByRand().OrderBy(e => e.L).ToList(); var rpool = new BT<long>(); var lpool = new BT<long>(); foreach (var item in sorted) { rpool.Add(item.R); lpool.Add(item.L); } { var val1 = Max(0, minl.R - minl.L + 1); var val2 = Max(0, rpool.Min() - lpool.Max() + 1); maxValue = Max(maxValue, val1 + val2); } var r = minl.R; foreach (var item in sorted) { rpool.Remove(item.R); lpool.Remove(item.L); r = Min(r, item.R); var val1 = Max(0, r - item.L + 1); var val2 = Max(0, rpool.Min() - lpool.Max() + 1); maxValue = Max(maxValue, val1 + val2); } Console.WriteLine(maxValue); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); static Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; } static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } static List<T> LCS<T>(T[] s, T[] t) where T : IEquatable<T> { int sl = s.Length, tl = t.Length; var dp = new int[sl + 1, tl + 1]; for (var i = 0; i < sl; i++) for (var j = 0; j < tl; j++) dp[i + 1, j + 1] = s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]); { var r = new List<T>(); int i = sl, j = tl; while (i > 0 && j > 0) if (s[--i].Equals(t[--j])) r.Add(s[i]); else if (dp[i, j + 1] > dp[i + 1, j]) ++j; else ++i; r.Reverse(); return r; } } static long LIS<T>(T[] array, bool strict) { var l = new List<T>(); foreach (var e in array) { var i = l.BinarySearch(e); if (i < 0) i = ~i; else if (!strict) ++i; if (i == l.Count) l.Add(e); else l[i] = e; } return l.Count; } class PQ<T> { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) {} public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TK, TV> { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) {} public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {} public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v)); public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; public UF(long s) { d = Repeat(-1L, s).ToArray(); } public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } public bool IsSame(long x, long y) => Root(x) == Root(y); public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); public long Count(long x) => -d[Root(x)]; } struct Mod : IEquatable<Mod>, IEquatable<long> { static public long _mod = 1000000007; long v; public Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; } static public implicit operator Mod(long x) => new Mod(x); static public implicit operator long(Mod x) => x.v; public void Add(Mod x) { if ((v += x.v) >= _mod) v -= _mod; } public void Sub(Mod x) { if ((v -= x.v) < 0) v += _mod; } public void Mul(Mod x) => v = (v * x.v) % _mod; public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod; static public Mod operator +(Mod x, Mod y) { var t = x.v + y.v; return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t }; } static public Mod operator -(Mod x, Mod y) { var t = x.v - y.v; return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t }; } static public Mod operator *(Mod x, Mod y) => x.v * y.v; static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v); static public bool operator ==(Mod x, Mod y) => x.v == y.v; static public bool operator !=(Mod x, Mod y) => x.v != y.v; static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } public bool Equals(Mod x) => v == x.v; public bool Equals(long x) => v == x; public override bool Equals(object x) => x == null ? false : Equals((Mod)x); public override int GetHashCode() => v.GetHashCode(); public override string ToString() => v.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; public int c; } Comparison<T> c; Node r; bool ch; T lm; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} bool R(Node n) => n != null && !n.b; bool B(Node n) => n != null && n.b; long C(Node n) => n?.c ?? 0; Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } public void Add(T x) { r = A(r, x); r.b = true; } Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); } Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } public T this[long i] { get { return At(r, i); } } T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); } public bool Have(T x) { var t = FindUpper(x); return t < C(r) && c(At(r, t), x) == 0; } public long FindUpper(T x, bool allowSame = true) => allowSame ? FL(r, x) + 1 : FU(r, x); long FU(Node n, T x) { if (n == null) return 0; var r = c(x, n.v); if (r < 0) return FU(n.l, x); return C(n.l) + 1 + FU(n.r, x); } public long FindLower(T x, bool allowSame = true) { var t = FL(r, x); if (allowSame) return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1 : t < 0 ? C(r) : t; return t < 0 ? C(r) : t; } long FL(Node n, T x) { if (n == null) return -1; var r = c(x, n.v); if (r > 0) return C(n.l) + 1 + FL(n.r, x); return FL(n.l, x); } public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } public bool Any() => r != null; public long Count() => C(r); public IEnumerable<T> List() => L(r); IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; public Dict(Func<K, V> _d) { d = _d; } public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } public override int GetHashCode() { var ret = 0; for (var e = GetEnumerator(); e.MoveNext();) { ret ^= e.Current.Key.GetHashCode(); ret ^= e.Current.Value.GetHashCode(); } return ret; } public override bool Equals(object obj) { var o = (Dict<K, V>)obj; foreach (var kv in o) { if (!ContainsKey(kv.Key) || !this[kv.Key].Equals(kv.Value)) return false; } return o.Count == Count; } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } public Deque(int cap = 16) { b = new T[c = cap]; } int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } class SegTree<T> { int n; T ti; Func<T, T, T> f; T[] dat; public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); } public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } } } class LazySegTree<T, E> { int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz; public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]); void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; } void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); } void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); } public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); } public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); } public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } } } class SlidingWindowAggregation<T> { T[][] l; T[][] a; int[] n; Func<T, T, T> f; public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) { l = new T[2][]; a = new T[2][]; n = new int[2]; f = _f; l[0] = new T[16]; a[0] = new T[16]; n[0] = 0; if (ary.Any()) { var t = ary.ToArray(); n[1] = t.Length; l[1] = new T[n[1]]; a[1] = new T[n[1]]; for (var i = 0; i < l[1].Length; i++) { l[1][i] = t[i]; if (i == 0) a[1][i] = t[i]; else a[1][i] = this.f(a[1][i - 1], t[i]); } } else { l[1] = new T[16]; a[1] = new T[16]; n[1] = 0; } } public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {} public int Count => n[0] + n[1]; void Push(int la, T v) { if (l[la].Length == n[la]) { var nar = new T[n[la] * 2]; var nag = new T[n[la] * 2]; Array.Copy(l[la], nar, n[la]); Array.Copy(a[la], nag, n[la]); l[la] = nar; a[la] = nag; } if (n[la] == 0) a[la][0] = v; else a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v); l[la][n[la]++] = v; } public void PushBack(T val) => Push(1, val); public void PushFront(T val) => Push(0, val); public T Pop(int la) { var lb = 1 - la; if (n[la] == 0) { if (n[lb] == 0) throw new Exception(); var m = (n[lb] - 1) / 2; if (l[la].Length <= m) { l[la] = new T[m + 1]; a[la] = new T[m + 1]; } n[la] = 0; for (var i = m; i >= 0; i--) { if (n[la] == 0) a[la][n[la]] = l[lb][i]; else a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1]) : f(a[la][n[la] - 1], l[lb][i]); l[la][n[la]++] = l[lb][i]; } for (var i = m + 1; i < n[lb]; i++) { var j = i - m - 1; if (j == 0) a[lb][j] = l[lb][i]; else a[lb][j] = la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]); l[lb][j] = l[lb][i]; } n[lb] -= n[la]; } return l[la][--n[la]]; } public T PopBack() => Pop(1); public T PopFront() => Pop(0); public T Aggregate() { if (n[0] == 0 && n[1] == 0) throw new Exception(); else if (n[1] == 0) return a[0][n[0] - 1]; else if (n[0] == 0) return a[1][n[1] - 1]; else return f(a[0][n[0] - 1], a[1][n[1] - 1]); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class AGC040B { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var lrList = Repeat(0, N).Select(_ => new { L = NN, R = NN }).ToList(); var lrListHenka = lrList.Select(e => new { e.R, e.L, len = e.R - e.L + 1 }) .OrderByRand() .OrderByDescending(e => e.len) .ToList(); var maxValue = lrListHenka.First().len + Max(0, lrListHenka.Skip(1).Min(e => e.R) - lrListHenka.Skip(1).Max(e => e.L) + 1); var minl = lrList.OrderByRand().OrderBy(e => e.L).First(); lrList.Remove(minl); var sorted = lrList.OrderByRand().OrderBy(e => e.L).ToList(); var rpool = new BT<long>(); var lpool = new BT<long>(); foreach (var item in sorted) { rpool.Add(item.R); lpool.Add(item.L); } { var val1 = Max(0, minl.R - minl.L + 1); var val2 = Max(0, rpool.Min() - lpool.Max() + 1); maxValue = Max(maxValue, val1 + val2); } var r = minl.R; foreach (var item in sorted) { rpool.Remove(item.R); lpool.Remove(item.L); r = Min(r, item.R); var val1 = Max(0, r - item.L + 1); var val2 = Max(0, rpool.Min() - lpool.Max() + 1); maxValue = Max(maxValue, val1 + val2); } Console.WriteLine(maxValue); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); static Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; } static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } static List<T> LCS<T>(T[] s, T[] t) where T : IEquatable<T> { int sl = s.Length, tl = t.Length; var dp = new int[sl + 1, tl + 1]; for (var i = 0; i < sl; i++) for (var j = 0; j < tl; j++) dp[i + 1, j + 1] = s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]); { var r = new List<T>(); int i = sl, j = tl; while (i > 0 && j > 0) if (s[--i].Equals(t[--j])) r.Add(s[i]); else if (dp[i, j + 1] > dp[i + 1, j]) ++j; else ++i; r.Reverse(); return r; } } static long LIS<T>(T[] array, bool strict) { var l = new List<T>(); foreach (var e in array) { var i = l.BinarySearch(e); if (i < 0) i = ~i; else if (!strict) ++i; if (i == l.Count) l.Add(e); else l[i] = e; } return l.Count; } class PQ<T> { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) {} public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TK, TV> { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) {} public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {} public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v)); public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; public UF(long s) { d = Repeat(-1L, s).ToArray(); } public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } public bool IsSame(long x, long y) => Root(x) == Root(y); public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); public long Count(long x) => -d[Root(x)]; } struct Mod : IEquatable<Mod>, IEquatable<long> { static public long _mod = 1000000007; long v; public Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; } static public implicit operator Mod(long x) => new Mod(x); static public implicit operator long(Mod x) => x.v; public void Add(Mod x) { if ((v += x.v) >= _mod) v -= _mod; } public void Sub(Mod x) { if ((v -= x.v) < 0) v += _mod; } public void Mul(Mod x) => v = (v * x.v) % _mod; public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod; static public Mod operator +(Mod x, Mod y) { var t = x.v + y.v; return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t }; } static public Mod operator -(Mod x, Mod y) { var t = x.v - y.v; return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t }; } static public Mod operator *(Mod x, Mod y) => x.v * y.v; static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v); static public bool operator ==(Mod x, Mod y) => x.v == y.v; static public bool operator !=(Mod x, Mod y) => x.v != y.v; static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } public bool Equals(Mod x) => v == x.v; public bool Equals(long x) => v == x; public override bool Equals(object x) => x == null ? false : Equals((Mod)x); public override int GetHashCode() => v.GetHashCode(); public override string ToString() => v.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; public int c; } Comparison<T> c; Node r; bool ch; T lm; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} bool R(Node n) => n != null && !n.b; bool B(Node n) => n != null && n.b; long C(Node n) => n?.c ?? 0; Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } public void Add(T x) { r = A(r, x); r.b = true; } Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); } Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } public T this[long i] { get { return At(r, i); } } T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); } public bool Have(T x) { var t = FindUpper(x); return t < C(r) && c(At(r, t), x) == 0; } public long FindUpper(T x, bool allowSame = true) => allowSame ? FL(r, x) + 1 : FU(r, x); long FU(Node n, T x) { if (n == null) return 0; var r = c(x, n.v); if (r < 0) return FU(n.l, x); return C(n.l) + 1 + FU(n.r, x); } public long FindLower(T x, bool allowSame = true) { var t = FL(r, x); if (allowSame) return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1 : t < 0 ? C(r) : t; return t < 0 ? C(r) : t; } long FL(Node n, T x) { if (n == null) return -1; var r = c(x, n.v); if (r > 0) return C(n.l) + 1 + FL(n.r, x); return FL(n.l, x); } public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } public bool Any() => r != null; public long Count() => C(r); public IEnumerable<T> List() => L(r); IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; public Dict(Func<K, V> _d) { d = _d; } public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } public override int GetHashCode() { var ret = 0; for (var e = GetEnumerator(); e.MoveNext();) { ret ^= e.Current.Key.GetHashCode(); ret ^= e.Current.Value.GetHashCode(); } return ret; } public override bool Equals(object obj) { var o = (Dict<K, V>)obj; foreach (var kv in o) { if (!ContainsKey(kv.Key) || !this[kv.Key].Equals(kv.Value)) return false; } return o.Count == Count; } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } public Deque(int cap = 16) { b = new T[c = cap]; } int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } class SegTree<T> { int n; T ti; Func<T, T, T> f; T[] dat; public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); } public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } } } class LazySegTree<T, E> { int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz; public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]); void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; } void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); } void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); } public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); } public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); } public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } } } class SlidingWindowAggregation<T> { T[][] l; T[][] a; int[] n; Func<T, T, T> f; public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) { l = new T[2][]; a = new T[2][]; n = new int[2]; f = _f; l[0] = new T[16]; a[0] = new T[16]; n[0] = 0; if (ary.Any()) { var t = ary.ToArray(); n[1] = t.Length; l[1] = new T[n[1]]; a[1] = new T[n[1]]; for (var i = 0; i < l[1].Length; i++) { l[1][i] = t[i]; if (i == 0) a[1][i] = t[i]; else a[1][i] = this.f(a[1][i - 1], t[i]); } } else { l[1] = new T[16]; a[1] = new T[16]; n[1] = 0; } } public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {} public int Count => n[0] + n[1]; void Push(int la, T v) { if (l[la].Length == n[la]) { var nar = new T[n[la] * 2]; var nag = new T[n[la] * 2]; Array.Copy(l[la], nar, n[la]); Array.Copy(a[la], nag, n[la]); l[la] = nar; a[la] = nag; } if (n[la] == 0) a[la][0] = v; else a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v); l[la][n[la]++] = v; } public void PushBack(T val) => Push(1, val); public void PushFront(T val) => Push(0, val); public T Pop(int la) { var lb = 1 - la; if (n[la] == 0) { if (n[lb] == 0) throw new Exception(); var m = (n[lb] - 1) / 2; if (l[la].Length <= m) { l[la] = new T[m + 1]; a[la] = new T[m + 1]; } n[la] = 0; for (var i = m; i >= 0; i--) { if (n[la] == 0) a[la][n[la]] = l[lb][i]; else a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1]) : f(a[la][n[la] - 1], l[lb][i]); l[la][n[la]++] = l[lb][i]; } for (var i = m + 1; i < n[lb]; i++) { var j = i - m - 1; if (j == 0) a[lb][j] = l[lb][i]; else a[lb][j] = la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]); l[lb][j] = l[lb][i]; } n[lb] -= n[la]; } return l[la][--n[la]]; } public T PopBack() => Pop(1); public T PopFront() => Pop(0); public T Aggregate() { if (n[0] == 0 && n[1] == 0) throw new Exception(); else if (n[1] == 0) return a[0][n[0] - 1]; else if (n[0] == 0) return a[1][n[1] - 1]; else return f(a[0][n[0] - 1], a[1][n[1] - 1]); } } } }
[["+", 0, 200, 0, 212, 0, 16, 12, 213, 63, 22], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 16, 12, 213, 3, 4, 0, 25]]
8
9,907
5
using System; namespace AtCoder { class Program { static void Main(string[] args) { string[] n = Console.ReadLine().Split(); int a = int.Parse(n[0]); int b = int.Parse(n[1]); if (a < 10 || b < 10) { Console.WriteLine(a * b); } else { Console.WriteLine(-1); } } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) { string[] n = Console.ReadLine().Split(); int a = int.Parse(n[0]); int b = int.Parse(n[1]); if (a < 10 && b < 10) { Console.WriteLine(a * b); } else { Console.WriteLine(-1); } } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
8
95
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc144_a { class Program { static void Main(string[] args) { string[] N = Console.ReadLine().Split(' '); int A = int.Parse(N[0]); int B = int.Parse(N[0]); if (A <= 9 && B <= 9) { Console.WriteLine(A * B); } else { Console.WriteLine(-1); } Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc144_a { class Program { static void Main(string[] args) { string[] N = Console.ReadLine().Split(' '); int A = int.Parse(N[0]); int B = int.Parse(N[1]); if (A <= 9 && B <= 9) { Console.WriteLine(A * B); } else { Console.WriteLine(-1); } Console.Read(); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
128
2
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var a = int.Parse(spl[0]); var b = int.Parse(spl[1]); if (a > 9) return No; if (b > 9) return No; return a * b; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var a = int.Parse(spl[0]); var b = int.Parse(spl[1]); if (a > 9) return -1; if (b > 9) return -1; return a * b; } }
[["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 22], ["+", 8, 196, 0, 57, 64, 37, 0, 241, 0, 33], ["+", 8, 196, 0, 57, 64, 37, 0, 241, 0, 203]]
8
184
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp11 { class Class1 { static void Main() { string[] S = Console.ReadLine().Split(); int A = int.Parse(S[0]); int B = int.Parse(S[1]); int ans; if (A < 10 & B < 10) ans = -1; else ans = A * B; Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp11 { class Class1 { static void Main() { string[] S = Console.ReadLine().Split(); int A = int.Parse(S[0]); int B = int.Parse(S[1]); int ans; if (!(A < 10 & B < 10)) ans = -1; else ans = A * B; Console.WriteLine(ans); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 241, 0, 111], ["+", 8, 196, 0, 57, 15, 241, 0, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 241, 0, 23, 0, 25]]
8
115
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC144A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = a * b; d = -1; if (a < 10 || b < 10) Console.WriteLine(c); else Console.WriteLine(d); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC144A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = a * b; d = -1; if (a < 10 && b < 10) Console.WriteLine(c); else Console.WriteLine(d); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
8
131
2
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Linq.Expressions; using static System.Console; using static System.Math; class Program { void Solve() { var A = io.Int; var B = io.Int; if (A <= 10 && B <= 10) { WriteLine(A * B); } else { WriteLine(-1); } } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Program().Stream(); private void Stream() { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // SetIn(exStdIn); Solve(); io.Flush(); } } class SimpleIO { string[] _nextBuffer; int _bufferCnt; char[] cs = new char[] { ' ', '"', ',' }; StreamWriter sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public SimpleIO() { _nextBuffer = new string[0]; _bufferCnt = 0; SetOut(sw); } string Next() { if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++]; var st = ReadLine(); while (st == string.Empty) st = 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 Flush() => Out.Flush(); }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; using System.Linq.Expressions; using static System.Console; using static System.Math; class Program { void Solve() { var A = io.Int; var B = io.Int; if (A < 10 && B < 10) { WriteLine(A * B); } else { WriteLine(-1); } } SimpleIO io = new SimpleIO(); public static void Main(string[] args) => new Program().Stream(); private void Stream() { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // SetIn(exStdIn); Solve(); io.Flush(); } } class SimpleIO { string[] _nextBuffer; int _bufferCnt; char[] cs = new char[] { ' ', '"', ',' }; StreamWriter sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public SimpleIO() { _nextBuffer = new string[0]; _bufferCnt = 0; SetOut(sw); } string Next() { if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++]; var st = ReadLine(); while (st == string.Empty) st = 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 Flush() => Out.Flush(); }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18]]
8
362
4
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int b = int.Parse(input[0]); int c = int.Parse(input[1]); if (b > 10 && c > 10) { //出力 Console.WriteLine(-1); } else { //出力 Console.WriteLine(b * c); } } }
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int b = int.Parse(input[0]); int c = int.Parse(input[1]); if (b > 9 || c > 9) { //出力 Console.WriteLine(-1); } else { //出力 Console.WriteLine(b * c); } } }
[["-", 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, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
97
6
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main() { var l = ReadLine(); if (10 < l[0] || 10 < l[1]) { Console.WriteLine("-1"); } else { Console.WriteLine(l[0] * l[1]); } } 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() { var l = ReadLine(); if (9 < l[0] || 9 < l[1]) { Console.WriteLine("-1"); } else { Console.WriteLine(l[0] * l[1]); } } static List<int> ReadLine() { var line = Console.ReadLine(); var array = line.Split(' '); return array.Select(x => int.Parse(x)).ToList(); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203]]
8
132
4
using System; namespace AtCoder { class Program { static void Main(string[] args) { string input; int a, b; int result; input = Console.ReadLine(); Int32.TryParse(input.Split(' ')[0], out a); Int32.TryParse(input.Split(' ')[1], out b); if (a > 10 || b > 10) result = -1; else result = a * b; Console.WriteLine(result.ToString()); } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) { string input; int a, b; int result; input = Console.ReadLine(); Int32.TryParse(input.Split(' ')[0], out a); Int32.TryParse(input.Split(' ')[1], out b); if (a >= 10 || b >= 10) result = -1; else result = a * b; Console.WriteLine(result.ToString()); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20]]
8
114
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _1027_buginner_A { class Program { static void Main(string[] args) { int result; String[] inputNum = Console.ReadLine().Split(' '); int numA = int.Parse(inputNum[0]); int numB = int.Parse(inputNum[1]); if (((numA < 10) || (0 < numA)) && ((numB < 10) || (0 < numB))) { result = numA * numB; } else { result = -1; } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _1027_buginner_A { class Program { static void Main(string[] args) { int result; String[] inputNum = Console.ReadLine().Split(' '); int numA = int.Parse(inputNum[0]); int numB = int.Parse(inputNum[1]); if (((numA < 10) && (0 < numA)) && ((numB < 10) && (0 < numB))) { result = numA * numB; } else { result = -1; } Console.WriteLine(result); } } }
[["-", 0, 57, 15, 16, 31, 23, 0, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98]]
8
146
4
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得 int A = int.Parse(str[0]); int B = int.Parse(str[1]); // string[] strHeight = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string[] results = new string[N]; if (1 > A || A > 10) { Console.WriteLine("-1"); return; } if (1 > B || B > 10) { Console.WriteLine("-1"); return; } int result = A * B; Console.WriteLine(result.ToString()); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); // 2つ以上のスペース区切り入力の取得 int A = int.Parse(str[0]); int B = int.Parse(str[1]); // string[] strHeight = Console.ReadLine().Split(' // ');//2つ以上のスペース区切り入力の取得 string[] results = new string[N]; if (1 > A || A >= 10) { Console.WriteLine("-1"); return; } if (1 > B || B >= 10) { Console.WriteLine("-1"); return; } int result = A * B; Console.WriteLine(result.ToString()); } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20]]
8
136
4
namespace AtCoder.ABC.A144 { using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.IO; using AtCoder.ABC.IO; public class Quest { public object Solve(Parser parser) { int a = parser.Integer(); int b = parser.Integer(); if (a > 10 || b > 10) { return -1; } return a * b; } } static class Program { static void Main(string[] args) { var i = new Parser(Console.OpenStandardInput()); var o = new Printer(Console.OpenStandardOutput()); var got = new Quest().Solve(i); o.WriteLine(got); o.Flush(); } } } namespace AtCoder.ABC.IO { #region IO using System; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Globalization; public class Parser { public Parser(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } public IEnumerable<Parser> Take(int n) { return Enumerable.Range(1, n).Select(_ => this); } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } #endregion }
namespace AtCoder.ABC.A144 { using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.IO; using AtCoder.ABC.IO; public class Quest { public object Solve(Parser parser) { int a = parser.Integer(); int b = parser.Integer(); if (a > 9 || b > 9) { return -1; } return a * b; } } static class Program { static void Main(string[] args) { var i = new Parser(Console.OpenStandardInput()); var o = new Printer(Console.OpenStandardOutput()); var got = new Quest().Solve(i); o.WriteLine(got); o.Flush(); } } } namespace AtCoder.ABC.IO { #region IO using System; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Globalization; public class Parser { public Parser(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof; public bool IsEndOfStream { get { return isEof; } } public IEnumerable<Parser> Take(int n) { return Enumerable.Range(1, n).Select(_ => this); } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n'; b = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } #endregion }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
999
4
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Globalization; using System.Numerics; using System.Text.RegularExpressions; // byte 255 int<2147483647 ≒ 2 * 10^9 long < 9223372036854775807 ≒ 9 * 10^18 // decimal 29桁 class Myon { // chokudaiさんのコードをコピペ static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); // test(); return 0; } public void calc() { int a = cin.nextInt(); int b = cin.nextInt(); if (a <= 1 || a >= 10 || b <= 1 || b >= 10) ShowL(-1); else ShowL(a * b); } static long nibuntansaku(long[] a, long searchingNumber, long iLast) { // sが挿入されてソートされるaのindex long f = 0, l = iLast; long len = a.Length; long index = -1; while (l - f >= 1) { // index = (f + l) / 2; if (a[index] == searchingNumber) { f = index; break; } else if (a[index] > searchingNumber) l = index; else f = index + 1; } return f; } #region utilities public static void ShowL() { Console.WriteLine(""); } public static void ShowL<T>(T s) { Console.WriteLine(s); } public static void Show<T>(T s) { Console.Write(s); } public static void Yorn(bool isOK, string ifOK = "Yes", string ifNOTOK = "No") { if (isOK) ShowL(ifOK); else ShowL(ifNOTOK); } #endregion utilities } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] nextIntArr(long n) { int[] output = new int[n]; for (long i = 0; i < n; i++) output[i] = nextInt(); return output; } public long nextLong() { return long.Parse(next()); } public long[] nextLongArr(long n) { long[] output = new long[n]; for (long i = 0; i < n; i++) output[i] = nextLong(); return output; } public double nextDouble() { return double.Parse(next()); } } static class SMath { /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 12 なら 2,2,3 です。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> Factorization(long n) { if (n <= 0) return null; List<long> output = new List<long>(); int i = 2; long max = (long)Math.Sqrt(n); ; while (n > 1) { if (i > max) { output.Add(n); break; } while (n % i == 0) { output.Add(i); n /= i; } i++; } return output; } /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1  remainder = 1です。(打ち切られない) /// 13 = 0,0,...0 remainder = 2019 /// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) /// </summary> /// <param name="n"></param> /// <param name="remainder"></param> /// <returns></returns> public static List<long> Factorization(long n, out long remainder) { // output[i] が i-1番目の素数の数を示す //ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) remainder = 1; if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; long max = (long)Math.Sqrt(n); bool[] isNOTPrime = new bool[max + 1]; while (n > 1) { if (tempn > max) { remainder = n; break; } if (!isNOTPrime[tempn]) { output.Add(0); while (n % tempn == 0) { output[output.Count - 1]++; n /= tempn; } for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } /// <summary> /// i番目の素数をoutput[i-1]に返します。 /// ただしnより大きい素数については判定しません。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> GetPrimeNumbers(long n) { if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; bool[] isNOTPrime = new bool[n + 1]; while (n > 1) { if (tempn > n) { break; } if (!isNOTPrime[tempn]) { output.Add(tempn); for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } private static long[][] combMemo; private static int maxn_combination = -1; public static long Combination(int n, int k) { if (n < 0 || k > n) return 0; if (n == k || k == 0) return 1; if (k > n / 2) return Combination(n, n - k); if (maxn_combination < n) { maxn_combination = n; combMemo = new long [n + 1][]; } if (combMemo[n] == null) combMemo[n] = new long[n / 2 + 1]; if (combMemo[n][k] != 0) return combMemo[n][k]; else { combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1); return combMemo[n][k]; } } public static long Gcd(long a, long b) { if (a <= 0) return -1; // if (a > b) return gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public class pairComparer : IComparer<int[]> { int index = 0; public pairComparer(int n) { index = n; } public pairComparer() { index = 0; } public int Compare(int[] x, int[] y) { return y[index] - y[index]; } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Globalization; using System.Numerics; using System.Text.RegularExpressions; // byte 255 int<2147483647 ≒ 2 * 10^9 long < 9223372036854775807 ≒ 9 * 10^18 // decimal 29桁 class Myon { // chokudaiさんのコードをコピペ static Scanner cin; public Myon() {} public static int Main() { // Console.SetOut(new Printer(Console.OpenStandardOutput())); cin = new Scanner(); new Myon().calc(); // test(); return 0; } public void calc() { int a = cin.nextInt(); int b = cin.nextInt(); if (a < 1 || a >= 10 || b < 1 || b >= 10) ShowL(-1); else ShowL(a * b); } static long nibuntansaku(long[] a, long searchingNumber, long iLast) { // sが挿入されてソートされるaのindex long f = 0, l = iLast; long len = a.Length; long index = -1; while (l - f >= 1) { // index = (f + l) / 2; if (a[index] == searchingNumber) { f = index; break; } else if (a[index] > searchingNumber) l = index; else f = index + 1; } return f; } #region utilities public static void ShowL() { Console.WriteLine(""); } public static void ShowL<T>(T s) { Console.WriteLine(s); } public static void Show<T>(T s) { Console.Write(s); } public static void Yorn(bool isOK, string ifOK = "Yes", string ifNOTOK = "No") { if (isOK) ShowL(ifOK); else ShowL(ifNOTOK); } #endregion utilities } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] nextIntArr(long n) { int[] output = new int[n]; for (long i = 0; i < n; i++) output[i] = nextInt(); return output; } public long nextLong() { return long.Parse(next()); } public long[] nextLongArr(long n) { long[] output = new long[n]; for (long i = 0; i < n; i++) output[i] = nextLong(); return output; } public double nextDouble() { return double.Parse(next()); } } static class SMath { /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 12 なら 2,2,3 です。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> Factorization(long n) { if (n <= 0) return null; List<long> output = new List<long>(); int i = 2; long max = (long)Math.Sqrt(n); ; while (n > 1) { if (i > max) { output.Add(n); break; } while (n % i == 0) { output.Add(i); n /= i; } i++; } return output; } /// <summary> /// 素因数分解して、n番目に見つかった素因数をoutput[n-1]に返します。 /// 84 = (2^2 * 3 * 7) なら 2, 1, 0, 1  remainder = 1です。(打ち切られない) /// 13 = 0,0,...0 remainder = 2019 /// ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) /// </summary> /// <param name="n"></param> /// <param name="remainder"></param> /// <returns></returns> public static List<long> Factorization(long n, out long remainder) { // output[i] が i-1番目の素数の数を示す //ただし、試行を打ち切った時に限り残りをremainderに返す。(remainderは素数または1となる) remainder = 1; if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; long max = (long)Math.Sqrt(n); bool[] isNOTPrime = new bool[max + 1]; while (n > 1) { if (tempn > max) { remainder = n; break; } if (!isNOTPrime[tempn]) { output.Add(0); while (n % tempn == 0) { output[output.Count - 1]++; n /= tempn; } for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } /// <summary> /// i番目の素数をoutput[i-1]に返します。 /// ただしnより大きい素数については判定しません。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<long> GetPrimeNumbers(long n) { if (n <= 0) return null; List<long> output = new List<long>(); long tempn = 2; bool[] isNOTPrime = new bool[n + 1]; while (n > 1) { if (tempn > n) { break; } if (!isNOTPrime[tempn]) { output.Add(tempn); for (long j = tempn * 2; j < isNOTPrime.Length; j += tempn) isNOTPrime[j] = true; } tempn++; } return output; } private static long[][] combMemo; private static int maxn_combination = -1; public static long Combination(int n, int k) { if (n < 0 || k > n) return 0; if (n == k || k == 0) return 1; if (k > n / 2) return Combination(n, n - k); if (maxn_combination < n) { maxn_combination = n; combMemo = new long [n + 1][]; } if (combMemo[n] == null) combMemo[n] = new long[n / 2 + 1]; if (combMemo[n][k] != 0) return combMemo[n][k]; else { combMemo[n][k] = Combination(n - 1, k) + Combination(n - 1, k - 1); return combMemo[n][k]; } } public static long Gcd(long a, long b) { if (a <= 0) return -1; // if (a > b) return gcd(b, a); if (b == 0) return a; return Gcd(b, a % b); } public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public class pairComparer : IComparer<int[]> { int index = 0; public pairComparer(int n) { index = n; } public pairComparer() { index = 0; } public int Compare(int[] x, int[] y) { return y[index] - y[index]; } } }
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18]]
8
1,412
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq); public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq); } static class MyMath { static public long GCD(long a, long b) => (a < b) ? GCD(b, a) : ((b == 0) ? a : GCD(b, a % b)); static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a); static private readonly long _m = 1000000000 + 7; static public long Mod(long val) => (val % _m + _m) % _m; static private long ExtGCD(long a, long b, ref long x, ref long y) => (b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0) : (ExtGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0); static private long ModInverseInner(long a, long dummy1 = 0, long dummy2 = 0) => ExtGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1); static public long ModInverse(long a) => ModInverseInner(a, 0, 0); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static void Main() { int[] nm = Console.ReadLine().ToIntArray(); int N = nm[0]; int M = nm[1]; int[] itemList = Console.ReadLine().ToIntArray(); var q = PriorityQueue<int>.Create(n => n, PriorityKind.BiggerIsPrior); foreach (var item in itemList) { q.Enqueue(item); } for (int i = 0; i < M; i++) { var val = q.Dequeue(); val /= 2; q.Enqueue(val); } Console.WriteLine(q.Sum()); } public enum PriorityKind { BiggerIsPrior, SmallerIsPrior, } public abstract class PriorityQueue<T> : IEnumerable<T> { public static PriorityQueue<T> Create<U>(Func<T, U> prioritySelector, PriorityKind kind) { return new PriorityQueueInner<T, U>(prioritySelector, kind); } public abstract IEnumerator<T> GetEnumerator(); public abstract void Enqueue(T item); public abstract T Dequeue(); IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } /// <summary> /// 優先度順に取り出されるキュー /// </summary> /// <typeparam name="T"></typeparam> private class PriorityQueueInner<T, U> : PriorityQueue<T> { private Comparison<T> comparison; private List<T> heap = new List<T>(); /// <summary> /// 優先度セレクタを指定して初期化 /// </summary> /// <param name="comparison"></param> public PriorityQueueInner(Func<T, U> prioritySelector, PriorityKind kind) { var comparer = Comparer<U>.Default; Comparison<T> biggerPriorComparison = (T x, T y) => { return comparer.Compare(prioritySelector(y), prioritySelector(x)); }; Comparison<T> smallerPriorComparison = (T x, T y) => { return comparer.Compare(prioritySelector(x), prioritySelector(y)); }; if (kind == PriorityKind.BiggerIsPrior) { this.comparison = biggerPriorComparison; } else { this.comparison = smallerPriorComparison; } } public override void Enqueue(T item) { heap.Add(item); int i = heap.Count - 1; while (i > 0) { //親のノードの番号 int p = (i - 1) / 2; //もう逆転していないなら抜ける if (comparison(item, heap[p]) >= 0) break; //親のノードの数字を下ろして、自分は上に heap[i] = heap[p]; i = p; } heap[i] = item; } public override T Dequeue() { int nextSize = heap.Count - 1; T ret = heap[0]; //根に持ってくる値 T x = heap[nextSize]; //根から下ろしていく int i = 0; while (i * 2 + 1 < nextSize) { //子同士を比較 int a = i * 2 + 1; int b = i * 2 + 2; if (b < nextSize && comparison(heap[a], heap[b]) > 0) a = b; //もう逆転していないなら終わり if (comparison(heap[a], x) >= 0) break; //子の数字を持ち上げる heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(nextSize); return ret; } public override IEnumerator<T> GetEnumerator() { return heap.GetEnumerator(); } public int Count => heap.Count; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); public static Queue<T> ToQueue<T>(this IEnumerable<T> seq) => new Queue<T>(seq); public static Stack<T> ToStack<T>(this IEnumerable<T> seq) => new Stack<T>(seq); public static HashSet<T> ToHashSet<T>(this IEnumerable<T> seq) => new HashSet<T>(seq); } static class MyMath { static public long GCD(long a, long b) => (a < b) ? GCD(b, a) : ((b == 0) ? a : GCD(b, a % b)); static public long LCM(long a, long b) => (a > b) ? (a / GCD(a, b) * b) : (b / GCD(a, b) * a); static private readonly long _m = 1000000000 + 7; static public long Mod(long val) => (val % _m + _m) % _m; static private long ExtGCD(long a, long b, ref long x, ref long y) => (b == 0) ? (a + (x = 1) * 0 + (y = 0) * 0) : (ExtGCD(b, a % b, ref y, ref x) + (y -= a / b * x) * 0); static private long ModInverseInner(long a, long dummy1 = 0, long dummy2 = 0) => ExtGCD(a, _m, ref dummy1, ref dummy2) * 0 + Mod(dummy1); static public long ModInverse(long a) => ModInverseInner(a, 0, 0); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static void Main() { int[] nm = Console.ReadLine().ToIntArray(); int N = nm[0]; int M = nm[1]; long[] itemList = Console.ReadLine().ToLongArray(); var q = PriorityQueue<long>.Create(n => n, PriorityKind.BiggerIsPrior); foreach (var item in itemList) { q.Enqueue(item); } for (int i = 0; i < M; i++) { var val = q.Dequeue(); val /= 2; q.Enqueue(val); } Console.WriteLine(q.Sum()); } public enum PriorityKind { BiggerIsPrior, SmallerIsPrior, } public abstract class PriorityQueue<T> : IEnumerable<T> { public static PriorityQueue<T> Create<U>(Func<T, U> prioritySelector, PriorityKind kind) { return new PriorityQueueInner<T, U>(prioritySelector, kind); } public abstract IEnumerator<T> GetEnumerator(); public abstract void Enqueue(T item); public abstract T Dequeue(); IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } /// <summary> /// 優先度順に取り出されるキュー /// </summary> /// <typeparam name="T"></typeparam> private class PriorityQueueInner<T, U> : PriorityQueue<T> { private Comparison<T> comparison; private List<T> heap = new List<T>(); /// <summary> /// 優先度セレクタを指定して初期化 /// </summary> /// <param name="comparison"></param> public PriorityQueueInner(Func<T, U> prioritySelector, PriorityKind kind) { var comparer = Comparer<U>.Default; Comparison<T> biggerPriorComparison = (T x, T y) => { return comparer.Compare(prioritySelector(y), prioritySelector(x)); }; Comparison<T> smallerPriorComparison = (T x, T y) => { return comparer.Compare(prioritySelector(x), prioritySelector(y)); }; if (kind == PriorityKind.BiggerIsPrior) { this.comparison = biggerPriorComparison; } else { this.comparison = smallerPriorComparison; } } public override void Enqueue(T item) { heap.Add(item); int i = heap.Count - 1; while (i > 0) { //親のノードの番号 int p = (i - 1) / 2; //もう逆転していないなら抜ける if (comparison(item, heap[p]) >= 0) break; //親のノードの数字を下ろして、自分は上に heap[i] = heap[p]; i = p; } heap[i] = item; } public override T Dequeue() { int nextSize = heap.Count - 1; T ret = heap[0]; //根に持ってくる値 T x = heap[nextSize]; //根から下ろしていく int i = 0; while (i * 2 + 1 < nextSize) { //子同士を比較 int a = i * 2 + 1; int b = i * 2 + 2; if (b < nextSize && comparison(heap[a], heap[b]) > 0) a = b; //もう逆転していないなら終わり if (comparison(heap[a], x) >= 0) break; //子の数字を持ち上げる heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(nextSize); return ret; } public override IEnumerator<T> GetEnumerator() { return heap.GetEnumerator(); } public int Count => heap.Count; } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 236, 237, 238, 0, 199], ["+", 0, 213, 63, 214, 205, 236, 237, 238, 0, 199]]
8
1,284
6
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class ABC000A { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var S = NS; var lenList = new int [N][]; for (var i = 0; i < N; i++) { var chList = new long[N - i]; for (var j = i; j < N; j++) { chList[j - i] = S[j]; } lenList[i] = ZAlgorithm(chList); } var ans = 0L; for (var i = 0; i < N; i++) { for (var j = 0; j < lenList[i].Length; j++) { if (lenList[i][j] <= j) { ans = Max(ans, lenList[i][j]); } } } Console.WriteLine(ans); } static int[] ZAlgorithm(long[] s) { var ret = new int[s.Length]; ret[0] = s.Length; int i = 1, j = 0; while (i < s.Length) { while (i + j < s.Length && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } var k = 1; while (i + k < s.Length && k + ret[i] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); static Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; } static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } static List<T> LCS<T>(T[] s, T[] t) where T : IEquatable<T> { int sl = s.Length, tl = t.Length; var dp = new int[sl + 1, tl + 1]; for (var i = 0; i < sl; i++) for (var j = 0; j < tl; j++) dp[i + 1, j + 1] = s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]); { var r = new List<T>(); int i = sl, j = tl; while (i > 0 && j > 0) if (s[--i].Equals(t[--j])) r.Add(s[i]); else if (dp[i, j + 1] > dp[i + 1, j]) ++j; else ++i; r.Reverse(); return r; } } static long LIS<T>(T[] array, bool strict) { var l = new List<T>(); foreach (var e in array) { var i = l.BinarySearch(e); if (i < 0) i = ~i; else if (!strict) ++i; if (i == l.Count) l.Add(e); else l[i] = e; } return l.Count; } class PQ<T> { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) {} public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TK, TV> { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) {} public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {} public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v)); public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; public UF(long s) { d = Repeat(-1L, s).ToArray(); } public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } public bool IsSame(long x, long y) => Root(x) == Root(y); public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); public long Count(long x) => -d[Root(x)]; } struct Mod : IEquatable<Mod>, IEquatable<long> { static public long _mod = 1000000007; long v; public Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; } static public implicit operator Mod(long x) => new Mod(x); static public implicit operator long(Mod x) => x.v; public void Add(Mod x) { if ((v += x.v) >= _mod) v -= _mod; } public void Sub(Mod x) { if ((v -= x.v) < 0) v += _mod; } public void Mul(Mod x) => v = (v * x.v) % _mod; public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod; static public Mod operator +(Mod x, Mod y) { var t = x.v + y.v; return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t }; } static public Mod operator -(Mod x, Mod y) { var t = x.v - y.v; return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t }; } static public Mod operator *(Mod x, Mod y) => x.v * y.v; static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v); static public bool operator ==(Mod x, Mod y) => x.v == y.v; static public bool operator !=(Mod x, Mod y) => x.v != y.v; static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } public bool Equals(Mod x) => v == x.v; public bool Equals(long x) => v == x; public override bool Equals(object x) => x == null ? false : Equals((Mod)x); public override int GetHashCode() => v.GetHashCode(); public override string ToString() => v.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; public int c; } Comparison<T> c; Node r; bool ch; T lm; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} bool R(Node n) => n != null && !n.b; bool B(Node n) => n != null && n.b; long C(Node n) => n?.c ?? 0; Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } public void Add(T x) { r = A(r, x); r.b = true; } Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); } Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } public T this[long i] { get { return At(r, i); } } T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); } public bool Have(T x) { var t = FindUpper(x); return t < C(r) && c(At(r, t), x) == 0; } public long FindUpper(T x, bool allowSame = true) => allowSame ? FL(r, x) + 1 : FU(r, x); long FU(Node n, T x) { if (n == null) return 0; var r = c(x, n.v); if (r < 0) return FU(n.l, x); return C(n.l) + 1 + FU(n.r, x); } public long FindLower(T x, bool allowSame = true) { var t = FL(r, x); if (allowSame) return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1 : t < 0 ? C(r) : t; return t < 0 ? C(r) : t; } long FL(Node n, T x) { if (n == null) return -1; var r = c(x, n.v); if (r > 0) return C(n.l) + 1 + FL(n.r, x); return FL(n.l, x); } public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } public bool Any() => r != null; public long Count() => C(r); public IEnumerable<T> List() => L(r); IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; public Dict(Func<K, V> _d) { d = _d; } public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } public Deque(int cap = 16) { b = new T[c = cap]; } int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } class SegTree<T> { int n; T ti; Func<T, T, T> f; T[] dat; public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); } public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } } } class LazySegTree<T, E> { int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz; public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]); void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; } void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); } void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); } public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); } public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); } public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } } } class SlidingWindowAggregation<T> { T[][] l; T[][] a; int[] n; Func<T, T, T> f; public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) { l = new T[2][]; a = new T[2][]; n = new int[2]; f = _f; l[0] = new T[16]; a[0] = new T[16]; n[0] = 0; if (ary.Any()) { var t = ary.ToArray(); n[1] = t.Length; l[1] = new T[n[1]]; a[1] = new T[n[1]]; for (var i = 0; i < l[1].Length; i++) { l[1][i] = t[i]; if (i == 0) a[1][i] = t[i]; else a[1][i] = this.f(a[1][i - 1], t[i]); } } else { l[1] = new T[16]; a[1] = new T[16]; n[1] = 0; } } public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {} public int Count => n[0] + n[1]; void Push(int la, T v) { if (l[la].Length == n[la]) { var nar = new T[n[la] * 2]; var nag = new T[n[la] * 2]; Array.Copy(l[la], nar, n[la]); Array.Copy(a[la], nag, n[la]); l[la] = nar; a[la] = nag; } if (n[la] == 0) a[la][0] = v; else a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v); l[la][n[la]++] = v; } public void PushBack(T val) => Push(1, val); public void PushFront(T val) => Push(0, val); public T Pop(int la) { var lb = 1 - la; if (n[la] == 0) { if (n[lb] == 0) throw new Exception(); var m = (n[lb] - 1) / 2; if (l[la].Length <= m) { l[la] = new T[m + 1]; a[la] = new T[m + 1]; } n[la] = 0; for (var i = m; i >= 0; i--) { if (n[la] == 0) a[la][n[la]] = l[lb][i]; else a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1]) : f(a[la][n[la] - 1], l[lb][i]); l[la][n[la]++] = l[lb][i]; } for (var i = m + 1; i < n[lb]; i++) { var j = i - m - 1; if (j == 0) a[lb][j] = l[lb][i]; else a[lb][j] = la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]); l[lb][j] = l[lb][i]; } n[lb] -= n[la]; } return l[la][--n[la]]; } public T PopBack() => Pop(1); public T PopFront() => Pop(0); public T Aggregate() { if (n[0] == 0 && n[1] == 0) throw new Exception(); else if (n[1] == 0) return a[0][n[0] - 1]; else if (n[0] == 0) return a[1][n[1] - 1]; else return f(a[0][n[0] - 1], a[1][n[1] - 1]); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class ABC000A { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var S = NS; var lenList = new int [N][]; for (var i = 0; i < N; i++) { var chList = new long[N - i]; for (var j = i; j < N; j++) { chList[j - i] = S[j]; } lenList[i] = ZAlgorithm(chList); } var ans = 0L; for (var i = 0; i < N; i++) { for (var j = 0; j < lenList[i].Length; j++) { if (lenList[i][j] <= j) { ans = Max(ans, lenList[i][j]); } } } Console.WriteLine(ans); } static int[] ZAlgorithm(long[] s) { var ret = new int[s.Length]; ret[0] = s.Length; int i = 1, j = 0; while (i < s.Length) { while (i + j < s.Length && s[j] == s[i + j]) ++j; ret[i] = j; if (j == 0) { ++i; continue; } var k = 1; while (i + k < s.Length && k + ret[k] < j) { ret[i + k] = ret[k]; ++k; } i += k; j -= k; } return ret; } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } static long LCM(long a, long b) => a * b / GCD(a, b); static Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; } static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; static void _B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static long Comb(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } static List<T> LCS<T>(T[] s, T[] t) where T : IEquatable<T> { int sl = s.Length, tl = t.Length; var dp = new int[sl + 1, tl + 1]; for (var i = 0; i < sl; i++) for (var j = 0; j < tl; j++) dp[i + 1, j + 1] = s[i].Equals(t[j]) ? dp[i, j] + 1 : Max(dp[i + 1, j], dp[i, j + 1]); { var r = new List<T>(); int i = sl, j = tl; while (i > 0 && j > 0) if (s[--i].Equals(t[--j])) r.Add(s[i]); else if (dp[i, j + 1] > dp[i + 1, j]) ++j; else ++i; r.Reverse(); return r; } } static long LIS<T>(T[] array, bool strict) { var l = new List<T>(); foreach (var e in array) { var i = l.BinarySearch(e); if (i < 0) i = ~i; else if (!strict) ++i; if (i == l.Count) l.Add(e); else l[i] = e; } return l.Count; } class PQ<T> { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, Comparer<T>.Default.Compare, asc) {} public PQ(bool asc = true) : this(Comparer<T>.Default.Compare, asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TK, TV> { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, Comparer<TK>.Default.Compare, asc) {} public PQ(bool asc = true) : this(Comparer<TK>.Default.Compare, asc) {} public void Push(TK k, TV v) => q.Push(Tuple.Create(k, v)); public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; public UF(long s) { d = Repeat(-1L, s).ToArray(); } public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } public bool IsSame(long x, long y) => Root(x) == Root(y); public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); public long Count(long x) => -d[Root(x)]; } struct Mod : IEquatable<Mod>, IEquatable<long> { static public long _mod = 1000000007; long v; public Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; } static public implicit operator Mod(long x) => new Mod(x); static public implicit operator long(Mod x) => x.v; public void Add(Mod x) { if ((v += x.v) >= _mod) v -= _mod; } public void Sub(Mod x) { if ((v -= x.v) < 0) v += _mod; } public void Mul(Mod x) => v = (v * x.v) % _mod; public void Div(Mod x) => v = (v * Inverse(x.v)) % _mod; static public Mod operator +(Mod x, Mod y) { var t = x.v + y.v; return t >= _mod ? new Mod { v = t - _mod } : new Mod { v = t }; } static public Mod operator -(Mod x, Mod y) { var t = x.v - y.v; return t < 0 ? new Mod { v = t + _mod } : new Mod { v = t }; } static public Mod operator *(Mod x, Mod y) => x.v * y.v; static public Mod operator /(Mod x, Mod y) => x.v * Inverse(y.v); static public bool operator ==(Mod x, Mod y) => x.v == y.v; static public bool operator !=(Mod x, Mod y) => x.v != y.v; static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } public bool Equals(Mod x) => v == x.v; public bool Equals(long x) => v == x; public override bool Equals(object x) => x == null ? false : Equals((Mod)x); public override int GetHashCode() => v.GetHashCode(); public override string ToString() => v.ToString(); static List<Mod> _fact = new List<Mod>() { 1 }; static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } static public Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; public int c; } Comparison<T> c; Node r; bool ch; T lm; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} bool R(Node n) => n != null && !n.b; bool B(Node n) => n != null && n.b; long C(Node n) => n?.c ?? 0; Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } public void Add(T x) { r = A(r, x); r.b = true; } Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); } Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } public T this[long i] { get { return At(r, i); } } T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); } public bool Have(T x) { var t = FindUpper(x); return t < C(r) && c(At(r, t), x) == 0; } public long FindUpper(T x, bool allowSame = true) => allowSame ? FL(r, x) + 1 : FU(r, x); long FU(Node n, T x) { if (n == null) return 0; var r = c(x, n.v); if (r < 0) return FU(n.l, x); return C(n.l) + 1 + FU(n.r, x); } public long FindLower(T x, bool allowSame = true) { var t = FL(r, x); if (allowSame) return t + 1 < C(r) && c(At(r, t + 1), x) == 0 ? t + 1 : t < 0 ? C(r) : t; return t < 0 ? C(r) : t; } long FL(Node n, T x) { if (n == null) return -1; var r = c(x, n.v); if (r > 0) return C(n.l) + 1 + FL(n.r, x); return FL(n.l, x); } public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } public bool Any() => r != null; public long Count() => C(r); public IEnumerable<T> List() => L(r); IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; public Dict(Func<K, V> _d) { d = _d; } public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } public Deque(int cap = 16) { b = new T[c = cap]; } int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } class SegTree<T> { int n; T ti; Func<T, T, T> f; T[] dat; public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); } public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } } } class LazySegTree<T, E> { int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz; public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]); void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; } void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); } void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); } public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); } public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); } public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } } } class SlidingWindowAggregation<T> { T[][] l; T[][] a; int[] n; Func<T, T, T> f; public SlidingWindowAggregation(IEnumerable<T> ary, Func<T, T, T> _f) { l = new T[2][]; a = new T[2][]; n = new int[2]; f = _f; l[0] = new T[16]; a[0] = new T[16]; n[0] = 0; if (ary.Any()) { var t = ary.ToArray(); n[1] = t.Length; l[1] = new T[n[1]]; a[1] = new T[n[1]]; for (var i = 0; i < l[1].Length; i++) { l[1][i] = t[i]; if (i == 0) a[1][i] = t[i]; else a[1][i] = this.f(a[1][i - 1], t[i]); } } else { l[1] = new T[16]; a[1] = new T[16]; n[1] = 0; } } public SlidingWindowAggregation(Func<T, T, T> f) : this(new T[0], f) {} public int Count => n[0] + n[1]; void Push(int la, T v) { if (l[la].Length == n[la]) { var nar = new T[n[la] * 2]; var nag = new T[n[la] * 2]; Array.Copy(l[la], nar, n[la]); Array.Copy(a[la], nag, n[la]); l[la] = nar; a[la] = nag; } if (n[la] == 0) a[la][0] = v; else a[la][n[la]] = la == 0 ? f(v, a[la][n[la] - 1]) : f(a[la][n[la] - 1], v); l[la][n[la]++] = v; } public void PushBack(T val) => Push(1, val); public void PushFront(T val) => Push(0, val); public T Pop(int la) { var lb = 1 - la; if (n[la] == 0) { if (n[lb] == 0) throw new Exception(); var m = (n[lb] - 1) / 2; if (l[la].Length <= m) { l[la] = new T[m + 1]; a[la] = new T[m + 1]; } n[la] = 0; for (var i = m; i >= 0; i--) { if (n[la] == 0) a[la][n[la]] = l[lb][i]; else a[la][n[la]] = la == 0 ? f(l[lb][i], a[la][n[la] - 1]) : f(a[la][n[la] - 1], l[lb][i]); l[la][n[la]++] = l[lb][i]; } for (var i = m + 1; i < n[lb]; i++) { var j = i - m - 1; if (j == 0) a[lb][j] = l[lb][i]; else a[lb][j] = la == 0 ? f(l[lb][i], a[lb][j - 1]) : f(a[lb][j - 1], l[lb][i]); l[lb][j] = l[lb][i]; } n[lb] -= n[la]; } return l[la][--n[la]]; } public T PopBack() => Pop(1); public T PopFront() => Pop(0); public T Aggregate() { if (n[0] == 0 && n[1] == 0) throw new Exception(); else if (n[1] == 0) return a[0][n[0] - 1]; else if (n[0] == 0) return a[1][n[1] - 1]; else return f(a[0][n[0] - 1], a[1][n[1] - 1]); } } } }
[["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
9,711
2
using System; using static System.Console; class Program { public static void Main() { int n = int.Parse(ReadLine()); string s = ReadLine(); int res = 0; int[,] dp = new int[n + 1, n + 1]; for (int i = n - 1; i >= 0; i--) { for (int j = n - 1; j > i; j--) { if (s[i] == s[j]) dp[i, j] = Math.Max(dp[i, j], dp[i + 1, j + 1] + 1); res = Math.Max(res, Math.Min(dp[i, j], j - 1)); } } WriteLine(res); } }
using System; using static System.Console; class Program { public static void Main() { int n = int.Parse(ReadLine()); string s = ReadLine(); int res = 0; int[,] dp = new int[n + 1, n + 1]; for (int i = n - 1; i >= 0; i--) { for (int j = n - 1; j > i; j--) { if (s[i] == s[j]) dp[i, j] = Math.Max(dp[i, j], dp[i + 1, j + 1] + 1); res = Math.Max(res, Math.Min(dp[i, j], j - i)); } } WriteLine(res); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
173
2
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); #if DEBUG ReadLine(); #endif } void Solve(ConsoleInput cin) { int n = cin.ReadInt; string s = cin.Read; int ans = 0; for (int i = 1; i < n; i++) { int[] prefix = ZAlgorithm(s.Substring(i)); for (int j = 0; j < prefix.Length; j++) { if (prefix[j] <= j && ans < prefix[j]) { ans = prefix[j]; } } } Console.WriteLine(ans); } class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } int[] ZAlgorithm(string s) { int[] prefix = new int[s.Length]; for (int i = 1, j = 0; i < s.Length; i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = Math.Max(0, j + prefix[j] - i); while (i + k < s.Length && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.Length; return prefix; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { class Program { static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); #if DEBUG ReadLine(); #endif } void Solve(ConsoleInput cin) { int n = cin.ReadInt; string s = cin.Read; int ans = 0; for (int i = 0; i < n; i++) { int[] prefix = ZAlgorithm(s.Substring(i)); for (int j = 0; j < prefix.Length; j++) { if (prefix[j] <= j && ans < prefix[j]) { ans = prefix[j]; } } } Console.WriteLine(ans); } class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } int[] ZAlgorithm(string s) { int[] prefix = new int[s.Length]; for (int i = 1, j = 0; i < s.Length; i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = Math.Max(0, j + prefix[j] - i); while (i + k < s.Length && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.Length; return prefix; } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
679
2
using System; using System.Collections.Generic; using System.Linq; namespace Contest { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); long ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (s[i] != s[j]) continue; if (i >= 1 && s[i - 1] == s[j - 1]) continue; for (int k = 0; k < n + 1; k++) { int kx = k + 1; int ky = k + j; if (kx >= j) break; if (ky >= n) break; if (s[kx] != s[ky]) break; ans = Math.Max(ans, k + 1); } } } Console.WriteLine(ans.ToString()); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Contest { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); long ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (s[i] != s[j]) continue; if (i >= 1 && s[i - 1] == s[j - 1]) continue; for (int k = 0; k < n + 1; k++) { int kx = k + i; int ky = k + j; if (kx >= j) break; if (ky >= n) break; if (s[kx] != s[ky]) break; ans = Math.Max(ans, k + 1); } } } Console.WriteLine(ans.ToString()); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
214
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); /*var th = new Thread(Run, 1 << 26); th.Start(); th.Join();*/ Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { int N = Int; var A = _ReadSplitLong; long ans = 0; for (var i = 0; i < N; i++) ans ^= A[i]; for (var i = 0; i < N; i++) A[i] &= (ans ^ ((1L << 60) - 1)); var b = new List<long>(); for (var i = 0; i < N; i++) { long v = A[i]; foreach (var e in b) { v = Min(v, v ^ e); } if (v != 0) b.Add(v); } long ev = 0; foreach (var e in b) ev = Max(ev, ev ^ e); Out_Sep(b); ans += (ev << 1); OutL(ans); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class IO_ShortCut { public static string[] _ReadSplit => Console.ReadLine().Split(); public static int[] _ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] _ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] _ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using static System.Math; using static System.Array; using static AtCoder.IO_ShortCut; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); /*var th = new Thread(Run, 1 << 26); th.Start(); th.Join();*/ Run(); Console.Out.Flush(); } static void Run() { int Testcase = 1; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { int N = Int; var A = _ReadSplitLong; long ans = 0; for (var i = 0; i < N; i++) ans ^= A[i]; for (var i = 0; i < N; i++) A[i] &= (ans ^ ((1L << 60) - 1)); var b = new List<long>(); for (var i = 0; i < N; i++) { long v = A[i]; foreach (var e in b) { v = Min(v, v ^ e); } if (v != 0) b.Add(v); } long ev = 0; foreach (var e in b) ev = Max(ev, ev ^ e); ans += (ev << 1); OutL(ans); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class IO_ShortCut { public static string[] _ReadSplit => Console.ReadLine().Split(); public static int[] _ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] _ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] _ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = _ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
[["-", 0, 195, 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, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
2,329
5
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Console.WriteLine(Math.Pow(2, 3)); } } }
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Console.WriteLine(Math.Pow(N, 3)); } } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22]]
8
55
2
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); if (N == 1) { Console.WriteLine(1); } else if (N == 2) { Console.WriteLine(8); } else { Console.WriteLine(27); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); if (N == 1) { Console.WriteLine(1); } else if (N == 2) { Console.WriteLine(8); } else { Console.WriteLine(N * N * N); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
82
6
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(); int N = cin.nextInt(); Console.WriteLine(Math.Pow(2, N)); } } 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(); int N = cin.nextInt(); Console.WriteLine(Math.Pow(N, 3)); } } 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, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203]]
8
706
4
using System; namespace ABC140B { class Program { static void Main(string[] args) { int aa = int.Parse(Console.ReadLine()); int[] b = new int[aa + 1]; int[] c = new int[aa]; int[] d = new int[aa + 1]; int v = 0; int x = 0; var a = Console.ReadLine().Split(' '); var ab = Console.ReadLine().Split(' '); var ac = Console.ReadLine().Split(' '); int n = int.Parse(a[aa - 1]); for (int i = 1; i <= aa; i++) { d[i] = int.Parse(a[i - 1]); b[i] = int.Parse(ab[i - 1]); x += b[i]; } for (int i = 1; i <= aa - 1; i++) { c[i] = int.Parse(ac[i - 1]); } for (int i = 1; i <= aa - 1; i++) { if (d[i + 1] - d[i] == 1) x += c[i - 1]; } Console.WriteLine(x); } } }
using System; namespace ABC140B { class Program { static void Main(string[] args) { int aa = int.Parse(Console.ReadLine()); int[] b = new int[aa + 1]; int[] c = new int[aa]; int[] d = new int[aa + 1]; int v = 0; int x = 0; var a = Console.ReadLine().Split(' '); var ab = Console.ReadLine().Split(' '); var ac = Console.ReadLine().Split(' '); int n = int.Parse(a[aa - 1]); for (int i = 1; i <= aa; i++) { d[i] = int.Parse(a[i - 1]); b[i] = int.Parse(ab[i - 1]); x += b[i]; } for (int i = 1; i <= aa - 1; i++) { c[i] = int.Parse(ac[i - 1]); } for (int i = 1; i <= aa - 1; i++) { if (d[i + 1] - d[i] == 1) x += c[d[i]]; } Console.WriteLine(x); } } }
[["+", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73]]
8
288
5
using System; using System.Collections.Generic; using System.Linq; public class AtCoderB { static void Main() { int n = int.Parse(Console.ReadLine()); int[] dish = new int[n]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { dish[i] = int.Parse(words[i]); } } int[] point = new int[n]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { point[i] = int.Parse(words[i]); } } int[] extra = new int[n]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { extra[i] = int.Parse(words[i]); } } int answer = 0; int previous = int.MinValue; for (int i = 0; i < n; i++) { int current = dish[i] - 1; answer += point[current]; if (current == previous + 1) { answer += extra[previous]; } previous = current; } Console.WriteLine(answer); } }
using System; using System.Collections.Generic; using System.Linq; public class AtCoderB { static void Main() { int n = int.Parse(Console.ReadLine()); int[] dish = new int[n]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { dish[i] = int.Parse(words[i]); } } int[] point = new int[n]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { point[i] = int.Parse(words[i]); } } int[] extra = new int[n - 1]; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n - 1; i++) { extra[i] = int.Parse(words[i]); } } int answer = 0; int previous = int.MinValue; for (int i = 0; i < n; i++) { int current = dish[i] - 1; answer += point[current]; if (current == previous + 1) { answer += extra[previous]; } previous = current; } Console.WriteLine(answer); } }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 33], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 0, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
309
4
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int n = ReadLineInt(); int[] aList = ReadLineIntArray(); int[] bList = ReadLineIntArray(); int[] cList = ReadLineIntArray(); int rtn = 0; int wk = -10; for (int i = 0; i < n; i++) { rtn += bList[aList[i]]; if (wk == aList[i] - 1) { rtn += cList[aList[i] - 1]; } wk = aList[i]; } Console.WriteLine(rtn); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int n = ReadLineInt(); int[] aList = ReadLineIntArray(); int[] bList = ReadLineIntArray(); int[] cList = ReadLineIntArray(); int rtn = 0; int wk = -10; for (int i = 0; i < n; i++) { rtn += bList[aList[i] - 1]; if (wk == aList[i] - 1) { rtn += cList[aList[i] - 2]; } wk = aList[i]; } Console.WriteLine(rtn); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } }
[["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
623
4
using System; using System.Collections; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[n - 1]; string[] s = Console.ReadLine().Split(); for (int i = 0; i < n; i++) { a[i] = int.Parse(s[i].ToString()); } s = Console.ReadLine().Split(); for (int i = 0; i < n; i++) { b[i] = int.Parse(s[i].ToString()); } s = Console.ReadLine().Split(); for (int i = 0; i < n - 1; i++) { c[i] = int.Parse(s[i].ToString()); } int sum = 0; int pre = -1; for (int i = 0; i < n; i++) { sum += b[a[i] - 1]; if (pre + 1 == a[i] - 1) { sum += c[pre]; } pre = a[i] - 1; } Console.WriteLine(sum); } }
using System; using System.Collections; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] a = new int[n]; int[] b = new int[n]; int[] c = new int[n - 1]; string[] s = Console.ReadLine().Split(); for (int i = 0; i < n; i++) { a[i] = int.Parse(s[i].ToString()); } s = Console.ReadLine().Split(); for (int i = 0; i < n; i++) { b[i] = int.Parse(s[i].ToString()); } s = Console.ReadLine().Split(); for (int i = 0; i < n - 1; i++) { c[i] = int.Parse(s[i].ToString()); } int sum = 0; int pre = -2; for (int i = 0; i < n; i++) { sum += b[a[i] - 1]; if (pre + 1 == a[i] - 1) { sum += c[pre]; } pre = a[i] - 1; } Console.WriteLine(sum); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203]]
8
302
2
using System; using System.Linq; namespace B_Buffet { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int[] B = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int[] C = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int satisfy = 0; satisfy += B.Sum(); for (int i = 0; i < N - 1; i++) { if (A[i] + 1 == A[i + 1]) { satisfy += C[A[i]]; } } Console.WriteLine(satisfy.ToString()); } } }
using System; using System.Linq; namespace B_Buffet { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int[] B = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int[] C = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int satisfy = 0; satisfy += B.Sum(); for (int i = 0; i < N - 1; i++) { if (A[i] + 1 == A[i + 1]) { satisfy += C[A[i] - 1]; } } Console.WriteLine(satisfy.ToString()); } } }
[["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
213
2
using System; class Program { static void Main(string[] args) { // 入力文字列を取得 int n = int.Parse(Console.ReadLine()); string[] aArrayStr = Console.ReadLine().Split(' '); string[] bArrayStr = Console.ReadLine().Split(' '); string[] cArrayStr = Console.ReadLine().Split(' '); // A列を数値に変換 int[] aArray = new int[n]; for (int a = 0; a < n; a++) { aArray[a] = int.Parse(aArrayStr[a]); } // B列を数値に変換 int[] bArray = new int[n]; for (int b = 0; b < n; b++) { bArray[b] = int.Parse(bArrayStr[b]); } // C列を数値に変換 int[] cArray = new int[n - 1]; for (int c = 0; c < n - 1; c++) { cArray[c] = int.Parse(cArrayStr[c]); } int sum = 0; for (int i = 0; i < n; i++) { // 満足度 sum += bArray[aArray[i] - 1]; // 追加満足度 if ((0 < i) && (aArray[i] - 1 == aArray[i - 1])) { sum += cArray[aArray[i - 1]]; } } Console.WriteLine(sum); } }
using System; class Program { static void Main(string[] args) { // 入力文字列を取得 int n = int.Parse(Console.ReadLine()); string[] aArrayStr = Console.ReadLine().Split(' '); string[] bArrayStr = Console.ReadLine().Split(' '); string[] cArrayStr = Console.ReadLine().Split(' '); // A列を数値に変換 int[] aArray = new int[n]; for (int a = 0; a < n; a++) { aArray[a] = int.Parse(aArrayStr[a]); } // B列を数値に変換 int[] bArray = new int[n]; for (int b = 0; b < n; b++) { bArray[b] = int.Parse(bArrayStr[b]); } // C列を数値に変換 int[] cArray = new int[n - 1]; for (int c = 0; c < n - 1; c++) { cArray[c] = int.Parse(cArrayStr[c]); } int sum = 0; for (int i = 0; i < n; i++) { // 満足度 sum += bArray[aArray[i] - 1]; // 追加満足度 if ((0 < i) && (aArray[i] - 1 == aArray[i - 1])) { sum += cArray[aArray[i - 1] - 1]; } } Console.WriteLine(sum); } }
[["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
300
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace atcoder { class test { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] A = Console.ReadLine().Split(' '); string[] B = Console.ReadLine().Split(' '); string[] C = Console.ReadLine().Split(' '); List<string> stringA = new List<string>(); List<string> stringB = new List<string>(); List<string> stringC = new List<string>(); List<int> intA = new List<int>(); List<int> intB = new List<int>(); List<int> intC = new List<int>(); stringA.AddRange(A); stringB.AddRange(B); stringC.AddRange(C); intA = stringA.ConvertAll(x => int.Parse(x)); intB = stringB.ConvertAll(x => int.Parse(x)); intC = stringC.ConvertAll(x => int.Parse(x)); int satuation = 0; int menu = 0; int prevmenu = 0; for (int i = 0; i < N; i++) { prevmenu = menu; menu = intA[i]; satuation += intB[menu - 1]; if (i > 0) { if ((menu - prevmenu) == 1) { satuation += intC[i - 2]; } } } Console.WriteLine(satuation); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace atcoder { class test { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] A = Console.ReadLine().Split(' '); string[] B = Console.ReadLine().Split(' '); string[] C = Console.ReadLine().Split(' '); List<string> stringA = new List<string>(); List<string> stringB = new List<string>(); List<string> stringC = new List<string>(); List<int> intA = new List<int>(); List<int> intB = new List<int>(); List<int> intC = new List<int>(); stringA.AddRange(A); stringB.AddRange(B); stringC.AddRange(C); intA = stringA.ConvertAll(x => int.Parse(x)); intB = stringB.ConvertAll(x => int.Parse(x)); intC = stringC.ConvertAll(x => int.Parse(x)); int satuation = 0; int menu = 0; int prevmenu = 0; for (int i = 0; i < N; i++) { prevmenu = menu; menu = intA[i]; satuation += intB[menu - 1]; if (i > 0) { if ((menu - prevmenu) == 1) { satuation += intC[prevmenu - 1]; } } } Console.WriteLine(satuation); } } }
[["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
347
4
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int number = int.Parse(Console.ReadLine()); int[] cuisine = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] satisfaction = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] bonus = Console.ReadLine().Split().Select(int.Parse).ToArray(); int result = 0; int beforeCuisine = -1; for (int i = 0; i < number; i++) { int currentCuisineIndex = cuisine[i] - 1; result += satisfaction[currentCuisineIndex]; if (beforeCuisine + 1 == cuisine[i]) { result += bonus[currentCuisineIndex]; } beforeCuisine = cuisine[i]; } Console.WriteLine(result.ToString()); } } }
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int number = int.Parse(Console.ReadLine()); int[] cuisine = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] satisfaction = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] bonus = Console.ReadLine().Split().Select(int.Parse).ToArray(); int result = 0; int beforeCuisine = -1; for (int i = 0; i < number; i++) { int currentCuisineIndex = cuisine[i] - 1; result += satisfaction[currentCuisineIndex]; if (beforeCuisine + 1 == cuisine[i]) { result += bonus[beforeCuisine - 1]; } beforeCuisine = cuisine[i]; } Console.WriteLine(result.ToString()); } } }
[["-", 0, 11, 12, 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, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
201
4
using System; using System.Linq; public class Program { public static void Main() { int N = int.Parse(Console.ReadLine().Trim()); int[] A = Console.ReadLine() .Trim() .Split(' ') .Select(x => int.Parse(x)) .ToArray(); int[] B = Console.ReadLine() .Trim() .Split(' ') .Select(x => int.Parse(x)) .ToArray(); int[] C = Console.ReadLine() .Trim() .Split(' ') .Select(x => int.Parse(x)) .ToArray(); int sum = 0; int previous = 1; foreach (var i in A) { sum += B[i - 1]; if (i == previous + 1) { sum += C[previous - 1]; } previous = i; } Console.WriteLine(sum); } }
using System; using System.Linq; public class Program { public static void Main() { int N = int.Parse(Console.ReadLine().Trim()); int[] A = Console.ReadLine() .Trim() .Split(' ') .Select(x => int.Parse(x)) .ToArray(); int[] B = Console.ReadLine() .Trim() .Split(' ') .Select(x => int.Parse(x)) .ToArray(); int[] C = Console.ReadLine() .Trim() .Split(' ') .Select(x => int.Parse(x)) .ToArray(); int sum = 0; int previous = -1; foreach (var i in A) { sum += B[i - 1]; if (i == previous + 1) { sum += C[previous - 1]; } previous = i; } Console.WriteLine(sum); } }
[["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33]]
8
211
1