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
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); int x = cin.Int(); long sum = 0; for (int i = 0; i < x; i++) { sum += i; if (sum >= x) { Console.WriteLine(i); return; } } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); int x = cin.Int(); long sum = 0; for (int i = 0; i < x; i++) { sum += i + 1; if (sum >= x) { Console.WriteLine(i + 1); return; } } } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
467
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc_056_C { class Program { static void Main(string[] args) { int ans = 0; int a = int.Parse(Console.ReadLine()); for (int i = 1; i > 0; i++) { ans = i * (i + 1) / 2; if (ans > a) { Console.WriteLine(i); break; } } Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace abc_056_C { class Program { static void Main(string[] args) { int ans = 0; int a = int.Parse(Console.ReadLine()); for (int i = 1; i > 0; i++) { ans = i * (i + 1) / 2; if (ans >= a) { Console.WriteLine(i); break; } } Console.ReadLine(); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
116
using System; class Program { static void Main(string[] args) { long X = long.Parse(Console.ReadLine()); long temp = 0; long ans; for (long i = 1;; i++) { temp += i; if (temp <= X) { ans = i; break; } } Console.WriteLine(ans); } }
using System; class Program { static void Main(string[] args) { long X = long.Parse(Console.ReadLine()); long temp = 0; long ans; for (long i = 1;; i++) { temp += i; if (temp >= X) { ans = i; break; } } Console.WriteLine(ans); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
78
using System; namespace arc070_a { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); int i; int sum = 0; for (i = 0; sum < x; i++) { sum += i; } Console.WriteLine(i); } } }
using System; namespace arc070_a { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); int i; int sum = 0; for (i = 0; sum < x; i++) { sum += i; } Console.WriteLine(i - 1); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
70
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { long x = long.Parse(Console.ReadLine()); long answer = 0; long memo = 0; for (int i = 1; i > 0; i++) { memo += i; answer++; if (x >= memo) break; } Console.WriteLine(answer); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { long x = long.Parse(Console.ReadLine()); long answer = 0; long memo = 0; for (int i = 1; i > 0; i++) { memo += i; answer++; if (x <= memo) break; } Console.WriteLine(answer); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
95
using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { var x = double.Parse(Console.ReadLine()); var i = (int)Math.Floor((Math.Sqrt(8 * x + 1) - 1) / 2); Console.WriteLine(i); } }
using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { var x = double.Parse(Console.ReadLine()); var i = (int)Math.Ceiling((Math.Sqrt(8 * x + 1) - 1) / 2); Console.WriteLine(i); } }
[["-", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22]]
8
77
using System; using System.Globalization; using System.IO; using System.Linq; namespace AtCoder { internal class Program { static void Main(string[] args) { var sr = new InputReader(Console.In); // var sr = new InputReader(new StreamReader("input.txt")); using (var sw = Console.Out) // using (var sw = new StreamWriter("output.txt")) { Solve(sr, sw); } } internal static void Solve(InputReader sr, TextWriter sw) { var n = sr.NextInt32(); var i = 0; var sum = 0; while (true) { if (sum == n) { sw.WriteLine(i); return; } sum += ++i; } } } internal class InputReader : IDisposable { private bool isDispose; private readonly TextReader sr; public InputReader(TextReader stream) { sr = stream; } public void Dispose() { // Dispose(true); GC.SuppressFinalize(this); } public string NextString() { var result = sr.ReadLine(); return result; } public int NextInt32() { return int.Parse(NextString()); } public long NextInt64() { return long.Parse(NextString()); } public string[] NextSplitStrings() { return NextString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } public string[] NextSplitInts() { return NextString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } public T[] ReadArray<T>(Func<string, CultureInfo, T> func) { return NextSplitStrings() .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } // protected void Dispose(bool dispose) //{ // if (isDispose) return; // if (dispose) // { // sr.Close(); // } // isDispose = true; //} //~InputReader() //{ // Dispose(false); //} } }
using System; using System.Globalization; using System.IO; using System.Linq; namespace AtCoder { internal class Program { static void Main(string[] args) { var sr = new InputReader(Console.In); // var sr = new InputReader(new StreamReader("input.txt")); using (var sw = Console.Out) // using (var sw = new StreamWriter("output.txt")) { Solve(sr, sw); } } internal static void Solve(InputReader sr, TextWriter sw) { var n = sr.NextInt32(); var i = 0; var sum = 0; while (true) { if (sum >= n) { sw.WriteLine(i); return; } sum += ++i; } } } internal class InputReader : IDisposable { private bool isDispose; private readonly TextReader sr; public InputReader(TextReader stream) { sr = stream; } public void Dispose() { // Dispose(true); GC.SuppressFinalize(this); } public string NextString() { var result = sr.ReadLine(); return result; } public int NextInt32() { return int.Parse(NextString()); } public long NextInt64() { return long.Parse(NextString()); } public string[] NextSplitStrings() { return NextString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } public string[] NextSplitInts() { return NextString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } public T[] ReadArray<T>(Func<string, CultureInfo, T> func) { return NextSplitStrings() .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str) { return str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => func(s, CultureInfo.InvariantCulture)) .ToArray(); } // protected void Dispose(bool dispose) //{ // if (isDispose) return; // if (dispose) // { // sr.Close(); // } // isDispose = true; //} //~InputReader() //{ // Dispose(false); //} } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20]]
8
403
using System; using static System.Math; class Program { static int n, k; static int[] a; static bool[,] dp; static int before = 0; static void Main() { string[] s = Console.ReadLine().Split(); n = int.Parse(s[0]); k = int.Parse(s[1]); a = new int[n]; s = Console.ReadLine().Split(); for (int i = 0; i < n; i++) a[i] = int.Parse(s[i]); Array.Sort(a); dp = new bool[n + 1, k]; dp[0, 0] = true; if (Need(0)) { Console.WriteLine(0); return; } if (Need(n - 1)) { Console.WriteLine(n); return; } int l = 0; int r = n - 1; while (r - l > 1) { int m = l + (r - l) / 2; if (Need(m)) { r = m; continue; } l = m; } Console.WriteLine(r); } static bool Need(int x) { for (int i = Min(before, x) + 1; i <= n; i++) { for (long j = 0; j < k; j++) { if (j >= a[i - 1] && i - 1 != x) dp[i, j] = dp[i - 1, j] || dp[i - 1, j - a[i - 1]]; else dp[i, j] = dp[i - 1, j]; } } bool f = false; for (long j = Max(0, k - a[x]); j < k; j++) f = f || dp[n, j]; before = x; return f; } }
using System; using static System.Math; class Program { static int n, k; static int[] a; static bool[,] dp; static int before = 0; static void Main() { string[] s = Console.ReadLine().Split(); n = int.Parse(s[0]); k = int.Parse(s[1]); a = new int[n]; s = Console.ReadLine().Split(); for (int i = 0; i < n; i++) a[i] = int.Parse(s[i]); Array.Sort(a); dp = new bool[n + 1, k]; dp[0, 0] = true; if (Need(0)) { Console.WriteLine(0); return; } if (!Need(n - 1)) { Console.WriteLine(n); return; } int l = 0; int r = n - 1; while (r - l > 1) { int m = l + (r - l) / 2; if (Need(m)) { r = m; continue; } l = m; } Console.WriteLine(r); } static bool Need(int x) { for (int i = Min(before, x) + 1; i <= n; i++) { for (long j = 0; j < k; j++) { if (j >= a[i - 1] && i - 1 != x) dp[i, j] = dp[i - 1, j] || dp[i - 1, j - a[i - 1]]; else dp[i, j] = dp[i - 1, j]; } } bool f = false; for (long j = Max(0, k - a[x]); j < k; j++) f = f || dp[n, j]; before = x; return f; } }
[["+", 0, 195, 8, 196, 0, 57, 15, 241, 0, 111]]
8
421
using System; using System.Collections.Generic; class Solver { static Scanner cin; public Solver() {} public static int Main() { cin = new Scanner(); new Solver().solve(); return 0; } public void solve() { int n; n = cin.nextInt(); long[] l, r, mid, width; l = new long[n]; r = new long[n]; mid = new long[n]; width = new long[n]; for (int i = 0; i < n; ++i) { l[i] = cin.nextLong(); r[i] = cin.nextLong(); l[i] *= 2; r[i] *= 2; width[i] = r[i] - l[i]; mid[i] = (r[i] + l[i]) / 2; } long leftOffset, rightOffset; leftOffset = rightOffset = 0; long minValue = 0; var left = new PriorityQueue<long>(); var right = new PriorityQueue<long>((long x, long y) => x > y); left.Push(mid[0]); right.Push(mid[0]); for (int i = 1; i < n; ++i) { long myWidth = (width[i] + width[i - 1]) / 2; leftOffset -= myWidth; rightOffset += myWidth; long maxLeft = left.Top(); long minRight = right.Top(); if (maxLeft + leftOffset <= mid[i] && mid[i] <= minRight + rightOffset) { left.Push(mid[i] - leftOffset); right.Push(mid[i] - rightOffset); } else { if (mid[i] < maxLeft + leftOffset) { minValue += maxLeft + leftOffset - mid[i]; right.Push(maxLeft + leftOffset - rightOffset); left.Pop(); left.Push(mid[i] - leftOffset); left.Push(mid[i] - leftOffset); } else { minValue += mid[i] - (minRight + rightOffset); left.Push(minRight + rightOffset - leftOffset); right.Pop(); right.Push(mid[i] - rightOffset); right.Push(mid[i] - rightOffset); } } } Console.WriteLine(minValue / 2); } } class PriorityQueue<T> where T : IComparable, new() { private List<T> _heap; private Func<T, T, bool> _compare; public PriorityQueue(Func<T, T, bool> compare) { this.Init(); _compare = compare; } public PriorityQueue() { this.Init(); this._compare = (T x, T y) => x.CompareTo(y) < 0; } public void Init() { _heap = new List<T>(); _heap.Add(new T()); } public void Push(T x) { _heap.Add(x); for (int i = _heap.Count - 1; i > 1; i /= 2) { if (_compare(_heap[i], _heap[i / 2])) { return; } else { Swap(_heap, i, i / 2); } } } public void Pop() { int _size = _heap.Count - 1; _heap[1] = _heap[_size]; _heap.RemoveAt(_size); _size -= 1; for (int i = 1;;) { int j = 2 * i; int k = 2 * i + 1; if (j > _size) { return; } if (k > _size) { if (_compare(_heap[j], _heap[i])) { return; } Swap(_heap, i, j); i = j; } if (_compare(_heap[j], _heap[i]) && _compare(_heap[k], _heap[i])) { return; } if (_compare(_heap[j], _heap[k])) { Swap(_heap, i, k); i = k; } else { Swap(_heap, i, j); i = j; } } } public T Top() { if (this.IsEmpty()) { throw new InvalidOperationException("A priority queue is empty."); } return _heap[1]; } public int GetSize() { return _heap.Count - 1; } public bool IsEmpty() { return this.GetSize() == 0; } public void Swap(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } public void Swap(List<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = list[indexB]; list[indexB] = tmp; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
using System; using System.Collections.Generic; class Solver { static Scanner cin; public Solver() {} public static int Main() { cin = new Scanner(); new Solver().solve(); return 0; } public void solve() { int n; n = cin.nextInt(); long[] l, r, mid, width; l = new long[n]; r = new long[n]; mid = new long[n]; width = new long[n]; for (int i = 0; i < n; ++i) { l[i] = cin.nextLong(); r[i] = cin.nextLong(); l[i] *= 2; r[i] *= 2; width[i] = r[i] - l[i]; mid[i] = (r[i] + l[i]) / 2; } long leftOffset, rightOffset; leftOffset = rightOffset = 0; long minValue = 0; var left = new PriorityQueue<long>(); var right = new PriorityQueue<long>((long x, long y) => x > y); left.Push(mid[0]); right.Push(mid[0]); for (int i = 1; i < n; ++i) { long myWidth = (width[i] + width[i - 1]) / 2; leftOffset -= myWidth; rightOffset += myWidth; long maxLeft = left.Top(); long minRight = right.Top(); if (maxLeft + leftOffset <= mid[i] && mid[i] <= minRight + rightOffset) { left.Push(mid[i] - leftOffset); right.Push(mid[i] - rightOffset); } else { if (mid[i] < maxLeft + leftOffset) { minValue += maxLeft + leftOffset - mid[i]; right.Push(maxLeft + leftOffset - rightOffset); left.Pop(); left.Push(mid[i] - leftOffset); left.Push(mid[i] - leftOffset); } else { minValue += mid[i] - (minRight + rightOffset); left.Push(minRight + rightOffset - leftOffset); right.Pop(); right.Push(mid[i] - rightOffset); right.Push(mid[i] - rightOffset); } } } Console.WriteLine(minValue / 2); } } class PriorityQueue<T> where T : IComparable, new() { private List<T> _heap; private Func<T, T, bool> _compare; public PriorityQueue(Func<T, T, bool> compare) { this.Init(); _compare = compare; } public PriorityQueue() { this.Init(); this._compare = (T x, T y) => x.CompareTo(y) < 0; } public void Init() { _heap = new List<T>(); _heap.Add(new T()); } public void Push(T x) { _heap.Add(x); for (int i = _heap.Count - 1; i > 1; i /= 2) { if (_compare(_heap[i], _heap[i / 2])) { return; } else { Swap(_heap, i, i / 2); } } } public void Pop() { int _size = _heap.Count - 1; _heap[1] = _heap[_size]; _heap.RemoveAt(_size); _size -= 1; for (int i = 1;;) { int j = 2 * i; int k = 2 * i + 1; if (j > _size) { return; } if (k > _size) { if (_compare(_heap[j], _heap[i])) { return; } Swap(_heap, i, j); i = j; continue; } if (_compare(_heap[j], _heap[i]) && _compare(_heap[k], _heap[i])) { return; } if (_compare(_heap[j], _heap[k])) { Swap(_heap, i, k); i = k; } else { Swap(_heap, i, j); i = j; } } } public T Top() { if (this.IsEmpty()) { throw new InvalidOperationException("A priority queue is empty."); } return _heap[1]; } public int GetSize() { return _heap.Count - 1; } public bool IsEmpty() { return this.GetSize() == 0; } public void Swap(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } public void Swap(List<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = list[indexB]; list[indexB] = tmp; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { while (i >= s.Length) { string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; } return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35]]
8
1,183
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var n = input[0]; var c = input[1]; var k = input[2]; long p = 0; var t = new long[n]; for (int i = 0; i < n; i++) { t[i] = Read(); } Array.Sort(t); p = t[0] + k; long ans = 1; long count = 0; for (int i = 1; i < n; i++) { if (p <= t[i] || c == count) { ans++; p = t[i] + k; count = 0; } else count++; } Console.WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var n = input[0]; var c = input[1]; var k = input[2]; long p = 0; var t = new long[n]; for (int i = 0; i < n; i++) { t[i] = Read(); } Array.Sort(t); p = t[0] + k; long ans = 1; long count = 1; for (int i = 1; i < n; i++) { if (p < t[i] || c <= count) { ans++; p = t[i] + k; count = 1; } else count++; } Console.WriteLine(ans); Console.Out.Flush(); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 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, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
278
using System; using System.Collections.Generic; namespace AGC011A { class Program { static void Main(string[] args) { var target = Console.ReadLine().Split(' '); int N = int.Parse(target[0]); int C = int.Parse(target[1]); int K = int.Parse(target[2]); var t = new List<int>(); for (int i = 0; i < N; i++) { t.Add(int.Parse(Console.ReadLine())); } t.Sort(); int count = 1; int p1 = 1; int num = 1; // bus int time = t[0]; while (p1 < t.Count) { if (num < C && t[p1] - time <= C) { num++; } else { count++; time = t[p1]; num = 1; } p1++; } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; namespace AGC011A { class Program { static void Main(string[] args) { var target = Console.ReadLine().Split(' '); int N = int.Parse(target[0]); int C = int.Parse(target[1]); int K = int.Parse(target[2]); var t = new List<int>(); for (int i = 0; i < N; i++) { t.Add(int.Parse(Console.ReadLine())); } t.Sort(); int count = 1; int p1 = 1; int num = 1; // bus int time = t[0]; while (p1 < t.Count) { if (num < C && t[p1] - time <= K) { num++; } else { count++; time = t[p1]; num = 1; } p1++; } Console.WriteLine(count); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
214
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC011_A { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var customers = int.Parse(input[0]); var busCapacity = int.Parse(input[1]); var angryTime = double.Parse(input[2]); var arrivalTime = new List<double>(); //各乗客の到着時刻 for (int i = 0; i < customers; i++) { arrivalTime.Add(double.Parse(Console.ReadLine())); } arrivalTime.Sort(); var passenger = 0; //バスの現在の乗客 var needBuses = 0; for (int i = 0; i < customers; i++) { if (i == customers - 1) { needBuses++; break; } if (arrivalTime[i] + angryTime < arrivalTime[i + 1]) { passenger = 0; needBuses++; } else if (arrivalTime[i] + angryTime >= arrivalTime[i + 1] && arrivalTime[i] + angryTime <= arrivalTime[i + 1] + angryTime) { passenger++; if (passenger == busCapacity) { passenger = 0; needBuses++; } } } Console.WriteLine(needBuses); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC011_A { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var customers = int.Parse(input[0]); var busCapacity = int.Parse(input[1]); var angryTime = double.Parse(input[2]); var arrivalTime = new List<double>(); //各乗客の到着時刻 for (int i = 0; i < customers; i++) { arrivalTime.Add(double.Parse(Console.ReadLine())); } arrivalTime.Sort(); var passenger = 0; //バスの現在の乗客 var needBuses = 0; for (int i = 0; i < customers; i++) { if (i == customers - 1) { needBuses++; break; } if (arrivalTime[i - passenger] + angryTime < arrivalTime[i + 1]) { passenger = 0; needBuses++; } else if (arrivalTime[i - passenger] + angryTime >= arrivalTime[i + 1] && arrivalTime[i - passenger] + angryTime <= arrivalTime[i + 1] + angryTime) { passenger++; if (passenger == busCapacity) { passenger = 0; needBuses++; } } } Console.WriteLine(needBuses); } } }
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
8
278
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int c = sc.NextInt(); int k = sc.NextInt(); int[] t = new int[n]; for (int i = 0; i < n; i++) { t[i] = sc.NextInt(); } t = t.OrderBy(i => i).ToArray(); int answer = 0; int limit = 0; int count = 0; for (int i = 0; i < n; i++) { if (limit == 0 || t[i] > limit) { limit = t[i] + k; answer++; count++; } else { count++; } if (count == c) { limit = 0; count = 0; } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int c = sc.NextInt(); int k = sc.NextInt(); int[] t = new int[n]; for (int i = 0; i < n; i++) { t[i] = sc.NextInt(); } t = t.OrderBy(i => i).ToArray(); int answer = 0; int limit = 0; int count = 0; for (int i = 0; i < n; i++) { if (limit == 0 || t[i] > limit) { limit = t[i] + k; answer++; count = 1; } else { count++; } if (count == c) { limit = 0; count = 0; } } 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, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
504
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { AGC011.A(); } class AGC011 { public static void A() { var N = Read.Int(); var C = Read.Long(); var K = Read.Long(); var T = Enumerable.Range(0, N).Select(i => Read.Long()).ToArray(); Array.Sort(T); int count = 1; int pass = 1; long t = T[0]; for (int i = 1; i < N; ++i) { if (pass >= C || T[i] > t + C) { count++; pass = 1; t = T[i]; } else { pass++; } } Console.WriteLine(count); } public static void B() {} } class Util { public static int[] CalcDistance_OnTree(Dictionary<int, HashSet<int>> adj, int N, int start) { var dist = Enumerable.Range(0, N + 1).Select(i => -1).ToArray(); dist[start] = 0; Queue<int> queue = new Queue<int>(); queue.Enqueue(start); while (queue.Count > 0) { var v = queue.Dequeue(); foreach (var w in adj[v]) { if (dist[w] < 0) { dist[w] = dist[v] + 1; queue.Enqueue(w); } } } return dist; } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { AGC011.A(); } class AGC011 { public static void A() { var N = Read.Int(); var C = Read.Long(); var K = Read.Long(); var T = Enumerable.Range(0, N).Select(i => Read.Long()).ToArray(); Array.Sort(T); int count = 1; int pass = 1; long t = T[0]; for (int i = 1; i < N; ++i) { if (pass >= C || T[i] > t + K) { count++; pass = 1; t = T[i]; } else { pass++; } } Console.WriteLine(count); } public static void B() {} } class Util { public static int[] CalcDistance_OnTree(Dictionary<int, HashSet<int>> adj, int N, int start) { var dist = Enumerable.Range(0, N + 1).Select(i => -1).ToArray(); dist[start] = 0; Queue<int> queue = new Queue<int>(); queue.Enqueue(start); while (queue.Count > 0) { var v = queue.Dequeue(); foreach (var w in adj[v]) { if (dist[w] < 0) { dist[w] = dist[v] + 1; queue.Enqueue(w); } } } return dist; } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 22]]
8
1,368
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class AtCoderrr { static void Main(string[] args) { int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray(); var ls = new List<int>(); for (int i = 0; i < s[0]; i++) { ls.Add(int.Parse(ReadLine())); } ls.Sort(); long ans = 1; int now = 1; int first = ls[0]; for (int i = 1; i < s[0]; i++) { if (now == s[1]) { ans++; now = 1; first = ls[i]; } else if (ls[i] - first < s[2]) { now++; } else { ans++; now = 1; first = ls[i]; } } WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCoder { class AtCoderrr { static void Main(string[] args) { int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray(); var ls = new List<int>(); for (int i = 0; i < s[0]; i++) { ls.Add(int.Parse(ReadLine())); } ls.Sort(); long ans = 1; int now = 1; int first = ls[0]; for (int i = 1; i < s[0]; i++) { if (now == s[1]) { ans++; now = 1; first = ls[i]; } else if (ls[i] - first <= s[2]) { now++; } else { ans++; now = 1; first = ls[i]; } } WriteLine(ans); } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19]]
8
237
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long n = long.Parse(input[0]); long c = long.Parse(input[1]); long k = long.Parse(input[2]); long[] nums = new long[n]; long answer = 1; long startTime = 0; long playerNum = 1; for (int i = 0; i < n; i++) { nums[i] = long.Parse(Console.ReadLine()); } Array.Sort(nums); startTime = nums[0]; for (int i = 1; i < n; i++) { if (nums[i] > startTime + k || playerNum > c) { answer++; startTime = nums[i]; } else playerNum++; } Console.WriteLine(answer); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split( ' '); // Splitで区切り文字を指定して複数個受け取る。 long n = long.Parse(input[0]); long c = long.Parse(input[1]); long k = long.Parse(input[2]); long[] nums = new long[n]; long answer = 1; long startTime = 0; long playerNum = 1; for (int i = 0; i < n; i++) { nums[i] = long.Parse(Console.ReadLine()); } Array.Sort(nums); startTime = nums[0]; for (int i = 1; i < n; i++) { if (nums[i] > startTime + k || playerNum >= c) { answer++; playerNum = 1; startTime = nums[i]; } else playerNum++; } Console.WriteLine(answer); } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
217
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; class Prog { public Prog() {} public static int Main() { new Prog().calc(); return 0; } Scanner cin; public void calc() { cin = new Scanner(); long N = cin.nextLong(); long C = cin.nextLong(); long K = cin.nextLong(); long[] T = new long[N]; for (long l = 0; l < N; l++) { T[l] = cin.nextLong(); } Array.Sort(T); long now = T[0]; long ans = 1; long pas = 1; for (long l = 1; l < N; l++) { long t = T[l]; if (pas >= C) { now = t; pas = 1; ans++; continue; } if (t > now + K) { now = t; pas++; ans++; continue; } pas++; } Console.WriteLine(ans); Console.Read(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; class Prog { public Prog() {} public static int Main() { new Prog().calc(); return 0; } Scanner cin; public void calc() { cin = new Scanner(); long N = cin.nextLong(); long C = cin.nextLong(); long K = cin.nextLong(); long[] T = new long[N]; for (long l = 0; l < N; l++) { T[l] = cin.nextLong(); } Array.Sort(T); long now = T[0]; long ans = 1; long pas = 1; for (long l = 1; l < N; l++) { long t = T[l]; if (pas >= C) { now = t; pas = 1; ans++; continue; } if (t > now + K) { now = t; pas = 1; ans++; continue; } pas++; } Console.WriteLine(ans); Console.Read(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } }
[["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
416
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray(); long accum = 0; int res = 0; for (int i = 0; i < a.Length - 1; i++) { accum += a[i]; if (a[i + 1] < accum * 2) res++; else res = 0; } Console.WriteLine(res + 1); } }
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray(); long accum = 0; int res = 0; for (int i = 0; i < a.Length - 1; i++) { accum += a[i]; if (a[i + 1] <= accum * 2) res++; else res = 0; } Console.WriteLine(res + 1); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
205
using System; using System.Collections.Generic; using CompLib.Util; public class Program { private int N; private int M; private List<int>[] E; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); M = sc.NextInt(); E = new List<int>[N]; for (int i = 0; i < N; i++) { E[i] = new List<int>(); } for (int i = 0; i < M; i++) { int u = sc.NextInt() - 1; int v = sc.NextInt() - 1; E[u].Add(v); E[v].Add(u); } // 自己辺が無い // (a,b)-(a,b'), (a,b)-(a',b)は無い // // 辺の個数 2M^2 // 連結グラフ A,Bがある // Cを同じルールで構成するとき、連結成分の個数 // Aにおいてa-a' Bに b-b'に長さ一致パスがある // Cに(a,b)-(a'b')のパスがある // 遠回りすると長さ2増やせるのでパリティが一致してれば良い // A,B // 片方の頂点1つ辺0個 // Cに辺作れない 連結成分A,Bの頂点の積 // 片方が二部グラフじゃない // Bが二部グラフじゃないとする // Bの奇数長サイクル // a'-b' // a'->奇数長サイクル->b' // a'-b'のパスは偶奇両方できる // 連結成分1個 // 両方二部グラフ // Aのa-b,Bのa'-b'の偶奇が一致してる頂点で連結成分作れる // 連結成分2個 // 頂点数1個連結成分 long g1 = 0; // 二部グラフ連結成分 long g2 = 0; // それ以外連結成分 long g3 = 0; var q = new Queue<int>(); int[] parity = new int[N]; for (int i = 0; i < N; i++) { if (parity[i] != 0) continue; parity[i] = 1; if (E[i].Count == 0) { g1++; continue; } // 二部グラフか? bool f2 = true; q.Enqueue(i); while (q.Count > 0) { var d = q.Dequeue(); foreach (int to in E[d]) { if (parity[to] == 0) { parity[to] = -parity[d]; q.Enqueue(to); } else { f2 &= parity[to] == -parity[d]; } } } if (f2) g2++; else g3++; } long ans = 0; // g1 ans += g1 * N + (N - g1); // g2 ans += g2 * g2 * 2; // g3 とg2,g3 ans += g3 * (g2 + g3) + g2 * g3; Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s; do { s = Console.ReadLine(); } while (s.Length == 0); _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public string ReadLine() { _index = _line.Length; return Console.ReadLine(); } 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() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.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 CompLib.Util; public class Program { private int N; private int M; private List<int>[] E; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); M = sc.NextInt(); E = new List<int>[N]; for (int i = 0; i < N; i++) { E[i] = new List<int>(); } for (int i = 0; i < M; i++) { int u = sc.NextInt() - 1; int v = sc.NextInt() - 1; E[u].Add(v); E[v].Add(u); } // 自己辺が無い // (a,b)-(a,b'), (a,b)-(a',b)は無い // // 辺の個数 2M^2 // 連結グラフ A,Bがある // Cを同じルールで構成するとき、連結成分の個数 // Aにおいてa-a' Bに b-b'に長さ一致パスがある // Cに(a,b)-(a'b')のパスがある // 遠回りすると長さ2増やせるのでパリティが一致してれば良い // A,B // 片方の頂点1つ辺0個 // Cに辺作れない 連結成分A,Bの頂点の積 // 片方が二部グラフじゃない // Bが二部グラフじゃないとする // Bの奇数長サイクル // a'-b' // a'->奇数長サイクル->b' // a'-b'のパスは偶奇両方できる // 連結成分1個 // 両方二部グラフ // Aのa-b,Bのa'-b'の偶奇が一致してる頂点で連結成分作れる // 連結成分2個 // 頂点数1個連結成分 long g1 = 0; // 二部グラフ連結成分 long g2 = 0; // それ以外連結成分 long g3 = 0; var q = new Queue<int>(); int[] parity = new int[N]; for (int i = 0; i < N; i++) { if (parity[i] != 0) continue; parity[i] = 1; if (E[i].Count == 0) { g1++; continue; } // 二部グラフか? bool f2 = true; q.Enqueue(i); while (q.Count > 0) { var d = q.Dequeue(); foreach (int to in E[d]) { if (parity[to] == 0) { parity[to] = -parity[d]; q.Enqueue(to); } else { f2 &= parity[to] == -parity[d]; } } } if (f2) g2++; else g3++; } long ans = 0; // g1 ans += g1 * N + (N - g1) * g1; // g2 ans += g2 * g2 * 2; // g3 とg2,g3 ans += g3 * (g2 + g3) + g2 * g3; Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { if (_index >= _line.Length) { string s; do { s = Console.ReadLine(); } while (s.Length == 0); _line = s.Split(Separator); _index = 0; } return _line[_index++]; } public string ReadLine() { _index = _line.Length; return Console.ReadLine(); } 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() { string s = Console.ReadLine(); _line = s.Length == 0 ? new string[0] : s.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, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 22]]
8
813
using System; using System.Text; using System.Collections.Generic; class Solve { int N; List<int>[] T; bool[] b; long[,] DP; public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { N = int.Parse(Console.ReadLine()); T = new List<int>[N]; for (int i = 0; i < N; i++) { T[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]) - 1; int b = int.Parse(str[1]) - 1; T[a].Add(b); T[b].Add(a); } int center1; int center2; int diamater; { Tree G = new Tree(T); G.Center(); center1 = G.center1; center2 = G.center2; diamater = G.diamater; } if (center2 == -1) { long count = 0; b = new bool[N]; DP = new long[N, 2 * N + 2]; dfs(center1, diamater / 2, N + 1); for (int i = 0; i < 2 * N + 2; i++) { count = (count + DP[center1, i]) % Define.mod; } sb.Append(count + "\n"); } else { long count = 0; b = new bool[N]; DP = new long[N, 2 * N + 2]; b[center2] = true; dfs(center1, diamater / 2 + 1, N); dfs(center2, diamater / 2, N); for (int i = 1; i < 2 * N + 1; i++) { count = (count + DP[center1, i] * (DP[center2, i - 1] + DP[center2, i + 1])) % Define.mod; } b = new bool[N]; DP = new long[N, 2 * N + 2]; b[center2] = true; dfs(center1, diamater / 2, N + 1); dfs(center2, diamater / 2 + 1, N + 1); for (int i = 1; i < 2 * N + 1; i++) { count = (count + DP[center1, i] * (DP[center2, i - 1] + DP[center2, i + 1])) % Define.mod; } b = new bool[N]; DP = new long[N, 2 * N + 2]; b[center2] = true; dfs(center1, diamater / 2, N); dfs(center2, diamater / 2, N + 1); for (int i = 1; i < 2 * N + 1; i++) { count = (count + 2 * (Define.mod - DP[center1, i]) * (DP[center2, i - 1] + DP[center2, i + 1])) % Define.mod; } sb.Append(count + "\n"); } } void dfs(int v, int l, int Z) { b[v] = true; for (int i = Z - l; i <= Z + l; i++) { DP[v, i] = 1; } for (int i = 0; i < T[v].Count; i++) { int t = T[v][i]; if (!b[t]) { dfs(t, l - 1, Z); for (int j = Z - l; j <= Z + l; j++) { DP[v, j] = DP[v, j] * (DP[t, j + 1] + DP[t, j - 1]) % Define.mod; } } } } } public class Tree { List<int>[] T; bool[] b; int N; int temp1; int temp2; public int center1; public int center2; public int diamater; public Tree(List<int>[] G) { T = G; N = G.Length; } void calcLongestPath(int v) { b = new bool[N]; temp1 = 0; temp2 = 0; dfs1(v, 0); } public int LongestPathDistance(int v) { calcLongestPath(v); return temp1; } public int LongestPath(int v) { calcLongestPath(v); return temp2; } public void Diamater() { int x1 = LongestPath(0); int x2 = LongestPath(x1); diamater = temp1; } public void Center() { int x1 = LongestPath(0); int x2 = LongestPath(x1); diamater = temp1; if (diamater % 2 == 0) { center1 = Search(x1, x2, diamater / 2); center2 = -1; } else { center1 = Search(x1, x2, diamater / 2); center2 = Search(x1, x2, diamater / 2 + 1); } } public int Search(int s, int t, int l) { b = new bool[N]; dfs2(s, t, 0, l); return temp1; } void dfs1(int v, int l) { b[v] = true; for (int i = 0; i < T[v].Count; i++) { int t = T[v][i]; if (!b[t]) { dfs1(t, l + 1); } } if (l >= temp1) { temp1 = l; temp2 = v; } } bool dfs2(int v, int o, int l, int d) { b[v] = true; bool x = v == o; for (int i = 0; i < T[v].Count; i++) { int t = T[v][i]; if (!b[t]) { x |= dfs2(t, o, l + 1, d); } } if (x && l == d) { temp1 = v; } return true; } } public static class Define { public const long mod = 1000000007; }
using System; using System.Text; using System.Collections.Generic; class Solve { int N; List<int>[] T; bool[] b; long[,] DP; public Solve() {} StringBuilder sb; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); Calc(); Console.Write(sb.ToString()); } void Calc() { N = int.Parse(Console.ReadLine()); T = new List<int>[N]; for (int i = 0; i < N; i++) { T[i] = new List<int>(); } for (int i = 0; i < N - 1; i++) { string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]) - 1; int b = int.Parse(str[1]) - 1; T[a].Add(b); T[b].Add(a); } int center1; int center2; int diamater; { Tree G = new Tree(T); G.Center(); center1 = G.center1; center2 = G.center2; diamater = G.diamater; } if (center2 == -1) { long count = 0; b = new bool[N]; DP = new long[N, 2 * N + 2]; dfs(center1, diamater / 2, N + 1); for (int i = 0; i < 2 * N + 2; i++) { count = (count + DP[center1, i]) % Define.mod; } sb.Append(count + "\n"); } else { long count = 0; b = new bool[N]; DP = new long[N, 2 * N + 2]; b[center2] = true; dfs(center1, diamater / 2 + 1, N); dfs(center2, diamater / 2, N); for (int i = 1; i < 2 * N + 1; i++) { count = (count + DP[center1, i] * (DP[center2, i - 1] + DP[center2, i + 1])) % Define.mod; } b = new bool[N]; DP = new long[N, 2 * N + 2]; b[center2] = true; dfs(center1, diamater / 2, N + 1); dfs(center2, diamater / 2 + 1, N + 1); for (int i = 1; i < 2 * N + 1; i++) { count = (count + DP[center1, i] * (DP[center2, i - 1] + DP[center2, i + 1])) % Define.mod; } b = new bool[N]; DP = new long[N, 2 * N + 2]; b[center2] = true; dfs(center1, diamater / 2, N); dfs(center2, diamater / 2, N + 1); for (int i = 1; i < 2 * N + 1; i++) { count = (count + 2 * (Define.mod - DP[center1, i]) * (DP[center2, i - 1] + DP[center2, i + 1])) % Define.mod; } sb.Append(count + "\n"); } } void dfs(int v, int l, int Z) { b[v] = true; for (int i = Z - l; i <= Z + l; i++) { DP[v, i] = 1; } for (int i = 0; i < T[v].Count; i++) { int t = T[v][i]; if (!b[t]) { dfs(t, l - 1, Z); for (int j = Z - l; j <= Z + l; j++) { DP[v, j] = DP[v, j] * (DP[t, j + 1] + DP[t, j - 1]) % Define.mod; } } } } } public class Tree { List<int>[] T; bool[] b; int N; int temp1; int temp2; public int center1; public int center2; public int diamater; public Tree(List<int>[] G) { T = G; N = G.Length; } void calcLongestPath(int v) { b = new bool[N]; temp1 = 0; temp2 = 0; dfs1(v, 0); } public int LongestPathDistance(int v) { calcLongestPath(v); return temp1; } public int LongestPath(int v) { calcLongestPath(v); return temp2; } public void Diamater() { int x1 = LongestPath(0); int x2 = LongestPath(x1); diamater = temp1; } public void Center() { int x1 = LongestPath(0); int x2 = LongestPath(x1); diamater = temp1; if (diamater % 2 == 0) { center1 = Search(x1, x2, diamater / 2); center2 = -1; } else { center1 = Search(x1, x2, diamater / 2); center2 = Search(x1, x2, diamater / 2 + 1); } } public int Search(int s, int t, int l) { b = new bool[N]; dfs2(s, t, 0, l); return temp1; } void dfs1(int v, int l) { b[v] = true; for (int i = 0; i < T[v].Count; i++) { int t = T[v][i]; if (!b[t]) { dfs1(t, l + 1); } } if (l >= temp1) { temp1 = l; temp2 = v; } } bool dfs2(int v, int o, int l, int d) { b[v] = true; bool x = v == o; for (int i = 0; i < T[v].Count; i++) { int t = T[v][i]; if (!b[t]) { x |= dfs2(t, o, l + 1, d); } } if (x && l == d) { temp1 = v; } return x; } } public static class Define { public const long mod = 1000000007; }
[["-", 0, 195, 8, 196, 0, 37, 0, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 22]]
8
1,386
using System; class A { public static void Main() { int N = int.Parse(Console.ReadLine()); int C = N % 15 * 200; Console.WriteLine(N * 800 - C); } }
using System; class A { public static void Main() { int N = int.Parse(Console.ReadLine()); int C = (N / 15) * 200; Console.WriteLine((N * 800) - C); } }
[["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 109], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 85], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25]]
8
49
using System; class program { static void Main() { var input = int.Parse(Console.ReadLine()); var result = input - (input * 800 - (input / 15) * 200); Console.WriteLine(result); } }
using System; class program { static void Main() { var input = int.Parse(Console.ReadLine()); var result = input * 800 - input / 15 * 200; Console.WriteLine(result); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["-", 0, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 23, 0, 16, 12, 16, 31, 23, 0, 24], ["-", 12, 23, 0, 16, 12, 16, 31, 23, 0, 25], ["-", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
8
54
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int N = Input.ScanInt(); int res = N * 800 - (N / 15); Console.WriteLine(res); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int N = Input.ScanInt(); int res = N * 800 - (N / 15) * 200; Console.WriteLine(res); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
[["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203]]
8
530
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input= Console.ReadLine(); int input = int.Parse(Console.ReadLine()); Console.WriteLine(800 * input - (input / 2) * 200); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; class Program { static void Main() { //入力 // int[] input = Console.ReadLine().Split().Select(i => // int.Parse(i)).ToArray(); string input= Console.ReadLine(); int input = int.Parse(Console.ReadLine()); Console.WriteLine(800 * input - (input / 15) * 200); /* //処理速度計測 var sw = new System.Diagnostics.Stopwatch(); sw.Start(); //解法 //処理速度表示 sw.Stop(); TimeSpan ts = sw.Elapsed; Console.WriteLine((int)(Math.Floor((ts).TotalMilliseconds))+"ms"); */ Console.ReadLine(); } }
[["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203]]
8
78
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var n = int.Parse(Console.ReadLine()); var val = n * 800; val += -(200 * n / 15); Console.WriteLine(val); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var n = int.Parse(Console.ReadLine()); var val = n * 800; val += -(200 * (n / 15)); Console.WriteLine(val); } }
[["+", 12, 241, 0, 23, 0, 16, 12, 23, 0, 24], ["+", 12, 241, 0, 23, 0, 16, 12, 23, 0, 25]]
8
65
using System; namespace AtCoder { class Program { static void Main(string[] args) { // 整数の入力 var eatCount = int.Parse(Console.ReadLine()); var payment = eatCount * 800; var discountSum = eatCount / 15 * 200; Console.WriteLine(eatCount - discountSum); } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) { // 整数の入力 var eatCount = int.Parse(Console.ReadLine()); var payment = eatCount * 800; var discountSum = eatCount / 15 * 200; Console.WriteLine(payment - discountSum); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
62
using System; class IfSample { static void Main() { // 整数を入力してもらう int x, y, n, a; n = int.Parse(Console.ReadLine()); x = n * 800; y = n / 15 * 200; a = x - y; Console.WriteLine("{0}", n); } }
using System; class IfSample { static void Main() { // 整数を入力してもらう int x, y, n, a; a = int.Parse(Console.ReadLine()); x = a * 800; y = a / 15 * 200; n = x - y; Console.WriteLine("{0}", n); } }
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22]]
8
68
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder20170211 { class Program { static void Main(string[] args) { var input = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(input * 800 - Math.Floor(input / 20m) * 200); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder20170211 { class Program { static void Main(string[] args) { var input = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(input * 800 - Math.Floor(input / 15m) * 200); } } }
[["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 250], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 250]]
8
73
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; namespace VS_TopCoder { public class ANewHope { public int count(int[] firstWeek, int[] lastWeek, int D) { int N = firstWeek.Length; int shift = N - D; int ma = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (firstWeek[i] == lastWeek[j] && j < i) { int d = i - j; ma = Math.Max(ma, (d + shift - 1) / shift + 1); } } } return ma; } } class Program { static void Main(string[] args) { Test(); var N = Convert.ToInt32(Console.ReadLine()); var mul = N / 15; int answer = mul * 15 * 800 - mul * 200; Console.WriteLine(answer); } static List<string> Readlines() { List<string> answer = new List<string>(); do { var item = Console.ReadLine(); if (item == null) { break; } else { answer.Add(item); } } while (true); return answer; } static List<string[]> Readlines2D(string divider) { List<string[]> answer = new List<string[]>(); do { var item = Console.ReadLine(); if (item == null) { break; } else { answer.Add(item.Split(Convert.ToChar(divider))); } } while (true); return answer; } // priority queue [Conditional("DEBUG")] static private void Test() { Console.SetIn(new System.IO.StreamReader( @"c:\users\user\documents\visual studio 2015\Projects\VS TopCoder\VS TopCoder\Test.txt")); } } 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) { heap = new List<T>(capacity); compare = comparison; } public void Enqueue(T item) { 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; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; namespace VS_TopCoder { public class ANewHope { public int count(int[] firstWeek, int[] lastWeek, int D) { int N = firstWeek.Length; int shift = N - D; int ma = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (firstWeek[i] == lastWeek[j] && j < i) { int d = i - j; ma = Math.Max(ma, (d + shift - 1) / shift + 1); } } } return ma; } } class Program { static void Main(string[] args) { Test(); var N = Convert.ToInt32(Console.ReadLine()); var mul = N / 15; int answer = N * 800 - mul * 200; Console.WriteLine(answer); } static List<string> Readlines() { List<string> answer = new List<string>(); do { var item = Console.ReadLine(); if (item == null) { break; } else { answer.Add(item); } } while (true); return answer; } static List<string[]> Readlines2D(string divider) { List<string[]> answer = new List<string[]>(); do { var item = Console.ReadLine(); if (item == null) { break; } else { answer.Add(item.Split(Convert.ToChar(divider))); } } while (true); return answer; } // priority queue [Conditional("DEBUG")] static private void Test() { Console.SetIn(new System.IO.StreamReader( @"c:\users\user\documents\visual studio 2015\Projects\VS TopCoder\VS TopCoder\Test.txt")); } } 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) { heap = new List<T>(capacity); compare = comparison; } public void Enqueue(T item) { 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; } } }
[["-", 0, 212, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22]]
8
769
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long power = 1; for (int i = 1; i <= N; i++) { power *= i; } power %= (long)Math.Pow(10, 9) + 7; Console.WriteLine(power); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long power = 1; for (int i = 1; i <= N; i++) { power *= i; power %= (long)Math.Pow(10, 9) + 7; } Console.WriteLine(power); } } }
[["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
96
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); int mod = 1000000007; int answer = 1; for (int i = 1; i <= n; i++) { answer = (answer * i) % mod; } 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 mod = 1000000007; long answer = 1; for (long i = 1; i <= n; i++) { answer = (answer * i) % mod; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
8
386
using System; namespace ABC054B { static class Program { static void Main() { var n = long.Parse(Console.ReadLine()); long power = 1; long mod = 100000007; for (int i = 1; i < n + 1; i++) power = (power * i) % mod; Console.WriteLine(power); } } }
using System; namespace ABC054B { static class Program { static void Main() { var n = int.Parse(Console.ReadLine()); long power = 1; int mod = 1000000007; for (int i = 1; i <= n; i++) power = (power * i) % mod; Console.WriteLine(power); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
76
using System; namespace ABC054B { static class Program { static void Main() { var n = long.Parse(Console.ReadLine()); long power = 1; long mod = 100000007; for (int i = 1; i < n + 1; i++) power = (power * i) % mod; Console.WriteLine(power); } } }
using System; namespace ABC054B { static class Program { static void Main() { var n = int.Parse(Console.ReadLine()); long power = 1; long mod = 1000000007; for (int i = 1; i < n + 1; i++) power = (power * i) % mod; Console.WriteLine(power); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
76
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int N = int.Parse(Console.ReadLine()); int num = 1; for (int i = 1; i <= N; i++) { num = (num * i) % 1000000007; } Console.WriteLine(num); } }
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! int N = int.Parse(Console.ReadLine()); long num = 1; for (int i = 1; i <= N; i++) { num = (num * i) % 1000000007; } Console.WriteLine(num); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
74
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 a = int.Parse(Console.ReadLine()); long b = 1; for (int i = 1; i <= a; i++) { b = b * i; } b = b % (1000000000 + 7); Console.Write(b); } } }
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 a = int.Parse(Console.ReadLine()); long b = 1; for (int i = 1; i <= a; i++) { b = b * i; b = b % (1000000000 + 7); } Console.Write(b); } } }
[["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
104
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication20 { class Program { // b55 static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var result = Method(n); Console.WriteLine(result); } private static long Method(int n) { long p = 1; long result = 1; // 10の9乗+7 for (int i = 0; i < 9; i++) { // 9回回す p = p * 10;   p = p + 7; //毎回7を足す } for (int i = 1; i <= n; i++) { result = (result * i) % p; } return result; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication20 { class Program { // b55 static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var result = Method(n); Console.WriteLine(result); } private static long Method(int n) { long p = 1; long result = 1; for (int i = 0; i < 9; i++) { p = p * 10; // 10の9乗にする } p = p + 7; // 7を足す for (int i = 1; i <= n; i++) { result = result * i % p; } return result; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 8, 196], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 169], ["-", 8, 196, 0, 7, 8, 196, 0, 169, 0, 1], ["-", 0, 7, 8, 196, 0, 169, 0, 1, 0, 11], ["-", 8, 196, 0, 169, 0, 1, 0, 11, 31, 22], ["-", 0, 169, 0, 1, 0, 11, 31, 22, 0, 202], ["-", 0, 1, 0, 11, 31, 22, 0, 202, 12, 16], ["-", 0, 11, 31, 22, 0, 202, 12, 16, 0, 1], ["-", 31, 22, 0, 202, 12, 16, 0, 1, 0, 11], ["-", 0, 202, 12, 16, 0, 1, 0, 11, 31, 22], ["-", 12, 16, 0, 1, 0, 11, 31, 22, 0, 202], ["-", 0, 11, 31, 22, 0, 202, 12, 16, 0, 169], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
8
157
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class B055 { static void Main() { int mod = (int)Math.Pow(10, 9) + 7; int N = int.Parse(Console.ReadLine()); int ans = 1; for (int i = 1; i <= N; i++) ans = ans * i % mod; Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class B055 { static void Main() { int mod = (int)Math.Pow(10, 9) + 7; int N = int.Parse(Console.ReadLine()); long ans = 1; for (int i = 1; i <= N; i++) ans = (ans * i) % mod; Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 8, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
8
107
using System; namespace AtCoder { class Program { static void Main() { long answer = 1; int divNum = (int)Math.Pow(10.0, 9.0) + 7; int n = int.Parse(Console.ReadLine()); for (var i = 2; i <= n; i++) { answer *= i; } if (divNum < answer) { answer %= divNum; } Console.WriteLine(answer); } } }
using System; namespace AtCoder { class Program { static void Main() { long answer = 1; int divNum = (int)Math.Pow(10.0, 9.0) + 7; int n = int.Parse(Console.ReadLine()); for (var i = 2; i <= n; i++) { answer *= i; if (divNum < answer) { answer %= divNum; } } Console.WriteLine(answer); } } }
[["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
93
using System; namespace AtCoder { class Program { private static readonly int DIV = (int)Math.Pow(10, 9) + 7; static void Main(string[] args) { // 整数の入力 var traningCount = int.Parse(Console.ReadLine()); long power = 1; for (var i = 2; i < traningCount; ++i) { power *= i; if (power > DIV) { power %= DIV; } } Console.WriteLine(power); } } }
using System; namespace AtCoder { class Program { private static readonly int DIV = (int)Math.Pow(10, 9) + 7; static void Main(string[] args) { // 整数の入力 var traningCount = int.Parse(Console.ReadLine()); long power = 1; for (var i = 2; i <= traningCount; ++i) { power *= i; if (power > DIV) { power %= DIV; } } Console.WriteLine(power); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
101
using System; using System.Linq; class Program { static void Main(string[] args) { int N = Cin.Ni(); long answer = 1; for (int i = 0; i < N; i++) { answer *= i + 1; answer %= 100000007; } Console.WriteLine(answer); } } public class Cin { private static string[] s = new string[0]; private static int i = 0; private static char[] cs = new char[] { ' ' }; public static string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next(); } public static int Ni() { return int.Parse(Next()); } public static long NextLong() { return long.Parse(Next()); } public static double NextDouble() { return double.Parse(Next()); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int N = Cin.Ni(); long answer = 1; for (int i = 0; i < N; i++) { answer *= i + 1; answer %= 1000000007; } Console.WriteLine(answer); } } public class Cin { private static string[] s = new string[0]; private static int i = 0; private static char[] cs = new char[] { ' ' }; public static string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return Next(); } public static int Ni() { return int.Parse(Next()); } public static long NextLong() { return long.Parse(Next()); } public static double NextDouble() { return double.Parse(Next()); } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203]]
8
235
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Numerics; namespace ABC055.C { using static Util; public class Solver : SolverBase { public void Run() { long S, C; ReadLong2(out S, out C); long ans = 0; if (C <= S * 2) { ans = C / 2; } else { // 余ったCで、何個Sccを作れるか var rc = C - S * 2; // 4個のcで Sccを1個作れる ans += rc / 4; } WriteLine(ans); } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder /// をセットする。 /// </summary> public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key, int adder) { if (dic.ContainsKey(key)) { dic[key] += adder; } else { dic[key] = adder; } } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 /// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right // は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected string ReadString() => ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); // virtual protected void ReadInt2(out int x, out int y) { // var aryS = ReadLine().Split(' '); // x = int.Parse(aryS[0]); // y = int.Parse(aryS[1]); //} virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected int[] ReadIntArray() => ReadLine() .Split(' ') .Select<string, int>( s => int.Parse(s)) .ToArray(); virtual protected void ReadInt2(out int a, out int b) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadInt3(out int a, out int b, out int c) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadInt4(out int a, out int b, out int c, out int d) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected long[] ReadLongArray() => ReadLine() .Split(' ') .Select<string, long>( s => long.Parse(s)) .ToArray(); virtual protected void ReadLong2(out long a, out long b) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadLong3(out long a, out long b, out long c) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadLong4(out long a, out long b, out long c, out long d) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected double[] ReadDoubleArray() => ReadLine() .Split(' ') .Select<string, double>( s => double.Parse(s)) .ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Numerics; namespace ABC055.C { using static Util; public class Solver : SolverBase { public void Run() { long S, C; ReadLong2(out S, out C); long ans = 0; if (C <= S * 2) { ans = C / 2; } else { // 余ったCで、何個Sccを作れるか var rc = C - S * 2; // 4個のcで Sccを1個作れる ans += S + rc / 4; } WriteLine(ans); } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder /// をセットする。 /// </summary> public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key, int adder) { if (dic.ContainsKey(key)) { dic[key] += adder; } else { dic[key] = adder; } } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 /// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right // は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected string ReadString() => ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); // virtual protected void ReadInt2(out int x, out int y) { // var aryS = ReadLine().Split(' '); // x = int.Parse(aryS[0]); // y = int.Parse(aryS[1]); //} virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected int[] ReadIntArray() => ReadLine() .Split(' ') .Select<string, int>( s => int.Parse(s)) .ToArray(); virtual protected void ReadInt2(out int a, out int b) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadInt3(out int a, out int b, out int c) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadInt4(out int a, out int b, out int c, out int d) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected long[] ReadLongArray() => ReadLine() .Split(' ') .Select<string, long>( s => long.Parse(s)) .ToArray(); virtual protected void ReadLong2(out long a, out long b) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadLong3(out long a, out long b, out long c) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadLong4(out long a, out long b, out long c, out long d) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected double[] ReadDoubleArray() => ReadLine() .Split(' ') .Select<string, double>( s => double.Parse(s)) .ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
[["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72]]
8
2,048
using System; using System.Linq; class Program { public static void Main() { long[] input = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); if (input[1] <= input[0] * 2) { Console.WriteLine(input[0]); } else { Console.WriteLine(input[0] + (input[1] - input[0] * 2) / 4); } } }
using System; using System.Linq; class Program { public static void Main() { long[] input = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); if (input[1] <= input[0] * 2) { Console.WriteLine(input[1] / 2); } else { Console.WriteLine(input[0] + (input[1] - input[0] * 2) / 4); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
109
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp110 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = st[0]; long M = st[1]; long sum = N * 2 + M; if (N * 2 >= M) { Console.WriteLine(N); } else { Console.WriteLine(sum / 4); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp110 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = st[0]; long M = st[1]; long sum = N * 2 + M; if (N * 2 >= M) { Console.WriteLine(M / 2); } else { Console.WriteLine(sum / 4); } } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
124
using System; using System.IO; using System.Text; namespace Contest { class Program { private Scanner sc; private string S, T; public void Solve() { sc = new Scanner(); long N = sc.NextLong(); long M = sc.NextLong(); long cnt = 0; cnt += Math.Min(N, M * 2); N -= cnt; M -= cnt * 2; cnt += M / 4; Console.WriteLine(cnt); } static void Main() => new Program().Solve(); } } class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; _separator = ' '; } private readonly char _separator; private readonly StreamReader _stream; private int _pos; private string[] _line; #region get a element public string Next() { if (_pos >= _line.Length) { _line = _stream.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 convert array 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 get array public string[] Array() { if (_pos >= _line.Length) _line = _stream.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; using System.IO; using System.Text; namespace Contest { class Program { private Scanner sc; private string S, T; public void Solve() { sc = new Scanner(); long N = sc.NextLong(); long M = sc.NextLong(); long cnt = 0; cnt += Math.Min(N, M / 2); N -= cnt; M -= cnt * 2; cnt += M / 4; Console.WriteLine(cnt); } static void Main() => new Program().Solve(); } } class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; _separator = ' '; } private readonly char _separator; private readonly StreamReader _stream; private int _pos; private string[] _line; #region get a element public string Next() { if (_pos >= _line.Length) { _line = _stream.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 convert array 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 get array public string[] Array() { if (_pos >= _line.Length) _line = _stream.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 }
[["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
556
using System; using System.Collections.Generic; using static System.Console; using System.Linq; namespace ConsoleApp2 { class Program { static void Main(string[] Args) { long res = 0; var NM = new List<string>(ReadLine().Split(' ')).Select(long.Parse).ToList(); res += Math.Min(NM[0], NM[1] / 2); NM[1] -= NM[0] * 2; res += NM[1] / 4; WriteLine(res); ReadLine(); } } }
using System; using System.Collections.Generic; using static System.Console; using System.Linq; namespace ConsoleApp2 { class Program { static void Main(string[] Args) { long res = 0; var NM = new List<string>(ReadLine().Split(' ')).Select(long.Parse).ToList(); res += Math.Min(NM[0], NM[1] / 2); NM[1] -= res * 2; res += NM[1] / 4; WriteLine(res); ReadLine(); } } }
[["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22]]
8
126
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_C { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); long N = long.Parse(s[0]); long M = long.Parse(s[1]); long X; if (N > 2 * M) { X = M / 2; } else { X = N + (M - 2 * N) / 4; } Console.WriteLine(X.ToString()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_C { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); long N = long.Parse(s[0]); long M = long.Parse(s[1]); long X; if (N * 2 >= M) { X = M / 2; } else { X = N + (M - 2 * N) / 4; } Console.WriteLine(X.ToString()); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20]]
8
137
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] input = ReadLine().Split(' '); long a = long.Parse(input[0]); long b = long.Parse(input[1]); if (a * 2 > b) { WriteLine(a); } else { b -= a * 2; b /= 4; WriteLine(a + b); } } }
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] input = ReadLine().Split(' '); long a = long.Parse(input[0]); long b = long.Parse(input[1]); if (a * 2 > b) { WriteLine(b / 2); } else { b -= a * 2; b /= 4; WriteLine(a + b); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
105
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var N = a[0]; var M = a[1]; var s = Math.Min(N, M / 4); var c = (M - s * 2) / 4; Console.WriteLine(s + c); } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var N = a[0]; var M = a[1]; var s = Math.Min(N, M / 2); var c = (M - s * 2) / 4; Console.WriteLine(s + c); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
107
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(' '); long b = long.Parse(a[0]); long c = long.Parse(a[1]); long d; if (c - b * 2 > 0) { d = b + (long)((c - b * 2) / 4); } else { d = b - c / 2; } Console.Write(d); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(' '); long b = long.Parse(a[0]); long c = long.Parse(a[1]); long d; if (c - b * 2 > 0) { d = b + (long)((c - b * 2) / 4); } else { d = c / 2; } Console.Write(d); } } }
[["-", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 33]]
8
142
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var read = Console.ReadLine().Split(' ').Select(long.Parse); var sCount = read.ElementAt(0); var cCount = read.ElementAt(1); if (cCount <= sCount * 2) { Console.WriteLine(cCount / 2); } else { var sccCount = cCount - sCount * 2; Console.WriteLine(sccCount + cCount / 8); } } } }
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var read = Console.ReadLine().Split(' ').Select(long.Parse); var sCount = read.ElementAt(0); var cCount = read.ElementAt(1); if (cCount <= sCount * 2) { Console.WriteLine(cCount / 2); } else { cCount -= sCount * 2; Console.WriteLine(sCount + cCount / 4); } } } }
[["-", 75, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203]]
8
112
using System; namespace AtCoder { class Program { static void Main() { string input = Console.ReadLine(); long s_count = long.Parse(input.Split(' ')[0]); long c_count = long.Parse(input.Split(' ')[1]); long scc_count = Math.Min(s_count, c_count / 2); s_count -= scc_count; c_count -= scc_count; scc_count += c_count / 4; Console.WriteLine(scc_count); } } }
using System; namespace AtCoder { class Program { static void Main() { string input = Console.ReadLine(); long s_count = long.Parse(input.Split(' ')[0]); long c_count = long.Parse(input.Split(' ')[1]); long scc_count = Math.Min(s_count, c_count / 2); s_count -= scc_count; c_count -= scc_count * 2; scc_count += c_count / 4; Console.WriteLine(scc_count); } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
102
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("1 6"); // 2 } else if (InputPattern == "Input2") { WillReturn.Add("12345 678901"); // 175897 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); long[] wkArr = InputList[0].Split(' ').Select(X => long.Parse(X)).ToArray(); long CurrSCnt = wkArr[0]; long CurrCCnt = wkArr[1]; long Answer = 0; //戦略1 SとcのペアでSccを作れるだけ作る long CanCreateCnt1 = Math.Min(CurrSCnt, CurrCCnt * 2); CurrSCnt -= CanCreateCnt1; CurrCCnt -= CanCreateCnt1 * 2; //戦略2 残ったcでSccを作れるだけ作る long CanCreateCnt2 = CurrCCnt / 4; Console.WriteLine(CanCreateCnt1 + CanCreateCnt2); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("1 6"); // 2 } else if (InputPattern == "Input2") { WillReturn.Add("12345 678901"); // 175897 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); long[] wkArr = InputList[0].Split(' ').Select(X => long.Parse(X)).ToArray(); long CurrSCnt = wkArr[0]; long CurrCCnt = wkArr[1]; //手順1 SとcのペアでSccを作れるだけ作る long CanCreateCnt1 = Math.Min(CurrSCnt, CurrCCnt / 2); CurrSCnt -= CanCreateCnt1; CurrCCnt -= CanCreateCnt1 * 2; //手順2 残ったcでSccを作れるだけ作る long CanCreateCnt2 = CurrCCnt / 4; Console.WriteLine(CanCreateCnt1 + CanCreateCnt2); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85]]
8
232
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; class Class_ { void Test() { var NM = A_Long_(); var N = NM[0]; var M = NM[1]; if (N > M * 2) { Console.WriteLine(N); } else { var a = N; var b = (M - 2 * N) / 4; Console.WriteLine(a + b); } } static void Main(string[] args) { new Class_().Test(); } #region string S_String_() { return Console.ReadLine(); } // string[] A_String_() { return Console.ReadLine().Split(); } int[] A_Int_(int n) { var x = new int[n]; for (var i = 0; i < n; i++) { x[i] = int.Parse(Console.ReadLine()); } return x; } // int[] A_Int_() { var ss = Console.ReadLine().Split(); var x = new int[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = int.Parse(ss[i]); return x; } long[] A_Long_() { var ss = Console.ReadLine().Split(); var x = new long[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = long.Parse(ss[i]); return x; } #endregion }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; class Class_ { void Test() { var NM = A_Long_(); var N = NM[0]; var M = NM[1]; // Console.WriteLine( (N * 2 + M)/4); // return; if (N >= M / 2) { Console.WriteLine(M / 2); } else { var a = N; var b = (M - 2 * N) / 4; Console.WriteLine(a + b); } } static void Main(string[] args) { new Class_().Test(); } #region string S_String_() { return Console.ReadLine(); } // string[] A_String_() { return Console.ReadLine().Split(); } int[] A_Int_(int n) { var x = new int[n]; for (var i = 0; i < n; i++) { x[i] = int.Parse(Console.ReadLine()); } return x; } // int[] A_Int_() { var ss = Console.ReadLine().Split(); var x = new int[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = int.Parse(ss[i]); return x; } long[] A_Long_() { var ss = Console.ReadLine().Split(); var x = new long[ss.Length]; for (var i = 0; i < ss.Length; i++) x[i] = long.Parse(ss[i]); return x; } #endregion }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
356
using System; using System.Linq; public class Aprob { public static void Main() { string[] readSome = new string[2]; readSome = Console.ReadLine().Split(' '); long S = long.Parse(readSome[0]); long C = long.Parse(readSome[1]); long pairs = 0; if (C <= 2 * S) { pairs = S; } else { pairs = S; C -= 2 * S; S = 0; pairs += C / 4; } Console.WriteLine(pairs); } }
using System; using System.Linq; public class Aprob { public static void Main() { string[] readSome = new string[2]; readSome = Console.ReadLine().Split(' '); long S = long.Parse(readSome[0]); long C = long.Parse(readSome[1]); long pairs = 0; if (C <= 2 * S) { pairs = C / 2; } else { pairs = S; C -= 2 * S; S = 0; pairs += C / 4; } Console.WriteLine(pairs); } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
122
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var N = Sarray()[0]; var s = ReadLine(); var ans = new int[N + 2]; var sheep = 0; var wolf = 1; for (var ai = 0; ai < 2; ++ai) { for (var aj = 0; aj < 2; ++aj) { ans[0] = ai; ans[1] = aj; for (var i = 1; i < N; ++i) { if (ans[i] == sheep && s[i % (int)N] == 'o' || ans[i] == wolf && s[i % (int)N] == 'x') ans[i + 1] = ans[i - 1]; else ans[i + 1] = (ans[i - 1] + 1) % 2; } if (ans[N] == ans[0] && ans[N + 1] == ans[1]) { for (var i = 0; i < N; ++i) Write(ans[i] == 0 ? 'S' : 'W'); return; } } } WriteLine(-1); } static long Mod = (long)1e9 + 7; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var N = Sarray()[0]; var s = ReadLine(); var ans = new int[N + 2]; var sheep = 0; var wolf = 1; for (var ai = 0; ai < 2; ++ai) { for (var aj = 0; aj < 2; ++aj) { ans[0] = ai; ans[1] = aj; for (var i = 1; i <= N; ++i) { if (ans[i] == sheep && s[i % (int)N] == 'o' || ans[i] == wolf && s[i % (int)N] == 'x') ans[i + 1] = ans[i - 1]; else ans[i + 1] = (ans[i - 1] + 1) % 2; } if (ans[N] == ans[0] && ans[N + 1] == ans[1]) { for (var i = 0; i < N; ++i) Write(ans[i] == 0 ? 'S' : 'W'); return; } } } WriteLine(-1); } static long Mod = (long)1e9 + 7; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
621
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Numerics; namespace ABC055.D { using static Util; public class Solver : SolverBase { int N; string S; public void Run() { N = ReadInt(); S = ReadLine(); // Dump(new string(animals)); // 4通り試して、OKパターンが出たら終了 // 出なかったら -1 出力 var ani = new char[N]; if (S[0] == 'o') { // ○-> SSS ani[N - 1] = 'S'; ani[0] = 'S'; ani[1] = 'S'; if (Test(ani)) return; // WSW InitArray(ani, default(char)); ani[N - 1] = 'W'; ani[0] = 'S'; ani[1] = 'W'; if (Test(ani)) return; // ○-> SWW InitArray(ani, default(char)); ani[N - 1] = 'S'; ani[0] = 'W'; ani[1] = 'W'; if (Test(ani)) return; // WWS InitArray(ani, default(char)); ani[N - 1] = 'W'; ani[0] = 'W'; ani[1] = 'S'; if (Test(ani)) return; } else { // ×-> WSS ani[N - 1] = 'W'; ani[0] = 'S'; ani[1] = 'S'; if (Test(ani)) return; // SSW InitArray(ani, default(char)); ani[N - 1] = 'S'; ani[0] = 'S'; ani[1] = 'W'; if (Test(ani)) return; // ×-> SWS InitArray(ani, default(char)); ani[N - 1] = 'S'; ani[0] = 'W'; ani[1] = 'S'; if (Test(ani)) return; // WSW InitArray(ani, default(char)); ani[N - 1] = 'W'; ani[0] = 'S'; ani[1] = 'W'; if (Test(ani)) return; } // ここまで来た=解無し WriteLine("-1"); } bool Test(char[] ani) { if (Check(ani)) { WriteLine(new string(ani)); return true; } else { return false; } } bool Check(char[] ani) { for (int i = 1; i < N; i++) { if ((S[i] == 'o' && ani[i] == 'S') || (S[i] == 'x' && ani[i] == 'W')) { if (i < N - 2) { ani[i + 1] = ani[i - 1]; } else if (i < N - 1) { if (ani[i + 1] != ani[i - 1]) return false; } else { if (ani[0] != ani[i - 1]) return false; } } else { if (i < N - 2) { ani[i + 1] = ani[i - 1] == 'S' ? 'W' : 'S'; } else if (i < N - 1) { if (ani[i + 1] == ani[i - 1]) return false; } else { if (ani[0] == ani[i - 1]) return false; } } } return true; } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder /// をセットする。 /// </summary> public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key, int adder) { if (dic.ContainsKey(key)) { dic[key] += adder; } else { dic[key] = adder; } } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 /// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right // は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected string ReadString() => ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); // virtual protected void ReadInt2(out int x, out int y) { // var aryS = ReadLine().Split(' '); // x = int.Parse(aryS[0]); // y = int.Parse(aryS[1]); //} virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected int[] ReadIntArray() => ReadLine() .Split(' ') .Select<string, int>( s => int.Parse(s)) .ToArray(); virtual protected void ReadInt2(out int a, out int b) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadInt3(out int a, out int b, out int c) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadInt4(out int a, out int b, out int c, out int d) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected long[] ReadLongArray() => ReadLine() .Split(' ') .Select<string, long>( s => long.Parse(s)) .ToArray(); virtual protected void ReadLong2(out long a, out long b) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadLong3(out long a, out long b, out long c) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadLong4(out long a, out long b, out long c, out long d) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected double[] ReadDoubleArray() => ReadLine() .Split(' ') .Select<string, double>( s => double.Parse(s)) .ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(bool[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j] ? "x " : ". "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(char[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j]); sb.Append(" "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Numerics; namespace ABC055.D { using static Util; public class Solver : SolverBase { int N; string S; public void Run() { N = ReadInt(); S = ReadLine(); // Dump(new string(animals)); // 4通り試して、OKパターンが出たら終了 // 出なかったら -1 出力 var ani = new char[N]; if (S[0] == 'o') { // ○-> SSS ani[N - 1] = 'S'; ani[0] = 'S'; ani[1] = 'S'; if (Test(ani)) return; // WSW InitArray(ani, default(char)); ani[N - 1] = 'W'; ani[0] = 'S'; ani[1] = 'W'; if (Test(ani)) return; // ○-> SWW InitArray(ani, default(char)); ani[N - 1] = 'S'; ani[0] = 'W'; ani[1] = 'W'; if (Test(ani)) return; // WWS InitArray(ani, default(char)); ani[N - 1] = 'W'; ani[0] = 'W'; ani[1] = 'S'; if (Test(ani)) return; } else { // ×-> WSS ani[N - 1] = 'W'; ani[0] = 'S'; ani[1] = 'S'; if (Test(ani)) return; // SSW InitArray(ani, default(char)); ani[N - 1] = 'S'; ani[0] = 'S'; ani[1] = 'W'; if (Test(ani)) return; // ×-> SWS InitArray(ani, default(char)); ani[N - 1] = 'S'; ani[0] = 'W'; ani[1] = 'S'; if (Test(ani)) return; // WWW InitArray(ani, default(char)); ani[N - 1] = 'W'; ani[0] = 'W'; ani[1] = 'W'; if (Test(ani)) return; } // ここまで来た=解無し WriteLine("-1"); } bool Test(char[] ani) { if (Check(ani)) { WriteLine(new string(ani)); return true; } else { return false; } } bool Check(char[] ani) { for (int i = 1; i < N; i++) { if ((S[i] == 'o' && ani[i] == 'S') || (S[i] == 'x' && ani[i] == 'W')) { if (i < N - 2) { ani[i + 1] = ani[i - 1]; } else if (i < N - 1) { if (ani[i + 1] != ani[i - 1]) return false; } else { if (ani[0] != ani[i - 1]) return false; } } else { if (i < N - 2) { ani[i + 1] = ani[i - 1] == 'S' ? 'W' : 'S'; } else if (i < N - 1) { if (ani[i + 1] == ani[i - 1]) return false; } else { if (ani[0] == ani[i - 1]) return false; } } } return true; } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// dic[key]にadderを加算する。keyが存在しなかった場合はdic[key]=adder /// をセットする。 /// </summary> public static void AddTo<TKey>(this Dictionary<TKey, int> dic, TKey key, int adder) { if (dic.ContainsKey(key)) { dic[key] += adder; } else { dic[key] = adder; } } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 /// ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right // は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected string ReadString() => ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); // virtual protected void ReadInt2(out int x, out int y) { // var aryS = ReadLine().Split(' '); // x = int.Parse(aryS[0]); // y = int.Parse(aryS[1]); //} virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected int[] ReadIntArray() => ReadLine() .Split(' ') .Select<string, int>( s => int.Parse(s)) .ToArray(); virtual protected void ReadInt2(out int a, out int b) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadInt3(out int a, out int b, out int c) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadInt4(out int a, out int b, out int c, out int d) { var ary = ReadIntArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected long[] ReadLongArray() => ReadLine() .Split(' ') .Select<string, long>( s => long.Parse(s)) .ToArray(); virtual protected void ReadLong2(out long a, out long b) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; } virtual protected void ReadLong3(out long a, out long b, out long c) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; } virtual protected void ReadLong4(out long a, out long b, out long c, out long d) { var ary = ReadLongArray(); a = ary[0]; b = ary[1]; c = ary[2]; d = ary[3]; } virtual protected double[] ReadDoubleArray() => ReadLine() .Split(' ') .Select<string, double>( s => double.Parse(s)) .ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); virtual protected void WriteGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid(IEnumerable<IEnumerable<char>> arrayOfArray) { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { foreach (var c in a) { sb.Append(c); } sb.AppendLine(); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(bool[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j] ? "x " : ". "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpGrid(char[,] grid) { var sb = new StringBuilder(); for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { sb.Append(grid[i, j]); sb.Append(" "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
[["-", 75, 196, 0, 1, 0, 11, 12, 252, 0, 253], ["+", 75, 196, 0, 1, 0, 11, 12, 252, 0, 253]]
8
2,902
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_D { class D055 { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); char[] c = Console.ReadLine().ToCharArray(); char[,] r = new char[N + 2, 4]; r[0, 0] = 'S'; r[0, 1] = 'S'; r[0, 2] = 'W'; r[0, 3] = 'W'; r[1, 0] = 'S'; r[1, 1] = 'W'; r[1, 2] = 'S'; r[1, 3] = 'W'; for (int j = 0; j < 4; j++) { for (int i = 1; i <= N; i++) { if ((r[i, j] == 'S' && c[i] == 'o') || (r[i, j] == 'W' && c[i] == 'x')) { r[i + 1, j] = r[i - 1, j]; } else { r[i + 1, j] = r[i - 1, j] == 'S' ? 'W' : 'S'; } } if (r[0, j] == r[N, j] && r[1, j] == r[N + 1, j]) { char[] z = new char[N]; for (int i = 0; i < N; i++) { z[i] = r[i, j]; } string text = new string(z); Console.WriteLine(text); return; } } Console.WriteLine(-1); return; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_D { class D055 { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); char[] c = Console.ReadLine().ToCharArray(); char[,] r = new char[N + 2, 4]; r[0, 0] = 'S'; r[0, 1] = 'S'; r[0, 2] = 'W'; r[0, 3] = 'W'; r[1, 0] = 'S'; r[1, 1] = 'W'; r[1, 2] = 'S'; r[1, 3] = 'W'; for (int j = 0; j < 4; j++) { for (int i = 1; i <= N; i++) { if ((r[i, j] == 'S' && c[i % N] == 'o') || (r[i, j] == 'W' && c[i % N] == 'x')) { r[i + 1, j] = r[i - 1, j]; } else { r[i + 1, j] = r[i - 1, j] == 'S' ? 'W' : 'S'; } } if (r[0, j] == r[N, j] && r[1, j] == r[N + 1, j]) { char[] z = new char[N]; for (int i = 0; i < N; i++) { z[i] = r[i, j]; } string text = new string(z); Console.WriteLine(text); return; } } Console.WriteLine(-1); return; } } }
[["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 109], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
8
411
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ARC069C { class Program { static void Solve(Input input) { var n = input.NextLong(); var m = input.NextLong(); long count = 0; if (n >= m * 2) { // Sの方が多いので、Sの数だけしか作れない count += n; } else { // 先にSを消費しきる count += n; m -= n * 2; // cだけでSccを作るには、cが4の倍数必要 count += m / 4; } Console.WriteLine(count); } #region Competitive Template public static void Main(string[] args) { var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する static readonly char[] separator = { ' ', '\r', '\n' }; public bool IsEof { get; set; } Queue<string> q { get; set; } StreamReader sr; public Input(string path = "") { IsEof = false; q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public string[] Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToArray(); public int[] NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToArray(); public long[] NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToArray(); public double[] NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToArray(); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ARC069C { class Program { static void Solve(Input input) { var n = input.NextLong(); var m = input.NextLong(); long count = 0; if (n >= m / 2) { // Sの方が多いので、cに制約される数だけしか作れない count += m / 2; } else { // 先にSを消費しきる count += n; m -= n * 2; // cだけでSccを作るには、cが4の倍数必要 count += m / 4; } Console.WriteLine(count); } #region Competitive Template public static void Main(string[] args) { var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する static readonly char[] separator = { ' ', '\r', '\n' }; public bool IsEof { get; set; } Queue<string> q { get; set; } StreamReader sr; public Input(string path = "") { IsEof = false; q = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> bool read() { var s = sr.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public string[] Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToArray(); public int[] NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToArray(); public long[] NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToArray(); public double[] NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToArray(); } static class Utils { public static void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } } #endregion } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 48], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
868
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var N = Int1; var s = Str; // animal[k]==0 sheep // animal[k]==1 wolf for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { var animal = Enumerable.Repeat(-1, N).ToArray(); animal[0] = i; animal[1] = j; for (int k = 2; k < N; ++k) { if (animal[k - 1] == 0) { if (s[k - 1] == 'o') { animal[k] = animal[k - 2]; } else { animal[k] = animal[k - 2] == 1 ? 0 : 1; } } else { if (s[k - 1] == 'x') { animal[k] = animal[k - 2]; } else { animal[k] = animal[k - 2] == 1 ? 0 : 1; } } } Put(animal); var flg = false; var flg2 = false; if (animal[N - 1] == 0 && s[N - 1] == 'o' && animal[N - 2] == animal[0]) flg = true; if (animal[N - 1] == 0 && s[N - 1] == 'x' && animal[N - 2] != animal[0]) flg = true; if (animal[N - 1] == 1 && s[N - 1] == 'o' && animal[N - 2] != animal[0]) flg = true; if (animal[N - 1] == 1 && s[N - 1] == 'x' && animal[N - 2] == animal[0]) flg = true; if (animal[0] == 0 && s[0] == 'o' && animal[N - 1] == animal[1]) flg2 = true; if (animal[0] == 0 && s[0] == 'x' && animal[N - 1] != animal[1]) flg2 = true; if (animal[0] == 1 && s[0] == 'o' && animal[N - 1] != animal[1]) flg2 = true; if (animal[0] == 1 && s[0] == 'x' && animal[N - 1] == animal[1]) flg2 = true; if (flg && flg2) { var ans = new StringBuilder(); for (int k = 0; k < N; ++k) { if (animal[k] == 0) ans.Append('S'); else ans.Append('W'); } Put(ans); return; } } } Put("-1"); } } 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 a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } 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; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } } 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 Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void VerticalPut<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var N = Int1; var s = Str; // animal[k]==0 sheep // animal[k]==1 wolf for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { var animal = Enumerable.Repeat(-1, N).ToArray(); animal[0] = i; animal[1] = j; for (int k = 2; k < N; ++k) { if (animal[k - 1] == 0) { if (s[k - 1] == 'o') { animal[k] = animal[k - 2]; } else { animal[k] = animal[k - 2] == 1 ? 0 : 1; } } else { if (s[k - 1] == 'x') { animal[k] = animal[k - 2]; } else { animal[k] = animal[k - 2] == 1 ? 0 : 1; } } } var flg = false; var flg2 = false; if (animal[N - 1] == 0 && s[N - 1] == 'o' && animal[N - 2] == animal[0]) flg = true; if (animal[N - 1] == 0 && s[N - 1] == 'x' && animal[N - 2] != animal[0]) flg = true; if (animal[N - 1] == 1 && s[N - 1] == 'o' && animal[N - 2] != animal[0]) flg = true; if (animal[N - 1] == 1 && s[N - 1] == 'x' && animal[N - 2] == animal[0]) flg = true; if (animal[0] == 0 && s[0] == 'o' && animal[N - 1] == animal[1]) flg2 = true; if (animal[0] == 0 && s[0] == 'x' && animal[N - 1] != animal[1]) flg2 = true; if (animal[0] == 1 && s[0] == 'o' && animal[N - 1] != animal[1]) flg2 = true; if (animal[0] == 1 && s[0] == 'x' && animal[N - 1] == animal[1]) flg2 = true; if (flg && flg2) { var ans = new StringBuilder(); for (int k = 0; k < N; ++k) { if (animal[k] == 0) ans.Append('S'); else ans.Append('W'); } Put(ans); return; } } } Put("-1"); } } 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 a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { if (r > n - r) r = n - r; long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno = (Deno * i) % MOD; Nume = Nume * (n - i + 1) % MOD; } return (Nume * inv(Deno)) % MOD; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } public static long inv(long x, int MOD = 1000000007) { return Power(x, MOD - 2, MOD); } } 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; } public static string ConvertBase(long N, int K) { StringBuilder ret = new StringBuilder(); while (N > 0) { var r = N % K; N /= K; ret.Append(r); } return new string(ret.ToString().ToCharArray().Reverse().ToArray()); } } 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 Put(string a) => Console.WriteLine(a); public static void Put(params object[] i) => Put(string.Join(" ", i)); public static void Put<T>(IEnumerable<T> a) => Put(string.Join(" ", a)); public static void VerticalPut<T>(IEnumerable<T> a) { foreach (var z in a) Put(z); } public static void YN(bool i) { if (i) Put("Yes"); else Put("No"); } }
[["-", 0, 7, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
1,610
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { private const int MODULO = 1000000007; private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static int Mod(int a, int b) { return (a % b + b) % b; } static int[] Convert(string s) { return s.Select(c => (c == 'S') ? 1 : -1).ToArray(); } static int[] Solve(int N, int[] S) { foreach (int[] t in new[] { new[] { -1, -1 }, new[] { -1, 1 }, new[] { 1, -1 }, new[] { 1, 1 } }) { int[] ans = new int[N]; Array.Copy(t, ans, 2); for (int i = 2; i < N; ++i) { int a0 = Mod(i - 2, N); int a1 = Mod(i - 1, N); int a2 = Mod(i - 0, N); ans[a2] = ans[a0] * ans[a1] * S[a1]; } if (new[] { 0, 1 }.All(i => { int a0 = Mod(i - 1, N); int a1 = Mod(i, N); int a2 = Mod(i + 1, N); return (ans[a0] * ans[a2] == ans[a1] * S[a1]); })) { return ans; } } return null; } static void Main(string[] args) { int N = ReadInt(); string s = Read(); int[] ans = Solve(N, s.Select(c => (c == 'o') ? 1 : -1).ToArray()); Console.WriteLine((ans != null) ? new string(Array.ConvertAll( ans, n => (n == 1) ? 'S' : 'W')) : "-1"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { private const int MODULO = 1000000007; private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static int Mod(int a, int b) { return (a % b + b) % b; } static int[] Convert(string s) { return s.Select(c => (c == 'S') ? 1 : -1).ToArray(); } static int[] Solve(int N, int[] S) { foreach (int[] t in new[] { new[] { -1, -1 }, new[] { -1, 1 }, new[] { 1, -1 }, new[] { 1, 1 } }) { int[] ans = new int[N]; Array.Copy(t, ans, 2); for (int i = 2; i < N; ++i) { int a0 = Mod(i - 2, N); int a1 = Mod(i - 1, N); int a2 = Mod(i - 0, N); ans[a2] = ans[a0] * ans[a1] * S[a1]; } if (Enumerable.Range(0, N).All(i => { int a0 = Mod(i - 1, N); int a1 = Mod(i, N); int a2 = Mod(i + 1, N); return (ans[a0] * ans[a2] == ans[a1] * S[a1]); })) { return ans; } } return null; } static void Main(string[] args) { int N = ReadInt(); string s = Read(); int[] ans = Solve(N, s.Select(c => (c == 'o') ? 1 : -1).ToArray()); Console.WriteLine((ans != null) ? new string(Array.ConvertAll( ans, n => (n == 1) ? 'S' : 'W')) : "-1"); } } }
[["-", 0, 57, 15, 213, 63, 214, 205, 297, 0, 228], ["-", 0, 57, 15, 213, 63, 214, 205, 297, 0, 70], ["-", 0, 57, 15, 213, 63, 214, 205, 297, 0, 73], ["-", 15, 213, 63, 214, 205, 297, 0, 229, 0, 45], ["+", 15, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 15, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 15, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 15, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 15, 213, 63, 214, 205, 297, 0, 229, 0, 203], ["-", 15, 213, 63, 214, 205, 297, 0, 229, 0, 46], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 213, 63, 214, 205, 213, 3, 4, 0, 25]]
8
596
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderRegularContest069 { public class Program { static void Main(string[] args) { Console.WriteLine( program1(new String[] { Console.ReadLine(), Console.ReadLine() })); } public static string program1(string[] args) { var n = int.Parse(args[0]); var s = args[1].ToCharArray(); var animalPattern = new List<char>[] { new List<char>() { 'S', 'S' }, new List<char> { 'S', 'W' }, new List<char> { 'W', 'W' }, new List<char> { 'W', 'S' } }; return string.Join( "", animalPattern .Select(animals => { var prevAnimal = animals.First(); foreach (var ans in s.Skip(1)) { var last = animals.Last(); if (last == 'S' && ans == 'x' || last == 'W' && ans == 'o') { animals.Add(prevAnimal == 'S' ? 'W' : 'S'); } else { animals.Add(prevAnimal); } prevAnimal = last; } return animals.Take(n); }) .FirstOrDefault(animals => { if (animals.First() == animals.Last()) { if (s.First() == 'o' && animals.First() == 'S' || s.First() == 'x' && animals.First() == 'W') { return animals.ElementAt(1) == animals.ElementAt(n - 1); } else { return animals.ElementAt(1) != animals.ElementAt(n - 1); } } else return false; })?.Take(n) ?? new List<char>() { '-', '1' }); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderRegularContest069 { public class Program { static void Main(string[] args) { Console.WriteLine( program1(new String[] { Console.ReadLine(), Console.ReadLine() })); } public static string program1(string[] args) { var n = int.Parse(args[0]); var s = args[1].ToCharArray(); var animalPattern = new List<char>[] { new List<char>() { 'S', 'S' }, new List<char> { 'S', 'W' }, new List<char> { 'W', 'W' }, new List<char> { 'W', 'S' } }; return string.Join( "", animalPattern .Select(animals => { var prevAnimal = animals.First(); foreach (var ans in s.Skip(1)) { var last = animals.Last(); if (last == 'S' && ans == 'x' || last == 'W' && ans == 'o') { animals.Add(prevAnimal == 'S' ? 'W' : 'S'); } else { animals.Add(prevAnimal); } prevAnimal = last; } return animals; }) .FirstOrDefault(animals => { if (animals.First() == animals.Last()) { if (s.First() == 'o' && animals.First() == 'S' || s.First() == 'x' && animals.First() == 'W') { return animals.ElementAt(1) == animals.ElementAt(n - 1); } else { return animals.ElementAt(1) != animals.ElementAt(n - 1); } } else return false; })?.Take(n) ?? new List<char>() { '-', '1' }); } } }
[["-", 8, 196, 0, 37, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 37, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 37, 0, 213, 3, 4, 0, 24], ["-", 0, 37, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 37, 0, 213, 3, 4, 0, 25]]
8
436
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest._700problems { class ARC069_E { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int n = ReadInt(); long[] array = ReadLongs(); PriorityQueue<long> queue = new PriorityQueue<long>(); long[] res = new long[n]; SegTree<long> segTree = new SegTree<long>(n, 0, Max, 0); for (int i = 0; i < n; i++) { segTree.Update(i, array[i]); } for (int i = n - 1; i > 0; i--) { queue.Enqueue(-array[i], 1); long leftMax = segTree.Scan(0, i); if (array[i] > leftMax) { long cnt = 0; long sum = 0; while (queue.Count > 0 && -queue.Top().Key > array[i - 1]) { var pair = queue.Dequeue(); cnt += pair.Value; sum += (-pair.Key - leftMax) * pair.Value; } res[i] = sum; queue.Enqueue(-leftMax, cnt); } } queue.Enqueue(-array[0], 1); long last = 0; while (queue.Count > 0) { var pair = queue.Dequeue(); last += -pair.Key * pair.Value; } res[0] = last; for (int i = 0; i < n; i++) WriteLine(res[i]); } class SegTree<T> { int totalLength; T[] tree; Func<T, T, T> integrate; T exValue; public SegTree(int length, Func<T, T, T> integrate, T exValue) { this.integrate = integrate; this.exValue = exValue; totalLength = 1; while (totalLength < length) totalLength *= 2; tree = new T[2 * totalLength - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = exValue; } public SegTree(int length, T initialValue, Func<T, T, T> integrate, T exValue) : this(length, integrate, exValue) { for (int i = 0; i < length; i++) { tree[i + totalLength - 1] = initialValue; } UpdateAll(); } public void AssignWithoutUpdate(int i, T value) { tree[i + totalLength - 1] = value; } public void Update(int i, T value) { int now = i + totalLength - 1; tree[now] = value; while (now > 0) { now = (now - 1) / 2; tree[now] = integrate(tree[now * 2 + 1], tree[now * 2 + 2]); } } public void UpdateAll() { for (int i = totalLength - 2; i >= 0; i--) { tree[i] = integrate(tree[i * 2 + 1], tree[i * 2 + 2]); } } public T Look(int i) { return tree[i + totalLength - 1]; } //[top,last) public T Scan(int top, int last) { return Query(top, last, 0, 0, totalLength); } T Query(int top, int last, int i, int left, int right) { if (right <= top || last <= left) return exValue; if (top <= left && right <= last) return tree[i]; T leftValue = Query(top, last, i * 2 + 1, left, (left + right) / 2); T rightValue = Query(top, last, (i + 1) * 2, (left + right) / 2, right); return integrate(leftValue, rightValue); } } class PriorityQueue<T> { private readonly List<KeyValuePair<long, T>> list; public int Count { get; private set; } public PriorityQueue() { list = new List<KeyValuePair<long, T>>(); Count = 0; } private void Add(KeyValuePair<long, T> pair) { if (Count == list.Count) { list.Add(pair); } else { list[Count] = pair; } Count++; } private void Swap(int a, int b) { KeyValuePair<long, T> tmp = list[a]; list[a] = list[b]; list[b] = tmp; } public void Enqueue(long key, T value) { Add(new KeyValuePair<long, T>(key, value)); int c = Count - 1; while (c > 0) { int p = (c - 1) / 2; if (list[c].Key >= list[p].Key) break; Swap(p, c); c = p; } } public KeyValuePair<long, T> Top() { return list[0]; } public KeyValuePair<long, T> Dequeue() { KeyValuePair<long, T> pair = list[0]; Count--; if (Count == 0) return pair; list[0] = list[Count]; int p = 0; while (true) { int c1 = p * 2 + 1; int c2 = p * 2 + 2; if (c1 >= Count) break; int c = (c2 >= Count || list[c1].Key < list[c2].Key) ? c1 : c2; if (list[c].Key >= list[p].Key) break; Swap(p, c); p = c; } return pair; } } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest._700problems { class ARC069_E { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { int n = ReadInt(); long[] array = ReadLongs(); PriorityQueue<long> queue = new PriorityQueue<long>(); long[] res = new long[n]; SegTree<long> segTree = new SegTree<long>(n, 0, Max, 0); for (int i = 0; i < n; i++) { segTree.Update(i, array[i]); } for (int i = n - 1; i > 0; i--) { queue.Enqueue(-array[i], 1); long leftMax = segTree.Scan(0, i); if (array[i] > leftMax) { long cnt = 0; long sum = 0; while (queue.Count > 0 && -queue.Top().Key > leftMax) { var pair = queue.Dequeue(); cnt += pair.Value; sum += (-pair.Key - leftMax) * pair.Value; } res[i] = sum; queue.Enqueue(-leftMax, cnt); } } queue.Enqueue(-array[0], 1); long last = 0; while (queue.Count > 0) { var pair = queue.Dequeue(); last += -pair.Key * pair.Value; } res[0] = last; for (int i = 0; i < n; i++) WriteLine(res[i]); } class SegTree<T> { int totalLength; T[] tree; Func<T, T, T> integrate; T exValue; public SegTree(int length, Func<T, T, T> integrate, T exValue) { this.integrate = integrate; this.exValue = exValue; totalLength = 1; while (totalLength < length) totalLength *= 2; tree = new T[2 * totalLength - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = exValue; } public SegTree(int length, T initialValue, Func<T, T, T> integrate, T exValue) : this(length, integrate, exValue) { for (int i = 0; i < length; i++) { tree[i + totalLength - 1] = initialValue; } UpdateAll(); } public void AssignWithoutUpdate(int i, T value) { tree[i + totalLength - 1] = value; } public void Update(int i, T value) { int now = i + totalLength - 1; tree[now] = value; while (now > 0) { now = (now - 1) / 2; tree[now] = integrate(tree[now * 2 + 1], tree[now * 2 + 2]); } } public void UpdateAll() { for (int i = totalLength - 2; i >= 0; i--) { tree[i] = integrate(tree[i * 2 + 1], tree[i * 2 + 2]); } } public T Look(int i) { return tree[i + totalLength - 1]; } //[top,last) public T Scan(int top, int last) { return Query(top, last, 0, 0, totalLength); } T Query(int top, int last, int i, int left, int right) { if (right <= top || last <= left) return exValue; if (top <= left && right <= last) return tree[i]; T leftValue = Query(top, last, i * 2 + 1, left, (left + right) / 2); T rightValue = Query(top, last, (i + 1) * 2, (left + right) / 2, right); return integrate(leftValue, rightValue); } } class PriorityQueue<T> { private readonly List<KeyValuePair<long, T>> list; public int Count { get; private set; } public PriorityQueue() { list = new List<KeyValuePair<long, T>>(); Count = 0; } private void Add(KeyValuePair<long, T> pair) { if (Count == list.Count) { list.Add(pair); } else { list[Count] = pair; } Count++; } private void Swap(int a, int b) { KeyValuePair<long, T> tmp = list[a]; list[a] = list[b]; list[b] = tmp; } public void Enqueue(long key, T value) { Add(new KeyValuePair<long, T>(key, value)); int c = Count - 1; while (c > 0) { int p = (c - 1) / 2; if (list[c].Key >= list[p].Key) break; Swap(p, c); c = p; } } public KeyValuePair<long, T> Top() { return list[0]; } public KeyValuePair<long, T> Dequeue() { KeyValuePair<long, T> pair = list[0]; Count--; if (Count == 0) return pair; list[0] = list[Count]; int p = 0; while (true) { int c1 = p * 2 + 1; int c2 = p * 2 + 2; if (c1 >= Count) break; int c = (c2 >= Count || list[c1].Key < list[c2].Key) ? c1 : c2; if (list[c].Key >= list[p].Key) break; Swap(p, c); p = c; } return pair; } } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 52, 15, 16, 12, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 52, 15, 16, 12, 16, 12, 22]]
8
1,448
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int a = sc.NextInt(); int b = sc.NextInt(); string answer = ""; if (a == 1 && b == 1) { answer = "Draw"; } else if (a == 1) { answer = "Alice"; } else if (b == 1) { answer = "Bob"; } else { answer = a > b ? "Alice" : "Bob"; } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int a = sc.NextInt(); int b = sc.NextInt(); string answer = ""; if (a == b) { answer = "Draw"; } else if (a == 1) { answer = "Alice"; } else if (b == 1) { answer = "Bob"; } else { answer = a > b ? "Alice" : "Bob"; } 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(); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
430
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC054A___One_Card_Poker { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string[] card = input.Split(' '); Console.WriteLine(Judgment(int.Parse(card[0]), int.Parse(card[1]))); } public static string Judgment(int cardA, int cardB) { string result = ""; if (cardA == 11) { cardA = 14; } if (cardB == 1) { cardB = 14; } switch (cardA.CompareTo(cardB)) { case -1: result = "Bob"; break; case 0: result = "Draw"; break; case 1: result = "Alice"; break; } return result; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC054A___One_Card_Poker { class Program { static void Main(string[] args) { string input = Console.ReadLine(); string[] card = input.Split(' '); Console.WriteLine(Judgment(int.Parse(card[0]), int.Parse(card[1]))); } public static string Judgment(int cardA, int cardB) { string result = ""; if (cardA == 1) { cardA = 14; } if (cardB == 1) { cardB = 14; } switch (cardA.CompareTo(cardB)) { case -1: result = "Bob"; break; case 0: result = "Draw"; break; case 1: result = "Alice"; break; } return result; } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
188
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Atcoderrrrrrr { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); if (a == 1) { a += 13; } else if (b == 1) { b += 13; } string ans = ""; if (a > b) { ans = "Alice"; } else if (a < b) { ans = "Bob"; } else { ans = "Draw"; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Atcoderrrrrrr { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); if (a == 1) { a += 13; } if (b == 1) { b += 13; } string ans = ""; if (a > b) { ans = "Alice"; } else if (a < b) { ans = "Bob"; } else { ans = "Draw"; } Console.WriteLine(ans); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
166
using System; using System.Collections; using System.Collections.Generic; using System.Linq; public class Test { public static void Main() { int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); if (nums[0] == 1) nums[0] = 14; if (nums[1] == 1) nums[1] = 14; if (nums[0] > nums[1]) { Console.WriteLine("Bob"); } else if (nums[1] > nums[0]) { Console.WriteLine("Alice"); } else { Console.WriteLine("Draw"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; public class Test { public static void Main() { int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); if (nums[0] == 1) nums[0] = 14; if (nums[1] == 1) nums[1] = 14; if (nums[0] > nums[1]) { Console.WriteLine("Alice"); } else if (nums[1] > nums[0]) { Console.WriteLine("Bob"); } else { Console.WriteLine("Draw"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
158
using System; using System.Linq; namespace abc054_a { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (x[0] == 1) x[0] = 114514; if (x[1] == 1) x[1] = 114514; if (x[0] == x[1]) Console.WriteLine("Draw"); else Console.WriteLine(x[0] < x[1] ? "Alice" : "Bob"); } } }
using System; using System.Linq; namespace abc054_a { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (x[0] == 1) x[0] = 114514; if (x[1] == 1) x[1] = 114514; if (x[0] == x[1]) Console.WriteLine("Draw"); else Console.WriteLine(x[0] > x[1] ? "Alice" : "Bob"); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 47]]
8
130
using System; namespace Sample1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int alice = int.Parse(input.Split(' ')[0]); int bob = int.Parse(input.Split(' ')[1]); if (bob == alice) { Console.WriteLine("Draw"); } else if (bob == 1 & alice != 1) { Console.WriteLine("Bob"); } else if (alice == 1 & bob != 1) { Console.WriteLine("alice"); } else if (bob > alice & alice != 1) { Console.WriteLine("Bob"); } else if (alice > bob & bob != 1) { Console.WriteLine("alice"); } } } }
using System; namespace Sample1 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int alice = int.Parse(input.Split(' ')[0]); int bob = int.Parse(input.Split(' ')[1]); if (bob == alice) { Console.WriteLine("Draw"); } else if (bob == 1 & alice != 1) { Console.WriteLine("Bob"); } else if (alice == 1 & bob != 1) { Console.WriteLine("Alice"); } else if (bob > alice & alice != 1) { Console.WriteLine("Bob"); } else if (alice > bob & bob != 1) { Console.WriteLine("Alice"); } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
176
// Rextester.Program.Main is the entry point for your code. Don't change it. // Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { // Your code goes here var array = Console.ReadLine().Split(' '); var a = int.Parse(array[0]); var b = int.Parse(array[1]); if (a == 1) { a = 13; } if (b == 1) { b = 13; } if (a > b) Console.WriteLine("Alice"); else if (a < b) Console.WriteLine("Bob"); else { Console.WriteLine("Draw"); } } } }
// Rextester.Program.Main is the entry point for your code. Don't change it. // Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { // Your code goes here var array = Console.ReadLine().Split(' '); var a = int.Parse(array[0]); var b = int.Parse(array[1]); if (a == 1) { a = 14; } if (b == 1) { b = 14; } if (a > b) Console.WriteLine("Alice"); else if (a < b) Console.WriteLine("Bob"); else { Console.WriteLine("Draw"); } } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
155
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var ans = "DRAW"; var ab = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (ab[0] == 1) { if (ab[1] == 1) { //なにもしない } else { ans = "Alice"; } } else if (ab[1] != 1) { if (ab[0] == ab[1]) { //なにもしない } else if (ab[0] > ab[1]) { ans = "Alice"; } else { ans = "Bob"; } } else { ans = "Bob"; } Console.WriteLine(ans); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var ans = "Draw"; var ab = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (ab[0] == 1) { if (ab[1] == 1) { //なにもしない } else { ans = "Alice"; } } else if (ab[1] != 1) { if (ab[0] == ab[1]) { //なにもしない } else if (ab[0] > ab[1]) { ans = "Alice"; } else { ans = "Bob"; } } else { ans = "Bob"; } Console.WriteLine(ans); Console.ReadLine(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
8
181
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int b = int.Parse(input[0]); int c = int.Parse(input[1]); if (b == 1) b = 14; if (c == 1) c = 14; string result = "Draw"; if (b > c) result = "Alice"; if (c < b) result = "Bob"; Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int b = int.Parse(input[0]); int c = int.Parse(input[1]); if (b == 1) b = 14; if (c == 1) c = 14; string result = "Draw"; if (b > c) result = "Alice"; if (b < c) result = "Bob"; Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22]]
8
148
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Main { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int a, b; a = int.Parse(str[0]); b = int.Parse(str[1]); if (a == 1) a = 14; if (b == 1) b = 14; if (a < b) Console.WriteLine("Alice"); else if (a == b) Console.WriteLine("Draw"); else Console.WriteLine("Bob"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Main { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int a, b; a = int.Parse(str[0]); b = int.Parse(str[1]); if (a == 1) a = 14; if (b == 1) b = 14; if (a < b) Console.WriteLine("Bob"); else if (a == b) Console.WriteLine("Draw"); else Console.WriteLine("Alice"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
154
using System; using System.Text; using System.Collections.Generic; using System.Collections; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { class Program { static long N; static long M; static string[] A; static string[] B; static void Main(string[] args) { // N = long.Parse(Console.ReadLine()); var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); N = NM[0]; M = NM[1]; A = new string[N]; B = new string[M]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } var ans = false; for (int i = 0; !ans && i < N - M; i++) { for (int j = 0; !ans && j < N - M; j++) { ans = Match(i, j); } } Console.WriteLine(ans ? "Yes" : "No"); } static bool Match(int i, int j) { var orii = i; var orij = j; // for (;i < orii+M; i++) //{ // for (j = orij; j < orij + M; j++) // { // if(A[i][j] != B[i - orii][j - orij]) // { // return false; // } // } //} for (int k = 0; k < M; k++) { for (int l = 0; l < M; l++) { if (A[orii + k][orij + l] != B[k][l]) { return false; } } } return true; } } }
using System; using System.Text; using System.Collections.Generic; using System.Collections; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { class Program { static long N; static long M; static string[] A; static string[] B; static void Main(string[] args) { // N = long.Parse(Console.ReadLine()); var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); N = NM[0]; M = NM[1]; A = new string[N]; B = new string[M]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } var ans = false; for (int i = 0; !ans && i < N - M + 1; i++) { for (int j = 0; !ans && j < N - M + 1; j++) { ans = Match(i, j); } } Console.WriteLine(ans ? "Yes" : "No"); // Console.WriteLine("Yes"); } static bool Match(int i, int j) { var orii = i; var orij = j; // for (;i < orii+M; i++) //{ // for (j = orij; j < orij + M; j++) // { // if(A[i][j] != B[i - orii][j - orij]) // { // return false; // } // } //} for (int k = 0; k < M; k++) { for (int l = 0; l < M; l++) { if (A[orii + k][orij + l] != B[k][l]) { return false; } } } return true; } } }
[["+", 0, 7, 15, 16, 12, 16, 12, 16, 17, 72], ["+", 0, 7, 15, 16, 12, 16, 12, 16, 12, 203]]
8
358
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp69 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = st[0]; int M = st[1]; string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } bool flg = true; for (int i = 0; i <= N - M; i++) { for (int j = 0; j <= N - M; j++) { flg = true; //チェック工程 for (int k = 0; k < M; k++) { for (int l = 0; l < M; l++) { if (A[i][j] != B[k][l]) { //チェック工程を抜ける k = M; l = M; flg = false; } } } if (flg) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp69 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = st[0]; int M = st[1]; string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } bool flg = true; for (int i = 0; i <= N - M; i++) { for (int j = 0; j <= N - M; j++) { flg = true; //チェック工程 for (int k = 0; k < M; k++) { for (int l = 0; l < M; l++) { if (A[i + k][j + l] != B[k][l]) { //チェック工程を抜ける k = M; l = M; flg = false; } } } if (flg) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
[["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
8
299
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var A = sc.ReadStrArray(N); var B = sc.ReadStrArray(M); for (int i = 0; i < N - M; i++) { var s = A[i]; for (int j = 0; j < N - M; j++) { var t1 = B[0]; if (s.Substring(j, M) == t1) { // 1行目のデータが一致するとき var ok = true; for (int k = 1; k < M; k++) { var tn = B[k]; var sn = A[i + k].Substring(j, M); if (tn != sn) ok = false; } if (ok) { Console.WriteLine("Yes"); return; } } } } Console.WriteLine("No"); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var A = sc.ReadStrArray(N); var B = sc.ReadStrArray(M); for (int i = 0; i <= N - M; i++) { var s = A[i]; for (int j = 0; j <= N - M; j++) { var t1 = B[0]; if (s.Substring(j, M) == t1) { // 1行目のデータが一致するとき var ok = true; for (int k = 1; k < M; k++) { var tn = B[k]; var sn = A[i + k].Substring(j, M); if (tn != sn) ok = false; } if (ok) { Console.WriteLine("Yes"); return; } } } } Console.WriteLine("No"); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
731
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC054B___Template_Matching { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); List<string> nImage = new List<string>(); List<string> mImage = new List<string>(); for (int index = 1; index <= n; index++) { nImage.Add(Console.ReadLine()); } for (int index = 1; index <= m; index++) { mImage.Add(Console.ReadLine()); } string result = "No"; if (ContainBInA(nImage, mImage)) { result = "Yes"; } Console.WriteLine(result); } public static bool ContainBInA(List<string> nImage, List<string> mImage) { bool res = false; int n = nImage.Count; int m = mImage.Count; // row pattern number int rowPattern = n - m + 1; // col pattern number int colPattern = n - m + 1; // search row for (int rowIndex = 0; rowIndex < rowPattern; rowIndex++) { // search col for (int colIndex = 0; colIndex < colPattern; colIndex++) { // select target in nImage int startCol = colIndex; // int endCol = colIndex + m - 1; int startRow = rowIndex; int endRow = rowIndex + m - 1; int mImageRow = 0; bool result = true; for (int index = startRow; index < endRow; index++) { if (nImage[index].Substring(startCol, m) != mImage[mImageRow]) { result = false; } mImageRow++; } if (result) { return true; } } } return res; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC054B___Template_Matching { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); List<string> nImage = new List<string>(); List<string> mImage = new List<string>(); for (int index = 1; index <= n; index++) { nImage.Add(Console.ReadLine()); } for (int index = 1; index <= m; index++) { mImage.Add(Console.ReadLine()); } string result = "No"; if (ContainBInA(nImage, mImage)) { result = "Yes"; } Console.WriteLine(result); } public static bool ContainBInA(List<string> nImage, List<string> mImage) { bool res = false; int n = nImage.Count; int m = mImage.Count; // row pattern number int rowPattern = n - m + 1; // col pattern number int colPattern = n - m + 1; // search row for (int rowIndex = 0; rowIndex < rowPattern; rowIndex++) { // search col for (int colIndex = 0; colIndex < colPattern; colIndex++) { // select target in nImage int startCol = colIndex; // int endCol = colIndex + m - 1; int startRow = rowIndex; int endRow = rowIndex + m - 1; int mImageRow = 0; bool result = true; for (int index = startRow; index <= endRow; index++) { if (nImage[index].Substring(startCol, m) != mImage[mImageRow]) { result = false; } mImageRow++; } if (result) { return true; } } } return res; } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
382
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCorder { 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 m = cin.ReadInt; var a = cin.ReadStrArray(n); var b = cin.ReadStrArray(m); for (int i = 0; i < n - m + 1; i++) { for (int j = 0; j < n - m + 1; j++) { var now = 0; while (true) { if (now == m) { WriteLine("Yes"); return; } var sub = a[i + now].Substring(i, m); if (b[now] != sub) { break; } else { now++; continue; } } } } 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 AtCorder { 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 m = cin.ReadInt; var a = cin.ReadStrArray(n); var b = cin.ReadStrArray(m); for (int i = 0; i < n - m + 1; i++) { for (int j = 0; j < n - m + 1; j++) { var now = 0; while (true) { if (now == m) { WriteLine("Yes"); return; } var sub = a[i + now].Substring(j, m); if (b[now] != sub) { break; } else { now++; continue; } } } } 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, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22]]
8
571
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC054B { class Program { public static void Solve(Input input) { var n = input.NextInt(); var m = input.NextInt(); var a = new string[n]; var b = new string[m]; for (int i = 0; i < n; i++) { a[i] = input.Next(); } for (int i = 0; i < m; i++) { b[i] = input.Next(); } for (int i = 0; i < n - m; i++) { for (int j = 0; j < n - m; j++) { if (same(a, b, i, j)) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } static bool same(string[] a, string[] b, int sx, int sy) { for (int i = 0; i < b.Length; i++) { for (int j = 0; j < b.Length; j++) { if (a[sy + i][sx + j] != b[i][j]) { return false; } } } return true; } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #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 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } 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 (s == null) 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 void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC054B { class Program { public static void Solve(Input input) { var n = input.NextInt(); var m = input.NextInt(); var a = new string[n]; var b = new string[m]; for (int i = 0; i < n; i++) { a[i] = input.Next(); } for (int i = 0; i < m; i++) { b[i] = input.Next(); } for (int i = 0; i < n - m + 1; i++) { for (int j = 0; j < n - m + 1; j++) { if (same(a, b, i, j)) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } static bool same(string[] a, string[] b, int sx, int sy) { for (int i = 0; i < b.Length; i++) { for (int j = 0; j < b.Length; j++) { if (a[sy + i][sx + j] != b[i][j]) { return false; } } } return true; } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // その場合は出力がボトルネックになっていないので、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText(""); Solve(input); Console.Out.Flush(); } #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 /// <summary> /// 値を書き換え可能なTuple(ぐらいのイメージ) /// </summary> public class Pair<T, U> : IComparable<Pair<T, U>>, IEquatable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T V1 { get; set; } public U V2 { get; set; } public Pair(T v1, U v2) { this.V1 = v1; this.V2 = v2; } public Pair(Pair<T, U> src) : this(src.V1, src.V2) {} public int CompareTo(Pair<T, U> other) { var r = this.V1.CompareTo(other.V1); if (r == 0) r = this.V2.CompareTo(other.V2); return r; } public bool Equals(Pair<T, U> other) => (other != null && this.CompareTo(other) == 0); public override string ToString() => $"{V1} {V2}"; public override bool Equals(object obj) => Equals(obj as Pair<T, U>); public override int GetHashCode() { var hashCode = 1989511945; hashCode = hashCode * -1521134295 + V1.GetHashCode(); hashCode = hashCode * -1521134295 + V2.GetHashCode(); return hashCode; } public static bool operator ==(Pair<T, U> a, Pair<T, U> b) { if (object.ReferenceEquals(a, null)) { return object.ReferenceEquals(b, null); } return a.Equals(b); } public static bool operator !=(Pair<T, U> a, Pair<T, U> b) => !(a == b); public static bool operator<(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator <=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) <= 0; public static bool operator>(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator >=(Pair<T, U> a, Pair<T, U> b) => a.CompareTo(b) >= 0; } 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 (s == null) 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 void Print<T>(IEnumerable<T> ie, string sep = " ") => Console.WriteLine(string.Join(sep, ie)); public static void Print<T>(params T[] objs) => Print(objs); public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); public static void Swap<T>(ref T x, ref T y) where T : struct { var t = x; x = y; y = t; } public static void Swap<T>(IList<T> list, int i, int j) where T : struct { var t = list[i]; list[i] = list[j]; list[j] = t; } /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v = default(T)) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
1,884
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int[] num = Input.ScanIntArray(); int N = num[0], M = num[1]; string[] A = new string[num[0]]; string[] B = new string[num[1]]; for (int i = 0; i < num[0]; i++) A[i] = Input.ScanStr(); for (int i = 0; i < num[1]; i++) B[i] = Input.ScanStr(); for (int i = 0; i <= N - M; i++) { for (int j = 0; j <= N - M; j++) { bool isSub = true; for (int k = j; k < j + M; k++) { isSub &= A[k].Substring(i, num[1]) == B[k]; } if (isSub) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
using System; using System.Linq; using System.Collections.Generic; namespace program { class Program { static void Main() { int[] num = Input.ScanIntArray(); int N = num[0], M = num[1]; string[] A = new string[num[0]]; string[] B = new string[num[1]]; for (int i = 0; i < num[0]; i++) A[i] = Input.ScanStr(); for (int i = 0; i < num[1]; i++) B[i] = Input.ScanStr(); for (int i = 0; i <= N - M; i++) { for (int j = 0; j <= N - M; j++) { bool isSub = true; for (int k = 0; k < M; k++) { isSub &= A[k + j].Substring(i, num[1]) == B[k]; } if (isSub) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } static class Input { static public int ScanInt() { return int.Parse(Console.ReadLine()); } static public uint ScanUint() { return uint.Parse(Console.ReadLine()); } static public long ScanLong() { return long.Parse(Console.ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); } static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return Console.ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(' '); } } static class MyMath { public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong GCD(ulong a, ulong b) { Func<ulong, ulong, ulong> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static ulong LCM(ulong a, ulong b) { return a * b / GCD(a, b); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
8
718
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); string[] A = new string[N]; for (int i = 0; i < N; i++) A[i] = Console.ReadLine(); string[] B = new string[M]; for (int i = 0; i < M; i++) B[i] = Console.ReadLine(); bool isOK = false; for (int y = 0; y < N - M; y++) { for (int x = 0; x < N - M; x++) { if (A[y][x] == B[0][0]) { isOK = true; for (int i = 0; i < M; i++) { if (A[y + i].Substring(x, M) != B[i]) { isOK = false; break; } } } if (isOK) break; } if (isOK) break; } Console.WriteLine(isOK ? "Yes" : "No"); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); int M = int.Parse(s[1]); string[] A = new string[N]; for (int i = 0; i < N; i++) A[i] = Console.ReadLine(); string[] B = new string[M]; for (int i = 0; i < M; i++) B[i] = Console.ReadLine(); bool isOK = false; for (int y = 0; y <= N - M; y++) { for (int x = 0; x <= N - M; x++) { if (A[y][x] == B[0][0]) { isOK = true; for (int i = 0; i < M; i++) { if (A[y + i].Substring(x, M) != B[i]) { isOK = false; break; } } } if (isOK) break; } if (isOK) break; } Console.WriteLine(isOK ? "Yes" : "No"); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
283
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { int[] nums = SpRead(' ').Select(a => int.Parse(a)).ToArray(); int N = nums[0]; int M = nums[1]; string[] s_1 = new string[N]; string[] s_2 = new string[M]; for (int i = 0; i < N; i++) { s_1[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { s_2[i] = Console.ReadLine(); } string s = ""; for (int i = 0; i < (N - M) + 1; i++) { for (int j = 0; j < (N - M) + 1; j++) { s = s_1[i].Substring(j, M); if (s == s_2[0]) { for (int k = 1; k < M; k++) { s = s_1[i + k].Substring(j, M); if (s != s_2[k]) break; if (k + 1 == M) { Console.WriteLine("Yes"); return; } } } } } Console.WriteLine("No"); } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string strReverce(string s) { return new string(s.Reverse().ToArray()); } public static int Cin() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } }
using System; using System.Collections.Generic; using System.Linq; using static Atcoder; using System.Threading.Tasks; using System.ComponentModel; public class Hello { public static void Main() { int[] nums = SpRead(' ').Select(a => int.Parse(a)).ToArray(); int N = nums[0]; int M = nums[1]; string[] s_1 = new string[N]; string[] s_2 = new string[M]; for (int i = 0; i < N; i++) { s_1[i] = Console.ReadLine(); } for (int i = 0; i < M; i++) { s_2[i] = Console.ReadLine(); } string s = ""; for (int i = 0; i < (N - M) + 1; i++) { for (int j = 0; j < (N - M) + 1; j++) { s = s_1[i].Substring(j, M); if (s == s_2[0]) { for (int k = 0; k < M; k++) { s = s_1[i + k].Substring(j, M); if (s != s_2[k]) break; if (k + 1 == M) { Console.WriteLine("Yes"); return; } } } } } Console.WriteLine("No"); } } public class Atcoder { static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static int LCM(int a, int b) { int c = a * b; if (a < b) Swap(ref a, ref b); int d = a % b; while (d != 0) { a = b; b = d; d = a % b; } return c / b; } public static string strReverce(string s) { return new string(s.Reverse().ToArray()); } public static int Cin() { return int.Parse(Console.ReadLine()); } public static bool IsPrime(int n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; // double sqrtNum = Math.Sqrt(n); for (int i = 3; i < n; i += 2) { if (n % i == 0) return false; } return true; } public static string[] SpRead(char c) { return Console.ReadLine().Split(c); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
556
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Simple { int N, M; string[] A, B; void Solve() { // input N = io.Int; M = io.Int; A = new string[N]; B = new string[M]; for (int i = 0; i < N; ++i) A[i] = io.String; for (int j = 0; j < M; ++j) B[j] = io.String; // cal for (int shiftX = 0; shiftX < N - M; ++shiftX) { for (int shiftY = 0; shiftY < N - M; ++shiftY) { for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j) { if (A[i + shiftY][j + shiftX] != B[i][j]) goto BR; } } // res(Contain) Console.WriteLine("Yes"); return; BR:; } } // res(!Contain) Console.WriteLine("No"); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) { new Simple().Stream(); } void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Simple { int N, M; string[] A, B; void Solve() { // input N = io.Int; M = io.Int; A = new string[N]; B = new string[M]; for (int i = 0; i < N; ++i) A[i] = io.String; for (int j = 0; j < M; ++j) B[j] = io.String; // cal for (int shiftX = 0; shiftX < N - M + 1; ++shiftX) { for (int shiftY = 0; shiftY < N - M + 1; ++shiftY) { for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j) { if (A[i + shiftY][j + shiftX] != B[i][j]) goto BR; } } // res(Contain) Console.WriteLine("Yes"); return; BR:; } } // res(!Contain) Console.WriteLine("No"); } SimpleIO io = new SimpleIO(); public static void Main(string[] args) { new Simple().Stream(); } void Stream() { Solve(); io.writeFlush(); } } class SimpleIO { string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' }; StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public SimpleIO() { nextBuffer = new string[0]; BufferCnt = 0; Console.SetOut(sw); } public string Next() { if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); BufferCnt = 0; return nextBuffer[BufferCnt++]; } public string String => Next(); public char Char => char.Parse(String); public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public void writeFlush() { Console.Out.Flush(); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
510
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp62 { class Program { static void Main(string[] args) { string[] NM = Console.ReadLine().Split(' '); int N = int.Parse(NM[0]); int M = int.Parse(NM[1]); string[] A = new string[N]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } string[] B = new string[M]; for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } for (int n = 0; n <= N - M; n++) { for (int m = 0; m <= N - M; m++) { bool maru = true; for (int j = 0; j < M; j++) { for (int k = 0; k < M; k++) { if (A[n + j][m + k] != B[j][k]) { maru = false; break; } } if (maru == false) { break; } } if (maru) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); return; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp62 { class Program { static void Main(string[] args) { string[] NM = Console.ReadLine().Split(' '); int N = int.Parse(NM[0]); int M = int.Parse(NM[1]); string[] A = new string[N]; for (int i = 0; i < N; i++) { A[i] = Console.ReadLine(); } string[] B = new string[M]; for (int i = 0; i < M; i++) { B[i] = Console.ReadLine(); } for (int n = 0; n <= N - M; n++) { for (int m = 0; m <= N - M; m++) { bool maru = true; for (int j = 0; j < M; j++) { for (int k = 0; k < M; k++) { if (A[n + j][m + k] != B[j][k]) { maru = false; break; } } if (maru == false) { break; } } if (maru) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); return; } } }
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
307
using System; using System.Text; using System.Linq; using System.Collections; using System.Threading.Tasks; using System.Collections.Generic; using System.Runtime.InteropServices; using static System.Console; using static System.Math; namespace NotFounds { public class Program { public static void Main(string[] args) { new Program().Solve(); } public void Solve() { MyInputStream cin = new MyInputStream(); var N = cin.ReadInt(); var M = cin.ReadInt(); var img1 = new int[N, N]; var img2 = new int[M, M]; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) img1[i, j] = Read(); Read(); } for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j) img2[i, j] = Read(); Read(); } for (int i = 0; i < N - M; ++i) { for (int j = 0; j < N - M; ++j) { var flag = true; for (int k = 0; flag && k < M; ++k) { for (int l = 0; flag && l < M; ++l) { if (img1[i + k, j + l] != img2[k, l]) { // WriteLine($"({i + k}, {j + l}):[{(char)img1[i+k, j+l]}] ({k}, // {l}):[{(char)img2[k, l]}]"); flag = false; } } } if (flag) { WriteLine("Yes"); return; } } } WriteLine("No"); } } public static class MyExtensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class MyInputStream { private char separator = ' '; private Queue<string> inputStream; public MyInputStream(char separator = ' ') { this.separator = separator; inputStream = new Queue<string>(); } public string Read() { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = Console.ReadLine().Split(separator); for (int i = 0; i < tmp.Length; i++) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } public string ReadLine() => Console.ReadLine(); public int ReadInt() => int.Parse(Read()); public long ReadLong() => long.Parse(Read()); public double ReadDouble() => double.Parse(Read()); } public class Pair<T1, T2> { public T1 First; public T2 Second; public Pair() { First = default(T1); Second = default(T2); } public Pair(T1 f, T2 s) { First = f; Second = s; } public override string ToString() { return "(" + First + ", " + Second + ")"; } public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); } public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) return true; else if (obj == null) return false; var tmp = obj as Pair<T1, T2>; return (object)tmp != null && First.Equals(tmp.First) && Second.Equals(tmp.Second); } } #region HashMap public class HashMap<K, V> : Dictionary<K, V> { public HashMap() : base() {} public HashMap(int cap) : base(cap) {} public HashMap(IDictionary<K, V> dictionary) : base(dictionary) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = default(V); } set { base[i] = value; } } } #endregion }
using System; using System.Text; using System.Linq; using System.Collections; using System.Threading.Tasks; using System.Collections.Generic; using System.Runtime.InteropServices; using static System.Console; using static System.Math; namespace NotFounds { public class Program { public static void Main(string[] args) { new Program().Solve(); } public void Solve() { MyInputStream cin = new MyInputStream(); var N = cin.ReadInt(); var M = cin.ReadInt(); var img1 = new int[N, N]; var img2 = new int[M, M]; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) img1[i, j] = Read(); Read(); } for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j) img2[i, j] = Read(); Read(); } for (int i = 0; i < N - M + 1; ++i) { for (int j = 0; j < N - M + 1; ++j) { var flag = true; for (int k = 0; flag && k < M; ++k) { for (int l = 0; flag && l < M; ++l) { if (img1[i + k, j + l] != img2[k, l]) { // WriteLine($"({i + k}, {j + l}):[{(char)img1[i+k, j+l]}] ({k}, // {l}):[{(char)img2[k, l]}]"); flag = false; } } } if (flag) { WriteLine("Yes"); return; } } } WriteLine("No"); } } public static class MyExtensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } public class MyInputStream { private char separator = ' '; private Queue<string> inputStream; public MyInputStream(char separator = ' ') { this.separator = separator; inputStream = new Queue<string>(); } public string Read() { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = Console.ReadLine().Split(separator); for (int i = 0; i < tmp.Length; i++) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } public string ReadLine() => Console.ReadLine(); public int ReadInt() => int.Parse(Read()); public long ReadLong() => long.Parse(Read()); public double ReadDouble() => double.Parse(Read()); } public class Pair<T1, T2> { public T1 First; public T2 Second; public Pair() { First = default(T1); Second = default(T2); } public Pair(T1 f, T2 s) { First = f; Second = s; } public override string ToString() { return "(" + First + ", " + Second + ")"; } public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); } public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) return true; else if (obj == null) return false; var tmp = obj as Pair<T1, T2>; return (object)tmp != null && First.Equals(tmp.First) && Second.Equals(tmp.Second); } } #region HashMap public class HashMap<K, V> : Dictionary<K, V> { public HashMap() : base() {} public HashMap(int cap) : base(cap) {} public HashMap(IDictionary<K, V> dictionary) : base(dictionary) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = default(V); } set { base[i] = value; } } } #endregion }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
856
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace ConsoleApplication { public class main { static void Main() { string[] vals = Console.ReadLine().Split(' '); int N = int.Parse(vals[0]); int M = int.Parse(vals[1]); string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; i++) A[i] = Console.ReadLine(); for (int i = 0; i < M; i++) B[i] = Console.ReadLine(); for (int y = 0; y < N - M; y++) { for (int x = 0; x <= N - M; x++) { bool match = true; for (int j = 0; j < M; j++) { for (int i = 0; i < M; i++) { if (A[y + j][x + i] != B[j][i]) { match = false; } } } if (match) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace ConsoleApplication { public class main { static void Main() { string[] vals = Console.ReadLine().Split(' '); int N = int.Parse(vals[0]); int M = int.Parse(vals[1]); string[] A = new string[N]; string[] B = new string[M]; for (int i = 0; i < N; i++) A[i] = Console.ReadLine(); for (int i = 0; i < M; i++) B[i] = Console.ReadLine(); for (int y = 0; y <= N - M; y++) { for (int x = 0; x <= N - M; x++) { bool match = true; for (int j = 0; j < M; j++) { for (int i = 0; i < M; i++) { if (A[y + j][x + i] != B[j][i]) { match = false; } } } if (match) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
281
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Main { class Program { static void Main(string[] args) { bool flag = false; string[] str = Console.ReadLine().Split(' '); int N, M, buf; N = int.Parse(str[0]); M = int.Parse(str[1]); string[] map = new string[N]; string[] check = new string[M]; for (int a = 0; a < N; a++) { map[a] = Console.ReadLine(); } for (int a = 0; a < M; a++) { check[a] = Console.ReadLine(); } for (int a = 0; a < N - M; a++) { buf = map[a].IndexOf(check[0]); if (buf != -1) { flag = true; for (int b = 0; b < M; b++) { if (map[a + b].IndexOf(check[b], buf) != buf) { flag = false; break; } } } if (flag == true) break; } if (flag == true) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Main { class Program { static void Main(string[] args) { bool flag = false; string[] str = Console.ReadLine().Split(' '); int N, M, buf; N = int.Parse(str[0]); M = int.Parse(str[1]); string[] map = new string[N]; string[] check = new string[M]; for (int a = 0; a < N; a++) { map[a] = Console.ReadLine(); } for (int a = 0; a < M; a++) { check[a] = Console.ReadLine(); } for (int a = 0; a < N - M + 1; a++) { buf = map[a].IndexOf(check[0]); if (buf != -1) { flag = true; for (int b = 0; b < M; b++) { if (map[a + b].IndexOf(check[b], buf) != buf) { flag = false; break; } } } if (flag == true) break; } if (flag == true) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
300
using System; using System.Collections.Generic; namespace abc052 { public class Program { public static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); string s = Console.ReadLine(); int x = 0; int max = 0; for (int i = 0; i < s.Length - 1; i++) { if (s[i] == 'I') { x++; } else if (s[i] == 'D') { x--; } if (max < x) { max = x; } } Console.WriteLine(max.ToString()); } } }
using System; using System.Collections.Generic; namespace abc052 { public class Program { public static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); string s = Console.ReadLine(); int x = 0; int max = 0; for (int i = 0; i < s.Length; i++) { if (s[i] == 'I') { x++; } else if (s[i] == 'D') { x--; } if (max < x) { max = x; } } Console.WriteLine(max.ToString()); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
140
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int mod = 1000000000 + 7; var N = ConsoleUtil.IntReadLine(); var primes = GetPrimeNumbers().TakeWhile(n => n <= N).ToArray(); var counter = new int[primes.Length]; for (int i = 1; i <= N; i++) { Count(i, primes, counter); } int ans = 1; for (int i = 0; i < counter.Length; i++) { ans *= (counter[i] + 1); ans %= mod; } Console.WriteLine(ans); } static void Count(int n, int[] primes, int[] counter) { for (int i = 0; i < primes.Length; i++) { int nCpy = n; int prime = primes[i]; while (nCpy % prime == 0) { nCpy /= prime; counter[i]++; } } } static IEnumerable<int> GetPrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } } static class ConsoleUtil { public static string[] StrArrayReadLine(char sepalator) { string str = Console.ReadLine(); return str.Split(sepalator).ToArray(); } public static string[] StrArrayReadLine() { string str = Console.ReadLine(); if (str.Contains(',')) { return str.Split(',').ToArray(); } { return str.Split(' ').ToArray(); } } public static int[] IntArrayReadLine() { return StrArrayReadLine().Select(s => int.Parse(s)).ToArray(); } public static int[] IntArrayReadLine(char sepalator) { return StrArrayReadLine(sepalator).Select(s => int.Parse(s)).ToArray(); } public static int IntReadLine() => int.Parse(Console.ReadLine()); }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int mod = 1000000000 + 7; var N = ConsoleUtil.IntReadLine(); var primes = GetPrimeNumbers().TakeWhile(n => n <= N).ToArray(); var counter = new int[primes.Length]; for (int i = 1; i <= N; i++) { Count(i, primes, counter); } long ans = 1; for (int i = 0; i < counter.Length; i++) { ans *= (counter[i] + 1); ans %= mod; } Console.WriteLine(ans); } static void Count(int n, int[] primes, int[] counter) { for (int i = 0; i < primes.Length; i++) { int nCpy = n; int prime = primes[i]; while (nCpy % prime == 0) { nCpy /= prime; counter[i]++; } } } static IEnumerable<int> GetPrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } } static class ConsoleUtil { public static string[] StrArrayReadLine(char sepalator) { string str = Console.ReadLine(); return str.Split(sepalator).ToArray(); } public static string[] StrArrayReadLine() { string str = Console.ReadLine(); if (str.Contains(',')) { return str.Split(',').ToArray(); } { return str.Split(' ').ToArray(); } } public static int[] IntArrayReadLine() { return StrArrayReadLine().Select(s => int.Parse(s)).ToArray(); } public static int[] IntArrayReadLine(char sepalator) { return StrArrayReadLine(sepalator).Select(s => int.Parse(s)).ToArray(); } public static int IntReadLine() => int.Parse(Console.ReadLine()); }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
533
using System; using System.Collections.Generic; using System.Linq; class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } } class Program { static Scanner cin = new Scanner(); static Dictionary<int, long> dic = new Dictionary<int, long>(); static void Main() { int N = cin.Int(); for (int i = N; i >= 2; i--) { prime_factorization(i); } long ans = 1; foreach (var v in dic.Values) { ans = ans % 1000000007 * (v + 1); } Console.WriteLine(ans); Console.ReadLine(); } static void prime_factorization(int n) // Key:素数, Value:指数 { int i = 2, tmp = n; while (i * i <= n) { if (tmp % i == 0) { if (dic.ContainsKey(i)) dic[i]++; else dic[i] = 1; tmp /= i; } else i++; } if (tmp > 1) { if (dic.ContainsKey(tmp)) dic[tmp]++; else dic[tmp] = 1; } } }
using System; using System.Collections.Generic; using System.Linq; class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int Int() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } } class Program { static Scanner cin = new Scanner(); static Dictionary<int, long> dic = new Dictionary<int, long>(); static void Main() { int N = cin.Int(); for (int i = N; i >= 2; i--) { prime_factorization(i); } long ans = 1; foreach (var v in dic.Values) { ans = (ans % 1000000007 * (v + 1)) % 1000000007; } Console.WriteLine(ans); Console.ReadLine(); } static void prime_factorization(int n) // Key:素数, Value:指数 { int i = 2, tmp = n; while (i * i <= n) { if (tmp % i == 0) { if (dic.ContainsKey(i)) dic[i]++; else dic[i] = 1; tmp /= i; } else i++; } if (tmp > 1) { if (dic.ContainsKey(tmp)) dic[tmp]++; else dic[tmp] = 1; } } }
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
502
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine()); var arr = new long[1001]; var ans = 1L; for (var i = 2; i <= n; i++) { var temp = i; for (var j = 2; j <= i; j++) { while (temp % j == 0) { arr[j]++; temp /= j; } } } for (var i = 2; i <= 1000; i++) { if (arr[i] != 0) { ans *= arr[i] + 1; } } Console.WriteLine(ans); } }
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine()); var arr = new long[1001]; var ans = 1L; for (var i = 2; i <= n; i++) { var temp = i; for (var j = 2; j <= i; j++) { while (temp % j == 0) { arr[j]++; temp /= j; } } } for (var i = 2; i <= 1000; i++) { if (arr[i] != 0) { ans *= arr[i] + 1; ans %= 1000000007; } } Console.WriteLine(ans); } }
[["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
144
using System; using System.Linq; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string ans = s.Replace('.', ' '); Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { string s = Console.ReadLine(); string ans = s.Replace(',', ' '); Console.WriteLine(ans); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["+", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253]]
8
55
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class B { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var KS = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var (K, S) = (KS[0], KS[1]); var answer = 0; for (var x = 0; x <= K; x++) { for (var y = 0; y <= K; y++) { var z = S - x - y; if (z >= 0) answer++; } } Console.WriteLine(answer); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class B { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var KS = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var (K, S) = (KS[0], KS[1]); var answer = 0; for (var x = 0; x <= K; x++) { for (var y = 0; y <= K; y++) { var z = S - x - y; if (z >= 0 && z <= K) answer++; } } Console.WriteLine(answer); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
202
using System; using System.Linq; namespace testes { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int K = int.Parse(str[0]); int S = int.Parse(str[1]); int ans = 0; for (int i = 0; i <= K; i++) { for (int j = 0; j <= K; j++) { int tmp = S - i - j; if (0 <= tmp) ans++; } } Console.WriteLine(ans); } public static void func(int L, int R, bool x, bool y) {} public static int LIS(int[] c) { // 部分数列和 int count = 1; int N = c.Length; int[] array = new int[N]; array[0] = c[0]; for (int i = 1; i < N; i++) { // for (int p = 0; p < N; p++) Console.Write($"{array[p]},"); // Console.WriteLine(""); if (array[count - 1] < c[i]) { array[count] = c[i]; count++; continue; } for (int j = count - 2; j >= 0; j--) { if (array[j] < c[i]) { array[j + 1] = c[i]; break; } } if (array[0] > c[i]) array[0] = c[i]; } return count; } public static void Rotation(char[] array, int l, int r) {} } } /* int a, b, c; a = int.Parse(Console.ReadLine()); //標準入力 string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得 b = int.Parse(str[0]); //数値で受け取りたい場合は変換する c = int.Parse(str[1]); string S = Console.ReadLine(); char[] C = new char[N]; C = S.ToCharArray(); Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力 Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力 string[] str = Console.ReadLine().Split(' '); int[] a = new int[N]; for(int i = 0; i < N; i++) a[i] = int.Parse(str[i]); */
using System; using System.Linq; namespace testes { class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int K = int.Parse(str[0]); int S = int.Parse(str[1]); int ans = 0; for (int i = 0; i <= K; i++) { for (int j = 0; j <= K; j++) { int tmp = S - i - j; if (0 <= tmp && tmp <= K) ans++; } } Console.WriteLine(ans); } public static void func(int L, int R, bool x, bool y) {} public static int LIS(int[] c) { // 部分数列和 int count = 1; int N = c.Length; int[] array = new int[N]; array[0] = c[0]; for (int i = 1; i < N; i++) { // for (int p = 0; p < N; p++) Console.Write($"{array[p]},"); // Console.WriteLine(""); if (array[count - 1] < c[i]) { array[count] = c[i]; count++; continue; } for (int j = count - 2; j >= 0; j--) { if (array[j] < c[i]) { array[j + 1] = c[i]; break; } } if (array[0] > c[i]) array[0] = c[i]; } return count; } public static void Rotation(char[] array, int l, int r) {} } } /* int a, b, c; a = int.Parse(Console.ReadLine()); //標準入力 string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得 b = int.Parse(str[0]); //数値で受け取りたい場合は変換する c = int.Parse(str[1]); string S = Console.ReadLine(); char[] C = new char[N]; C = S.ToCharArray(); Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力 Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力 string[] str = Console.ReadLine().Split(' '); int[] a = new int[N]; for(int i = 0; i < N; i++) a[i] = int.Parse(str[i]); */
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
337
using System; namespace ABC051B_SumofThreeIntegers { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int k = int.Parse(input[0]); int s = int.Parse(input[1]); int x = 0; int y = 0; int z = 0; int counter = 0; for (int indexX = 0; indexX <= k; indexX++) { x = indexX; for (int indexY = 0; indexY <= k; indexY++) { y = indexY; z = s - x - y; if (0 <= z && z <= s) { counter++; } } } Console.WriteLine(counter); } } }
using System; namespace ABC051B_SumofThreeIntegers { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int k = int.Parse(input[0]); int s = int.Parse(input[1]); int x = 0; int y = 0; int z = 0; int counter = 0; for (int indexX = 0; indexX <= k; indexX++) { x = indexX; for (int indexY = 0; indexY <= k; indexY++) { y = indexY; z = s - x - y; if (0 <= z && z <= k) { counter++; } } } Console.WriteLine(counter); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
156
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramC { struct Info { public int to; public string path; } static Queue<Info> _q = new Queue<Info>(); static List<int>[] _graph; static int _count; static int _n; static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); _n = int.Parse(inputs[0]); var m = int.Parse(inputs[1]); _graph = new List<int>[_n]; for (var i = 0; i < _n; i++) { _graph[i] = new List<int>(); } for (var i = 0; i < _n; i++) { var inputs1 = Console.ReadLine().Split(" "); var a = int.Parse(inputs1[0]) - 1; var b = int.Parse(inputs1[1]) - 1; _graph[a].Add(b); _graph[b].Add(a); } _q.Enqueue(new Info() { to = 0, path = "0" }); while (_q.Count > 0) { var info = _q.Dequeue(); var v = info.to; var path = info.path; foreach (var t in _graph[v]) { if (path.Contains(t.ToString())) continue; _q.Enqueue(new Info() { to = t, path = path + t.ToString(), }); } if (path.Count() == _n) _count++; } Console.WriteLine(_count); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC { class ProgramC { struct Info { public int to; public string path; } static Queue<Info> _q = new Queue<Info>(); static List<int>[] _graph; static int _count; static int _n; static void Main(string[] args) { var inputs = Console.ReadLine().Split(" "); _n = int.Parse(inputs[0]); var m = int.Parse(inputs[1]); _graph = new List<int>[_n]; for (var i = 0; i < _n; i++) { _graph[i] = new List<int>(); } for (var i = 0; i < m; i++) { var inputs1 = Console.ReadLine().Split(" "); var a = int.Parse(inputs1[0]) - 1; var b = int.Parse(inputs1[1]) - 1; _graph[a].Add(b); _graph[b].Add(a); } _q.Enqueue(new Info() { to = 0, path = "0" }); while (_q.Count > 0) { var info = _q.Dequeue(); var v = info.to; var path = info.path; foreach (var t in _graph[v]) { if (path.Contains(t.ToString())) continue; _q.Enqueue(new Info() { to = t, path = path + t.ToString(), }); } if (path.Count() == _n) _count++; } Console.WriteLine(_count); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
368
// // InputProblemIdHere // URL : // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.IO.Pipes; namespace AtCoder { class InputProblemIdHere { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static int N; public static int M; public static bool[,] Edges; public static int ans; public static void Solve() { { int[] inputArray = Console.ReadLine() .Split(' ') .Select(_inputStr => int.Parse(_inputStr)) .ToArray(); N = inputArray[0]; M = inputArray[1]; } Edges = new bool[N, N]; for (int i = 0; i < M; ++i) { var inputArray = Console.ReadLine() .Split(' ') .Select(_inputStr => int.Parse(_inputStr)) .ToArray(); int a = inputArray[0] - 1; int b = inputArray[1] - 1; Edges[a, b] = true; Edges[b, a] = true; } ans = 0; var visited = new bool[N]; FindPathesSub(0, ref visited); Console.WriteLine(ans); } public static void FindPathesSub(int start, ref bool[] visited) { if (visited[start] == true) { return; } visited[start] = true; if (visited.All(x => x == true) == true) { //探索終了 ++ans; return; } //探索続行 //次に行く頂点を探す var nextNodes = new List<int>(N); for (int next = 0; next < M; ++next) { if (Edges[start, next] == false) { continue; } nextNodes.Add(next); // Console.Write (next + " "); } // Console.WriteLine(); //行く頂点がないということはない、必ずどこかの頂点には移動しようとする if (nextNodes.Count == 1) { FindPathesSub(nextNodes[0], ref visited); } else { foreach (var next in nextNodes) { var visitedCopy = new bool[N]; for (int i = 0; i < visited.Length; ++i) { visitedCopy[i] = visited[i]; } FindPathesSub(next, ref visitedCopy); } } } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
// // InputProblemIdHere // URL : // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.IO.Pipes; namespace AtCoder { class InputProblemIdHere { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static int N; public static int M; public static bool[,] Edges; public static int ans; public static void Solve() { { int[] inputArray = Console.ReadLine() .Split(' ') .Select(_inputStr => int.Parse(_inputStr)) .ToArray(); N = inputArray[0]; M = inputArray[1]; } Edges = new bool[N, N]; for (int i = 0; i < M; ++i) { var inputArray = Console.ReadLine() .Split(' ') .Select(_inputStr => int.Parse(_inputStr)) .ToArray(); int a = inputArray[0] - 1; int b = inputArray[1] - 1; Edges[a, b] = true; Edges[b, a] = true; } ans = 0; var visited = new bool[N]; FindPathesSub(0, ref visited); Console.WriteLine(ans); } public static void FindPathesSub(int start, ref bool[] visited) { if (visited[start] == true) { return; } visited[start] = true; if (visited.All(x => x == true) == true) { //探索終了 ++ans; return; } //探索続行 //次に行く頂点を探す var nextNodes = new List<int>(N); for (int next = 0; next < N; ++next) { if (Edges[start, next] == false) { continue; } nextNodes.Add(next); // Console.Write (next + " "); } // Console.WriteLine(); //行く頂点がないということはない、必ずどこかの頂点には移動しようとする if (nextNodes.Count == 1) { FindPathesSub(nextNodes[0], ref visited); } else { foreach (var next in nextNodes) { var visitedCopy = new bool[N]; for (int i = 0; i < visited.Length; ++i) { visitedCopy[i] = visited[i]; } FindPathesSub(next, ref visitedCopy); } } } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
1,110
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static AtCoderTemplate.MyLibrary; namespace AtCoderTemplate { class Program { static int N, M, i; static bool[,] connect; static bool[] reached; static int count = 0, length = 0; static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); N = int.Parse(str1[0]); M = int.Parse(str1[1]); reached = new bool[N]; connect = new bool[N, N]; //辺の読み込み for (i = 0; i < N; i++) { string[] str2 = Console.ReadLine().Split(' '); connect[int.Parse(str2[0]) - 1, int.Parse(str2[1]) - 1] = true; connect[int.Parse(str2[1]) - 1, int.Parse(str2[0]) - 1] = true; } reached[0] = true; Search(0); Console.WriteLine(count); } static void Search(int n) { for (int k = 0; k < N; k++) { if (connect[n, k] == true && reached[k] == false) { length++; reached[k] = true; Search(k); reached[k] = false; } } if (length == N - 1) count++; length--; } } class MyLibrary { // 自作の関数 public static int MyFunction(int n) { return 0; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static AtCoderTemplate.MyLibrary; namespace AtCoderTemplate { class Program { static int N, M, i; static bool[,] connect; static bool[] reached; static int count = 0, length = 0; static void Main(string[] args) { string[] str1 = Console.ReadLine().Split(' '); N = int.Parse(str1[0]); M = int.Parse(str1[1]); reached = new bool[N]; connect = new bool[N, N]; //辺の読み込み for (i = 0; i < M; i++) { string[] str2 = Console.ReadLine().Split(' '); connect[int.Parse(str2[0]) - 1, int.Parse(str2[1]) - 1] = true; connect[int.Parse(str2[1]) - 1, int.Parse(str2[0]) - 1] = true; } reached[0] = true; Search(0); Console.WriteLine(count); } static void Search(int n) { for (int k = 0; k < N; k++) { if (connect[n, k] == true && reached[k] == false) { length++; reached[k] = true; Search(k); reached[k] = false; } } if (length == N - 1) { count++; } length--; } } class MyLibrary { // 自作の関数 public static int MyFunction(int n) { return 0; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
363
using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace Capp { class Program { public enum En { a, b, c, d, e, f } static void Main(string[] args) { var c = new Solve(); c.S(); } } public class Solve { List<int>[] es = new List<int>[10]; int n; int m; int res = 0; int t = 0; void rec(int x) { if (t == (1 << n) - 1) { res++; return; } foreach (var v in es[x]) { if ((t & (1 << v)) > 0) continue; t |= (1 << v); rec(v); t ^= (1 << v); } } public void S() { var nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); n = nm[0]; m = nm[0]; for (int i = 0; i < 10; i++) { es[i] = new List<int>(); } for (int i = 0; i < m; i++) { var s = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var a = s[0] - 1; var b = s[1] - 1; es[a].Add(b); es[b].Add(a); } t = 1; rec(0); Console.WriteLine(res); } } public class Test<T> : ITest<T> { public string S { get; set; } } public interface ITest<out T> { string S { get; set; } } struct c { public string s { get; set; } private dynamic _d; public dynamic d { get { return _d; } } public void Setd(dynamic d) { _d = d; } } class AsTest { internal async Task<int> AsyncMethod(int x) { var t1 = Task.Run(() => { Thread.Sleep(10000); return 10 * x; }); var res = await t1; Console.WriteLine($"asyncmethod {res}"); return res; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace Capp { class Program { public enum En { a, b, c, d, e, f } static void Main(string[] args) { var c = new Solve(); c.S(); } } public class Solve { List<int>[] es = new List<int>[10]; int n; int m; int res = 0; int t = 0; void rec(int x) { if (t == (1 << n) - 1) { res++; return; } foreach (var v in es[x]) { if ((t & (1 << v)) > 0) continue; t |= (1 << v); rec(v); t ^= (1 << v); } } public void S() { var nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); n = nm[0]; m = nm[1]; for (int i = 0; i < 10; i++) { es[i] = new List<int>(); } for (int i = 0; i < m; i++) { var s = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var a = s[0] - 1; var b = s[1] - 1; es[a].Add(b); es[b].Add(a); } t = 1; rec(0); Console.WriteLine(res); } } public class Test<T> : ITest<T> { public string S { get; set; } } public interface ITest<out T> { string S { get; set; } } struct c { public string s { get; set; } private dynamic _d; public dynamic d { get { return _d; } } public void Setd(dynamic d) { _d = d; } } class AsTest { internal async Task<int> AsyncMethod(int x) { var t1 = Task.Run(() => { Thread.Sleep(10000); return 10 * x; }); var res = await t1; Console.WriteLine($"asyncmethod {res}"); return res; } } }
[["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203]]
8
520
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Cs { class hutatu { int a, b = 0; public hutatu(int a, int b) { this.a = a; this.b = b; } public bool doti(int c) { return a == c || b == c; } public int gyaku(int c) { if (a == c) { return b; } if (b == c) { return a; } return -1; } } class Program { static void Main(string[] args) { var str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int m = int.Parse(str[0]); List<hutatu> ab = new List<hutatu>(); int[] dye = new int[n]; for (int i = 0; i < m; i++) { var str2 = Console.ReadLine().Split(' '); ab.Add(new hutatu(int.Parse(str2[0]), int.Parse(str2[1]))); } Console.WriteLine(mycheck(1, dye, ab)); } static int mycheck(int me, int[] die, List<hutatu> newab) { die[me - 1] = 1; if (die.All(c => c == 1)) { return 1; } int count = 0; List<hutatu> ne = newab.ToList(); ne.RemoveAll(c => c.doti(me)); bool botti = true; for (int i = 0; i < newab.Count; i++) { int k = newab[i].gyaku(me); if (k == -1) { continue; } botti = false; count += mycheck(k, die.ToArray(), ne); } if (botti) { return 0; } return count; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Cs { class hutatu { int a, b = 0; public hutatu(int a, int b) { this.a = a; this.b = b; } public bool doti(int c) { return a == c || b == c; } public int gyaku(int c) { if (a == c) { return b; } if (b == c) { return a; } return -1; } } class Program { static void Main(string[] args) { var str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int m = int.Parse(str[1]); List<hutatu> ab = new List<hutatu>(); int[] dye = new int[n]; for (int i = 0; i < m; i++) { var str2 = Console.ReadLine().Split(' '); ab.Add(new hutatu(int.Parse(str2[0]), int.Parse(str2[1]))); } Console.WriteLine(mycheck(1, dye, ab)); } static int mycheck(int me, int[] die, List<hutatu> newab) { die[me - 1] = 1; if (die.All(c => c == 1)) { return 1; } int count = 0; List<hutatu> ne = newab.ToList(); ne.RemoveAll(c => c.doti(me)); bool botti = true; for (int i = 0; i < newab.Count; i++) { int k = newab[i].gyaku(me); if (k == -1) { continue; } botti = false; count += mycheck(k, die.ToArray(), ne); } if (botti) { return 0; } return count; } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
431
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var AB = sc.ReadTupArray(N, -1); G = new List<int>[N]; for (int i = 0; i < N; i++) { G[i] = new List<int>(); } for (int i = 0; i < M; i++) { var a = AB[i].Item1; var b = AB[i].Item2; G[a].Add(b); G[b].Add(a); } Visited = new bool[N]; Rec(0, -1); Console.WriteLine(ans); } static void Rec(int now, int prev) { Visited[now] = true; var count = 0; foreach (var next in G[now]) { if (prev == next) continue; if (Visited[next]) continue; count++; Rec(next, now); } if (count == 0 && Visited.All(v => v)) ans++; Visited[now] = false; } static bool[] Visited; static long ans = 0; static int N; static List<int>[] G; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var AB = sc.ReadTupArray(M, -1); G = new List<int>[N]; for (int i = 0; i < N; i++) { G[i] = new List<int>(); } for (int i = 0; i < M; i++) { var a = AB[i].Item1; var b = AB[i].Item2; G[a].Add(b); G[b].Add(a); } Visited = new bool[N]; Rec(0, -1); Console.WriteLine(ans); } static void Rec(int now, int prev) { Visited[now] = true; var count = 0; foreach (var next in G[now]) { if (prev == next) continue; if (Visited[next]) continue; count++; Rec(next, now); } if (count == 0 && Visited.All(v => v)) ans++; Visited[now] = false; } static bool[] Visited; static long ans = 0; static int N; static List<int>[] G; static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22]]
8
1,269