buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); long m = cin.Long(); long[] a = cin.ArrayLong(n); Array.Sort(a); long target = m; long left = -1; long right = a[n - 1] * 2; int[] indexes = new int[n]; long num = 0; while (right - left > 1) { long mid = (right + left) / 2; num = Search(n, a, mid, indexes); if (num == target + 1 || num == target) { right = mid; break; } if (num <= target) { right = mid; } else { left = mid; } } num = Search(n, a, right, indexes); long[] sums = new long[n]; sums[0] = a[0]; for (int i = 1; i < n; i++) { sums[i] = a[i] + sums[i - 1]; } long ans = 0; for (int i = 0; i < n; i++) { int count = indexes[i]; long temp = count == n ? sums[n - 1] : sums[n - 1] - sums[n - 1 - count]; temp += a[i] * count; ans += temp; } if (num == target + 1) { long min = long.MaxValue; for (int i = 0; i < n; i++) { if (indexes[i] > 0) { min = Math.Min(min, a[i] + a[n - indexes[i]]); } } if (min != long.MaxValue) { ans -= min; } } Console.WriteLine(ans); } public static long Search(int n, long[] a, long target, int[] indexes) { long count = 0; for (int i = 0; i < n; i++) { int left = -1; int right = n; while (right - left > 1) { int mid = (right + left) / 2; long temp = a[mid] + a[i]; if (temp >= target) { right = mid; } else { left = mid; } } indexes[i] = n - right; count += indexes[i]; } return count; } public static int LowerBound(IReadOnlyList<long> list, long target) { int left = -1; int right = list.Count(); while (right - left > 1) { int mid = (right + left) / 2; if (list[mid] >= target) { right = mid; } else { left = mid; } } return right; } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); long m = cin.Long(); long[] a = cin.ArrayLong(n); Array.Sort(a); long target = m; long left = -1; long right = a[n - 1] * 2; int[] indexes = new int[n]; long num = 0; while (right - left > 1) { long mid = (right + left) / 2; num = Search(n, a, mid, indexes); if (num < target) { right = mid; } else { left = mid; } } num = Search(n, a, left, indexes); long[] sums = new long[n]; sums[0] = a[0]; for (int i = 1; i < n; i++) { sums[i] = a[i] + sums[i - 1]; } long ans = 0; for (int i = 0; i < n; i++) { int count = indexes[i]; long temp = count == n ? sums[n - 1] : sums[n - 1] - sums[n - 1 - count]; temp += a[i] * count; ans += temp; } if (num > target) { long min = long.MaxValue; for (int i = 0; i < n; i++) { if (indexes[i] > 0) { min = Math.Min(min, a[i] + a[n - indexes[i]]); } } if (min != long.MaxValue) { ans -= min * (num - target); } } Console.WriteLine(ans); } public static long Search(int n, long[] a, long target, int[] indexes) { long count = 0; for (int i = 0; i < n; i++) { int left = -1; int right = n; while (right - left > 1) { int mid = (right + left) / 2; long temp = a[mid] + a[i]; if (temp >= target) { right = mid; } else { left = mid; } } indexes[i] = n - right; count += indexes[i]; } return count; } public static int LowerBound(IReadOnlyList<long> list, long target) { int left = -1; int right = list.Count(); while (right - left > 1) { int mid = (right + left) / 2; if (list[mid] >= target) { right = mid; } else { left = mid; } } return right; } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 72], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
8
1,092
34
using System; namespace ConsoleApp11 { class Class1 { public static void Main() { string[] IN = Console.ReadLine().Split(); long N = long.Parse(IN[0]); long A = long.Parse(IN[1]); long B = long.Parse(IN[2]); long up; long down; long small; long big; long ans; if ((A + B) % 2 == 0) ans = Math.Abs((A - B) / 2); else { up = Math.Max(A - 1, B - 1); down = Math.Max(N - A, N - B); if (up < down) { ans = Math.Min(A - 1, B - 1) + 1 + (B - 1 - (Math.Min(A - 1, B - 1) + 1)) / 2; } else ans = Math.Min(N - A, N - B) + 1 + (N - B - (Math.Min(N - A, N - B) + 1)) / 2; } Console.WriteLine(ans); } } }
using System; namespace ConsoleApp11 { class Class1 { public static void Main() { string[] IN = Console.ReadLine().Split(); long N = long.Parse(IN[0]); long A = long.Parse(IN[1]); long B = long.Parse(IN[2]); long up; long down; long small; long big; long ans; if ((A + B) % 2 == 0) ans = Math.Abs((A - B) / 2); else { up = Math.Max(A - 1, B - 1); down = Math.Max(N - A, N - B); if (up < down) { ans = Math.Min(A - 1, B - 1) + 1 + (Math.Max(A - 1, B - 1) - (Math.Min(A - 1, B - 1) + 1)) / 2; } else ans = Math.Min(N - A, N - B) + 1 + (Math.Max(N - A, N - B) - (Math.Min(N - A, N - B) + 1)) / 2; } Console.WriteLine(ans); } } }
[["+", 31, 23, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 31, 23, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 31, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 23, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 31, 23, 0, 16, 31, 213, 3, 4, 0, 21], ["+", 31, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 16, 12, 16, 31, 23, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
248
18
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Contests.AGC041 { /// <summary> /// /// </summary> static class A { static void Main(string[] args) { var n = NextLong(); var a = NextLong(); var b = NextLong(); if ((b - a) % 2 == 0) { Console.WriteLine((b - a) / 2); return; } Console.WriteLine(Math.Min(n - a, b - 1)); } #region Console static int _index = 0; static string[] _buffer; static string Next() { if (_buffer == null || _index >= _buffer.Length) { _buffer = Console.ReadLine().Split(); _index = 0; } return _buffer[_index++]; } static int NextInt() { return int.Parse(Next()); } static long NextLong() { return long.Parse(Next()); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } #endregion } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Contests.AGC041 { /// <summary> /// /// </summary> static class A { static void Main(string[] args) { var n = NextLong(); var a = NextLong(); var b = NextLong(); if ((b - a) % 2 == 0) { Console.WriteLine((b - a) / 2); return; } Console.WriteLine( Math.Min(a + (b - a - 1) / 2, (n - b + 1) + (b - a - 1) / 2)); } #region Console static int _index = 0; static string[] _buffer; static string Next() { if (_buffer == null || _index >= _buffer.Length) { _buffer = Console.ReadLine().Split(); _index = 0; } return _buffer[_index++]; } static int NextInt() { return int.Parse(Next()); } static long NextLong() { return long.Parse(Next()); } static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } #endregion } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 12, 16, 31, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 85], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 12, 22]]
8
560
24
using System; using System.Collections.Generic; namespace D { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] A = Console.ReadLine().Split(' '); int[] aa = new int[N]; int[] d = new int[N]; for (int i = 0; i < N; i++) { aa[i] = int.Parse(A[i]); } int j = 0; int k = 1; int m = 0; while (true) { if (j < N) { if (aa[j] == k) { d[j] = m; j++; k++; } else { m++; d[j] = m; j++; } } else { break; } } Console.Write(d[N - 1]); } } }
using System; using System.Collections.Generic; namespace D { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] A = Console.ReadLine().Split(' '); int[] aa = new int[N]; int[] d = new int[N]; for (int i = 0; i < N; i++) { aa[i] = int.Parse(A[i]); } int j = 0; int k = 1; int m = 0; while (true) { if (j < N) { if (aa[j] == k) { d[j] = m; j++; k++; } else { m++; d[j] = m; j++; } } else { break; } } if (d[N - 1] == N) { Console.WriteLine("-1"); } else { Console.Write(d[N - 1]); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
200
25
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp14 { class Program { static void Main(string[] args) { var solver = new Solver(); solver.Calc(); } } public class Solver { public void Calc() { var N = long.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); long count = 0; long num = 1; for (long i = 0; i < N - 1; i++) { if (a[i] == num) { num++; } else { count++; } } if (a[N - 1] == num) { Console.WriteLine(count); } else { Console.WriteLine(-1); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApp14 { class Program { static void Main(string[] args) { var solver = new Solver(); solver.Calc(); } } public class Solver { public void Calc() { var N = long.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); long count = 0; long num = 1; for (long i = 0; i < N; i++) { if (a[i] == num) { num++; } else { count++; } } Console.WriteLine((count != N) ? count : -1); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 3, 4, 0, 28, 0, 41, 15, 23, 0, 24], ["+", 0, 28, 0, 41, 15, 23, 0, 16, 17, 79], ["+", 0, 28, 0, 41, 15, 23, 0, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
187
29
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _20191224_ATC { class Program { static void Main(string[] args) { var n = Myself.NextInt()[0]; var a = Myself.NextInt(); int checkNum = 1; int ansNum = 0; int index = 0; for (int i = 0; i < a.Count; i++) { if (checkNum == a[i]) { if (checkNum == 1) { ansNum += i - index; } else { ansNum += i - index - 1; } index = i; checkNum++; } } if (checkNum == 1) { Myself.Print(-1); } else { Myself.Print(ansNum); } } private static void ABC148_C() { var n = Myself.NextLong(); var a = n[0]; var b = n[1]; //最小公倍数を求める問題 var lcm = Utility.Lcm(a, b); Console.WriteLine(lcm); } private static void ABC148_B() { var m = int.Parse(Console.ReadLine()); var str = Console.ReadLine().ToString().Split(' '); var s = str[0]; var t = str[1]; // Zip : 2つのリストから一個ずつ取り出して結合する // SelectMany : 結合したものを1文字ずつ1つのリストにまとめる var output = s.Zip(t, (x, y) => new[] { x, y }).SelectMany(xs => xs); // foreach (var item in output) //{ // Console.WriteLine(item); //} // char型のリストから文字列を生成 Console.WriteLine(string.Join("", output)); } private static void ABC148_A() { var a = int.Parse(Console.ReadLine()); var b = int.Parse(Console.ReadLine()); var c = Enumerable.Range(1, 3).Where(x => x != a && x != b).First(); Console.WriteLine(c); } } public class Myself { public static List<int> NextInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } public static List<long> NextLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } public static List<double> NextDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } public static List<string> NextString() { return Console.ReadLine().Split(' ').ToList(); } public static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } /// <summary> /// コンソール出力関数 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> public static void Print<T>(T a) { Console.WriteLine(a); } } public struct Point { public double X { get; set; } public double Y { get; set; } public Point(double x, double y) { X = x; Y = y; } public static Point CalcOffsetPoint(Point a, Point b) { b.X -= a.X; b.Y -= a.Y; return new Point(b.X, b.Y); } public static double CalcArea(Point a, Point b) { return Math.Abs((a.X * b.Y) - (a.Y * b.X)) / 2; } } class Utility { // 最小公倍数 public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 最大公約数 private static long Gcd(long a, long b) { if (a < b) { return Gcd(b, a); } long d = 0; do { d = a % b; a = b; b = d; } while (d != 0); return a; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _20191224_ATC { class Program { static void Main(string[] args) { var n = Myself.NextInt()[0]; var a = Myself.NextInt(); int checkNum = 1; int ansNum = 0; int index = 0; bool updated = false; for (int i = 0; i < a.Count; i++) { if (checkNum == a[i]) { if (checkNum == 1) { ansNum += i - index; } else { ansNum += i - index - 1; } index = i; checkNum++; updated = true; } else { updated = false; } if (i == a.Count - 1 && !updated) { ansNum += i - index; } } if (checkNum == 1) { Myself.Print(-1); } else { Myself.Print(ansNum); } } private static void ABC148_C() { var n = Myself.NextLong(); var a = n[0]; var b = n[1]; //最小公倍数を求める問題 var lcm = Utility.Lcm(a, b); Console.WriteLine(lcm); } private static void ABC148_B() { var m = int.Parse(Console.ReadLine()); var str = Console.ReadLine().ToString().Split(' '); var s = str[0]; var t = str[1]; // Zip : 2つのリストから一個ずつ取り出して結合する // SelectMany : 結合したものを1文字ずつ1つのリストにまとめる var output = s.Zip(t, (x, y) => new[] { x, y }).SelectMany(xs => xs); // foreach (var item in output) //{ // Console.WriteLine(item); //} // char型のリストから文字列を生成 Console.WriteLine(string.Join("", output)); } private static void ABC148_A() { var a = int.Parse(Console.ReadLine()); var b = int.Parse(Console.ReadLine()); var c = Enumerable.Range(1, 3).Where(x => x != a && x != b).First(); Console.WriteLine(c); } } public class Myself { public static List<int> NextInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } public static List<long> NextLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } public static List<double> NextDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } public static List<string> NextString() { return Console.ReadLine().Split(' ').ToList(); } public static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } /// <summary> /// コンソール出力関数 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> public static void Print<T>(T a) { Console.WriteLine(a); } } public struct Point { public double X { get; set; } public double Y { get; set; } public Point(double x, double y) { X = x; Y = y; } public static Point CalcOffsetPoint(Point a, Point b) { b.X -= a.X; b.Y -= a.Y; return new Point(b.X, b.Y); } public static double CalcArea(Point a, Point b) { return Math.Abs((a.X * b.Y) - (a.Y * b.X)) / 2; } } class Utility { // 最小公倍数 public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } // ユークリッドの互除法 最大公約数 private static long Gcd(long a, long b) { if (a < b) { return Gcd(b, a); } long d = 0; do { d = a % b; a = b; b = d; } while (d != 0); return a; } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 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], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 205, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 0, 131], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 111], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
821
37
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BrickBreak { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] strBricks = Console.ReadLine().Split(' '); int brick = 0; int nextBrick = 1; int countBreak = 0; for (int i = 0; i < n; i++) { brick = int.Parse(strBricks[i]); if (brick == nextBrick) { nextBrick++; } else { countBreak++; } } Console.Write(countBreak); Console.ReadKey(true); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BrickBreak { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] strBricks = Console.ReadLine().Split(' '); int brick = 0; int nextBrick = 1; int countBreak = 0; for (int i = 0; i < n; i++) { brick = int.Parse(strBricks[i]); if (brick == nextBrick) { nextBrick++; } else { countBreak++; } } if (nextBrick == 1) { Console.Write(-1); } else { Console.Write(countBreak); } Console.ReadKey(true); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
152
19
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace PaizaTest { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); // DP? var oneLine = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var num = -1; var nextNum = 1; var brokenBlocks = 0; // 砕いたレンガの数を要素にしてDPする for (int i = 0; i < N; i++) { if (oneLine[i] == nextNum) { num = oneLine[i]; nextNum++; continue; } brokenBlocks++; } Console.WriteLine(brokenBlocks); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace PaizaTest { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); // DP? var oneLine = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var num = -1; var nextNum = 1; var brokenBlocks = 0; // 砕いたレンガの数を要素にしてDPする for (int i = 0; i < N; i++) { if (oneLine[i] == nextNum) { num++; nextNum++; continue; } brokenBlocks++; } Console.WriteLine(num >= 0 ? brokenBlocks : -1); } } }
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 3, 4, 0, 28, 0, 41, 75, 241, 0, 33], ["+", 3, 4, 0, 28, 0, 41, 75, 241, 0, 203]]
8
152
13
using System; class p { static void Main() { int N = int.Parse(Console.ReadLine()); string[] ipt = Console.ReadLine().Split(' '); int[] arr = new int[N]; for (int i = 0; i < N; i++) { arr[i] = int.Parse(ipt[i]); } int count = 1, num = 0, prev = -1; for (int i = 0; i < N; i++) { if (arr[i] == count) { count++; num += i - (prev + 1); prev = i; } } Console.WriteLine(count == 1 ? -1 : num); } }
using System; class p { static void Main() { int N = int.Parse(Console.ReadLine()); string[] ipt = Console.ReadLine().Split(' '); int[] arr = new int[N]; for (int i = 0; i < N; i++) { arr[i] = int.Parse(ipt[i]); } int count = 1, num = 0; for (int i = 0; i < N; i++) { if (arr[i] == count) { count++; } else { num++; } } Console.WriteLine(count == 1 ? -1 : num); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 72], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29]]
8
160
21
using System; using System.Linq; namespace ABC148D { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); if (!As.Contains(1)) { Console.WriteLine(-1); return; } if (As.Length == 1 && As[0] == 1) { Console.WriteLine(0); return; } var ans = 0; var j = 1; for (var i = 0; i < N; i++) { if (As[i] == j) j++; else ans++; } if (ans > 0) Console.WriteLine(ans); else Console.WriteLine("-1"); } } }
using System; using System.Linq; namespace ABC148D { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); if (!As.Contains(1)) { Console.WriteLine(-1); return; } if (As.Length == 1 && As[0] == 1) { Console.WriteLine(0); return; } var ans = 0; var j = 1; for (var i = 0; i < N; i++) { if (As[i] == j) j++; else ans++; } if (ans > 0) Console.WriteLine(ans); else if (j - 1 == N) Console.WriteLine(0); else Console.WriteLine("-1"); } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 33], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
8
183
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace template { class Program { static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var n = int.Parse(cin.ReadLine); var r = cin.ReadIntArray(n); if (n == 1 && r[0] == 1) { Console.WriteLine(0); return; } int cnt = 0; int num = 1; bool flg = false; for (int i = 0; i < n - 1; i++) { if (r[i] == num) { num++; flg = true; } else { cnt++; } } if (flg) { Console.WriteLine(cnt); } else { if (r.Last() == 1) { Console.WriteLine(cnt); } else { Console.WriteLine(-1); } } } } 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.Collections.Generic; using System.Linq; using System.Text; namespace template { class Program { static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var n = int.Parse(cin.ReadLine); var r = cin.ReadIntArray(n); if (n == 1 && r[0] == 1) { Console.WriteLine(0); return; } int cnt = 0; int num = 1; bool flg = false; for (int i = 0; i < n; i++) { if (r[i] == num) { num++; flg = true; } else { cnt++; } } if (flg) { Console.WriteLine(cnt); } else { Console.WriteLine(-1); } } } 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; } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["-", 0, 57, 75, 196, 0, 57, 75, 196, 0, 46]]
8
558
24
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; internal static class CR { public static string Get() { return Console.ReadLine(); } public static long GetInteger() { return long.Parse(Console.ReadLine()); } public static IEnumerable<ulong> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)); } } namespace AtCoder.E { public class Program { public static long N { get; private set; } public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.WriteLine(r); } private static object GetResult() { N = CR.GetInteger(); // 奇数の時点でNG if (N % 2 != 0) return 0; var fize = 0L; var under = 10D; while (under < N) { fize += (long)Math.Floor(N / under); under *= 5; } return fize; } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; internal static class CR { public static string Get() { return Console.ReadLine(); } public static long GetInteger() { return long.Parse(Console.ReadLine()); } public static IEnumerable<ulong> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)); } } namespace AtCoder.E { public class Program { public static long N { get; private set; } public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.WriteLine(r); } private static object GetResult() { N = CR.GetInteger(); // 奇数の時点でNG if (N % 2 != 0) return 0; var fize = 0L; var under = 2L; while (under <= N) { under *= 5; // fize = (long)Math.Floor((double)N / under); // NG fize += N / under; } return fize; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 0, 131], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 74, 51, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 74, 51, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203]]
8
216
20
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var n = Read().ToDecimal(); var ans = Math.Min(G2(n, 2), G2(n, 5)); WriteRead(ans); } static decimal G1(decimal n, decimal p) { if (n == 0) return 0; return Math.Floor(n / p) + G1(Math.Floor(n / p), p); } static decimal G2(decimal n, decimal p) { decimal result = G1(Math.Floor(n / 2), p); if (p == 2) result += Math.Floor(n / 2); return result; } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double ToDouble(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var n = Read().ToDecimal(); if (n % 2 == 1) { WriteRead(0); return; } var ans = Math.Min(G2(n, 2), G2(n, 5)); WriteRead(ans); } static decimal G1(decimal n, decimal p) { if (n == 0) return 0; return Math.Floor(n / p) + G1(Math.Floor(n / p), p); } static decimal G2(decimal n, decimal p) { decimal result = G1(Math.Floor(n / 2), p); if (p == 2) result += Math.Floor(n / 2); return result; } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double ToDouble(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
390
17
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200331.Abc148_E.Cin; using static _20200331.Abc148_E.Util; using Pair = _20200331.Abc148_E.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200331 { public class Abc148_E { public static void Main(string[] args) { long N = rl; long n = N; long cnt2 = 0; while (0 < n) { n /= 2; cnt2 += n; } n = N / 2; long cnt5 = 0; while (0 < n) { n /= 5; cnt5 += n; } Console.WriteLine(Min(cnt2, cnt5)); } public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long a) { Value = a % MOD; if (Value < 0) Value += MOD; } static Mint i(long a) { return new Mint() { Value = a }; } public static Mint operator +(Mint a, Mint b) { long c = a.Value + b.Value; if (c > MOD) c -= MOD; return i(c); } public static Mint operator -(Mint a, Mint b) { long c = a.Value - b.Value; if (c < 0) c += MOD; return i(c); } public static Mint operator *(Mint a, Mint b) { long c = a.Value * b.Value; if (c > MOD) c %= MOD; return i(c); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object a) { return a is Mint && Value == ((Mint)a).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long b) { if (b == 0) return new Mint(1); Mint c = Pow(a, b >> 1); c *= c; if ((b & 1) == 1) c *= a; return c; } public static Mint Inv(Mint a) { long b = a.Value; long c = MOD; long d = 1; long e = 0; while (c != 0) { long f = b / c; long g = e; e = d - f * e; d = g; long h = b; b = c; c = h - (f * c); } return new Mint(d); } public bool Equals(Mint a) { return Value == a.Value; } public int CompareTo(Mint a) { return Comparer<long>.Default.Compare(Value, a.Value); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 a, T2 b) { Item1 = a; Item2 = b; } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2); } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; return Comparer<T2>.Default.Compare(Item2, a.Item2); } } public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>, System.IEquatable<VTuple<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple(T1 a, T2 b, T3 c) { Item1 = a; Item2 = b; Item3 = c; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c); } public bool Equals(VTuple<T1, T2, T3> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3); } public int CompareTo(VTuple<T1, T2, T3> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; return Comparer<T3>.Default.Compare(Item3, a.Item3); } } public struct VTuple<T1, T2, T3, T4> : System.IComparable<VTuple<T1, T2, T3, T4>>, System.IEquatable<VTuple<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple(T1 a, T2 b, T3 c, T4 d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; int d = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c, d); } public bool Equals(VTuple<T1, T2, T3, T4> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3) && EqualityComparer<T4>.Default.Equals(Item4, a.Item4); } public int CompareTo(VTuple<T1, T2, T3, T4> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; b = Comparer<T3>.Default.Compare(Item3, a.Item3); if (b != 0) return b; return Comparer<T4>.Default.Compare(Item4, a.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int a, int b) { uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } public static int CombineHashCodes(int a, int b) { return Combine(Combine(RandomSeed, a), b); } public static int CombineHashCodes(int a, int b, int c) { return Combine(CombineHashCodes(a, b), c); } public static int CombineHashCodes(int a, int b, int c, int d) { return Combine(CombineHashCodes(a, b, c), d); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static long GCD(long a, long b) { while (b != 0) { long c = a; a = b; b = c % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200331.Abc148_E.Cin; using static _20200331.Abc148_E.Util; using Pair = _20200331.Abc148_E.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200331 { public class Abc148_E { public static void Main(string[] args) { long N = rl; if (N % 2 == 1) { Console.WriteLine(0); return; } long n = N; long cnt2 = 0; while (0 < n) { n /= 2; cnt2 += n; } n = N / 2; long cnt5 = 0; while (0 < n) { n /= 5; cnt5 += n; } Console.WriteLine(Min(cnt2, cnt5)); } public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long a) { Value = a % MOD; if (Value < 0) Value += MOD; } static Mint i(long a) { return new Mint() { Value = a }; } public static Mint operator +(Mint a, Mint b) { long c = a.Value + b.Value; if (c > MOD) c -= MOD; return i(c); } public static Mint operator -(Mint a, Mint b) { long c = a.Value - b.Value; if (c < 0) c += MOD; return i(c); } public static Mint operator *(Mint a, Mint b) { long c = a.Value * b.Value; if (c > MOD) c %= MOD; return i(c); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object a) { return a is Mint && Value == ((Mint)a).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long b) { if (b == 0) return new Mint(1); Mint c = Pow(a, b >> 1); c *= c; if ((b & 1) == 1) c *= a; return c; } public static Mint Inv(Mint a) { long b = a.Value; long c = MOD; long d = 1; long e = 0; while (c != 0) { long f = b / c; long g = e; e = d - f * e; d = g; long h = b; b = c; c = h - (f * c); } return new Mint(d); } public bool Equals(Mint a) { return Value == a.Value; } public int CompareTo(Mint a) { return Comparer<long>.Default.Compare(Value, a.Value); } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 a, T2 b) { Item1 = a; Item2 = b; } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2); } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; return Comparer<T2>.Default.Compare(Item2, a.Item2); } } public struct VTuple<T1, T2, T3> : System.IComparable<VTuple<T1, T2, T3>>, System.IEquatable<VTuple<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple(T1 a, T2 b, T3 c) { Item1 = a; Item2 = b; Item3 = c; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3> && Equals((VTuple<T1, T2, T3>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c); } public bool Equals(VTuple<T1, T2, T3> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3); } public int CompareTo(VTuple<T1, T2, T3> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; return Comparer<T3>.Default.Compare(Item3, a.Item3); } } public struct VTuple<T1, T2, T3, T4> : System.IComparable<VTuple<T1, T2, T3, T4>>, System.IEquatable<VTuple<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple(T1 a, T2 b, T3 c, T4 d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } public override bool Equals(object a) { return a is VTuple<T1, T2, T3, T4> && Equals((VTuple<T1, T2, T3, T4>)a); } public override int GetHashCode() { int a = Item1 != null ? Item1.GetHashCode() : 0; int b = Item2 != null ? Item2.GetHashCode() : 0; int c = Item3 != null ? Item3.GetHashCode() : 0; int d = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(a, b, c, d); } public bool Equals(VTuple<T1, T2, T3, T4> a) { return EqualityComparer<T1>.Default.Equals(Item1, a.Item1) && EqualityComparer<T2>.Default.Equals(Item2, a.Item2) && EqualityComparer<T3>.Default.Equals(Item3, a.Item3) && EqualityComparer<T4>.Default.Equals(Item4, a.Item4); } public int CompareTo(VTuple<T1, T2, T3, T4> a) { int b = Comparer<T1>.Default.Compare(Item1, a.Item1); if (b != 0) return b; b = Comparer<T2>.Default.Compare(Item2, a.Item2); if (b != 0) return b; b = Comparer<T3>.Default.Compare(Item3, a.Item3); if (b != 0) return b; return Comparer<T4>.Default.Compare(Item4, a.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int a, int b) { uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } public static int CombineHashCodes(int a, int b) { return Combine(Combine(RandomSeed, a), b); } public static int CombineHashCodes(int a, int b, int c) { return Combine(CombineHashCodes(a, b), c); } public static int CombineHashCodes(int a, int b, int c, int d) { return Combine(CombineHashCodes(a, b, c), d); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static long GCD(long a, long b) { while (b != 0) { long c = a; a = b; b = c % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(i()); } public static long ReadLong() { return long.Parse(i()); } public static double ReadDouble() { return double.Parse(i()); } public static string ReadString() { return i(); } public static int[] ReadIntArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { g = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { g = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long b) { a = new long[b]; for (int c = 0; c < b; c++) a[c] = ReadLong(); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[,] ReadIntTable(int a, int b) { g = null; int[,] c = new int[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadInt(); } return c; } public static long[,] ReadLongTable(long a, long b) { g = null; long[,] c = new long[a, b]; for (int d = 0; d < a; d++) for (int e = 0; e < b; e++) { c[d, e] = ReadLong(); } return c; } public static char[,] ReadCharTable(int a, int b) { g = null; char[,] c = new char[a, b]; for (int d = 0; d < a; d++) { var e = ReadString(); for (int f = 0; f < b; f++) c[d, f] = e[f]; } return c; } static string[] g; static int h; static string i() { if (g == null || g.Length <= h) { g = Console.ReadLine().Split(' '); h = 0; } return g[h++]; } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
3,603
19
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; class Program { static void Main() { long N = long.Parse(Console.ReadLine()); long count5 = 0; if (N % 2 == 1) { WriteLine(0); ReadLine(); } count5 = (long)(N / 10); N = count5; for (int i = 1; i <= Log(N, 5); i++) { count5 += (long)(N / Math.Pow(5, i)); } Console.WriteLine(count5); Console.ReadLine(); } #region Reader static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrN() { return Console.ReadLine().Split(' '); } static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } static int[] ReadIntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } static long[] ReadLongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } static long[,] ReadLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReadTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReadTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadIntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReadTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReadAdjacencyList(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 = ReadIntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; class Program { static void Main() { long N = long.Parse(Console.ReadLine()); long count5 = 0; if (N % 2 == 1) { WriteLine(0); ReadLine(); return; } count5 = N / 10; N = count5; for (long i = 1; i <= Log(N, 5); i++) { count5 += N / (long)Math.Pow(5, i); } Console.WriteLine(count5); Console.ReadLine(); } #region Reader static string ReadStr() { return Console.ReadLine(); } static string[] ReadStrN() { return Console.ReadLine().Split(' '); } static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } static int[] ReadIntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } static long[] ReadLongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } static long[,] ReadLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReadTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReadTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadIntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReadTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReadAdjacencyList(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 = ReadIntN(); dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 1, 0, 11, 12, 74, 51, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 74, 51, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["-", 0, 11, 12, 74, 51, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 74, 51, 23, 0, 16, 17, 85], ["-", 51, 23, 0, 16, 12, 213, 3, 4, 0, 25]]
8
907
15
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { long read = rlong(); read /= 10; long counter = read; while (read >= 5) { read /= 5; counter += read; } WriteLine(counter); } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } // A/B小数点以下切上 static int divideup(int divided, int divid) { int temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } }
using System; using static System.Console; using static System.Math; public class Hello { public static void Main() { long read = rlong(); if (read % 2 == 0) { read /= 10; long counter = read; while (read >= 5) { read /= 5; counter += read; } WriteLine(counter); } else { WriteLine(0); } } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } // A/B小数点以下切上 static int divideup(int divided, int divid) { int temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
328
18
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { long n = IO.GetLong(); if (n % 2 == 1) { Console.WriteLine(0); return; } long ans = 0; long inc = 1; long dC = 0; do { long b = (long)Math.Pow(5, inc); // 5 dC = n / b; dC = (long)Math.Floor((double)dC / 2); // Console.WriteLine("n:"+n+" b:"+b+" dC:"+dC); ans += dC; inc++; } while (dC != 0 && inc != 26); Console.WriteLine(ans); } } static class IO { static public string GetString() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { long n = IO.GetLong(); if (n % 2 == 1) { Console.WriteLine(0); return; } long ans = 0; long inc = 1; long dC = 0; do { long b = (long)Math.Pow(5, inc); // 5 dC = n / (2 * b); // dC = (long)Math.Floor((double)dC/2); // Console.WriteLine("n:"+n+" b:"+b+" dC:"+dC); ans += dC; inc++; } while (dC != 0 && inc != 26); Console.WriteLine(ans); } } static class IO { static public string GetString() { return Console.ReadLine(); } static public int GetInt() { return int.Parse(Console.ReadLine()); } static public long GetLong() { return long.Parse(Console.ReadLine()); } static public List<string> GetStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> GetIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> GetLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 8, 196, 0, 82, 8, 196, 0, 1, 0, 35], ["-", 0, 82, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 0, 131], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 74, 51, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 51, 22], ["-", 51, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 48], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22]]
8
374
17
//ヒントがっつり見た using System; namespace tst { class Program { public static long Gusu(long x) { long cnt = 0; long bunbo = 10; while (x >= bunbo) { // doubleで切捨て、その値をlongにいれる cnt += (long)Math.Floor((double)x / bunbo); bunbo *= 5; } return cnt; } /*public static long Kisu(long x) { long sum = 1; for (int i = 1; i <= ((x+1) / 2); i++) { sum *= ((2 * i)-1); } return sum; }*/ public static void Main() { long n = long.Parse(Console.ReadLine()); if (n % 2 == 1) { // val = Kisu(n); //奇数は0になることがない Console.WriteLine(0); } else if (n % 2 == 0) { // 5の出てくる回数を数えよう Console.WriteLine(Gusu(n)); } } } }
//ヒントがっつり見た//キャストやめたら成功するようになった using System; namespace tst { class Program { public static long Gusu(long x) { long cnt = 0; long bunbo = 10; while (x >= bunbo) { cnt += x / bunbo; bunbo *= 5; } return cnt; } /*public static long Kisu(long x) { long sum = 1; for (int i = 1; i <= ((x+1) / 2); i++) { sum *= ((2 * i)-1); } return sum; }*/ public static void Main() { long n = long.Parse(Console.ReadLine()); if (n % 2 == 1) { // val = Kisu(n); //奇数は0になることがない Console.WriteLine(0); } else if (n % 2 == 0) { // 5の出てくる回数を数えよう Console.WriteLine(Gusu(n)); } } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 0, 131], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 74, 51, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["-", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["-", 0, 11, 12, 74, 51, 213, 3, 4, 0, 25]]
8
129
11
using System; using System.Linq; using System.Collections.Generic; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); long sum = 0; long i = 1; while (true) { if (N / (long)Math.Pow(5, i) > 0) { sum += N / (long)Math.Pow(5, i) / 2; } else { break; } i++; } Console.WriteLine(sum); } } }
using System; using System.Linq; using System.Collections.Generic; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); long sum = 0; long i = 1; if (N % 2 == 0) { while (true) { if (N / (long)Math.Pow(5, i) > 0) { sum += N / (long)Math.Pow(5, i) / 2; } else { break; } i++; } Console.WriteLine(sum); } else { Console.WriteLine("0"); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
124
22
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var N = long.Parse(Console.ReadLine()); var count = 0L; while (true) { N = N / 5; if (N == 0) { break; } count += N / 2; } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var N = long.Parse(Console.ReadLine()); var count = 0L; if (N % 2 == 0) { while (true) { N = N / 5; if (N == 0) { break; } count += N / 2; } } Console.WriteLine(count); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 46]]
8
174
10
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderBeginnerContest148 { class Program { static void Main(string[] args) { var input = long.Parse(Console.ReadLine()); if (input % 2 == 1) { Console.WriteLine("0"); return; } long result = 0; var index = 1; while (input > 0) { Console.WriteLine((long)(input / 10)); result += (long)(input / 10); index++; input /= 5; } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderBeginnerContest148 { class Program { static void Main(string[] args) { var input = long.Parse(Console.ReadLine()); if (input % 2 == 1) { Console.WriteLine("0"); return; } long result = 0; var index = 1; while (input > 0) { result += (long)(input / 10); index++; input /= 5; } Console.WriteLine(result); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 24], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 17, 85], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
126
14
using System; public class Program { private long N; public void Solve() { var sc = new Scanner(); N = sc.NextLong(); long ans = 0; // 偶数かつ5の倍数がいくつあるか long l = 1; for (int i = 0;; i++) { l *= 5; if (l * 2 > N) break; ans += N / (l * 2); } Console.WriteLine(ans); } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; public class Program { private long N; public void Solve() { var sc = new Scanner(); N = sc.NextLong(); if (N % 2 == 1) { Console.WriteLine("0"); return; } long ans = 0; // 偶数かつ5の倍数がいくつあるか long l = 1; while (true) { l *= 5; if (l * 2 > N) break; ans += N / (l * 2); } Console.WriteLine(ans); } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146]]
8
528
32
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { long N = GetLong(); if (N == 0) { WriteLine(1); return; } if (N % 2 == 1) { WriteLine(0); return; } WriteLine(Min(cntFactor(N / 2, 2) + 1, cntFactor(N / 2, 5))); } private long cntFactor(long N, long p) { long K = 0; long tmp = N; while (tmp > 0) { K++; tmp /= p; } var pow = new long[K]; pow[0] = p; for (int i = 1; i < K; i++) pow[i] = pow[i - 1] * p; long res = 0; for (int i = 0; i < K; i++) res += N / pow[i]; return res; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class E { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { long N = GetLong(); if (N < 2 || N % 2 == 1) { WriteLine(0); return; } WriteLine(Min(cntFactor(N / 2, 2) + 1, cntFactor(N / 2, 5))); } private long cntFactor(long N, long p) { long K = 0; long tmp = N; while (tmp > 0) { K++; tmp /= p; } var pow = new long[K]; pow[0] = p; for (int i = 1; i < K; i++) pow[i] = pow[i - 1] * p; long res = 0; for (int i = 0; i < K; i++) res += N / pow[i]; return res; } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106]]
8
658
17
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); long N = long.Parse(Console.ReadLine()); if (N % 2 != 0) { Console.WriteLine(0); return; } long n2 = -1; long n5 = 0; long cur = 1; while (true) { long ad = (N / (long)Pow(2, cur)); if (ad == 0) { break; } n2 += ad; cur++; } cur = 1; while (true) { long ad = (N / (long)Pow(5, cur)) / 2; if (ad == 0) { break; } n5 += ad; cur++; } Console.WriteLine(Min(n2, n5)); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Scanner { public int[] ReadSplit() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitL() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplitD() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); long N = long.Parse(Console.ReadLine()); if (N % 2 != 0) { Console.WriteLine(0); return; } if (N == 0) { Console.WriteLine(0); return; } long n2 = -1; long n5 = 0; long cur = 1; while (true) { long ad = (N / (long)Pow(2, cur)); if (ad == 0) { break; } n2 += ad; cur++; } cur = 1; while (true) { long ad = (N / (long)Pow(5, cur)) / 2; if (ad == 0) { break; } n5 += ad; cur++; } Console.WriteLine(Min(n2, n5)); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Scanner { public int[] ReadSplit() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitL() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplitD() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
601
17
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var (N, u, v) = ReadStream<int, int, int>(); u--; v--; var G = new Graph<int>(N); for (int i = 0; i < N - 1; i++) { var r = RInts(x => int.Parse(x) - 1); G.Add(r[0], r[1]); G.Add(r[1], r[0]); } var usedt = Enumerable.Repeat(-1, N).ToArray(); var useda = Enumerable.Repeat(-1, N).ToArray(); var que = new Queue<(int n, int c)>(); que.Enqueue((v, 0)); useda[v] = 0; while (que.Count > 0) { var t = que.Dequeue(); int n = t.n; int c = t.c; foreach (var i in G[n]) { if (useda[i] != -1) continue; useda[i] = c + 1; que.Enqueue((i, c + 1)); } } que = new Queue<(int n, int c)>(); que.Enqueue((u, 0)); usedt[u] = 0; while (que.Count > 0) { var t = que.Dequeue(); int n = t.n; int c = t.c; foreach (var i in G[n]) { if (usedt[i] != -1) continue; if (useda[i] < c + 1) continue; if (useda[i] == c + 1) { usedt[i] = c + 1; continue; } usedt[i] = c + 1; que.Enqueue((i, c + 1)); } } int ans = 0; for (int i = 0; i < N; i++) { if (usedt[i] == -1) continue; int time = usedt[i]; if (useda[i] - usedt[i] > 0) time += (useda[i] - usedt[i] - 1) / 2 * 2; ans = Math.Max(ans, time); } WriteLine(ans); } } class Graph<T> { private List<T>[] G; public Graph(int size) { G = new List<T>[size]; for (int i = 0; i < size; i++) { G[i] = new List<T>(); } } public List<T> this[int i] => G[i]; public void Add(int from, T to) => G[from].Add(to); public List<T>[] ToListArray() => G; public int Length => G.Length; } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { var (N, u, v) = ReadStream<int, int, int>(); u--; v--; var G = new Graph<int>(N); for (int i = 0; i < N - 1; i++) { var r = RInts(x => int.Parse(x) - 1); G.Add(r[0], r[1]); G.Add(r[1], r[0]); } var usedt = Enumerable.Repeat(-1, N).ToArray(); var useda = Enumerable.Repeat(-1, N).ToArray(); var que = new Queue<(int n, int c)>(); que.Enqueue((v, 0)); useda[v] = 0; while (que.Count > 0) { var t = que.Dequeue(); int n = t.n; int c = t.c; foreach (var i in G[n]) { if (useda[i] != -1) continue; useda[i] = c + 1; que.Enqueue((i, c + 1)); } } que = new Queue<(int n, int c)>(); que.Enqueue((u, 0)); usedt[u] = 0; while (que.Count > 0) { var t = que.Dequeue(); int n = t.n; int c = t.c; foreach (var i in G[n]) { if (usedt[i] != -1) continue; if (useda[i] == c) continue; if (useda[i] == c + 1) { usedt[i] = c + 1; continue; } usedt[i] = c + 1; que.Enqueue((i, c + 1)); } } int ans = 0; for (int i = 0; i < N; i++) { if (usedt[i] == -1) continue; int time = usedt[i]; if (useda[i] - usedt[i] > 0) time += (useda[i] - usedt[i] - 1); ans = Math.Max(ans, time); } WriteLine(ans); } } class Graph<T> { private List<T>[] G; public Graph(int size) { G = new List<T>[size]; for (int i = 0; i < size; i++) { G[i] = new List<T>(); } } public List<T> this[int i] => G[i]; public void Add(int from, T to) => G[from].Add(to); public List<T>[] ToListArray() => G; public int Length => G.Length; } class Scanner { public static int RInt() => int.Parse(Console.ReadLine()); public static long RLong() => long.Parse(Console.ReadLine()); public static string RString() => Console.ReadLine(); public static double RDouble() => double.Parse(Console.ReadLine()); public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadStream<T1>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); return r1; } public static (T1, T2) ReadStream<T1, T2>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); return (r1, r2); } public static (T1, T2, T3) ReadStream<T1, T2, T3>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); return (r1, r2, r3); } public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>() { var r = RStrings(); var r1 = (T1)Convert.ChangeType(r[0], typeof(T1)); var r2 = (T2)Convert.ChangeType(r[1], typeof(T2)); var r3 = (T3)Convert.ChangeType(r[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 64, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 64, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203]]
8
1,277
8
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC148F { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var u = NN - 1; var v = NN - 1; var AB = Repeat(0, N - 1).Select(_ => new { A = NN - 1, B = NN - 1 }).ToArray(); var path = Repeat(0, N).Select(_ => new List<long>()).ToArray(); foreach (var item in AB) { path[item.A].Add(item.B); path[item.B].Add(item.A); } Func<long, long, long, long> dfs0 = null; Func<long, long, long, long> dfs1 = null; Func<long, long, long> dfs2 = null; Func<long, long, long> dfs3 = null; var saienTyoten = -1L; var saienKyori = 0L; var map = new long[N]; dfs0 = (vtx, parent, dist) => { map[vtx] = dist; foreach (var item in path[vtx]) { if (item == parent) continue; dfs0(item, vtx, dist + 1); } return 0; }; dfs1 = (vtx, parent, dist) => { if (map[vtx] <= dist) return 0; if (saienKyori < dist) { saienKyori = dist; saienTyoten = vtx; } foreach (var item in path[vtx]) { if (item == parent) continue; dfs1(item, vtx, dist + 1); } return 0; }; dfs2 = (vtx, parent) => { var ret = -1L; if (vtx == saienTyoten) { return 0; } foreach (var item in path[vtx]) { if (item == parent) continue; ret = Max(dfs2(item, vtx), ret); } if (ret == -1) return -1; return ret + 1; }; dfs3 = (vtx, parent) => { var ret = -1L; if (vtx == u) { return 0; } foreach (var item in path[vtx]) { if (item == parent) continue; ret = Max(dfs3(item, vtx), ret); } if (ret == -1) return -1; return ret + 1; }; dfs0(v, -1, 0); dfs1(u, -1, 0); Console.WriteLine(Max(dfs2(v, -1), dfs3(v, -1)) - 1); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library {}
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC148F { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var u = NN - 1; var v = NN - 1; var AB = Repeat(0, N - 1).Select(_ => new { A = NN - 1, B = NN - 1 }).ToArray(); var path = Repeat(0, N).Select(_ => new List<long>()).ToArray(); foreach (var item in AB) { path[item.A].Add(item.B); path[item.B].Add(item.A); } Func<long, long, long, long> dfs0 = null; Func<long, long, long, long> dfs1 = null; Func<long, long, long> dfs2 = null; Func<long, long, long> dfs3 = null; var saienTyoten = -1L; var saienKyori = 0L; var map = new long[N]; dfs0 = (vtx, parent, dist) => { map[vtx] = dist; foreach (var item in path[vtx]) { if (item == parent) continue; dfs0(item, vtx, dist + 1); } return 0; }; dfs1 = (vtx, parent, dist) => { if (map[vtx] <= dist) return 0; if (saienKyori < map[vtx]) { saienKyori = map[vtx]; saienTyoten = vtx; } foreach (var item in path[vtx]) { if (item == parent) continue; dfs1(item, vtx, dist + 1); } return 0; }; dfs2 = (vtx, parent) => { var ret = -1L; if (vtx == saienTyoten) { return 0; } foreach (var item in path[vtx]) { if (item == parent) continue; ret = Max(dfs2(item, vtx), ret); } if (ret == -1) return -1; return ret + 1; }; dfs3 = (vtx, parent) => { var ret = -1L; if (vtx == u) { return 0; } foreach (var item in path[vtx]) { if (item == parent) continue; ret = Max(dfs3(item, vtx), ret); } if (ret == -1) return -1; return ret + 1; }; dfs0(v, -1, 0); dfs1(u, -1, 0); Console.WriteLine(Max(dfs2(v, -1), dfs3(v, -1)) - 1); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library {}
[["-", 12, 218, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
8
1,206
10
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { int N; int u; int v; Multi(out N, out u, out v); u--; v--; var G = GetUnweightedAdjacencyList(N, N - 1, false, false); var vlength = new int [N].Select(s => -1L).ToArray(); var queue = new Queue<int>(); vlength[v] = 0; queue.Enqueue(v); while (queue.Count() > 0) { var now = queue.Dequeue(); foreach (var next in G[now]) { if (vlength[next] != -1) continue; vlength[next] = vlength[now] + 1; queue.Enqueue(next); } } var ulength = new int [N].Select(s => -1L).ToArray(); queue = new Queue<int>(); ulength[u] = 0; queue.Enqueue(u); while (queue.Count() > 0) { var now = queue.Dequeue(); foreach (var next in G[now]) { if (ulength[next] != -1) continue; if (vlength[next] <= ulength[now] + 1) continue; ulength[next] = ulength[now] + 1; queue.Enqueue(next); } } var target = -1; long max = -1; for (int i = 0; i < N; i++) { if (ulength[i] > max) { max = ulength[i]; target = i; } } var dif = vlength[target] - ulength[target]; if (dif < 0) { while (true) ; } var ans = ulength[target] + dif / 2; Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { int N; int u; int v; Multi(out N, out u, out v); u--; v--; var G = GetUnweightedAdjacencyList(N, N - 1, false, false); var vlength = new int [N].Select(s => -1L).ToArray(); var queue = new Queue<int>(); vlength[v] = 0; queue.Enqueue(v); while (queue.Count() > 0) { var now = queue.Dequeue(); foreach (var next in G[now]) { if (vlength[next] != -1) continue; vlength[next] = vlength[now] + 1; queue.Enqueue(next); } } var ulength = new int [N].Select(s => -1L).ToArray(); queue = new Queue<int>(); ulength[u] = 0; queue.Enqueue(u); while (queue.Count() > 0) { var now = queue.Dequeue(); foreach (var next in G[now]) { if (ulength[next] != -1) continue; if (vlength[next] <= ulength[now] + 1) continue; ulength[next] = ulength[now] + 1; queue.Enqueue(next); } } var target = -1; long max = -1; for (int i = 0; i < N; i++) { if (vlength[i] > max && ulength[i] >= 0) { max = vlength[i]; target = i; } } var dif = vlength[target] - ulength[target]; if (dif < 0) { while (true) ; } var ans = ulength[target] + dif - 1; Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 17, 85], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
2,081
15
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { N = sc.ReadInt(); U = sc.ReadInt(); V = sc.ReadInt(); U--; V--; G = new List<int>[N]; for (int i = 0; i < N; i++) { G[i] = new List<int>(); } var dij = new Dijkstra(N); for (int i = 0; i < N - 1; i++) { var a = sc.ReadInt(); var b = sc.ReadInt(); a--; b--; G[a].Add(b); G[b].Add(a); dij.Add(a, b); dij.Add(b, a); } var distU = dij.Calc(U); var distV = dij.Calc(V); var ans = 0L; for (int i = 0; i < N; i++) { if (distU[i] < distV[i]) { var res = distU[i]; if (distU[V] % 2 == 0) res++; ans = Math.Max(ans, res); } } Console.WriteLine(ans); } static int N, U, V; static List<int>[] G; class Dijkstra { public const long INF = long.MaxValue / 2; public int V { get; set; } public int E { get; set; } public List<Edge>[] G { get; set; } public Dijkstra(int n) { this.V = n; this.G = new List<Edge>[V]; for (int i = 0; i < V; i++) { this.G[i] = new List<Edge>(); } } public void Add(int a, int b, long cost = 1) { this.G[a].Add(new Edge(b, cost)); this.E++; } public long GetMinCost(int start, int goal) { var cost = new long[V]; for (int i = 0; i < V; i++) cost[i] = INF; cost[start] = 0; var capacity = Math.Max(1, E); var q = new PriorityQueue<P>(false); q.Enqueue(new P(start, 0)); while (q.Count > 0) { var p = q.Dequeue(); if (p.Cost != cost[p.A]) continue; foreach (var e in this.G[p.A]) { if (cost[e.To] > p.Cost + e.Cost) { cost[e.To] = p.Cost + e.Cost; q.Enqueue(new P(e.To, cost[e.To])); } } } return cost[goal] == long.MaxValue ? -1 : cost[goal]; } public long[] Calc(int start) { var visited = new bool[V]; var cost = new long[V]; for (int i = 0; i < V; i++) cost[i] = INF; cost[start] = 0; var capacity = Math.Max(1, E); var q = new PriorityQueue<P>(false); q.Enqueue(new P(start, 0)); while (q.Count > 0) { var p = q.Dequeue(); visited[p.A] = true; if (p.Cost != cost[p.A]) continue; foreach (var e in this.G[p.A]) { if (cost[e.To] > p.Cost + e.Cost && !visited[e.To]) { cost[e.To] = p.Cost + e.Cost; q.Enqueue(new P(e.To, cost[e.To])); } } } return cost; } public struct Edge { public int To; public long Cost; public Edge(int to, long cost) { this.To = to; this.Cost = cost; } } public struct P : IComparable<P> { public int A; public long Cost; public P(int a, long cost) { this.A = a; this.Cost = cost; } public int CompareTo(P other) { return this.Cost.CompareTo(other.Cost); } } class PriorityQueue<T> { public int Count; private int Capacity; private bool IsMaxHeap; private T[] Buffer; private IComparer<T> Cmp; public PriorityQueue(bool isMaxHeap = true, IComparer<T> cmp = null) { Count = 0; Capacity = 1 << 10; IsMaxHeap = isMaxHeap; Buffer = new T[Capacity]; if (cmp != null) Cmp = cmp; else Cmp = Comparer<T>.Default; } public PriorityQueue(int capacity, bool isMaxHeap = true, IComparer<T> cmp = null) { Count = 0; Capacity = Math.Max(16, capacity); IsMaxHeap = isMaxHeap; Buffer = new T[Capacity]; if (cmp != null) Cmp = cmp; else Cmp = Comparer<T>.Default; } private void Resize() { Capacity <<= 1; Array.Resize(ref Buffer, Capacity); } public void Enqueue(T value) { if (Count == Capacity) Resize(); Buffer[Count] = value; Count++; UpHeap(); } public T Dequeue() { var res = Buffer[0]; Swap(0, Count - 1); Count--; DownHeap(); return res; } public T Peek() { return Buffer[0]; } private void Swap(int i, int j) { var tmp = Buffer[i]; Buffer[i] = Buffer[j]; Buffer[j] = tmp; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (Compare(Buffer[n], Buffer[parent]) > 0) { Swap(n, parent); n = parent; } else break; } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < Count - 1 && Compare(Buffer[child], Buffer[child + 1]) < 0) { child += 1; } if (Compare(Buffer[parent], Buffer[child]) < 0) { Swap(parent, child); parent = child; } else break; } } private int Compare(T x, T y) { var res = Cmp.Compare(x, y); if (!IsMaxHeap) res *= -1; return res; } } } 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; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { N = sc.ReadInt(); U = sc.ReadInt(); V = sc.ReadInt(); U--; V--; G = new List<int>[N]; for (int i = 0; i < N; i++) { G[i] = new List<int>(); } var dij = new Dijkstra(N); for (int i = 0; i < N - 1; i++) { var a = sc.ReadInt(); var b = sc.ReadInt(); a--; b--; G[a].Add(b); G[b].Add(a); dij.Add(a, b); dij.Add(b, a); } var distU = dij.Calc(U); var distV = dij.Calc(V); var ans = 0L; for (int i = 0; i < N; i++) { if (distU[i] < distV[i]) { var res = distV[i] - 1; ans = Math.Max(ans, res); } } Console.WriteLine(ans); } static int N, U, V; static List<int>[] G; class Dijkstra { public const long INF = long.MaxValue / 2; public int V { get; set; } public int E { get; set; } public List<Edge>[] G { get; set; } public Dijkstra(int n) { this.V = n; this.G = new List<Edge>[V]; for (int i = 0; i < V; i++) { this.G[i] = new List<Edge>(); } } public void Add(int a, int b, long cost = 1) { this.G[a].Add(new Edge(b, cost)); this.E++; } public long GetMinCost(int start, int goal) { var cost = new long[V]; for (int i = 0; i < V; i++) cost[i] = INF; cost[start] = 0; var capacity = Math.Max(1, E); var q = new PriorityQueue<P>(false); q.Enqueue(new P(start, 0)); while (q.Count > 0) { var p = q.Dequeue(); if (p.Cost != cost[p.A]) continue; foreach (var e in this.G[p.A]) { if (cost[e.To] > p.Cost + e.Cost) { cost[e.To] = p.Cost + e.Cost; q.Enqueue(new P(e.To, cost[e.To])); } } } return cost[goal] == long.MaxValue ? -1 : cost[goal]; } public long[] Calc(int start) { var visited = new bool[V]; var cost = new long[V]; for (int i = 0; i < V; i++) cost[i] = INF; cost[start] = 0; var capacity = Math.Max(1, E); var q = new PriorityQueue<P>(false); q.Enqueue(new P(start, 0)); while (q.Count > 0) { var p = q.Dequeue(); visited[p.A] = true; if (p.Cost != cost[p.A]) continue; foreach (var e in this.G[p.A]) { if (cost[e.To] > p.Cost + e.Cost && !visited[e.To]) { cost[e.To] = p.Cost + e.Cost; q.Enqueue(new P(e.To, cost[e.To])); } } } return cost; } public struct Edge { public int To; public long Cost; public Edge(int to, long cost) { this.To = to; this.Cost = cost; } } public struct P : IComparable<P> { public int A; public long Cost; public P(int a, long cost) { this.A = a; this.Cost = cost; } public int CompareTo(P other) { return this.Cost.CompareTo(other.Cost); } } class PriorityQueue<T> { public int Count; private int Capacity; private bool IsMaxHeap; private T[] Buffer; private IComparer<T> Cmp; public PriorityQueue(bool isMaxHeap = true, IComparer<T> cmp = null) { Count = 0; Capacity = 1 << 10; IsMaxHeap = isMaxHeap; Buffer = new T[Capacity]; if (cmp != null) Cmp = cmp; else Cmp = Comparer<T>.Default; } public PriorityQueue(int capacity, bool isMaxHeap = true, IComparer<T> cmp = null) { Count = 0; Capacity = Math.Max(16, capacity); IsMaxHeap = isMaxHeap; Buffer = new T[Capacity]; if (cmp != null) Cmp = cmp; else Cmp = Comparer<T>.Default; } private void Resize() { Capacity <<= 1; Array.Resize(ref Buffer, Capacity); } public void Enqueue(T value) { if (Count == Capacity) Resize(); Buffer[Count] = value; Count++; UpHeap(); } public T Dequeue() { var res = Buffer[0]; Swap(0, Count - 1); Count--; DownHeap(); return res; } public T Peek() { return Buffer[0]; } private void Swap(int i, int j) { var tmp = Buffer[i]; Buffer[i] = Buffer[j]; Buffer[j] = tmp; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (Compare(Buffer[n], Buffer[parent]) > 0) { Swap(n, parent); n = parent; } else break; } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < Count - 1 && Compare(Buffer[child], Buffer[child + 1]) < 0) { child += 1; } if (Compare(Buffer[parent], Buffer[child]) < 0) { Swap(parent, child); parent = child; } else break; } } private int Compare(T x, T y) { var res = Cmp.Compare(x, y); if (!IsMaxHeap) res *= -1; return res; } } } 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, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 64, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 64, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["-", 64, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
2,501
18
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static Asakatsu20200317E.Input; using static System.Math; namespace Asakatsu20200317E { class Input { private static String String() => Console.ReadLine(); private static IEnumerable<string> Split() => String().Split(' '); private static long[] Long() => Split().Select(long.Parse).ToArray(); /// <summary> /// 1行の文字列の入力 /// </summary> public static void @in(out string s) => s = String(); /// <summary> /// 複数行の文字列の入力 /// </summary> public static void @in(long rowNumber, out string[] s) { s = new String[rowNumber]; for (long i = 0; i < rowNumber; i++) @in(out s[i]); } /// <summary> /// 1行に書かれた1つの整数の入力 /// </summary> public static void @in(out int i) { i = int.Parse(String()); } /// <summary> /// 1行に書かれた1つの整数の入力 /// </summary> public static void @in(out long a) => a = Long()[0]; /// <summary> /// 1行に書かれた2つの整数の入力 /// </summary> public static void @in(out long a, out long b) { long[] lArr = Long(); a = lArr[0]; b = lArr[1]; } /// <summary> /// 1行に書かれた3つの整数の入力 /// </summary> public static void @in(out long a, out long b, out long c) { long[] lArr = Long(); a = lArr[0]; b = lArr[1]; c = lArr[2]; } /// <summary> /// 1行に書かれた4つの整数の入力 /// </summary> public static void @in(out long a, out long b, out long c, out long d) { long[] lArr = Long(); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; } /// <summary> /// 1行に書かれた5つの整数の入力 /// </summary> public static void @in(out long a, out long b, out long c, out long d, out long e) { long[] lArr = Long(); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; e = lArr[4]; } /// <summary> /// 1行に書かれた複数の整数列の入力 /// </summary> public static void @in(out long[] lArr) => lArr = Long(); /// <summary> /// rowNumber行に書かれた1つの整数列の入力 /// </summary> public static void @in(long rowNumber, out long[] lArr) { lArr = new long[rowNumber]; for (long i = 0; i < rowNumber; i++) @in(out lArr[i]); } /// <summary> /// rowNumber行に書かれた2つの整数列の入力 /// </summary> public static void @in(long rowNumber, out long[] a, out long[] b) { a = new long[rowNumber]; b = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) @in(out a[i], out b[i]); } /// <summary> /// rowNumber行に書かれた3つの整数列の入力 /// </summary> public static void @in(long rowNumber, out long[] a, out long[] b, out long[] c) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) @in(out a[i], out b[i], out c[i]); } /// <summary> /// rowNumber行に書かれた4つの整数列の入力 /// </summary> public static void @in(long rowNumber, out long[] a, out long[] b, out long[] c, out long[] d) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; d = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) @in(out a[i], out b[i], out c[i], out d[i]); } /// <summary> /// h行w列の整数の行列の入力 /// </summary> public static void @in(long h, long w, out long[][] a) { a = new long [h][]; for (long i = 0; i < h; i++) @in(out a[i]); } /// <summary> /// 1行に書かれた1つの小数の入力 /// </summary> public static void @in(out double d) => d = double.Parse(String()); /// <summary> /// 1行に書かれた小数の配列の入力 /// </summary> public static void @in(out double[] dArr) => dArr = Split().Select(double.Parse).ToArray(); } class Program { public static void Main(string[] args) { StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); new Solver().Solve(); Console.Out.Flush(); } public static void Debug() { new Solver().Solve(); } } class Solver { private long N; private long u; private long v; private long[] A; private long[] B; public void Solve() { @in(out N, out u, out v); @in(N - 1, out A, out B); HashSet<long>[] tree = new HashSet<long>[N + 1]; for (int i = 0; i < N + 1; i++) { tree[i] = new HashSet<long>(); } for (int i = 0; i < N - 1; i++) { tree[A[i]].Add(B[i]); tree[B[i]].Add(A[i]); } long[] tDiff = new long[N + 1]; long[] aDiff = new long[N + 1]; Queue<long> q = new Queue<long>(); HashSet<long> memo = new HashSet<long>(); tDiff[u] = 0; memo.Add(u); q.Enqueue(u); while (q.Count > 0) { var c = q.Dequeue(); foreach (long l in tree[c]) { if (memo.Contains(l)) { continue; } memo.Add(l); q.Enqueue(l); tDiff[l] = tDiff[c] + 1; } } q = new Queue<long>(); memo = new HashSet<long>(); aDiff[v] = 0; memo.Add(v); q.Enqueue(v); while (q.Count > 0) { var c = q.Dequeue(); foreach (long l in tree[c]) { if (memo.Contains(l)) { continue; } memo.Add(l); q.Enqueue(l); aDiff[l] = aDiff[c] + 1; } } long ans = 0; for (int i = 1; i <= N; i++) { if (aDiff[i] > tDiff[i]) { ans = aDiff[i]; } } Console.WriteLine(ans - 1); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static Asakatsu20200317E.Input; using static System.Math; namespace Asakatsu20200317E { class Input { private static String String() => Console.ReadLine(); private static IEnumerable<string> Split() => String().Split(' '); private static long[] Long() => Split().Select(long.Parse).ToArray(); /// <summary> /// 1行の文字列の入力 /// </summary> public static void @in(out string s) => s = String(); /// <summary> /// 複数行の文字列の入力 /// </summary> public static void @in(long rowNumber, out string[] s) { s = new String[rowNumber]; for (long i = 0; i < rowNumber; i++) @in(out s[i]); } /// <summary> /// 1行に書かれた1つの整数の入力 /// </summary> public static void @in(out int i) { i = int.Parse(String()); } /// <summary> /// 1行に書かれた1つの整数の入力 /// </summary> public static void @in(out long a) => a = Long()[0]; /// <summary> /// 1行に書かれた2つの整数の入力 /// </summary> public static void @in(out long a, out long b) { long[] lArr = Long(); a = lArr[0]; b = lArr[1]; } /// <summary> /// 1行に書かれた3つの整数の入力 /// </summary> public static void @in(out long a, out long b, out long c) { long[] lArr = Long(); a = lArr[0]; b = lArr[1]; c = lArr[2]; } /// <summary> /// 1行に書かれた4つの整数の入力 /// </summary> public static void @in(out long a, out long b, out long c, out long d) { long[] lArr = Long(); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; } /// <summary> /// 1行に書かれた5つの整数の入力 /// </summary> public static void @in(out long a, out long b, out long c, out long d, out long e) { long[] lArr = Long(); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; e = lArr[4]; } /// <summary> /// 1行に書かれた複数の整数列の入力 /// </summary> public static void @in(out long[] lArr) => lArr = Long(); /// <summary> /// rowNumber行に書かれた1つの整数列の入力 /// </summary> public static void @in(long rowNumber, out long[] lArr) { lArr = new long[rowNumber]; for (long i = 0; i < rowNumber; i++) @in(out lArr[i]); } /// <summary> /// rowNumber行に書かれた2つの整数列の入力 /// </summary> public static void @in(long rowNumber, out long[] a, out long[] b) { a = new long[rowNumber]; b = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) @in(out a[i], out b[i]); } /// <summary> /// rowNumber行に書かれた3つの整数列の入力 /// </summary> public static void @in(long rowNumber, out long[] a, out long[] b, out long[] c) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) @in(out a[i], out b[i], out c[i]); } /// <summary> /// rowNumber行に書かれた4つの整数列の入力 /// </summary> public static void @in(long rowNumber, out long[] a, out long[] b, out long[] c, out long[] d) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; d = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) @in(out a[i], out b[i], out c[i], out d[i]); } /// <summary> /// h行w列の整数の行列の入力 /// </summary> public static void @in(long h, long w, out long[][] a) { a = new long [h][]; for (long i = 0; i < h; i++) @in(out a[i]); } /// <summary> /// 1行に書かれた1つの小数の入力 /// </summary> public static void @in(out double d) => d = double.Parse(String()); /// <summary> /// 1行に書かれた小数の配列の入力 /// </summary> public static void @in(out double[] dArr) => dArr = Split().Select(double.Parse).ToArray(); } class Program { public static void Main(string[] args) { StreamWriter streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(streamWriter); new Solver().Solve(); Console.Out.Flush(); } public static void Debug() { new Solver().Solve(); } } class Solver { private long N; private long u; private long v; private long[] A; private long[] B; public void Solve() { @in(out N, out u, out v); @in(N - 1, out A, out B); HashSet<long>[] tree = new HashSet<long>[N + 1]; for (int i = 0; i < N + 1; i++) { tree[i] = new HashSet<long>(); } for (int i = 0; i < N - 1; i++) { tree[A[i]].Add(B[i]); tree[B[i]].Add(A[i]); } long[] t = new long[N + 1]; long[] a = new long[N + 1]; Queue<long> q = new Queue<long>(); HashSet<long> memo = new HashSet<long>(); t[u] = 0; memo.Add(u); q.Enqueue(u); while (q.Count > 0) { var c = q.Dequeue(); foreach (long l in tree[c]) { if (memo.Contains(l)) { continue; } memo.Add(l); q.Enqueue(l); t[l] = t[c] + 1; } } q = new Queue<long>(); memo = new HashSet<long>(); a[v] = 0; memo.Add(v); q.Enqueue(v); while (q.Count > 0) { var c = q.Dequeue(); foreach (long l in tree[c]) { if (memo.Contains(l)) { continue; } memo.Add(l); q.Enqueue(l); a[l] = a[c] + 1; } } long ans = 0; for (int i = 1; i <= N; i++) { if (a[i] > t[i]) { ans = Max(a[i], ans); } } Console.WriteLine(ans - 1); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
1,440
27
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static long[] distanceMemos = new long[2]; //キューから捨てた最短距離と頂点番号 static void Main() { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int u = int.Parse(input[1]) - 1; int v = int.Parse(input[2]) - 1; int answer = 0; int e = n - 1; long[,] edges = new long[2 * e, 3]; long[] answersU = new long[n]; long[] answersV = new long[n]; long[][] answersUV = new long [n][]; for (int i = 0; i < n; i++) { answersUV[i] = new long[2]; } for (long i = 0; i < e; i++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); edges[2 * i, 0] = nums[0] - 1; //有向辺でないなら2本必要 edges[2 * i, 1] = nums[1] - 1; edges[2 * i, 2] = 1; edges[2 * i + 1, 0] = nums[1] - 1; //有向辺でないなら2本必要 edges[2 * i + 1, 1] = nums[0] - 1; edges[2 * i + 1, 2] = 1; } answersU = Dijkstra(n, u, edges); answersV = Dijkstra(n, v, edges); for (int i = 0; i < n; i++) { answersUV[i][0] = answersU[i]; answersUV[i][1] = answersV[i]; } Array.Sort(answersUV, (a, b) => a[0].CompareTo(b[0])); for (int i = 0; i < n; i++) { if (answersUV[i][0] <= answersUV[i][1]) { if ((answersUV[i][1] - answersUV[i][0]) == 0) //同じ場所になる { answer = (int)Math.Max(answer, answersUV[i][1]); break; } else answer = (int)Math.Max(answer, answersUV[i][1] - 1); } } Console.WriteLine(answer); } static long[] Dijkstra(int vertexCount, int startV, long[, ] edges) { //ダイクストラ法により、O((|頂点数|+|辺数|)log頂点数)で各頂点への最短距離を求める //引数は頂点数、辺数、開始頂点(0-index)、辺の始点と終点と距離 //返り値は各頂点までの最短距離、ただし到達できない場合は-1 int n = vertexCount; int edgeCount = edges.GetLength(0); List<long[]>[] nextList = new List<long[]>[n]; //頂点番号ごとの隣接リスト。距離、隣接頂点番号 for (long i = 0; i < n; i++) { nextList[i] = new List<long[]>(); //リストの宣言が必要 } long[] colors = new long[n]; //最短距離未確定の頂点が0、確定で2 long[] distances = new long[n]; //各頂点への最短距離 for (long i = 0; i < edgeCount; i++) { long[] nextMemo = new long[2]; nextMemo[1] = edges[i, 1]; //隣接頂点番号 nextMemo[0] = edges[i, 2]; //距離 nextList[edges[i, 0]].Add(nextMemo); //隣接リストの作成 } List<long[]> distanceList = new List<long[]>(); //優先度付きキュー for (long i = 0; i < n; i++) { distances[i] = long.MaxValue; //最短距離を無限とおく } long[] newDistance = new long[2]; //スタート地点を決める newDistance[1] = startV; //スタート地点番号 distances[startV] = 0; colors[startV] = 1; newDistance[0] = 0; //スタートからスタートまでの距離0 distanceList.Add(newDistance); while (distanceList.Count() != 0) { distanceList = PopHeap(distanceList); long minVertex = distanceMemos[1]; //最短頂点の番号 colors[minVertex] = 2; if (distances[minVertex] < distanceMemos[0]) continue; //最小値が最短でないなら無視 for (long i = 0; i < nextList[minVertex].Count(); i++) { long v = nextList[minVertex][(int)i][1]; if (colors[v] == 2) continue; if (distances[v] > distances[minVertex] + nextList[minVertex][(int)i][0]) { distances[v] = distances[minVertex] + nextList[minVertex][(int)i][0]; long[] newDistanceSub = new long[2]; newDistanceSub[0] = distances[v]; newDistanceSub[1] = v; distanceList = PushHeap(distanceList, newDistanceSub); colors[v] = 1; } } } for (long i = 0; i < n; i++) { if (distances[i] == long.MaxValue) distances[i] = -1; //全頂点について最短距離の出力。到達不可能な頂点は-1を出力。 } return distances; } //引数は、昇順にソート済みのリスト static List<long[]> PushHeap(List<long[]> nums, long[] addNums) //現在のヒープnumsにaddNumを追加 { int n = nums.Count; nums.Add(addNums); while (n > 0) { int i = (n - 1) / 2; if (nums[n][0] < nums[i][0]) //親のほうが大きいなら入れ替え。 { long tmp = nums[n][0]; long tmpSub = nums[n][1]; nums[n][0] = nums[i][0]; nums[n][1] = nums[i][1]; nums[i][0] = tmp; nums[i][1] = tmpSub; } n = i; } return nums; } static List<long[]> PopHeap(List<long[]> nums) //ヒープnumsからポップ { int n = nums.Count - 1; distanceMemos[0] = nums[0][0]; //捨てる値の保存 distanceMemos[1] = nums[0][1]; nums[0][0] = nums[n][0]; //最小値である根を削除してリストの最後を持ってくる nums[0][1] = nums[n][1]; nums.RemoveAt(n); for (int i = 0, j; (j = 2 * i + 1) < n;) { if ((j != n - 1) && (nums[j][0] > nums[j + 1][0])) // 2つの子のうち、値の小さい方を選ぶ j++; if (nums[i][0] > nums[j][0]) //子が親より小さいなら入れ替え { long tmp = nums[j][0]; long tmpSub = nums[j][1]; nums[j][0] = nums[i][0]; nums[j][1] = nums[i][1]; nums[i][0] = tmp; nums[i][1] = tmpSub; } i = j; } return nums; } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static long[] distanceMemos = new long[2]; //キューから捨てた最短距離と頂点番号 static void Main() { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int u = int.Parse(input[1]) - 1; int v = int.Parse(input[2]) - 1; int answer = 0; bool skip = false; int e = n - 1; long[,] edges = new long[2 * e, 3]; long[] answersU = new long[n]; long[] answersV = new long[n]; long[][] answersUV = new long [n][]; for (int i = 0; i < n; i++) { answersUV[i] = new long[2]; } for (long i = 0; i < e; i++) { long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); edges[2 * i, 0] = nums[0] - 1; //有向辺でないなら2本必要 edges[2 * i, 1] = nums[1] - 1; edges[2 * i, 2] = 1; edges[2 * i + 1, 0] = nums[1] - 1; //有向辺でないなら2本必要 edges[2 * i + 1, 1] = nums[0] - 1; edges[2 * i + 1, 2] = 1; } answersU = Dijkstra(n, u, edges); answersV = Dijkstra(n, v, edges); for (int i = 0; i < n; i++) { answersUV[i][0] = answersU[i]; answersUV[i][1] = answersV[i]; } Array.Sort(answersUV, (a, b) => a[0].CompareTo(b[0])); for (int i = 0; i < n; i++) { // Console.WriteLine(answersUV[i][0]+" "+answersUV[i][1]); if (answersUV[i][0] <= answersUV[i][1]) { if ((answersUV[i][1] - answersUV[i][0]) == 0 && (!skip)) //同じ場所になるしかない { answer = (int)Math.Max(answer, answersUV[i][1]); skip = true; } else { answer = (int)Math.Max(answer, answersUV[i][1] - 1); } } } Console.WriteLine(answer); } static long[] Dijkstra(int vertexCount, int startV, long[, ] edges) { //ダイクストラ法により、O((|頂点数|+|辺数|)log頂点数)で各頂点への最短距離を求める //引数は頂点数、辺数、開始頂点(0-index)、辺の始点と終点と距離 //返り値は各頂点までの最短距離、ただし到達できない場合は-1 int n = vertexCount; int edgeCount = edges.GetLength(0); List<long[]>[] nextList = new List<long[]>[n]; //頂点番号ごとの隣接リスト。距離、隣接頂点番号 for (long i = 0; i < n; i++) { nextList[i] = new List<long[]>(); //リストの宣言が必要 } long[] colors = new long[n]; //最短距離未確定の頂点が0、確定で2 long[] distances = new long[n]; //各頂点への最短距離 for (long i = 0; i < edgeCount; i++) { long[] nextMemo = new long[2]; nextMemo[1] = edges[i, 1]; //隣接頂点番号 nextMemo[0] = edges[i, 2]; //距離 nextList[edges[i, 0]].Add(nextMemo); //隣接リストの作成 } List<long[]> distanceList = new List<long[]>(); //優先度付きキュー for (long i = 0; i < n; i++) { distances[i] = long.MaxValue; //最短距離を無限とおく } long[] newDistance = new long[2]; //スタート地点を決める newDistance[1] = startV; //スタート地点番号 distances[startV] = 0; colors[startV] = 1; newDistance[0] = 0; //スタートからスタートまでの距離0 distanceList.Add(newDistance); while (distanceList.Count() != 0) { distanceList = PopHeap(distanceList); long minVertex = distanceMemos[1]; //最短頂点の番号 colors[minVertex] = 2; if (distances[minVertex] < distanceMemos[0]) continue; //最小値が最短でないなら無視 for (long i = 0; i < nextList[minVertex].Count(); i++) { long v = nextList[minVertex][(int)i][1]; if (colors[v] == 2) continue; if (distances[v] > distances[minVertex] + nextList[minVertex][(int)i][0]) { distances[v] = distances[minVertex] + nextList[minVertex][(int)i][0]; long[] newDistanceSub = new long[2]; newDistanceSub[0] = distances[v]; newDistanceSub[1] = v; distanceList = PushHeap(distanceList, newDistanceSub); colors[v] = 1; } } } for (long i = 0; i < n; i++) { if (distances[i] == long.MaxValue) distances[i] = -1; //全頂点について最短距離の出力。到達不可能な頂点は-1を出力。 } return distances; } //引数は、昇順にソート済みのリスト static List<long[]> PushHeap(List<long[]> nums, long[] addNums) //現在のヒープnumsにaddNumを追加 { int n = nums.Count; nums.Add(addNums); while (n > 0) { int i = (n - 1) / 2; if (nums[n][0] < nums[i][0]) //親のほうが大きいなら入れ替え。 { long tmp = nums[n][0]; long tmpSub = nums[n][1]; nums[n][0] = nums[i][0]; nums[n][1] = nums[i][1]; nums[i][0] = tmp; nums[i][1] = tmpSub; } n = i; } return nums; } static List<long[]> PopHeap(List<long[]> nums) //ヒープnumsからポップ { int n = nums.Count - 1; distanceMemos[0] = nums[0][0]; //捨てる値の保存 distanceMemos[1] = nums[0][1]; nums[0][0] = nums[n][0]; //最小値である根を削除してリストの最後を持ってくる nums[0][1] = nums[n][1]; nums.RemoveAt(n); for (int i = 0, j; (j = 2 * i + 1) < n;) { if ((j != n - 1) && (nums[j][0] > nums[j + 1][0])) // 2つの子のうち、値の小さい方を選ぶ j++; if (nums[i][0] > nums[j][0]) //子が親より小さいなら入れ替え { long tmp = nums[j][0]; long tmpSub = nums[j][1]; nums[j][0] = nums[i][0]; nums[j][1] = nums[i][1]; nums[i][0] = tmp; nums[i][1] = tmpSub; } i = j; } return nums; } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 12, 23, 0, 241, 0, 111], ["+", 0, 57, 15, 16, 12, 23, 0, 241, 0, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
1,471
16
using System; using System.Collections.Generic; using System.Linq; namespace BlackJack { class Program { static void Main(string[] args) { var inputNums = Console.ReadLine(); if (Convert.ToInt32(inputNums[0]) + Convert.ToInt32(inputNums[1]) + Convert.ToInt32(inputNums[2]) >= 22) { Console.WriteLine("bust"); } else { Console.WriteLine("win"); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace BlackJack { class Program { static void Main(string[] args) { var inputNums = Console.ReadLine().Split(); if (int.Parse(inputNums[0]) + int.Parse(inputNums[1]) + int.Parse(inputNums[2]) >= 22) { Console.WriteLine("bust"); } else { Console.WriteLine("win"); } } } }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 31, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 205, 199], ["-", 31, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["-", 31, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 31, 16, 31, 16, 12, 213, 63, 214, 205, 199], ["-", 31, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 31, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["-", 15, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 205, 199], ["-", 15, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 141, 22]]
8
100
16
using System; using System.Collections.Generic; // using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; private static long max = 999999999999; static void Main(string[] args) { var n = Read().Int(); var r = ReadSplit(); var l = new long[n]; var bl = new long[3]; for (int i = 0; i < n; i++) { l[i] = r[i].Long(); } var ans = 1L; for (int i = 0; i < n; i++) { long count = bl.Count(x => x == l[i]); for (int j = 0; j < 3; j++) { if (bl[j] == l[i]) { ans = ans * count; ans %= mod; bl[j]++; break; } } } WriteRead(ans); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } /*優先度付きキュー*/ class PriorityQueue<T> where T : IComparable<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; public PriorityQueue(int capacity, bool greater = true) { this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { // 先頭要素を末尾にして再構成 this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { // 親要素の座標 var parent = (n - 1) / 2; if (this.Compare(this.Array[n], this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { // 左より右の子のほうが大きい値の場合、右を入れ替え対象にする child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } // aとbを比較する private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } // aとbを入れ替える private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } } private static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } //要素数Nを引数として渡し、0~N-1でできた順列をすべて返す static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } //配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; // using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; private static long max = 999999999999; static void Main(string[] args) { var n = Read().Int(); var r = ReadSplit(); var l = new long[n]; var bl = new long[3]; for (int i = 0; i < n; i++) { l[i] = r[i].Long(); } var ans = 1L; for (int i = 0; i < n; i++) { long count = bl.Count(x => x == l[i]); ans = ans * count; ans %= mod; for (int j = 0; j < 3; j++) { if (bl[j] == l[i]) { bl[j]++; break; } } } WriteRead(ans); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } /*優先度付きキュー*/ class PriorityQueue<T> where T : IComparable<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; public PriorityQueue(int capacity, bool greater = true) { this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { // 先頭要素を末尾にして再構成 this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { // 親要素の座標 var parent = (n - 1) / 2; if (this.Compare(this.Array[n], this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { // 左より右の子のほうが大きい値の場合、右を入れ替え対象にする child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } // aとbを比較する private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } // aとbを入れ替える private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } } private static bool NextPermutation(int[] array) { var size = array.Length; var ok = false; // array[i]<array[i+1]を満たす最大のiを求める int i = size - 2; for (; 0 <= i; i--) { if (array[i] < array[i + 1]) { ok = true; break; } } //全ての要素が降順の場合、NextPermutationは存在しない if (ok == false) return false; // array[i]<array[j]を満たす最大のjを求める int j = size - 1; for (;; j--) { if (array[i] < array[j]) break; } // iとjの要素をswapする var tmp = array[i]; array[i] = array[j]; array[j] = tmp; // i以降の要素を反転させる Array.Reverse(array, i + 1, size - (i + 1)); return true; } //要素数Nを引数として渡し、0~N-1でできた順列をすべて返す static List<int[]> GetAllPermutation(int N) { var res = new List<int[]>(); var array = Enumerable.Range(0, N).ToArray(); do { var copy = new int[N]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } //配列arrayを引数として渡し,辞書順がarray以上の順列をすべて返す static List<int[]> GetAllPermutation(int[] array) { var size = array.Length; var res = new List<int[]>(); do { var copy = new int[size]; array.CopyTo(copy, 0); res.Add(copy); } while (NextPermutation(array)); return res; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
8
1,282
20
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); string[] S = Console.ReadLine().Split(); long[] A = new long[N]; for (long i = 0; i < N; i++) A[i] = long.Parse(S[i]); long a = 0, b = 0, c = 0; long ans = 1; long count = 1; for (long i = 0; i < N; i++) { count = 1; if (A[i] == a) { a++; if (A[i] == b) count++; if (A[i] == c) count++; } else if (A[i] == b) { b++; if (A[i] == c) count++; } else { c++; } ans = (ans * count) % 1000000007; } Console.WriteLine(ans); } } }
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); string[] S = Console.ReadLine().Split(); long[] A = new long[N]; for (long i = 0; i < N; i++) A[i] = long.Parse(S[i]); long a = 0, b = 0, c = 0; long ans = 1; long count = 1; for (long i = 0; i < N; i++) { count = 1; if (A[i] == a) { a++; if (A[i] == b) count++; if (A[i] == c) count++; } else if (A[i] == b) { b++; if (A[i] == c) count++; } else if (A[i] == c) { c++; } else ans = 0; ans = (ans * count) % 1000000007; } Console.WriteLine(ans); } } }
[["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 57, 75, 1, 0, 11, 31, 22], ["+", 75, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 57, 75, 57, 75, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 75, 1, 0, 35]]
8
227
14
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { input_iter = LazyLoadAllLines(); //------------------------------------------------// // var x = Read<long>(); // var m = Read<long>(); // var x = Read<long>(); var n = Read<long>(); // var s = Read(); /*List<string> sls = new List<string>(); for(int i = 0; i < h; ++i) { sls.Add(Read()); }*/ var als = Read<long>(n); // var fls = Read<long>(n); // List<long> als = new List<long>(), bls = new List<long>(); /*List<List<long>> dcls = new List<List<long>>(); for (int i = 0; i < m; ++i) { dcls.Add(Read<long>(2)); }*/ // List<List<long>> abls = new List<List<long>>(); // List<long> cls = new List<long>(); /*List<long> edgeNum = Enumerable.Repeat(0L, (int)n).ToList(); for (int i = 0; i < n - 1; ++i) { abls.Add(Read<long>(2)); abls[i].Add(i); abls[i].Add(-1); --abls[i][0]; --abls[i][1]; //cls.Add(Read<long>()); ++edgeNum[(int)abls[i][0]]; ++edgeNum[(int)abls[i][1]]; }*/ // als.Sort((l, r) => (int)(l - r)); LongMod res = new LongMod(1); long[] cnts = new long[] { 0, 0, 0 }; for (int i = 0; i < n; ++i) { var pattern = 0L; var idx = -1; for (int j = 0; j < 3; ++j) { if (cnts[j] == als[i]) { ++pattern; idx = j; } } res *= pattern; ++cnts[idx]; } Console.WriteLine(res); } public static void Swap<_T>(ref _T l, ref _T r) { _T temp = r; r = l; l = temp; } public class LongMod { public long value { get; private set; } public long mod { get; private set; } public LongMod(long v, long m = 1000000007L) { value = v; mod = m; } public static implicit operator long(LongMod v) { return v.value; } public static bool operator ==(LongMod l, LongMod r) { return (l.value == r.value && l.mod == r.mod); } public static bool operator !=(LongMod l, LongMod r) { return !(l == r); } public static bool operator>(LongMod l, LongMod r) { return (l.value > r.value && l.mod == r.mod); } public static bool operator<(LongMod l, LongMod r) { return !(l > r) && !(l == r); } public static bool operator >=(LongMod l, LongMod r) { return !(l < r); } public static bool operator <=(LongMod l, LongMod r) { return !(l > r); } public static LongMod operator +(LongMod l, LongMod r) { return new LongMod((l.value + r.value) % l.mod, l.mod); } public static LongMod operator +(LongMod l, long r) { return new LongMod((l.value + r) % l.mod, l.mod); } public static LongMod operator -(LongMod l, LongMod r) { return new LongMod((l.value + l.mod - r.value) % l.mod, l.mod); } public static LongMod operator -(LongMod l, long r) { return new LongMod((l.value + l.mod - r) % l.mod, l.mod); } public static LongMod operator *(LongMod l, LongMod r) { return new LongMod(((l.value % l.mod) * (r.value % l.mod)) % l.mod, l.mod); } public static LongMod operator *(LongMod l, long r) { return new LongMod(((l.value % l.mod) * (r % l.mod)) % l.mod, l.mod); } public static LongMod operator /(LongMod l, LongMod r) { return new LongMod(l * r.Invert()); } public static LongMod operator /(LongMod l, long r) { return new LongMod(l * new LongMod(r, l.mod).Invert()); } public static LongMod operator %(LongMod l, LongMod r) { return new LongMod(l.value % r.value, r.value); } public static LongMod operator %(LongMod l, long r) { return new LongMod(l.value % r, r); } public LongMod Invert() { // 逆元 (1/x) : 存在条件 = valueとmodが互いに素 // memo : mod = 10^9+7(素数)の時, value != 0ならok. long a = value, b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; Swap(ref a, ref b); u -= t * v; Swap(ref u, ref v); } u %= mod; if (u < 0) u += mod; return new LongMod(u, mod); } public LongMod Power(long exp) { // べき乗 long a = value, res = 1; while (exp > 0) { if ((exp & 1) > 0) res = res * a % mod; a = a * a % mod; exp >>= 1; } return new LongMod(res, mod); } public LongMod Factorial() { // 階乗 LongMod res = new LongMod(1L, mod); for (long i = value; i > 0; --i) res *= i; return res; } } static IEnumerator<string> input_iter; static _T Read<_T>() where _T : struct { input_iter.MoveNext(); return (_T)Convert.ChangeType(input_iter.Current, typeof(_T)); } static string Read() { input_iter.MoveNext(); return input_iter.Current; } static List<_T> Read<_T>(long num) where _T : struct { return new List<_T>(Enumerate<_T>(num)); } static IEnumerable<_T> Enumerate<_T>(long num) { for (long i = 0; i < num; ++i) { input_iter.MoveNext(); yield return (_T)Convert.ChangeType(input_iter.Current, typeof(_T)); } } static IEnumerator<string> LazyLoadAllLines() { string line; do { line = Console.ReadLine(); foreach (var s in line.Split(' ')) yield return s; } while (line != null); } public class PriorityQueue<T> where T : IComparable { private IComparer<T> comparer = null; private bool isAccendingOrder; private List<T> heap; private int heapCurrentSize = 0; public PriorityQueue(IComparer<T> comparer, int initialHeapSize = 256) { heap = new List<T>(initialHeapSize); this.comparer = comparer; } public PriorityQueue(bool isAccending = true, int initialHeapSize = 256) { heap = new List<T>(initialHeapSize); isAccendingOrder = isAccending; } private int Compare(T x, T y) { if (comparer != null) return comparer.Compare(x, y); return isAccendingOrder ? x.CompareTo(y) : y.CompareTo(x); } public bool Empty() { return Count() == 0; } public int Count() { return heapCurrentSize; } public void Push(T x) { // node number var idx = heapCurrentSize++; if (heapCurrentSize > heap.Count) heap.Capacity *= 2; while (idx > 0) { // parent node number var parentIdx = (idx - 1) / 2; if (Compare(heap[parentIdx], x) <= 0) break; heap[idx] = heap[parentIdx]; idx = parentIdx; } heap[idx] = x; } public T Pop() { T ret = heap[0]; T x = heap[--heapCurrentSize]; int idx = 0; while (idx * 2 + 1 < heapCurrentSize) { // children int a = idx * 2 + 1; int b = idx * 2 + 2; if (b < heapCurrentSize && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[idx] = heap[a]; idx = a; } heap[idx] = x; return ret; } public T Peek() { return heap[0]; } public bool Contains(T x) { for (int i = 0; i < heapCurrentSize; i++) if (x.Equals(heap[i])) return true; return false; } public void Clear() { while (heapCurrentSize > 0) Pop(); } public IEnumerator<T> GetEnumerator() { var temp = new List<T>(); while (heapCurrentSize > 0) { temp.Add(Pop()); } foreach (var value in temp) { Push(value); yield return value; } } public T[] ToArray() { T[] array = new T[heapCurrentSize]; int i = 0; foreach (var r in this) { array[i] = r; ++i; } return array; } } } }
using System; using System.Collections.Generic; using System.Linq; // 91 // 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 11 11 11 // 12 12 12 13 13 13 14 14 14 15 15 15 16 16 16 17 17 17 18 18 18 19 19 19 20 20 // 20 21 21 21 22 22 22 23 23 23 24 24 24 25 25 25 26 26 26 27 27 27 28 28 28 29 // 29 29 30 30 30 namespace AtCoder { class Program { static void Main(string[] args) { input_iter = LazyLoadAllLines(); //------------------------------------------------// // var x = Read<long>(); // var m = Read<long>(); // var x = Read<long>(); var n = Read<long>(); // var s = Read(); /*List<string> sls = new List<string>(); for(int i = 0; i < h; ++i) { sls.Add(Read()); }*/ var als = Read<long>(n); // var fls = Read<long>(n); // List<long> als = new List<long>(), bls = new List<long>(); /*List<List<long>> dcls = new List<List<long>>(); for (int i = 0; i < m; ++i) { dcls.Add(Read<long>(2)); }*/ // List<List<long>> abls = new List<List<long>>(); // List<long> cls = new List<long>(); /*List<long> edgeNum = Enumerable.Repeat(0L, (int)n).ToList(); for (int i = 0; i < n - 1; ++i) { abls.Add(Read<long>(2)); abls[i].Add(i); abls[i].Add(-1); --abls[i][0]; --abls[i][1]; //cls.Add(Read<long>()); ++edgeNum[(int)abls[i][0]]; ++edgeNum[(int)abls[i][1]]; }*/ // als.Sort((l, r) => (int)(l - r)); LongMod res = new LongMod(1); long[] cnts = new long[] { 0, 0, 0 }; for (int i = 0; i < n; ++i) { var pattern = 0L; var idx = -1; for (int j = 0; j < 3; ++j) { if (cnts[j] == als[i]) { ++pattern; idx = j; } } res *= pattern; if (idx == -1) { Console.WriteLine(0); return; } ++cnts[idx]; } Console.WriteLine(res); } public static void Swap<_T>(ref _T l, ref _T r) { _T temp = r; r = l; l = temp; } public class LongMod { public long value { get; private set; } public long mod { get; private set; } public LongMod(long v, long m = 1000000007L) { value = v; mod = m; } public static implicit operator long(LongMod v) { return v.value; } public static bool operator ==(LongMod l, LongMod r) { return (l.value == r.value && l.mod == r.mod); } public static bool operator !=(LongMod l, LongMod r) { return !(l == r); } public static bool operator>(LongMod l, LongMod r) { return (l.value > r.value && l.mod == r.mod); } public static bool operator<(LongMod l, LongMod r) { return !(l > r) && !(l == r); } public static bool operator >=(LongMod l, LongMod r) { return !(l < r); } public static bool operator <=(LongMod l, LongMod r) { return !(l > r); } public static LongMod operator +(LongMod l, LongMod r) { return new LongMod((l.value + r.value) % l.mod, l.mod); } public static LongMod operator +(LongMod l, long r) { return new LongMod((l.value + r) % l.mod, l.mod); } public static LongMod operator -(LongMod l, LongMod r) { return new LongMod((l.value + l.mod - r.value) % l.mod, l.mod); } public static LongMod operator -(LongMod l, long r) { return new LongMod((l.value + l.mod - r) % l.mod, l.mod); } public static LongMod operator *(LongMod l, LongMod r) { return new LongMod(((l.value % l.mod) * (r.value % l.mod)) % l.mod, l.mod); } public static LongMod operator *(LongMod l, long r) { return new LongMod(((l.value % l.mod) * (r % l.mod)) % l.mod, l.mod); } public static LongMod operator /(LongMod l, LongMod r) { return new LongMod(l * r.Invert()); } public static LongMod operator /(LongMod l, long r) { return new LongMod(l * new LongMod(r, l.mod).Invert()); } public static LongMod operator %(LongMod l, LongMod r) { return new LongMod(l.value % r.value, r.value); } public static LongMod operator %(LongMod l, long r) { return new LongMod(l.value % r, r); } public LongMod Invert() { // 逆元 (1/x) : 存在条件 = valueとmodが互いに素 // memo : mod = 10^9+7(素数)の時, value != 0ならok. long a = value, b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; Swap(ref a, ref b); u -= t * v; Swap(ref u, ref v); } u %= mod; if (u < 0) u += mod; return new LongMod(u, mod); } public LongMod Power(long exp) { // べき乗 long a = value, res = 1; while (exp > 0) { if ((exp & 1) > 0) res = res * a % mod; a = a * a % mod; exp >>= 1; } return new LongMod(res, mod); } public LongMod Factorial() { // 階乗 LongMod res = new LongMod(1L, mod); for (long i = value; i > 0; --i) res *= i; return res; } } static IEnumerator<string> input_iter; static _T Read<_T>() where _T : struct { input_iter.MoveNext(); return (_T)Convert.ChangeType(input_iter.Current, typeof(_T)); } static string Read() { input_iter.MoveNext(); return input_iter.Current; } static List<_T> Read<_T>(long num) where _T : struct { return new List<_T>(Enumerate<_T>(num)); } static IEnumerable<_T> Enumerate<_T>(long num) { for (long i = 0; i < num; ++i) { input_iter.MoveNext(); yield return (_T)Convert.ChangeType(input_iter.Current, typeof(_T)); } } static IEnumerator<string> LazyLoadAllLines() { string line; do { line = Console.ReadLine(); foreach (var s in line.Split(' ')) yield return s; } while (line != null); } public class PriorityQueue<T> where T : IComparable { private IComparer<T> comparer = null; private bool isAccendingOrder; private List<T> heap; private int heapCurrentSize = 0; public PriorityQueue(IComparer<T> comparer, int initialHeapSize = 256) { heap = new List<T>(initialHeapSize); this.comparer = comparer; } public PriorityQueue(bool isAccending = true, int initialHeapSize = 256) { heap = new List<T>(initialHeapSize); isAccendingOrder = isAccending; } private int Compare(T x, T y) { if (comparer != null) return comparer.Compare(x, y); return isAccendingOrder ? x.CompareTo(y) : y.CompareTo(x); } public bool Empty() { return Count() == 0; } public int Count() { return heapCurrentSize; } public void Push(T x) { // node number var idx = heapCurrentSize++; if (heapCurrentSize > heap.Count) heap.Capacity *= 2; while (idx > 0) { // parent node number var parentIdx = (idx - 1) / 2; if (Compare(heap[parentIdx], x) <= 0) break; heap[idx] = heap[parentIdx]; idx = parentIdx; } heap[idx] = x; } public T Pop() { T ret = heap[0]; T x = heap[--heapCurrentSize]; int idx = 0; while (idx * 2 + 1 < heapCurrentSize) { // children int a = idx * 2 + 1; int b = idx * 2 + 2; if (b < heapCurrentSize && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[idx] = heap[a]; idx = a; } heap[idx] = x; return ret; } public T Peek() { return heap[0]; } public bool Contains(T x) { for (int i = 0; i < heapCurrentSize; i++) if (x.Equals(heap[i])) return true; return false; } public void Clear() { while (heapCurrentSize > 0) Pop(); } public IEnumerator<T> GetEnumerator() { var temp = new List<T>(); while (heapCurrentSize > 0) { temp.Add(Pop()); } foreach (var value in temp) { Push(value); yield return value; } } public T[] ToArray() { T[] array = new T[heapCurrentSize]; int i = 0; foreach (var r in this) { array[i] = r; ++i; } return array; } } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,762
18
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); long[] a = cin.ArrayLong(n); long ans = 1; long c1 = 0; long c2 = 0; long c3 = 0; for (int i = 0; i < n; i++) { long val = a[i]; if (c1 == val && c2 == val && c3 == val) { ans = (ans * 3) % MOD; c1++; } else if (c1 == val && c2 == val) { ans = (ans * 2) % MOD; c1++; } else if (c1 == val) { c1++; } else if (c2 == val && c3 == val) { ans = (ans * 2) % MOD; c2++; } else if (c2 == val) { c2++; } else { c3++; } } Console.WriteLine(ans); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); long[] a = cin.ArrayLong(n); long ans = 1; long c1 = 0; long c2 = 0; long c3 = 0; for (int i = 0; i < n; i++) { long val = a[i]; if (c1 == val && c2 == val && c3 == val) { ans = (ans * 3) % MOD; c1++; } else if (c1 == val && c2 == val) { ans = (ans * 2) % MOD; c1++; } else if (c1 == val) { c1++; } else if (c2 == val && c3 == val) { ans = (ans * 2) % MOD; c2++; } else if (c2 == val) { c2++; } else if (c3 == val) { c3++; } else { Console.WriteLine(0); return; } } Console.WriteLine(ans); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 60], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 57, 75, 57, 75, 196, 0, 37, 0, 38]]
8
695
18
using System; using System.Collections.Generic; using System.Linq; using static Constans; using static Common; public static class Common { public static void CountAdd<T>(this Dictionary<T, ModInt> dict, T key, ModInt v) { if (dict.ContainsKey(key)) { dict[key] += v; } else { dict[key] = v; } } } public static class Constans { public const long Mod = (long)1e9 + 7; } public struct ModInt { public long Num; public ModInt(long num) { Num = num; } // x^n public static long Power(long x, long n) { long pow = 1; while (n > 0) { if (n % 2 == 0) { x *= x; x %= Mod; n /= 2; } else { pow *= x; pow %= Mod; n--; } } return pow; } public static ModInt GetInv(long f) { // フェルマーの小定理 a^(-1) = a^(mod-2) return new ModInt(Power(f, Mod - 2)); } public ModInt GetInv() { return GetInv(Num); } public override string ToString() { return Num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.Num += r.Num; if (l.Num >= Mod) { l.Num -= Mod; } return l; } public static ModInt operator -(ModInt l, ModInt r) { l.Num -= r.Num; if (l.Num < 0) { l.Num += Mod; } return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.Num * r.Num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) { n += Mod; } return new ModInt(n); } } public struct State { public int[] Colors; public State(int[] colors) { Colors = colors; } public override bool Equals(object obj) { if (!(obj is State)) { return false; } return ((State)obj).Colors.SequenceEqual(Colors); } public override int GetHashCode() { return (Colors[0] << 16) ^ (Colors[1] << 8) ^ Colors[2]; } public static bool operator ==(State left, State right) { return left.Equals(right); } public static bool operator !=(State left, State right) { return !(left == right); } } public class Solution { public static void Main() { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Dictionary<State, ModInt> current = new Dictionary<State, ModInt>(); current.Add(new State(new int[3]), 1); foreach (var a in A) { var next = new Dictionary<State, ModInt>(); foreach (var cur in current) { for (int i = 0; i < 3; i++) { if (cur.Key.Colors[i] == a) { var colors = cur.Key.Colors.ToArray(); colors[i]++; var st = new State(colors); next.CountAdd(st, cur.Value); } } } current = next; } var sum = current.Values.Aggregate((a, b) => a + b); Console.WriteLine(sum); } }
using System; using System.Collections.Generic; using System.Linq; using static Constans; using static Common; public static class Common { public static void CountAdd<T>(this Dictionary<T, ModInt> dict, T key, ModInt v) { if (dict.ContainsKey(key)) { dict[key] += v; } else { dict[key] = v; } } } public static class Constans { public const long Mod = (long)1e9 + 7; } public struct ModInt { public long Num; public ModInt(long num) { Num = num; } // x^n public static long Power(long x, long n) { long pow = 1; while (n > 0) { if (n % 2 == 0) { x *= x; x %= Mod; n /= 2; } else { pow *= x; pow %= Mod; n--; } } return pow; } public static ModInt GetInv(long f) { // フェルマーの小定理 a^(-1) = a^(mod-2) return new ModInt(Power(f, Mod - 2)); } public ModInt GetInv() { return GetInv(Num); } public override string ToString() { return Num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.Num += r.Num; if (l.Num >= Mod) { l.Num -= Mod; } return l; } public static ModInt operator -(ModInt l, ModInt r) { l.Num -= r.Num; if (l.Num < 0) { l.Num += Mod; } return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.Num * r.Num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) { n += Mod; } return new ModInt(n); } } public struct State { public int[] Colors; public State(int[] colors) { Colors = colors; } public override bool Equals(object obj) { if (!(obj is State)) { return false; } return ((State)obj).Colors.SequenceEqual(Colors); } public override int GetHashCode() { return (Colors[0] << 16) ^ (Colors[1] << 8) ^ Colors[2]; } public static bool operator ==(State left, State right) { return left.Equals(right); } public static bool operator !=(State left, State right) { return !(left == right); } } public class Solution { public static void Main() { var N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Dictionary<State, ModInt> current = new Dictionary<State, ModInt>(); current.Add(new State(new int[3]), 1); foreach (var a in A) { var next = new Dictionary<State, ModInt>(); foreach (var cur in current) { for (int i = 0; i < 3; i++) { if (cur.Key.Colors[i] == a) { var colors = cur.Key.Colors.ToArray(); colors[i]++; var st = new State(colors); next.CountAdd(st, cur.Value); } } } current = next; } if (current.Count == 0) { Console.WriteLine(0); return; } var sum = current.Values.Aggregate((a, b) => a + b); Console.WriteLine(sum); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
746
19
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass { static void Main() { var T = ReadLine().Split().Select(long.Parse).ToArray(); var A = ReadLine().Split().Select(_ => long.Parse(_)).ToArray(); var B = ReadLine().Split().Select(_ => long.Parse(_)).ToArray(); var dif1 = (A[0] - B[0]) * T[0]; var dif2 = (A[1] - B[1]) * T[1]; if (dif1 + dif2 == 0) { WriteLine("infinity"); } else if ((dif1 <= 0 && dif2 >= 0) || (dif1 >= 0 && dif2 <= 0)) { long ans = 1; ans += Abs(dif1 / (dif1 + dif2)) * 2; if (dif1 % (dif1 + dif2) == 0) ans--; WriteLine(ans); } else WriteLine(0); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass { static void Main() { var T = ReadLine().Split().Select(long.Parse).ToArray(); var A = ReadLine().Split().Select(_ => long.Parse(_)).ToArray(); var B = ReadLine().Split().Select(_ => long.Parse(_)).ToArray(); var dif1 = (A[0] - B[0]) * T[0]; var dif2 = (A[1] - B[1]) * T[1]; if (dif1 + dif2 == 0) { WriteLine("infinity"); } else if ((dif1 >= 0 && dif1 + dif2 <= 0) || (dif1 <= 0 && dif1 + dif2 >= 0)) { long ans = 1; ans += Abs(dif1 / (dif1 + dif2)) * 2; if (dif1 % Abs(dif1 + dif2) == 0) ans--; WriteLine(ans); } else WriteLine(0); } }
[["-", 15, 16, 31, 23, 0, 16, 31, 16, 17, 19], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 20], ["+", 31, 23, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 31, 23, 0, 16, 12, 16, 31, 16, 17, 72], ["-", 15, 16, 31, 23, 0, 16, 12, 16, 17, 20], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 17, 19], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 20], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 19], ["+", 12, 23, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 12, 23, 0, 16, 12, 16, 31, 16, 17, 72], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 19], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 12, 213, 63, 22]]
8
242
13
using System; using CompLib.Util; public class Program { private long T1, T2; private long A1, A2; private long B1, B2; public void Solve() { var sc = new Scanner(); T1 = sc.NextLong(); T2 = sc.NextLong(); A1 = sc.NextLong(); A2 = sc.NextLong(); B1 = sc.NextLong(); B2 = sc.NextLong(); // A1のほうが大きいようにする if (A1 < B1) { long t = A1; A1 = B1; B1 = t; t = A2; A2 = B2; B2 = t; } long sA1 = A1 * T1; long sB1 = B1 * T1; long sA = sA1 + A2 * T2; long sB = sB1 + B2 * T2; // T1+T2ごとに会う if (sA == sB) { Console.WriteLine("infinity"); return; } // 追いつけない if (sA > sB) { Console.WriteLine("0"); return; } // 1が先行する // 2が追いつく // 1が先行できなくなる long diff = sB - sA; long d1 = sA1 - sB1; long ans = d1 / diff * 2 + 1; if (d1 % diff == 0) ans++; 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 CompLib.Util; public class Program { private long T1, T2; private long A1, A2; private long B1, B2; public void Solve() { var sc = new Scanner(); T1 = sc.NextLong(); T2 = sc.NextLong(); A1 = sc.NextLong(); A2 = sc.NextLong(); B1 = sc.NextLong(); B2 = sc.NextLong(); // A1のほうが大きいようにする if (A1 < B1) { long t = A1; A1 = B1; B1 = t; t = A2; A2 = B2; B2 = t; } long sA1 = A1 * T1; long sB1 = B1 * T1; long sA = sA1 + A2 * T2; long sB = sB1 + B2 * T2; // T1+T2ごとに会う if (sA == sB) { Console.WriteLine("infinity"); return; } // 追いつけない if (sA > sB) { Console.WriteLine("0"); return; } // 1が先行する // 2が追いつく // 1が先行できなくなる long diff = sB - sA; long d1 = sA1 - sB1; long ans; if (d1 % diff == 0) { ans = d1 / diff * 2; } else { ans = d1 / diff * 2 + 1; } 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, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 17, 85], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 17, 85], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
630
30
using System; using System.Text.RegularExpressions; public class Program { private long T1, T2; private long A1, A2; private long B1, B2; public void Solve() { var sc = new Scanner(); T1 = sc.NextInt(); T2 = sc.NextInt(); A1 = sc.NextLong() * T1; A2 = sc.NextLong() * T2; B1 = sc.NextLong() * T1; B2 = sc.NextLong() * T2; long aa = A1 + A2; long bb = B1 + B2; if (aa == bb) { Console.WriteLine("infinity"); return; } if (aa > bb) { Swap(ref aa, ref bb); Swap(ref A1, ref B1); Swap(ref A2, ref B2); } // aa < bb if (B1 > A1) { Console.WriteLine("0"); return; } // B1 < A1 long ans = 0; // T1で追い付く { // T1 開始時 AがBに追いつける位置にいる long d = A1 - B1; ans += (d) / (bb - aa); } // T2 { // T2開始時 Aが前にいる // T1開始時 AがBに追いつける位置にいる = T1の条件 ans *= 2; } Console.WriteLine(ans + 1); } void Swap(ref long x, ref long y) { long t = x; x = y; y = t; } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; using System.Text.RegularExpressions; public class Program { private long T1, T2; private long A1, A2; private long B1, B2; public void Solve() { var sc = new Scanner(); T1 = sc.NextInt(); T2 = sc.NextInt(); A1 = sc.NextLong() * T1; A2 = sc.NextLong() * T2; B1 = sc.NextLong() * T1; B2 = sc.NextLong() * T2; long aa = A1 + A2; long bb = B1 + B2; if (aa == bb) { Console.WriteLine("infinity"); return; } if (aa > bb) { Swap(ref aa, ref bb); Swap(ref A1, ref B1); Swap(ref A2, ref B2); } // aa < bb if (B1 > A1) { Console.WriteLine("0"); return; } // B1 < A1 long ans = 0; // T1で追い付く // T1 開始時 AがBに追いつける位置にいる long d = A1 - B1; long m = d % (bb - aa); ans += (d) / (bb - aa); // T2 // T2開始時 Aが前にいる // T1開始時 AがBに追いつける位置にいる = T1の条件 ans *= 2; if (m != 0) ans++; Console.WriteLine(ans); } void Swap(ref long x, ref long y) { long t = x; x = y; y = t; } public static void Main(string[] args) { new Program().Solve(); } } class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["-", 8, 201, 0, 195, 8, 196, 0, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 212, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
703
26
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace 三井住友信託銀行2019F { class Program { static void Main(string[] args) { var T1 = RLong; var T2 = RLong; var A1 = RLong; var A2 = RLong; var B1 = RLong; var B2 = RLong; var C1 = A1 * T1; var C2 = A2 * T2; var D1 = B1 * T1; var D2 = B2 * T2; if (C1 + C2 == D1 + D2) { Console.WriteLine("infinity"); return; } long ans = 0; ans = 1 + Math.Abs((C1 - D1) / (D1 + D2 - C1 - C2)) * 2; if (C1 <= D1 && C1 + C2 <= D1 + D2) ans = 0; if (C1 >= D1 && C1 + C2 >= D1 + D2) ans = 0; Console.WriteLine(ans); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a % mod, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { static public void Draw2D<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace 三井住友信託銀行2019F { class Program { static void Main(string[] args) { var T1 = RLong; var T2 = RLong; var A1 = RLong; var A2 = RLong; var B1 = RLong; var B2 = RLong; var C1 = A1 * T1; var C2 = A2 * T2; var D1 = B1 * T1; var D2 = B2 * T2; if (C1 + C2 == D1 + D2) { Console.WriteLine("infinity"); return; } long ans = 0; ans = 1 + Math.Abs((C1 - D1) / (D1 + D2 - C1 - C2)) * 2; if ((C1 - D1) % (D1 + D2 - C1 - C2) == 0) ans--; if (C1 <= D1 && C1 + C2 <= D1 + D2) ans = 0; if (C1 >= D1 && C1 + C2 >= D1 + D2) ans = 0; Console.WriteLine(ans); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a % mod, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { static public void Draw2D<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 12, 23, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 12, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 17, 33], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 68], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22]]
8
1,266
23
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_F(); } public static void Solve_A() { long n1, m1; long n2, m2; MyIO.ReadMulti(out n1, out m1); MyIO.ReadMulti(out n2, out m2); long ans = 0; if (n1 == n2) { ans = 0; } else { ans = 1; } MyIO.WriteMulti(ans); } public static void Solve_B() { long n; MyIO.ReadMulti(out n); ll a = (ll)(n / 1.08) - 2; string ans = ":("; if ((ll)(a * 1.08) == n) ans = a.ToString(); if ((ll)((a + 1) * 1.08) == n) ans = (a + 1).ToString(); if ((ll)((a + 2) * 1.08) == n) ans = (a + 2).ToString(); if ((ll)((a + 3) * 1.08) == n) ans = (a + 3).ToString(); if ((ll)((a + 4) * 1.08) == n) ans = (a + 4).ToString(); MyIO.WriteMulti(ans); } public static void Solve_C() { long n; MyIO.ReadMulti(out n); ll c5 = (n % 100) / 5; ll c0 = (n % 100) % 5 == 0 ? 0 : 1; long ans = 0; if ((c5 + c0) <= (ll)(n / 100)) ans = 1; MyIO.WriteMulti(ans); } public static void Solve_D() { long n; MyIO.ReadMulti(out n); string s; MyIO.ReadMulti(out s); ll[][] nidx = new ll[n][]; nidx[n - 1] = Enumerable.Repeat(-1L, 10).ToArray(); for (ll i = n - 2; 0 <= i; i--) { nidx[i] = new ll[10]; Array.Copy(nidx[i + 1], nidx[i], 10); nidx[i][int.Parse(s[(int)i + 1].ToString())] = i + 1; } long ans = 0; ll[] ai = new ll[10]; Array.Copy(nidx[0], ai, 10); ai[int.Parse(s[0].ToString())] = 0; foreach (var i1 in ai) { if (i1 == -1) continue; foreach (var i2 in nidx[i1]) { if (i2 == -1) continue; foreach (var i3 in nidx[i2]) { if (-1 < i3) ans++; } } } MyIO.WriteMulti(ans); } public static void Solve_E() { long n; MyIO.ReadMulti(out n); long[] a; MyIO.ReadArray(out a); long ans = 1; ll[] b = new ll[n + 1]; b[0] = 3; for (int i = 0; i < n; i++) { ans = (ans * (Math.Max(b[a[i]] - b[a[i] + 1], 0))) % MOD1; b[a[i] + 1]++; } MyIO.WriteMulti(ans); } public static void Solve_F() { long t1, t2; MyIO.ReadMulti(out t1, out t2); long a1, a2; MyIO.ReadMulti(out a1, out a2); long b1, b2; MyIO.ReadMulti(out b1, out b2); string ans = "infinity"; ll d1 = b1 * t1 - a1 * t1; ll d2 = b2 * t2 - a2 * t2; if ((d1 + d2) != 0) { ll cnt = 0; if ((0 < d1 && 0 > d2) || (0 > d1 && 0 < d2)) { if ((d1 + d2) < 0) { d1 *= -1; d2 *= -1; } cnt += -d1 / (d1 + d2) * 2 + 1; if (0 < cnt && ((-d1) % (d1 + d2) == 0)) cnt--; } ans = cnt.ToString(); } MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; using ll = System.Int64; public class Contest { static void Swap1<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void Swap2<T>(ref T a, ref T b) where T : IComparable { if (a.CompareTo(b) == 1) Swap1(ref a, ref b); } // b の方が小さければ交換 static bool Chmin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } // b の方が小さければ a を更新 static bool Chmax<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } // b の方が大きければ a を更新 static T[][] InitMat<T>(long len1, long len2, T val) { T[][] m = new T[len1][]; for (int i = 0; i < m.Length; i++) m[i] = Enumerable.Repeat(val, (int)len2).ToArray(); return m; } static T[][][] InitMat<T>(long len1, long len2, long len3, T val) { T[][][] m = new T[len1][][]; for (int i = 0; i < m.Length; i++) m[i] = InitMat(len2, len3, val); return m; } public const long MOD1 = 1000000007; // 10^9+7 public const double EPS1 = 1e-8; public static void Main() { Solve_F(); } public static void Solve_A() { long n1, m1; long n2, m2; MyIO.ReadMulti(out n1, out m1); MyIO.ReadMulti(out n2, out m2); long ans = 0; if (n1 == n2) { ans = 0; } else { ans = 1; } MyIO.WriteMulti(ans); } public static void Solve_B() { long n; MyIO.ReadMulti(out n); ll a = (ll)(n / 1.08) - 2; string ans = ":("; if ((ll)(a * 1.08) == n) ans = a.ToString(); if ((ll)((a + 1) * 1.08) == n) ans = (a + 1).ToString(); if ((ll)((a + 2) * 1.08) == n) ans = (a + 2).ToString(); if ((ll)((a + 3) * 1.08) == n) ans = (a + 3).ToString(); if ((ll)((a + 4) * 1.08) == n) ans = (a + 4).ToString(); MyIO.WriteMulti(ans); } public static void Solve_C() { long n; MyIO.ReadMulti(out n); ll c5 = (n % 100) / 5; ll c0 = (n % 100) % 5 == 0 ? 0 : 1; long ans = 0; if ((c5 + c0) <= (ll)(n / 100)) ans = 1; MyIO.WriteMulti(ans); } public static void Solve_D() { long n; MyIO.ReadMulti(out n); string s; MyIO.ReadMulti(out s); ll[][] nidx = new ll[n][]; nidx[n - 1] = Enumerable.Repeat(-1L, 10).ToArray(); for (ll i = n - 2; 0 <= i; i--) { nidx[i] = new ll[10]; Array.Copy(nidx[i + 1], nidx[i], 10); nidx[i][int.Parse(s[(int)i + 1].ToString())] = i + 1; } long ans = 0; ll[] ai = new ll[10]; Array.Copy(nidx[0], ai, 10); ai[int.Parse(s[0].ToString())] = 0; foreach (var i1 in ai) { if (i1 == -1) continue; foreach (var i2 in nidx[i1]) { if (i2 == -1) continue; foreach (var i3 in nidx[i2]) { if (-1 < i3) ans++; } } } MyIO.WriteMulti(ans); } public static void Solve_E() { long n; MyIO.ReadMulti(out n); long[] a; MyIO.ReadArray(out a); long ans = 1; ll[] b = new ll[n + 1]; b[0] = 3; for (int i = 0; i < n; i++) { ans = (ans * (Math.Max(b[a[i]] - b[a[i] + 1], 0))) % MOD1; b[a[i] + 1]++; } MyIO.WriteMulti(ans); } public static void Solve_F() { long t1, t2; MyIO.ReadMulti(out t1, out t2); long a1, a2; MyIO.ReadMulti(out a1, out a2); long b1, b2; MyIO.ReadMulti(out b1, out b2); string ans = "infinity"; ll d1 = b1 * t1 - a1 * t1; ll d2 = b2 * t2 - a2 * t2; if ((d1 + d2) != 0) { ll cnt = 0; if ((0 < d1 && 0 > d2) || (0 > d1 && 0 < d2)) { if ((d1 + d2) < 0) { d1 *= -1; d2 *= -1; } if (d1 < 0) { cnt = (-d1) / (d1 + d2) * 2 + 1; if (0 < cnt && ((-d1) % (d1 + d2) == 0)) cnt--; } } ans = cnt.ToString(); } MyIO.WriteMulti(ans); } } #region MyIO public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(long n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(long n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(long n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(long n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(long n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) => t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } } #endregion
[["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
3,078
12
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "sumitrust2019"; public const string ProblemName = "F"; public void Solve() { // long[] T = cin.ReadLongArray(2); // long[] A = cin.ReadLongArray(2); // long[] B = cin.ReadLongArray(2); // // if ((A[0] > B[0]) == (A[1] > B[1])) // { // cou.WriteLine(0); // return; // } // // long d1 = (A[0] - B[0]) * T[0]; // long d2 = (A[1] - B[1]) * T[1]; // // if (d1 + d2 == 0) // { // cou.WriteLine("infinity"); // return; // } // // if ((d1 > 0) == (d1 + d2 > 0)) // { // cou.WriteLine(0); // return; // } // // if (d1 < 0) // { // d1 = -d1; // d2 = -d2; // } // // long c = d1 / Math.Abs(d1 + d2); // // if (d1 % Math.Abs(d1 + d2) == 0) // { // cou.WriteLine(c * 2); // } // else // { // cou.WriteLine(c * 2 + 1); // } long[] T = cin.ReadLongArray(2); long[] A = cin.ReadLongArray(2); long[] B = cin.ReadLongArray(2); long[] D = new long[2]; for (int i = 0; i < 2; i++) { D[i] = (A[i] - B[i]) * T[i]; } if (D[0] + D[1] == 0) { cou.WriteLine("infinity"); return; } if ((D[0] > 0 && D[1] > 0) || (D[0] < 0 && D[1] < 0)) { cou.WriteLine(0); return; } if (D[0] < 0) { D[0] = -D[0]; D[1] = -D[1]; } long sum = D[0] + D[1]; sum = Math.Abs(sum); long d = Math.Abs(D[0]); // long d = Math.Min(Math.Abs(D[0]), Math.Abs(D[1])); if (d % sum == 0) { long p = d / sum; long ans = p * 2; cou.WriteLine(ans); } else { long p = d / sum; long ans = p * 2 + 1; cou.WriteLine(ans); } } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } //========================================================================================= // Library //========================================================================================= public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// 配列をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "sumitrust2019"; public const string ProblemName = "F"; public void Solve() { // long[] T = cin.ReadLongArray(2); // long[] A = cin.ReadLongArray(2); // long[] B = cin.ReadLongArray(2); // // if ((A[0] > B[0]) == (A[1] > B[1])) // { // cou.WriteLine(0); // return; // } // // long d1 = (A[0] - B[0]) * T[0]; // long d2 = (A[1] - B[1]) * T[1]; // // if (d1 + d2 == 0) // { // cou.WriteLine("infinity"); // return; // } // // if ((d1 > 0) == (d1 + d2 > 0)) // { // cou.WriteLine(0); // return; // } // // if (d1 < 0) // { // d1 = -d1; // d2 = -d2; // } // // long c = d1 / Math.Abs(d1 + d2); // // if (d1 % Math.Abs(d1 + d2) == 0) // { // cou.WriteLine(c * 2); // } // else // { // cou.WriteLine(c * 2 + 1); // } long[] T = cin.ReadLongArray(2); long[] A = cin.ReadLongArray(2); long[] B = cin.ReadLongArray(2); long[] D = new long[2]; for (int i = 0; i < 2; i++) { D[i] = (A[i] - B[i]) * T[i]; } if (D[0] + D[1] == 0) { cou.WriteLine("infinity"); return; } if ((D[0] > 0) == (D[0] + D[1] > 0)) { cou.WriteLine(0); return; } // if ((D[0] > 0 && D[1] > 0) || (D[0] < 0 && D[1] < 0)) // { // cou.WriteLine(0); // return; // } if (D[0] < 0) { D[0] = -D[0]; D[1] = -D[1]; } long sum = D[0] + D[1]; sum = Math.Abs(sum); long d = Math.Abs(D[0]); // long d = Math.Min(Math.Abs(D[0]), Math.Abs(D[1])); if (d % sum == 0) { long p = d / sum; long ans = p * 2; cou.WriteLine(ans); } else { long p = d / sum; long ans = p * 2 + 1; cou.WriteLine(ans); } } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } //========================================================================================= // Library //========================================================================================= public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// 配列をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
[["-", 0, 57, 15, 16, 31, 23, 0, 16, 17, 98], ["-", 31, 23, 0, 16, 12, 16, 31, 204, 205, 22], ["-", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 15, 16, 31, 23, 0, 16, 12, 16, 17, 47], ["-", 15, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 17, 18], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 72], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 47]]
8
3,414
15
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); long T1 = long.Parse(str[0]); long T2 = long.Parse(str[1]); string[] str2 = Console.ReadLine().Split(); long A1 = long.Parse(str2[0]); long A2 = long.Parse(str2[1]); string[] str3 = Console.ReadLine().Split(); long B1 = long.Parse(str3[0]); long B2 = long.Parse(str3[1]); long ans = 0; if (A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2) { Console.WriteLine("infinity"); } else { if (A1 * T1 > B1 * T1 && A1 * T1 + A2 * T2 > B1 * T1 + B2 * T2) { Console.WriteLine(0); } else if (A1 * T1 < B1 * T1 && A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2) { Console.WriteLine(0); } else { long L1 = Math.Abs(A1 * T1 - B1 * T1); long L2 = Math.Abs((A1 * T1 + A2 * T2) - (B1 * T1 + B2 * T2)); ans = L1 / L2 * 2 + 1; Console.WriteLine(ans); } } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); long T1 = long.Parse(str[0]); long T2 = long.Parse(str[1]); string[] str2 = Console.ReadLine().Split(); long A1 = long.Parse(str2[0]); long A2 = long.Parse(str2[1]); string[] str3 = Console.ReadLine().Split(); long B1 = long.Parse(str3[0]); long B2 = long.Parse(str3[1]); long ans = 0; if (A1 * T1 + A2 * T2 == B1 * T1 + B2 * T2) { Console.WriteLine("infinity"); } else { if (A1 * T1 > B1 * T1 && A1 * T1 + A2 * T2 > B1 * T1 + B2 * T2) { Console.WriteLine(0); } else if (A1 * T1 < B1 * T1 && A1 * T1 + A2 * T2 < B1 * T1 + B2 * T2) { Console.WriteLine(0); } else { long L1 = Math.Abs(A1 * T1 - B1 * T1); long L2 = Math.Abs((A1 * T1 + A2 * T2) - (B1 * T1 + B2 * T2)); ans = L1 / L2 * 2 + 1; if (L1 % L2 == 0) { ans -= 1; } Console.WriteLine(ans); } } } }
[["+", 0, 57, 75, 57, 75, 196, 0, 57, 0, 121], ["+", 0, 57, 75, 57, 75, 196, 0, 57, 0, 24], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 75, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 75, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 75, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 196, 0, 57, 0, 25], ["+", 75, 57, 75, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
8
320
14
using System; using System.Collections; using System.Collections.Generic; using static Exter; using System.Linq; using System.Numerics; #if DEBUG #else using console = System.Console; #endif public class App { public static void Main(string[] args) { cout = 6 - Array.IndexOf(new string[] { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" }, console.ReadLine()); } public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static long GcdRecursive(long a, long b) { if (b == 0) return a; return GcdRecursive(b, a % b); } } public class RollingHash { long[] h; long m = 2147483647; int b = 524287; Power baser; public RollingHash(string s) { baser = new Power(b); h = new long[s.Length]; h[0] = 0; for (int i = 1; i < s.Length; i++) { h[i] = (h[i - 1] * b + s[i]) % m; } } public long Calc(int l, int r) { cout = h[r]; cout = h[l] * baser.GetEntry(r - l - 1); return 0; } } public class PriorityQueue<T> : IEnumerable<T> where T : IComparable { List<T> buffer = new List<T>(); static void PushHeap(List<T> array, T elem) { int n = array.Count; array.Add(elem); while (n != 0) { int i = (n - 1) / 2; if (array[n].CompareTo(array[i]) < 0) { T tmp = array[n]; array[n] = array[i]; array[i] = tmp; } n = i; } } static void PopHeap(List<T> array) { int n = array.Count - 1; array[0] = array[n]; array.RemoveAt(array.Count - 1); for (int i = 0, j; (j = 2 * i + 1) < n;) { if ((j != n - 1) && (array[j].CompareTo(array[j + 1]) > 0)) j++; if (array[i].CompareTo(array[j]) > 0) { T tmp = array[j]; array[j] = array[i]; array[i] = tmp; } i = j; } } public int Count { get { return buffer.Count; } } public void Push(T elem) { PushHeap(this.buffer, elem); } public T Peek() { return buffer[0]; } public T Pop() { T a = buffer[0]; PopHeap(this.buffer); return a; } public IEnumerator<T> GetEnumerator() { var v = new List<T>(buffer); while (v.Count != 0) { yield return v[0]; PopHeap(v); } } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } public class Power { public int Base; private List<long> Value = new List<long>(); public Power(int v) { if (v == 1) new ArgumentOutOfRangeException(); long prev = -1; long g = v; Base = v; while (g > prev) { Value.Add(g); prev = g; g *= g; } } public long GetEntry(int exponent) { long s = 1; for (int i = 0; (1 << i) <= exponent; i++) { if ((exponent & (1 << i)) != 0) { s *= Value[i]; } } return s; } } public static class Exter { public static IEnumerable<long> PrimeFactors(long n) { int i = 2; long tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } public class LoopArray<T> { public readonly int Length; private T[] arr; public LoopArray(int Capacity) { Length = Capacity; } public LoopArray(T[] ar) { arr = new T[ar.Length]; Array.Copy(ar, arr, ar.Length); } } public class Point { public Point(int cx, int cy) { x = cx; y = cy; } public int x; public int y; } public static IEnumerable<Result> ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b, Func<T1, T2, Result> f) { foreach (var v in a) { foreach (var w in b) yield return f(v, w); } } public static IEnumerable<Result> ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b, Func<T1, T2, Result> f, Func<T1, T2, bool> s) { foreach (var v in a) { foreach (var w in b) if (s(v, w)) yield return f(v, w); } } public static int ToInt(this long v) => (int)v; public static int ToInt(this string v) => int.Parse(v); public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int a, int b) => b == 0 ? a : GcdRecursive(b, a % b); public static object cout { set { console.Write(value.ToString()); console.WriteLine(); } } public static void ToCout<t>(this IEnumerable<t> v) { cout = string.Join(",", v); } public static long[] readarr { get { preadarr = console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); return preadarr; } } public static long[] preadarr; } #if DEBUG public static class console { static int cursorLine = 0; static readonly string[] cin = System.IO.File.ReadAllLines("Input.txt"); static public string ReadLine() { if (cursorLine == cin.Length) cout = "Out"; return cin[cursorLine++]; } static public void WriteLine() { Console.WriteLine(); } static public void WriteLine<T>(T input) { Console.WriteLine(input); } static public void Write<T>(T input) { Console.Write(input); } static public void WriteLine(string s, params object[] arr) { Console.WriteLine(s, arr); } } #endif
using System; using System.Collections; using System.Collections.Generic; using static Exter; using System.Linq; using System.Numerics; #if DEBUG #else using console = System.Console; #endif public class App { public static void Main(string[] args) { cout = 7 - Array.IndexOf(new string[] { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }, console.ReadLine()); } public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static long GcdRecursive(long a, long b) { if (b == 0) return a; return GcdRecursive(b, a % b); } } public class RollingHash { long[] h; long m = 2147483647; int b = 524287; Power baser; public RollingHash(string s) { baser = new Power(b); h = new long[s.Length]; h[0] = 0; for (int i = 1; i < s.Length; i++) { h[i] = (h[i - 1] * b + s[i]) % m; } } public long Calc(int l, int r) { cout = h[r]; cout = h[l] * baser.GetEntry(r - l - 1); return 0; } } public class PriorityQueue<T> : IEnumerable<T> where T : IComparable { List<T> buffer = new List<T>(); static void PushHeap(List<T> array, T elem) { int n = array.Count; array.Add(elem); while (n != 0) { int i = (n - 1) / 2; if (array[n].CompareTo(array[i]) < 0) { T tmp = array[n]; array[n] = array[i]; array[i] = tmp; } n = i; } } static void PopHeap(List<T> array) { int n = array.Count - 1; array[0] = array[n]; array.RemoveAt(array.Count - 1); for (int i = 0, j; (j = 2 * i + 1) < n;) { if ((j != n - 1) && (array[j].CompareTo(array[j + 1]) > 0)) j++; if (array[i].CompareTo(array[j]) > 0) { T tmp = array[j]; array[j] = array[i]; array[i] = tmp; } i = j; } } public int Count { get { return buffer.Count; } } public void Push(T elem) { PushHeap(this.buffer, elem); } public T Peek() { return buffer[0]; } public T Pop() { T a = buffer[0]; PopHeap(this.buffer); return a; } public IEnumerator<T> GetEnumerator() { var v = new List<T>(buffer); while (v.Count != 0) { yield return v[0]; PopHeap(v); } } IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } public class Power { public int Base; private List<long> Value = new List<long>(); public Power(int v) { if (v == 1) new ArgumentOutOfRangeException(); long prev = -1; long g = v; Base = v; while (g > prev) { Value.Add(g); prev = g; g *= g; } } public long GetEntry(int exponent) { long s = 1; for (int i = 0; (1 << i) <= exponent; i++) { if ((exponent & (1 << i)) != 0) { s *= Value[i]; } } return s; } } public static class Exter { public static IEnumerable<long> PrimeFactors(long n) { int i = 2; long tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } public class LoopArray<T> { public readonly int Length; private T[] arr; public LoopArray(int Capacity) { Length = Capacity; } public LoopArray(T[] ar) { arr = new T[ar.Length]; Array.Copy(ar, arr, ar.Length); } } public class Point { public Point(int cx, int cy) { x = cx; y = cy; } public int x; public int y; } public static IEnumerable<Result> ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b, Func<T1, T2, Result> f) { foreach (var v in a) { foreach (var w in b) yield return f(v, w); } } public static IEnumerable<Result> ListAll<T1, T2, Result>(IEnumerable<T1> a, IEnumerable<T2> b, Func<T1, T2, Result> f, Func<T1, T2, bool> s) { foreach (var v in a) { foreach (var w in b) if (s(v, w)) yield return f(v, w); } } public static int ToInt(this long v) => (int)v; public static int ToInt(this string v) => int.Parse(v); public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int a, int b) => b == 0 ? a : GcdRecursive(b, a % b); public static object cout { set { console.Write(value.ToString()); console.WriteLine(); } } public static void ToCout<t>(this IEnumerable<t> v) { cout = string.Join(",", v); } public static long[] readarr { get { preadarr = console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); return preadarr; } } public static long[] preadarr; } #if DEBUG public static class console { static int cursorLine = 0; static readonly string[] cin = System.IO.File.ReadAllLines("Input.txt"); static public string ReadLine() { if (cursorLine == cin.Length) cout = "Out"; return cin[cursorLine++]; } static public void WriteLine() { Console.WriteLine(); } static public void WriteLine<T>(T input) { Console.WriteLine(input); } static public void Write<T>(T input) { Console.Write(input); } static public void WriteLine(string s, params object[] arr) { Console.WriteLine(s, arr); } } #endif
[["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 203], ["+", 0, 28, 0, 227, 0, 229, 0, 5, 0, 62], ["+", 0, 28, 0, 227, 0, 229, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 227, 0, 229, 0, 21], ["-", 0, 28, 0, 227, 0, 229, 0, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 227, 0, 229, 0, 21], ["-", 0, 28, 0, 227, 0, 229, 0, 5, 0, 222]]
8
1,577
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { String s = Console.ReadLine(); List<string> comp = new List<string> { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" }; int num = 6; foreach (string com in comp) { if (com.CompareTo(s) == 0) { break; } num--; } Console.WriteLine(num); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { String s = Console.ReadLine(); List<string> comp = new List<string> { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; int num = 7; foreach (string com in comp) { if (com.CompareTo(s) == 0) { break; } num--; } Console.WriteLine(num); } } }
[["+", 0, 212, 0, 230, 10, 229, 0, 5, 0, 222], ["+", 0, 212, 0, 230, 10, 229, 0, 5, 0, 62], ["+", 0, 200, 0, 212, 0, 230, 10, 229, 0, 21], ["-", 0, 212, 0, 230, 10, 229, 0, 5, 0, 62], ["-", 0, 200, 0, 212, 0, 230, 10, 229, 0, 21], ["-", 0, 212, 0, 230, 10, 229, 0, 5, 0, 222], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
135
10
using System; namespace A { class A { static void Main() { string day = Console.ReadLine(); switch (day) { case "SUN": Console.WriteLine("MON"); break; case "MON": Console.WriteLine("TUE"); break; case "TUE": Console.WriteLine("WED"); break; case "WED": Console.WriteLine("THU"); break; case "THU": Console.WriteLine("FRI"); break; case "FRI": Console.WriteLine("SAT"); break; case "SAT": Console.WriteLine("SUN"); break; default: Console.WriteLine("SUN"); break; } } } }
using System; namespace A { class A { static void Main() { string day = Console.ReadLine(); switch (day) { case "SUN": Console.WriteLine("7"); break; case "MON": Console.WriteLine("6"); break; case "TUE": Console.WriteLine("5"); break; case "WED": Console.WriteLine("4"); break; case "THU": Console.WriteLine("3"); break; case "FRI": Console.WriteLine("2"); break; case "SAT": Console.WriteLine("1"); break; default: Console.WriteLine("0"); break; } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
158
16
using System; using System.Collections.Generic; using System.Linq; namespace ProgramingStudying2 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); var ans = ""; for (int i = 0; i < s.Length; i++) { Console.WriteLine(s[i] + n); ans += (char)((s[i] + n - 65) % 26 + 65); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ProgramingStudying2 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); var ans = ""; for (int i = 0; i < s.Length; i++) { ans += (char)((s[i] + n - 65) % 26 + 65); } Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
122
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp11 { class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); string S = Console.ReadLine(); char[] A = new char[S.Length]; int num; string ans = ""; for (int i = 0; i < S.Count(); i++) { num = S[i] + N; if (num > 90) { num -= 25; } A[i] = (char)num; ans += A[i]; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp11 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); char[] A = new char[S.Length]; int num; for (int i = 0; i < S.Count(); i++) { num = S[i] + N; if (num > 90) num -= 26; A[i] = (char)num; } Console.WriteLine(A); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 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, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
156
2
using System; using System.Collections.Generic; using System.Text; public class Program { private static void Main() { int n = int.Parse(Console.ReadLine()); byte[] str = Encoding.ASCII.GetBytes(Console.ReadLine()); for (int i = 0; i < str.Length; i++) { if (str[i] + n > Encoding.ASCII.GetBytes("Z")[0]) { str[i] = (byte)(str[i] + n - Encoding.ASCII.GetBytes("Z")[0]); } else str[i] = (byte)(str[i] + n); } Console.WriteLine(Encoding.ASCII.GetString(str)); } }
using System; using System.Collections.Generic; using System.Text; public class Program { private static void Main() { int n = int.Parse(Console.ReadLine()); byte[] str = Encoding.ASCII.GetBytes(Console.ReadLine()); for (int i = 0; i < str.Length; i++) { if (str[i] + n > Encoding.ASCII.GetBytes("Z")[0]) { str[i] = (byte)(str[i] + n - 26); } else str[i] = (byte)(str[i] + n); } Console.WriteLine(Encoding.ASCII.GetString(str)); } }
[["-", 12, 204, 205, 213, 63, 214, 205, 214, 205, 22], ["-", 12, 204, 205, 213, 63, 214, 205, 214, 0, 131], ["-", 12, 204, 205, 213, 63, 214, 205, 214, 141, 22], ["-", 0, 16, 12, 204, 205, 213, 63, 214, 0, 131], ["-", 0, 16, 12, 204, 205, 213, 63, 214, 141, 22], ["-", 0, 16, 12, 204, 205, 213, 3, 4, 0, 24], ["-", 205, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 205, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 16, 12, 204, 205, 213, 3, 4, 0, 25], ["-", 51, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 51, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 74, 51, 23, 0, 16, 12, 203]]
8
166
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var waaaa = new waaaa(); waaaa.Solve(); } } public class waaaa { const int MOD = 1000000007; const int INF = 1 << 20; const long INFL = 1 << 62; const int MOD2 = 998244353; myinout IO = new myinout(); Math2 mmath = new Math2(); public void Solve() { //ここから var n = IO.int1; var edge = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();   //頂点vにつながる辺list var e = new Tuple<int, int>[n];   //from to for (int i = 0; i < n - 1; ++i) { var o = IO.intm; e[i] = new Tuple<int, int>(o[0]--, o[1]--); edge[e[i].Item1].Add(i); edge[e[i].Item2].Add(i); } var col = new int[n - 1]; var q = new Queue<int>(); q.Enqueue(0); while (q.Any()) { int p = q.Dequeue(); int pcol = 0; foreach (var item in edge[p]) //頂点につながる辺 { if (col[item] > 0) //すでに彩色なら { pcol = col[item];   //頂点pの色にする break; } } int c = 1; foreach (var item in edge[p]) { if (col[item] > 0) continue; //彩色してない辺について if (c == pcol) c++;   //頂点と同じ色なら違う色にする col[item] = c; c++; q.Enqueue( e[item].Item1 + e[item].Item2 - p); //辺itemのfromの頂点+toの頂点-今の頂点(いま見てない方向に行きたい) } } int k = col.Max(); foreach (var item in col) IO.wri(item); } } // b-aで降順 public class Math2 { public long[] fact; // Nまでの階乗 public long[] invfact; //階乗の逆元 // Nまでの階乗をセットしておく public void factoricalmodset(long N, long MOD = 1000000007) { fact = new long[N + 1]; invfact = new long[N + 1]; fact[0] = 1; for (long i = 1; i <= N; ++i) { fact[i] = fact[i - 1] * i % MOD; } invfact[N] = pow(fact[N], MOD - 2); for (long i = N; i > 0; --i) { invfact[i - 1] = invfact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long i, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * i % MOD; i = i * i % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long gcd(long i, long y) { while (y != 0) { var r = i % y; i = y; y = r; } return i; } //最小公倍数 引数:整数x,y public long lcm(long i, long y) { return i * y / gcd(i, y); } //素因数分解 引数:整数N public Dictionary<long, int> primefactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } //約数列挙 public List<long> divisorenumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } public void swap<T>(ref T a, ref T b) { var i = a; a = b; b = i; } } class myinout { // in public string str => Console.ReadLine(); public string[] strm => str.Split(' '); public long[] longm => strm.Select(long.Parse).ToArray(); public int[] intm => strm.Select(int.Parse).ToArray(); public char[] charm => str.ToArray(); public long long1 => longm[0]; public int int1 => intm[0]; public char char1 => charm[0]; // out public void wri<T>(T i) { Console.WriteLine(i); } public void yn(bool i) { if (i) wri("Yes"); else wri("No"); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var waaaa = new waaaa(); waaaa.Solve(); } } public class waaaa { const int MOD = 1000000007; const int INF = 1 << 20; const long INFL = 1 << 62; const int MOD2 = 998244353; myinout IO = new myinout(); Math2 mmath = new Math2(); public void Solve() { //ここから var n = IO.int1; var edge = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();   //頂点vにつながる辺list var e = new Tuple<int, int>[n];   //from to for (int i = 0; i < n - 1; ++i) { var o = IO.intm; e[i] = new Tuple<int, int>(o[0] - 1, o[1] - 1); edge[e[i].Item1].Add(i); edge[e[i].Item2].Add(i); } var col = new int[n - 1]; var q = new Queue<int>(); q.Enqueue(0); while (q.Any()) { int p = q.Dequeue(); int pcol = 0; foreach (var item in edge[p]) //頂点につながる辺 { if (col[item] > 0) //すでに彩色なら { pcol = col[item];   //頂点pの色にする break; } } int c = 1; foreach (var item in edge[p]) { if (col[item] > 0) continue; //彩色してない辺について if (c == pcol) c++;   //頂点と同じ色なら違う色にする col[item] = c; c++; q.Enqueue( e[item].Item1 + e[item].Item2 - p); //辺itemのfromの頂点+toの頂点-今の頂点(いま見てない方向に行きたい) } } int k = col.Max(); IO.wri(k); foreach (var item in col) IO.wri(item); } } // b-aで降順 public class Math2 { public long[] fact; // Nまでの階乗 public long[] invfact; //階乗の逆元 // Nまでの階乗をセットしておく public void factoricalmodset(long N, long MOD = 1000000007) { fact = new long[N + 1]; invfact = new long[N + 1]; fact[0] = 1; for (long i = 1; i <= N; ++i) { fact[i] = fact[i - 1] * i % MOD; } invfact[N] = pow(fact[N], MOD - 2); for (long i = N; i > 0; --i) { invfact[i - 1] = invfact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long i, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * i % MOD; i = i * i % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long gcd(long i, long y) { while (y != 0) { var r = i % y; i = y; y = r; } return i; } //最小公倍数 引数:整数x,y public long lcm(long i, long y) { return i * y / gcd(i, y); } //素因数分解 引数:整数N public Dictionary<long, int> primefactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } //約数列挙 public List<long> divisorenumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } public void swap<T>(ref T a, ref T b) { var i = a; a = b; b = i; } } class myinout { // in public string str => Console.ReadLine(); public string[] strm => str.Split(' '); public long[] longm => strm.Select(long.Parse).ToArray(); public int[] intm => strm.Select(int.Parse).ToArray(); public char[] charm => str.ToArray(); public long long1 => longm[0]; public int int1 => intm[0]; public char char1 => charm[0]; // out public void wri<T>(T i) { Console.WriteLine(i); } public void yn(bool i) { if (i) wri("Yes"); else wri("No"); } }
[["-", 12, 230, 3, 4, 0, 28, 0, 223, 0, 68], ["+", 12, 230, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 230, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
1,098
13
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N = GetInt(); List<int>[] A = Enumerable.Repeat(0, N).Select(s => new List<int>()).ToArray(); var G = new Tuple<int, int>[N - 1]; var color = new Dictionary<Tuple<int, int>, int>(); for (int i = 0; i < N - 1; i++) { var cin = GetIntArray().Select(s => s - 1).ToArray(); G[i] = new Tuple<int, int>(cin[0], cin[1]); A[cin[0]].Add(cin[1]); A[cin[1]].Add(cin[0]); color.Add(new Tuple<int, int>(cin[0], cin[1]), -1); color.Add(new Tuple<int, int>(cin[1], cin[0]), -1); } var next = new Queue<int>(); next.Enqueue(A[0].First()); var parcol = new int[N]; color[new Tuple<int, int>(0, A[0].First())] = 1; var K = 0; while (next.Count > 0) { var n = next.Dequeue(); var pc = parcol[n]; var k = 1; foreach (var a in A[n]) { K = Math.Max(k, K); if (color[new Tuple<int, int>(n, a)] != -1) continue; if (pc == k) k++; next.Enqueue(a); parcol[a] = k; color[new Tuple<int, int>(a, n)] = k; color[new Tuple<int, int>(n, a)] = k; k++; } } Console.WriteLine(K); G.Select(s => color[new Tuple<int, int>(s.Item1, s.Item2)]) .ToList() .ForEach(i => Console.WriteLine(i)); // Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N = GetInt(); List<int>[] A = Enumerable.Repeat(0, N).Select(s => new List<int>()).ToArray(); var G = new Tuple<int, int>[N - 1]; var color = new Dictionary<Tuple<int, int>, int>(); for (int i = 0; i < N - 1; i++) { var cin = GetIntArray().Select(s => s - 1).ToArray(); G[i] = new Tuple<int, int>(cin[0], cin[1]); A[cin[0]].Add(cin[1]); A[cin[1]].Add(cin[0]); color.Add(new Tuple<int, int>(cin[0], cin[1]), -1); color.Add(new Tuple<int, int>(cin[1], cin[0]), -1); } var next = new Queue<int>(); next.Enqueue(A[0].First()); var parcol = new int[N]; color[new Tuple<int, int>(0, A[0].First())] = 1; var K = 0; while (next.Count > 0) { var n = next.Dequeue(); var pc = parcol[n]; var k = 1; foreach (var a in A[n]) { if (color[new Tuple<int, int>(n, a)] != -1) continue; if (pc == k) k++; K = Math.Max(k, K); next.Enqueue(a); parcol[a] = k; color[new Tuple<int, int>(a, n)] = k; color[new Tuple<int, int>(n, a)] = k; k++; } } Console.WriteLine(K); G.Select(s => color[new Tuple<int, int>(s.Item1, s.Item2)]) .ToList() .ForEach(i => Console.WriteLine(i)); // Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } } }
[["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
1,603
22
using System; using System.Linq; using System.Collections.Generic; namespace lineAralgebra { class Edge { public int id; public int to; public Edge(int to, int id) { this.id = id; this.to = to; } } class Program { public static Dictionary<int, List<Edge>> graph = new Dictionary<int, List<Edge>>(); public static int[] ans; public static void Main(String[] args) { var n = int.Parse(Console.ReadLine()); ans = new int[n - 1]; for (var i = 0; i < n - 1; i++) { // System.Console.WriteLine("i is" + i); var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (!graph.ContainsKey(input[0])) { graph[input[0]] = new List<Edge>(); } if (!graph.ContainsKey(input[1])) { graph[input[1]] = new List<Edge>(); } graph[input[0]].Add(new Edge(input[1], i)); graph[input[1]].Add(new Edge(input[0], i)); } Dfs(1); var max = 0; foreach (var i in ans) { max = Math.Max(max, i); } System.Console.WriteLine(max); for (var i = 0; i < ans.Length; i++) { System.Console.WriteLine(ans[i]); } } public static void Dfs(int current, int parent = -1, int color = -1) { var k = 1; System.Console.WriteLine(current); foreach (var nodes in graph[current]) { var to = nodes.to; var id = nodes.id; if (to == parent) continue; if (k == color) k++; ans[id] = k; k++; Dfs(to, current, ans[id]); } } } }
using System; using System.Linq; using System.Collections.Generic; namespace lineAralgebra { class Edge { public int id; public int to; public Edge(int to, int id) { this.id = id; this.to = to; } } class Program { public static Dictionary<int, List<Edge>> graph = new Dictionary<int, List<Edge>>(); public static int[] ans; public static void Main(String[] args) { var n = int.Parse(Console.ReadLine()); ans = new int[n - 1]; for (var i = 0; i < n - 1; i++) { // System.Console.WriteLine("i is" + i); var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (!graph.ContainsKey(input[0])) { graph[input[0]] = new List<Edge>(); } if (!graph.ContainsKey(input[1])) { graph[input[1]] = new List<Edge>(); } graph[input[0]].Add(new Edge(input[1], i)); graph[input[1]].Add(new Edge(input[0], i)); } Dfs(1); var max = 0; foreach (var i in ans) { max = Math.Max(max, i); } System.Console.WriteLine(max); for (var i = 0; i < ans.Length; i++) { System.Console.WriteLine(ans[i]); } } public static void Dfs(int current, int parent = -1, int color = -1) { var k = 1; foreach (var nodes in graph[current]) { var to = nodes.to; var id = nodes.id; if (to == parent) continue; if (k == color) k++; ans[id] = k; k++; Dfs(to, current, ans[id]); } } } }
[["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
446
9
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm {     class Program     { static int col; static List<Edge>[] graph;         static void Main(string[] args)         { var n = int.Parse(Console.ReadLine()); graph = Enumerable.Repeat(0, n).Select(_ => new List<Edge>()).ToArray(); var edges = new List<Edge>(); for (var i = 0; i < n - 1; i++) { var t = Console.ReadLine().Split().Select(int.Parse).ToArray(); var edge = new Edge() { From = --t[0], To = --t[1] }; graph[edge.From].Add(edge); graph[edge.To].Add(edge); edges.Add(edge); } col = graph.Max(z => z.Count); Console.WriteLine(col); Dfs(0, int.MaxValue, -1); Console.WriteLine(string.Join("¥n", edges.Select(z => z.Color)));         } static void Dfs(int node, int from, int fromColor) { var color = 1; for (var i = 0; i < graph[node].Count; i++) { var edge = graph[node][i]; var to = edge.From ^ edge.To ^ node; if (from == to) continue; if (color == fromColor) color++; edge.Color = color; Dfs(to, node, color); color++; } }     } class Edge { public int From { get; set; } public int To { get; set; } public int Color { get; set; } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm {     class Program     { static int col; static List<Edge>[] graph;         static void Main(string[] args)         { var n = int.Parse(Console.ReadLine()); graph = Enumerable.Repeat(0, n).Select(_ => new List<Edge>()).ToArray(); var edges = new List<Edge>(); for (var i = 0; i < n - 1; i++) { var t = Console.ReadLine().Split().Select(int.Parse).ToArray(); var edge = new Edge() { From = --t[0], To = --t[1] }; graph[edge.From].Add(edge); graph[edge.To].Add(edge); edges.Add(edge); } col = graph.Max(z => z.Count); Console.WriteLine(col); Dfs(0, int.MaxValue, -1); foreach (var v in edges) Console.WriteLine(v.Color);         } static void Dfs(int node, int from, int fromColor) { var color = 1; for (var i = 0; i < graph[node].Count; i++) { var edge = graph[node][i]; var to = edge.From ^ edge.To ^ node; if (from == to) continue; if (color == fromColor) color++; edge.Color = color; Dfs(to, node, color); color++; } }     } class Edge { public int From { get; set; } public int To { get; set; } public int Color { get; set; } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 266], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 195, 8, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 267], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 0, 25], ["+", 0, 210, 8, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 210, 8, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
392
25
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using static System.Console; using static System.Math; class Program { static List<Edge>[] g; static void Main() { SetOut( new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var N = int.Parse(ReadLine()); var graph = new List<Edge>[N]; for (int i = 0; i < N; i++) { graph[i] = new List<Edge>(); } var d = new int[N]; for (int i = 0; i < N - 1; i++) { var ab = ReadLine().Split(); var a = int.Parse(ab[0]) - 1; var b = int.Parse(ab[1]) - 1; graph[a].Add(new Edge(b, i)); graph[b].Add(new Edge(a, i)); d[a]++; d[b]++; } var m = 0; var max = 0; for (int i = 0; i < N; i++) { if (max < d[i]) { max = d[i]; m = i; } } aa = max; g = graph; ans = new int[N - 1]; for (int i = 0; i < ans.Length; i++) { ans[i] = -1; } DFS(m, -1, -1); var aaa = ans.Max(); WriteLine(aaa + 1); for (int i = 0; i < N - 1; i++) { if (ans[i] == max) throw new Exception(); WriteLine(ans[i] + 1); } Out.Flush(); } static int aa; static int[] ans; static void DFS(int v, int p, int c) { var k = 0; foreach (var u in g[v]) { if (k == c) k++; // if(k==) if (u.to != p) { ans[u.id] = k; DFS(u.to, v, k); } k++; } } } public struct Edge { public int to; public int id; public Edge(int t, int i) { to = t; id = i; } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using static System.Console; using static System.Math; class Program { static List<Edge>[] g; static void Main() { SetOut( new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var N = int.Parse(ReadLine()); var graph = new List<Edge>[N]; for (int i = 0; i < N; i++) { graph[i] = new List<Edge>(); } var d = new int[N]; for (int i = 0; i < N - 1; i++) { var ab = ReadLine().Split(); var a = int.Parse(ab[0]) - 1; var b = int.Parse(ab[1]) - 1; graph[a].Add(new Edge(b, i)); graph[b].Add(new Edge(a, i)); d[a]++; d[b]++; } var m = 0; var max = 0; for (int i = 0; i < N; i++) { if (max < d[i]) { max = d[i]; m = i; } } aa = max; g = graph; ans = new int[N - 1]; for (int i = 0; i < ans.Length; i++) { ans[i] = -1; } DFS(m, -1, -1); var aaa = ans.Max(); WriteLine(aaa + 1); for (int i = 0; i < N - 1; i++) { if (aaa + 1 != max) throw new Exception(); WriteLine(ans[i] + 1); } Out.Flush(); } static int aa; static int[] ans; static void DFS(int v, int p, int c) { var k = 0; foreach (var u in g[v]) { if (k == c) k++; // if(k==) if (u.to != p) { ans[u.id] = k; DFS(u.to, v, k); k++; } } } } public struct Edge { public int to; public int id; public Edge(int t, int i) { to = t; id = i; } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
8
522
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication9 { class Program { static void Main(string[] args) { int a, b, c; string[] str = Console.ReadLine().Split(' '); a = int.Parse(str[0]); b = int.Parse(str[1]); c = int.Parse(str[2]); if (a + b + c >= 21) Console.WriteLine("win"); if (a + b + c >= 22) Console.WriteLine("bust"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication9 { class Program { static void Main(string[] args) { int a, b, c; string[] str = Console.ReadLine().Split(' '); a = int.Parse(str[0]); b = int.Parse(str[1]); c = int.Parse(str[2]); if (a + b + c <= 21) Console.WriteLine("win"); if (a + b + c >= 22) Console.WriteLine("bust"); Console.ReadKey(); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
8
145
8
using System; public class Program { public static void Main() { string[] input = Console.ReadLine().Split(' '); var a = int.Parse(input[0]); var b = int.Parse(input[1]); var c = int.Parse(input[2]); var s = a + b + c; Console.WriteLine(s); if (s >= 22) { Console.WriteLine("bust"); } else if (s < 22) { Console.WriteLine("win"); } } }
using System; public class Program { public static void Main() { string[] input = Console.ReadLine().Split(' '); var a = int.Parse(input[0]); var b = int.Parse(input[1]); var c = int.Parse(input[2]); var s = a + b + c; // Console.WriteLine(s); if (s >= 22) { Console.WriteLine("bust"); } else if (s < 22) { Console.WriteLine("win"); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
124
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder_with_csharp { using cl = Console; class Program { static void Main(string[] args) { var ap = new ArgsProcess(); var arg = ap.ArgsInt; var sum = arg.Sum(); cl.WriteLine(sum); var str = (sum >= 22) ? "bust" : "win"; cl.WriteLine(str); } } public class ArgsProcess { // 引数格納 public string[] Args { get; set; } // 引数格納(int) public int[] ArgsInt { get { return GetArgsAsArrayOfInteger(); } } public ArgsProcess(string args) { initialize(args); } public ArgsProcess() { // 入力してから var args = Console.ReadLine(); initialize(args); } private void initialize(string args) { // スペース区切り var s = args.Split(' ').ToList(); s.RemoveAll(x => x == ""); this.Args = s.ToArray(); } private int[] GetArgsAsArrayOfInteger() { int[] ret = Array.Empty<int>(); try { // intにparse ret = this.Args.ToList().ConvertAll(x => int.Parse(x)).ToArray(); } catch { Console.WriteLine("This args is not integer."); } return ret; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder_with_csharp { using cl = Console; class Program { static void Main(string[] args) { var ap = new ArgsProcess(); var arg = ap.ArgsInt; var sum = arg.Sum(); var str = (sum >= 22) ? "bust" : "win"; cl.WriteLine(str); } } public class ArgsProcess { // 引数格納 public string[] Args { get; set; } // 引数格納(int) public int[] ArgsInt { get { return GetArgsAsArrayOfInteger(); } } public ArgsProcess(string args) { initialize(args); } public ArgsProcess() { // 入力してから var args = Console.ReadLine(); initialize(args); } private void initialize(string args) { // スペース区切り var s = args.Split(' ').ToList(); s.RemoveAll(x => x == ""); this.Args = s.ToArray(); } private int[] GetArgsAsArrayOfInteger() { int[] ret = Array.Empty<int>(); try { // intにparse ret = this.Args.ToList().ConvertAll(x => int.Parse(x)).ToArray(); } catch { Console.WriteLine("This args is not integer."); } return ret; } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
289
7
using System; using System.Collections.Generic; using System.Linq; class main { public static void Main(string[] args) { string s = Console.ReadLine(); char[] former = new char[s.Length / 2]; char[] latter = new char[s.Length / 2]; int cnt = 0; for (int i = 0; i < former.Length; i++) { former[i] = s[i]; latter[i] = s[s.Length - 1 - i]; Console.WriteLine(former[i]); Console.WriteLine(latter[i]); if (former[i] != latter[i]) cnt++; } Console.WriteLine(cnt); } }
using System; using System.Collections.Generic; using System.Linq; class main { public static void Main(string[] args) { string s = Console.ReadLine(); char[] former = new char[s.Length / 2]; char[] latter = new char[s.Length / 2]; int cnt = 0; for (int i = 0; i < former.Length; i++) { former[i] = s[i]; latter[i] = s[s.Length - 1 - i]; if (former[i] != latter[i]) cnt++; } Console.WriteLine(cnt); } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
161
20
using System; using System.Linq; using System.Threading; namespace ConsoleApp19 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string r = string.Concat(s.Reverse()); int count = 0; for (int i = 0; i < s.Length; i++) { for (int k = 0; k < r.Length; k++) { if (s[i] == r[k]) { count++; } } } Console.WriteLine(count); } } }
using System; using System.Linq; using System.Threading; namespace ConsoleApp19 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string r = string.Concat(s.Reverse()); int count = 0; for (int i = 0; i < s.Length; i++) { if (s[i] != r[i]) { count++; } } Console.WriteLine(count / 2); } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 7, 0, 25], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
120
24
using System; using System.Collections.Generic; using System.Text; namespace Kyoupro { class Plactice { static void Main() { int count = 0; string S = Console.ReadLine(); int len = S.Length; for (int i = 0; i <= len / 2; i++) { if (S[i] != S[len - 1]) { count++; } len--; } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Text; namespace Kyoupro { class Plactice { static void Main() { int count = 0; string S = Console.ReadLine(); int len = S.Length; int Solidlen = len; for (int i = 0; i < Solidlen / 2; i++) { if (S[i] != S[len - 1]) { count++; } len--; } Console.WriteLine(count); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22]]
8
98
9
using System; using System.Linq; namespace ConsoleApp6 { class Program { static void Main(string[] args) { var source = Console.ReadLine(); var hugCount = 0; var x = (int)Math.Floor((decimal)(source.Length / 2)); for (int i = 0; i <= x; i++) { if (source[i] != source[source.Length - 1 - i]) { hugCount++; } } Console.WriteLine(hugCount); } } }
using System; using System.Diagnostics; using System.Linq; namespace ConsoleApp6 { class Program { static void Main(string[] args) { var source = Console.ReadLine(); var hugCount = 0; var x = (int)Math.Floor((decimal)(source.Length / 2)); for (int i = 0; i < x; i++) { if (source[i] != source[source.Length - 1 - i]) { hugCount++; } } Debug.WriteLine(hugCount); Console.WriteLine(hugCount); } } }
[["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
109
14
using System; using System.Linq; using System.Collections.Generic; using SyrupBeans.Competitive.IO; using E = System.Linq.Enumerable; public class Program { public static void Main() { var n = InputParser.TakeInt32(); var witness = new int[n + 1]; var mention = new int[n + 1]; for (int i = 1; i < witness.Length; ++i) { var a = InputParser.TakeInt32(); for (int j = 0; j < a; ++j) { var xy = InputParser.TakeInt32Array(2); witness[i] |= xy[1] << xy[0] - 1; mention[i] |= 1 << xy[0] - 1; } } var max = 0; var upperBound = 1 << n; for (int i = 0; i < upperBound; ++i) { var k = 0; var ok = true; for (int j = 0; j < n && ok; ++j) { var w = ~witness[j + 1]; if ((i >> j & 1) != 0) { w = ~w; ++k; } ok &= (w & mention[j + 1]) == (i & mention[j + 1]); } if (!ok) { continue; } max = Math.Max(max, k); } Console.WriteLine(max); } } namespace SyrupBeans.Competitive.IO { public static class InputParser { public static string BufferdString { get; private set; } private static int index; private static char Peek => BufferdString[index]; public static char TakeCharacter() => BufferdString[index++]; static InputParser() { Reset(); } public static void Reset() { InputParser.BufferdString = System.Console.In.ReadToEnd(); InputParser.index = 0; } private static void SeekToken() { while (char.IsWhiteSpace(InputParser.Peek)) { ++InputParser.index; } } private static char[] Separators { get; } = " \r\n".ToCharArray(); private static int CountTokens(string terminator) { int k = 0; int i = InputParser.index; int t = InputParser.BufferdString.IndexOf(terminator, i); if (t < 0) { t = InputParser.BufferdString.Length; } var c = InputParser.Peek; while (i < 0 || t <= i) { while (char.IsWhiteSpace(c)) { ++i; if (i >= t) { return k; } c = InputParser.BufferdString[i]; } ++k; i = InputParser.BufferdString.IndexOfAny(Separators, i); } return k; } public static int TakeInt32() { InputParser.SeekToken(); int sign = 1; if (InputParser.Peek == '-') { ++InputParser.index; sign = -1; } int x = 0; while (char.IsDigit(InputParser.Peek)) { x = x * 10 + InputParser.TakeCharacter() - '0'; } x *= sign; return x; } public static int[] TakeInt32Array(int length) { var xs = new int[length]; for (int i = 0; i < xs.Length; ++i) { xs[i] = InputParser.TakeInt32(); } return xs; } public static int[] TakeInt32Array(string terminator = "\0") => InputParser.TakeInt32Array(InputParser.CountTokens(terminator)); } }
using System; using System.Linq; using System.Collections.Generic; using SyrupBeans.Competitive.IO; using E = System.Linq.Enumerable; public class Program { public static void Main() { var n = InputParser.TakeInt32(); var witness = new int[n + 1]; var mention = new int[n + 1]; for (int i = 1; i < witness.Length; ++i) { var a = InputParser.TakeInt32(); for (int j = 0; j < a; ++j) { var xy = InputParser.TakeInt32Array(2); witness[i] |= xy[1] << xy[0] - 1; mention[i] |= 1 << xy[0] - 1; } } var max = 0; var upperBound = 1 << n; for (int i = 0; i < upperBound; ++i) { var k = 0; var ok = true; for (int j = 0; j < n && ok; ++j) { if ((i >> j & 1) == 0) { continue; } var w = witness[j + 1]; ok &= (w & mention[j + 1]) == (i & mention[j + 1]); ++k; } if (!ok) { continue; } max = Math.Max(max, k); } Console.WriteLine(max); } } namespace SyrupBeans.Competitive.IO { public static class InputParser { public static string BufferdString { get; private set; } private static int index; private static char Peek => BufferdString[index]; public static char TakeCharacter() => BufferdString[index++]; static InputParser() { Reset(); } public static void Reset() { InputParser.BufferdString = System.Console.In.ReadToEnd(); InputParser.index = 0; } private static void SeekToken() { while (char.IsWhiteSpace(InputParser.Peek)) { ++InputParser.index; } } private static char[] Separators { get; } = " \r\n".ToCharArray(); private static int CountTokens(string terminator) { int k = 0; int i = InputParser.index; int t = InputParser.BufferdString.IndexOf(terminator, i); if (t < 0) { t = InputParser.BufferdString.Length; } var c = InputParser.Peek; while (i < 0 || t <= i) { while (char.IsWhiteSpace(c)) { ++i; if (i >= t) { return k; } c = InputParser.BufferdString[i]; } ++k; i = InputParser.BufferdString.IndexOfAny(Separators, i); } return k; } public static int TakeInt32() { InputParser.SeekToken(); int sign = 1; if (InputParser.Peek == '-') { ++InputParser.index; sign = -1; } int x = 0; while (char.IsDigit(InputParser.Peek)) { x = x * 10 + InputParser.TakeCharacter() - '0'; } x *= sign; return x; } public static int[] TakeInt32Array(int length) { var xs = new int[length]; for (int i = 0; i < xs.Length; ++i) { xs[i] = InputParser.TakeInt32(); } return xs; } public static int[] TakeInt32Array(string terminator = "\0") => InputParser.TakeInt32Array(InputParser.CountTokens(terminator)); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 241, 0, 92], ["-", 0, 200, 0, 212, 0, 241, 0, 204, 205, 22], ["-", 0, 212, 0, 241, 0, 204, 206, 207, 0, 70], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 212, 0, 241, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 92], ["-", 64, 196, 0, 1, 0, 11, 12, 241, 0, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 241, 0, 29], ["-", 0, 57, 64, 196, 0, 1, 0, 241, 0, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 241, 0, 29], ["+", 0, 7, 8, 196, 0, 1, 0, 241, 0, 22]]
8
723
32
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int N = int.Parse(Console.ReadLine()); var A = new List<List<int>>(); for (var i = 0; i < N; i++) A.Add(new List<int>()); for (var i = 0; i < N; i++) { int a = int.Parse(Console.ReadLine()); for (var j = 0; j < a; j++) { var p = cin.ReadSplit(); A[i].Add(p[1] == 1 ? p[0] : -p[0]); } } long ans = 0; for (var bit = 0; bit < (1 << N); bit++) { long nans = N; var ho = new int[N]; Initialize(ref ho, 1); for (var i = 0; i < N; i++) { if (((1 << i) & bit) == 0) { ho[i] *= -1; nans--; } } for (var i = 0; i < N; i++) { for (var j = 0; j < A[i].Count(); j++) { int ind = Abs(A[i][j]) - 1; if ((A[i][j] * ho[i] > 0 && ho[ind] < 0) || (A[i][j] * ho[i] < 0 && ho[ind] > 0)) { nans = 0; } } } ans = Max(ans, nans); } Console.WriteLine(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } struct Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private readonly bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public Pair(T f, U s) { first = f; second = s; CompWithFirst = true; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } } public class PriorityQueue<T> where T : IComparable<T> { public readonly List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Contains(T obj) { return Q.Contains(obj); } } public class Scanner { public int[] ReadSplit() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] ReadSplitL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } } public class SegmentTree<T> { int n; T[] Tree; Func<T, T, T> f; T ex; public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { f = fun; ex = exvalue; n = 1; while (n < size) n <<= 1; Tree = new T[(n << 1) - 1]; for (var i = 0; i < Tree.Length; i++) Tree[i] = ex; } public SegmentTree(int size, Func<T, T, T> f, T exvalue, T initial) : this(size, f, exvalue) { for (var i = 0; i < size; i++) Tree[i + n - 1] = initial; Set_All(); } public void Set_All() { for (var i = n - 2; i >= 0; i--) { Tree[i] = f(Tree[(i << 1) + 1], Tree[(i << 1) + 2]); } } public void Assign(int ind, T val) { Tree[ind + n - 1] = val; } public void Update(int ind) { int i = ind + n - 1; while (i > 0) { i = (i - 1) >> 1; Tree[i] = f(Tree[(i << 1) + 1], Tree[(i << 1) + 2]); } } public void UpdateQuery(int ind, T val) { Assign(ind, val); Update(ind); } public T AnswerQuery(int l, int r) //[l,r) { return Scanning(l, r, 0, 0, n); } private T Scanning(int l, int r, int ind, int ind_l, int ind_r) { if (ind_r <= l || r <= ind_l) { return ex; } if (l <= ind_l && ind_r <= r) { return Tree[ind]; } return f(Scanning(l, r, (ind << 1) + 1, ind_l, (ind_l + ind_r) >> 1), Scanning(l, r, (ind << 1) + 2, (ind_l + ind_r) >> 1, ind_r)); } public T Look(int ind) { return Tree[ind + n - 1]; } public void Debug_Display_All() { for (var i = 0; i < n; i++) Console.Write($"{Tree[i + n - 1]} "); Console.WriteLine(); } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } public Modulo() {} } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int N = int.Parse(Console.ReadLine()); var A = new List<List<int>>(); for (var i = 0; i < N; i++) A.Add(new List<int>()); for (var i = 0; i < N; i++) { int a = int.Parse(Console.ReadLine()); for (var j = 0; j < a; j++) { var p = cin.ReadSplit(); A[i].Add(p[1] == 1 ? p[0] : -p[0]); } } long ans = 0; for (var bit = 0; bit < (1 << N); bit++) { long nans = N; var ho = new int[N]; Initialize(ref ho, 1); for (var i = 0; i < N; i++) { if (((1 << i) & bit) == 0) { ho[i] *= -1; nans--; } } for (var i = 0; i < N; i++) { if (ho[i] < 0) continue; for (var j = 0; j < A[i].Count(); j++) { int ind = Abs(A[i][j]) - 1; if ((A[i][j] * ho[i] > 0 && ho[ind] < 0) || (A[i][j] * ho[i] < 0 && ho[ind] > 0)) { nans = 0; } } } ans = Max(ans, nans); } Console.WriteLine(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } struct Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T first; public U second; private readonly bool CompWithFirst; public Pair(T f, U s, int comp) { first = f; second = s; CompWithFirst = comp == 1; } public Pair(T f, U s) { first = f; second = s; CompWithFirst = true; } public int CompareTo(Pair<T, U> other) { return CompWithFirst ? first.CompareTo(other.first) : second.CompareTo(other.second); } } } public class PriorityQueue<T> where T : IComparable<T> { public readonly List<T> Q; private readonly int r; public PriorityQueue(bool ascending) { if (ascending) { r = 1; } else { r = -1; } Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (list[n].CompareTo(list[pIndex]) * r > 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = list[c1].CompareTo(list[c2]) * r > 0 ? c1 : c2; } if (list[cur].CompareTo(list[comp]) * r < 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Contains(T obj) { return Q.Contains(obj); } } public class Scanner { public int[] ReadSplit() { int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray(); return array; } public long[] ReadSplitL() { long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray(); return array; } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } } public class SegmentTree<T> { int n; T[] Tree; Func<T, T, T> f; T ex; public SegmentTree(int size, Func<T, T, T> fun, T exvalue) { f = fun; ex = exvalue; n = 1; while (n < size) n <<= 1; Tree = new T[(n << 1) - 1]; for (var i = 0; i < Tree.Length; i++) Tree[i] = ex; } public SegmentTree(int size, Func<T, T, T> f, T exvalue, T initial) : this(size, f, exvalue) { for (var i = 0; i < size; i++) Tree[i + n - 1] = initial; Set_All(); } public void Set_All() { for (var i = n - 2; i >= 0; i--) { Tree[i] = f(Tree[(i << 1) + 1], Tree[(i << 1) + 2]); } } public void Assign(int ind, T val) { Tree[ind + n - 1] = val; } public void Update(int ind) { int i = ind + n - 1; while (i > 0) { i = (i - 1) >> 1; Tree[i] = f(Tree[(i << 1) + 1], Tree[(i << 1) + 2]); } } public void UpdateQuery(int ind, T val) { Assign(ind, val); Update(ind); } public T AnswerQuery(int l, int r) //[l,r) { return Scanning(l, r, 0, 0, n); } private T Scanning(int l, int r, int ind, int ind_l, int ind_r) { if (ind_r <= l || r <= ind_l) { return ex; } if (l <= ind_l && ind_r <= r) { return Tree[ind]; } return f(Scanning(l, r, (ind << 1) + 1, ind_l, (ind_l + ind_r) >> 1), Scanning(l, r, (ind << 1) + 2, (ind_l + ind_r) >> 1, ind_r)); } public T Look(int ind) { return Tree[ind + n - 1]; } public void Debug_Display_All() { for (var i = 0; i < n; i++) Console.Write($"{Tree[i + n - 1]} "); Console.WriteLine(); } } class Modulo { private const int M = 1000000007; private readonly int[] m_facs; public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } public Modulo(int n) { m_facs = new int[n + 1]; m_facs[0] = 1; for (int i = 1; i <= n; ++i) { m_facs[i] = Mul(m_facs[i - 1], i); } } public int Fac(int n) { return m_facs[n]; } public int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Mul(p1, p1); return ((m % 2) == 0) ? p2 : Mul(p2, a); } } public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } public int Ncr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Fac(n); res = Div(res, Fac(r)); res = Div(res, Fac(n - r)); return res; } public Modulo() {} } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
2,211
11
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { static class Program_D { class Solver { int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); // ABC147 Xor Sum 4 public void Solve() { var n = ri; // var a = new long[n]; var count0 = new long[64]; var count1 = new long[64]; for (int i = 0; i < n; ++i) { var a = rl; for (int j = 0; j < 64; ++j) { if ((a & 1) == 0) count0[j]++; else count1[j]++; a /= 2; } } var result = new ModInt(); long bit = 1; for (int i = 0; i < 64; ++i) { result += (ModInt)(bit * count0[i] * count1[i]); bit *= 2; } Wl(result); } // ---------------------------------------------------------------------------- static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } string Rl() { return Console.ReadLine(); } void Wl(UInt64 val) { Console.WriteLine(val); } void Wl(Int64 val) { Console.WriteLine(val); } void Wl(uint val) { Console.WriteLine(val); } void Wl(int val) { Console.WriteLine(val); } void Wl(double val) { Console.WriteLine(val); } void Wl(string mes) { Console.WriteLine(mes); } public int Int() { return int.Parse(Console.ReadLine()); } public int[] Ints(int subtract) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) - subtract) .ToArray(); } public Int64[] Int64s(Int64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => Int64.Parse(s) - subtract) .ToArray(); } public UInt64[] UInt64s(UInt64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => UInt64.Parse(s) - subtract) .ToArray(); } } static void Main(string[] args) { Console.SetOut( new Printer(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } struct ModInt { const int MOD = 1000000007; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GetInverse(long a) { long div; long p = MOD; long x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { static class Program_D { class Solver { int ri => sc.Integer(); long rl => sc.Long(); double rd => sc.Double(); string rs => sc.Scan(); public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); // ABC147 Xor Sum 4 public void Solve() { var n = ri; // var a = new long[n]; var count0 = new long[64]; var count1 = new long[64]; for (int i = 0; i < n; ++i) { var a = rl; for (int j = 0; j < 64; ++j) { if ((a & 1) == 0) count0[j]++; else count1[j]++; a /= 2; } } var result = new ModInt(); long bit = 1; for (int i = 0; i < 64; ++i) { var bitMod = new ModInt(bit); result += (ModInt)(count0[i] * count1[i]) * bitMod; bit *= 2; } Wl(result); } // ---------------------------------------------------------------------------- static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } string Rl() { return Console.ReadLine(); } void Wl(UInt64 val) { Console.WriteLine(val); } void Wl(Int64 val) { Console.WriteLine(val); } void Wl(uint val) { Console.WriteLine(val); } void Wl(int val) { Console.WriteLine(val); } void Wl(double val) { Console.WriteLine(val); } void Wl(string mes) { Console.WriteLine(mes); } public int Int() { return int.Parse(Console.ReadLine()); } public int[] Ints(int subtract) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) - subtract) .ToArray(); } public Int64[] Int64s(Int64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => Int64.Parse(s) - subtract) .ToArray(); } public UInt64[] UInt64s(UInt64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => UInt64.Parse(s) - subtract) .ToArray(); } } static void Main(string[] args) { Console.SetOut( new Printer(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } } public class Printer : StreamWriter { public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture; public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } struct ModInt { const int MOD = 1000000007; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GetInverse(long a) { long div; long p = MOD; long x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 212, 0, 230, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 12, 74, 51, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 74, 51, 23, 0, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
1,417
13
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; namespace V { partial class Solver { public void Solve() { // var n = Read; Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var n = Read; var a = Arr(n); var res = new Mint(); for (int i = 0; i < 61; i++) { long f = 1L << i; long a0 = a.Count(x => (x & f) == 0); long a1 = a.Count(x => (x & f) != 0); res += new Mint(f) * a0 *a1; } // res /= 2; return res.Value; } public bool SolveBool() { var n = Read; var res = false; return res; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SafeAdd<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { return false; } else { ts.Add(t); return false; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SafeRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafePlus<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToDigit(this char c) => (long)(c - '0'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToStr(this IEnumerable<char> cs) => new string(cs.ToArray()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToLong(this IEnumerable<char> s) { var basis = 1L; var res = 0L; foreach (var c in s) { var d = c.ToSmallAbcIndex() + 1; res += d * basis; basis *= 27; } return res; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] // public static bool TryMin<T>(this ref T current, T newer) where T : struct, // IComparable<T> //{ // if (current.CompareTo(newer) <= 0) // return false; // current = newer; // return true; //} //[MethodImpl(MethodImplOptions.AggressiveInlining)] // public static bool TryMax<T>(this ref T current, T newer) where T : struct, // IComparable<T> //{ // if (current.CompareTo(newer) >= 0) // return false; // current = newer; // return true; //} } class C { public class SegmentTree<T> { private readonly int valueCount; private readonly int baseCount; private readonly int baseIndex; private readonly T[] nodes; private readonly Func<T, T, T> func; private readonly T defaultValue; public SegmentTree(IReadOnlyList<T> ts, Func<T, T, T> func, T filling = default(T)) { this.func = func; this.defaultValue = filling; valueCount = ts.Count; baseCount = 1; while (valueCount > baseCount) baseCount <<= 1; nodes = new T[baseCount * 2 - 1]; baseIndex = baseCount - 1; for (int i = 0; i < ts.Count; i++) nodes[baseIndex + i] = ts[i]; for (int i = ts.Count; i < baseCount; i++) nodes[baseIndex + i] = filling; for (int i = baseIndex - 1; i >= 0; i--) nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int index, T t) { var i = baseIndex + index; nodes[i] = t; while (i > 0) { i -= 1; i /= 2; nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int leftIndex, int rightNextIndex) { T left = defaultValue; T right = defaultValue; int l = leftIndex + baseCount - 1; int r = rightNextIndex + baseCount - 1; for (; l < r; l >>= 1, r >>= 1) { if ((l & 1) == 0) { left = func.Invoke(left, nodes[l]); } if ((r & 1) == 0) { r--; right = func.Invoke(right, nodes[r]); } } return func.Invoke(left, right); } } public class SegmentTree { public static SegmentTree<int> Sum(IReadOnlyList<int> values) => new SegmentTree<int>(values, (x, y) => x + y); public static SegmentTree<long> Sum(IReadOnlyList<long> values) => new SegmentTree<long>(values, (x, y) => x + y); public static SegmentTree<double> Sum(IReadOnlyList<double> values) => new SegmentTree<double>(values, (x, y) => x + y); public static SegmentTree<int> Mult(IReadOnlyList<int> values) => new SegmentTree<int>(values, (x, y) => x * y, 1); public static SegmentTree<long> Mult(IReadOnlyList<long> values) => new SegmentTree<long>(values, (x, y) => x * y, 1); public static SegmentTree<double> Mult(IReadOnlyList<double> values) => new SegmentTree<double>(values, (x, y) => x * y, 1); public static SegmentTree<int> Min(IReadOnlyList<int> values) => new SegmentTree<int>(values, Math.Min, int.MaxValue); public static SegmentTree<long> Min(IReadOnlyList<long> values) => new SegmentTree<long>(values, Math.Min, long.MaxValue); public static SegmentTree<double> Min(IReadOnlyList<double> values) => new SegmentTree<double>(values, Math.Min, double.MaxValue); public static SegmentTree<int> Max(IReadOnlyList<int> values) => new SegmentTree<int>(values, Math.Max, int.MinValue); public static SegmentTree<long> Max(IReadOnlyList<long> values) => new SegmentTree<long>(values, Math.Max, long.MinValue); public static SegmentTree<double> Max(IReadOnlyList<double> values) => new SegmentTree<double>(values, Math.Max, double.MinValue); } public class UnionFind { private int[] parents; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UnionFind(int count) { parents = Enumerable.Repeat(-1, count).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryUnite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) return false; if (parents[rootY] < parents[rootX]) { var temp = rootX; rootX = rootY; rootY = temp; } parents[rootX] += parents[rootY]; parents[rootY] = rootX; return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Find(int x, int y) => GetRoot(x) == GetRoot(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetRoot(int x) { while (parents[x] >= 0) x = parents[x]; return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long GetSize(int x) => -parents[GetRoot(x)]; } public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } /// <summary> /// 木の直径(一番長い枝)を求める /// </summary> /// <returns>木の直径(一番長い枝)</returns> public long GetDiameter() { long firstFarthest = 0; long _1 = 0; GetDiameterImpl(-1, 0, 0, ref _1, ref firstFarthest); long maxDistance = 0; long _2 = 0; GetDiameterImpl(-1, firstFarthest, 0, ref maxDistance, ref _2); return maxDistance; } private void GetDiameterImpl(long from, long current, long distance, ref long maxDistance, ref long farthest) { if (distance > maxDistance) { maxDistance = distance; farthest = current; } foreach (var to in To(current)) { if (from == to) continue; GetDiameterImpl(current, to, distance + 1, ref maxDistance, ref farthest); } } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetCountLarger<T>(T x, IList<T> listOrdered) where T : IComparable { return listOrdered.Count - GetCountSmallerOrEqual(x, listOrdered); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetCountLargerOrEqual<T>(T x, IList<T> listOrdered) where T : IComparable { return listOrdered.Count - GetCountSmaller(x, listOrdered); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetCountSmaller<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered) + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetCountSmallerOrEqual<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low; if (listOrdered[high].CompareTo(x) <= 0) return high + 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid].CompareTo(x) > 0) high = mid; else low = mid + 1; } return low; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low - 1; if (listOrdered[0].CompareTo(x) >= 0) return low - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid].CompareTo(x) < 0) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(int a, int b) => Gcd((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(int a, int b) => Lcm((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(int n, int p) => Pow((long)n, (long)p); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(int n) => Divisors((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long InversionNumberCountWithCompression<T>(IList<T> list) where T : IComparable<T> { var compressed = list.Select((n, i) => new { n, i }) .GroupBy(x => x.n) .OrderBy(x => x.Key) .Select((g, i) => new { g, i }) .SelectMany(x => x.g.Select(xs => new { order = xs.i, index = x.i })) .OrderBy(x => x.index) .Select(x => x.order); return InversionNumberCount(compressed, list.Count); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long InversionNumberCountWithMinusCheck(IList<int> list) { var min = list.Min(); var max = list.Max(); if (min < 0) return InversionNumberCount(list.Select(x => x - min), max - min); else return InversionNumberCount(list, max); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long InversionNumberCount(IEnumerable<int> list, int maxValue) { var bit = new BinaryIndexTree(maxValue + 1); var res = 0L; var i = 0; foreach (var n in list) { res += i - bit.Sum(n); bit.Add(n, +1); i++; } return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<T> Repeat<T>(T t, long n) { for (long i = 0L; i < n; i++) yield return t; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set998244353() { divider = 998244353L; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, long b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, int b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, long b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, int b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, long b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, int b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, long b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, int b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint Pow(long p) => new Mint(PowImpl(Value, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; namespace V { partial class Solver { public void Solve() { // var n = Read; Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var n = Read; var r = new Random(); var a = Arr(n); //.Select(x => (long)Math.Abs(r.Next()) * //(long)Math.Abs(r.Next()) % (1L << 60)).ToArray(); var res = new Mint(); for (int i = 0; i < 61; i++) { long f = 1L << i; long a0 = a.LongCount(x => (x & f) == 0L); long a1 = a.LongCount(x => (x & f) != 0L); res += new Mint(f) * new Mint(a0) * new Mint(a1); } // var res2 = new Mint(); // for (int i = 0; i < n; i++) //{ // for (int j = i + 1; j < n; j++) // { // res2 += new Mint(a[i] ^ a[j]); // } //} // Wr(res2); return res.Value; } public bool SolveBool() { var n = Read; var res = false; return res; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SafeAdd<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { return false; } else { ts.Add(t); return false; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SafeRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafePlus<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToDigit(this char c) => (long)(c - '0'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToStr(this IEnumerable<char> cs) => new string(cs.ToArray()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToLong(this IEnumerable<char> s) { var basis = 1L; var res = 0L; foreach (var c in s) { var d = c.ToSmallAbcIndex() + 1; res += d * basis; basis *= 27; } return res; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] // public static bool TryMin<T>(this ref T current, T newer) where T : struct, // IComparable<T> //{ // if (current.CompareTo(newer) <= 0) // return false; // current = newer; // return true; //} //[MethodImpl(MethodImplOptions.AggressiveInlining)] // public static bool TryMax<T>(this ref T current, T newer) where T : struct, // IComparable<T> //{ // if (current.CompareTo(newer) >= 0) // return false; // current = newer; // return true; //} } class C { public class SegmentTree<T> { private readonly int valueCount; private readonly int baseCount; private readonly int baseIndex; private readonly T[] nodes; private readonly Func<T, T, T> func; private readonly T defaultValue; public SegmentTree(IReadOnlyList<T> ts, Func<T, T, T> func, T filling = default(T)) { this.func = func; this.defaultValue = filling; valueCount = ts.Count; baseCount = 1; while (valueCount > baseCount) baseCount <<= 1; nodes = new T[baseCount * 2 - 1]; baseIndex = baseCount - 1; for (int i = 0; i < ts.Count; i++) nodes[baseIndex + i] = ts[i]; for (int i = ts.Count; i < baseCount; i++) nodes[baseIndex + i] = filling; for (int i = baseIndex - 1; i >= 0; i--) nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int index, T t) { var i = baseIndex + index; nodes[i] = t; while (i > 0) { i -= 1; i /= 2; nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int leftIndex, int rightNextIndex) { T left = defaultValue; T right = defaultValue; int l = leftIndex + baseCount - 1; int r = rightNextIndex + baseCount - 1; for (; l < r; l >>= 1, r >>= 1) { if ((l & 1) == 0) { left = func.Invoke(left, nodes[l]); } if ((r & 1) == 0) { r--; right = func.Invoke(right, nodes[r]); } } return func.Invoke(left, right); } } public class SegmentTree { public static SegmentTree<int> Sum(IReadOnlyList<int> values) => new SegmentTree<int>(values, (x, y) => x + y); public static SegmentTree<long> Sum(IReadOnlyList<long> values) => new SegmentTree<long>(values, (x, y) => x + y); public static SegmentTree<double> Sum(IReadOnlyList<double> values) => new SegmentTree<double>(values, (x, y) => x + y); public static SegmentTree<int> Mult(IReadOnlyList<int> values) => new SegmentTree<int>(values, (x, y) => x * y, 1); public static SegmentTree<long> Mult(IReadOnlyList<long> values) => new SegmentTree<long>(values, (x, y) => x * y, 1); public static SegmentTree<double> Mult(IReadOnlyList<double> values) => new SegmentTree<double>(values, (x, y) => x * y, 1); public static SegmentTree<int> Min(IReadOnlyList<int> values) => new SegmentTree<int>(values, Math.Min, int.MaxValue); public static SegmentTree<long> Min(IReadOnlyList<long> values) => new SegmentTree<long>(values, Math.Min, long.MaxValue); public static SegmentTree<double> Min(IReadOnlyList<double> values) => new SegmentTree<double>(values, Math.Min, double.MaxValue); public static SegmentTree<int> Max(IReadOnlyList<int> values) => new SegmentTree<int>(values, Math.Max, int.MinValue); public static SegmentTree<long> Max(IReadOnlyList<long> values) => new SegmentTree<long>(values, Math.Max, long.MinValue); public static SegmentTree<double> Max(IReadOnlyList<double> values) => new SegmentTree<double>(values, Math.Max, double.MinValue); } public class UnionFind { private int[] parents; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UnionFind(int count) { parents = Enumerable.Repeat(-1, count).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryUnite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) return false; if (parents[rootY] < parents[rootX]) { var temp = rootX; rootX = rootY; rootY = temp; } parents[rootX] += parents[rootY]; parents[rootY] = rootX; return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Find(int x, int y) => GetRoot(x) == GetRoot(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetRoot(int x) { while (parents[x] >= 0) x = parents[x]; return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long GetSize(int x) => -parents[GetRoot(x)]; } public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } /// <summary> /// 木の直径(一番長い枝)を求める /// </summary> /// <returns>木の直径(一番長い枝)</returns> public long GetDiameter() { long firstFarthest = 0; long _1 = 0; GetDiameterImpl(-1, 0, 0, ref _1, ref firstFarthest); long maxDistance = 0; long _2 = 0; GetDiameterImpl(-1, firstFarthest, 0, ref maxDistance, ref _2); return maxDistance; } private void GetDiameterImpl(long from, long current, long distance, ref long maxDistance, ref long farthest) { if (distance > maxDistance) { maxDistance = distance; farthest = current; } foreach (var to in To(current)) { if (from == to) continue; GetDiameterImpl(current, to, distance + 1, ref maxDistance, ref farthest); } } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetCountLarger<T>(T x, IList<T> listOrdered) where T : IComparable { return listOrdered.Count - GetCountSmallerOrEqual(x, listOrdered); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetCountLargerOrEqual<T>(T x, IList<T> listOrdered) where T : IComparable { return listOrdered.Count - GetCountSmaller(x, listOrdered); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetCountSmaller<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered) + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetCountSmallerOrEqual<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low; if (listOrdered[high].CompareTo(x) <= 0) return high + 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid].CompareTo(x) > 0) high = mid; else low = mid + 1; } return low; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low - 1; if (listOrdered[0].CompareTo(x) >= 0) return low - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid].CompareTo(x) < 0) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(int a, int b) => Gcd((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(int a, int b) => Lcm((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(int n, int p) => Pow((long)n, (long)p); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(int n) => Divisors((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long InversionNumberCountWithCompression<T>(IList<T> list) where T : IComparable<T> { var compressed = list.Select((n, i) => new { n, i }) .GroupBy(x => x.n) .OrderBy(x => x.Key) .Select((g, i) => new { g, i }) .SelectMany(x => x.g.Select(xs => new { order = xs.i, index = x.i })) .OrderBy(x => x.index) .Select(x => x.order); return InversionNumberCount(compressed, list.Count); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long InversionNumberCountWithMinusCheck(IList<int> list) { var min = list.Min(); var max = list.Max(); if (min < 0) return InversionNumberCount(list.Select(x => x - min), max - min); else return InversionNumberCount(list, max); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long InversionNumberCount(IEnumerable<int> list, int maxValue) { var bit = new BinaryIndexTree(maxValue + 1); var res = 0L; var i = 0; foreach (var n in list) { res += i - bit.Sum(n); bit.Add(n, +1); i++; } return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<T> Repeat<T>(T t, long n) { for (long i = 0L; i < n; i++) yield return t; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set998244353() { divider = 998244353L; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint(long value) { this.Value = value % divider; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, long b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, int b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, long b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, int b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, long b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, int b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, long b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, int b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint Pow(long p) => new Mint(PowImpl(Value, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 11, 12, 16, 31, 16, 12, 230, 0, 228], ["+", 0, 11, 12, 16, 31, 16, 12, 230, 39, 22], ["+", 12, 16, 31, 16, 12, 230, 3, 4, 0, 24], ["+", 12, 16, 31, 16, 12, 230, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 230, 0, 228], ["+", 0, 1, 0, 11, 12, 16, 12, 230, 39, 22], ["+", 0, 11, 12, 16, 12, 230, 3, 4, 0, 24], ["+", 0, 11, 12, 16, 12, 230, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
10,623
26
using System; public class Program { private int N; private long[] A; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); A = sc.LongArray(); // [i+1,N)のxor // [0,i)で j桁目が1の奴の個数の和 cnt[j,i] long[][] cnt = new long [60][]; for (int i = 0; i < 60; i++) { cnt[i] = new long[N + 1]; } for (int i = 0; i < N; i++) { for (int j = 0; j < 60; j++) { long bit = 1L << j; if ((A[i] & bit) > 0) { cnt[j][i + 1] = cnt[j][i] + 1; } else { cnt[j][i + 1] = cnt[j][i]; } } } ModInt ans = 0; for (int i = 0; i < N - 1; i++) { for (int j = 0; j < 60; j++) { // [i+1, N)の個数 long on = cnt[j][N] - cnt[j][i + 1]; long off = N - i - 1 - on; long b = 1L << j; bool bit = (A[i] & b) > 0; if (bit) { ans += off * b; } else { ans += on * b; } } } Console.WriteLine(ans); } public static void Main(string[] args) { new Program().Solve(); } } #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; public class Program { private int N; private long[] A; public void Solve() { var sc = new Scanner(); N = sc.NextInt(); A = sc.LongArray(); // [i+1,N)のxor // [0,i)で j桁目が1の奴の個数の和 cnt[j,i] long[][] cnt = new long [60][]; for (int i = 0; i < 60; i++) { cnt[i] = new long[N + 1]; } for (int i = 0; i < N; i++) { for (int j = 0; j < 60; j++) { long bit = 1L << j; if ((A[i] & bit) > 0) { cnt[j][i + 1] = cnt[j][i] + 1; } else { cnt[j][i + 1] = cnt[j][i]; } } } ModInt ans = 0; for (int i = 0; i < N - 1; i++) { for (int j = 0; j < 60; j++) { // [i+1, N)の個数 long on = cnt[j][N] - cnt[j][i + 1]; long off = N - i - 1 - on; long b = 1L << j; bool bit = (A[i] & b) > 0; ModInt bb = b; if (bit) { ans += off * bb; } else { ans += on * bb; } } } Console.WriteLine(ans); } public static void Main(string[] args) { new Program().Solve(); } } #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion class Scanner { public Scanner() { _pos = 0; _line = new string[0]; } const char Separator = ' '; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = Console.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = Console.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 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, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
1,091
9
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.D { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var N = ReadLong(); var A = ReadLongs(); var zeroCountByDigits = new long[60]; var oneCountByDigits = new long[60]; for (var i = 0; i < N; i++) { var bit = Convert.ToString(A[i], 2).PadLeft(60, '0'); for (var j = 0; j < 60; j++) { var x = bit[60 - 1 - j]; if (x == '0') { zeroCountByDigits[j]++; } else { oneCountByDigits[j]++; } } } var sum = new Modular(); for (var i = 0; i < 60; i++) { sum += (long)Math.Pow(2, i) * zeroCountByDigits[i] * oneCountByDigits[i]; } return sum; } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion public class Modular { public long Value { get; private set; } private static readonly long _mod = (long)Math.Pow(10, 9) + 7; private static readonly List<int> _facCache = new List<int> { 1 }; public static explicit operator long(Modular m) { return m.Value; } public static implicit operator Modular(long a) { var m = a % _mod; return new Modular { Value = (m < 0) ? m + _mod : m }; } public static Modular operator +(Modular a, Modular b) { return a.Value + b.Value; } public static Modular operator -(Modular a, Modular b) { return a.Value - b.Value; } public static Modular operator *(Modular a, Modular b) { return a.Value * b.Value; } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, _mod - 2); } public static Modular Pow(Modular a, long n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular Factorial(long n) { for (var i = _facCache.Count; i <= n; ++i) { var fac = (int)(Math.BigMul(_facCache.Last(), i) % _mod); _facCache.Add(fac); } return _facCache[(int)n]; } public static Modular Combination(long n, long r) { Modular ans = 1; for (var i = 0; i < r; i++) { ans *= n - i; } for (var i = 1; i <= r; i++) { ans /= i; } return ans; } public override string ToString() { return Value.ToString(); } } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.D { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var N = ReadLong(); var A = ReadLongs(); var zeroCountByDigits = new long[60]; var oneCountByDigits = new long[60]; for (var i = 0; i < N; i++) { var bit = Convert.ToString(A[i], 2).PadLeft(60, '0'); for (var j = 0; j < 60; j++) { var x = bit[60 - 1 - j]; if (x == '0') { zeroCountByDigits[j]++; } else { oneCountByDigits[j]++; } } } var sum = new Modular(); for (var i = 0; i < 60; i++) { var pow = (Modular)(long)Math.Pow(2, i); sum += pow * zeroCountByDigits[i] * oneCountByDigits[i]; } return sum; } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion public class Modular { public long Value { get; private set; } private static readonly long _mod = (long)Math.Pow(10, 9) + 7; private static readonly List<int> _facCache = new List<int> { 1 }; public static explicit operator long(Modular m) { return m.Value; } public static implicit operator Modular(long a) { var m = a % _mod; return new Modular { Value = (m < 0) ? m + _mod : m }; } public static Modular operator +(Modular a, Modular b) { return a.Value + b.Value; } public static Modular operator -(Modular a, Modular b) { return a.Value - b.Value; } public static Modular operator *(Modular a, Modular b) { return a.Value * b.Value; } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, _mod - 2); } public static Modular Pow(Modular a, long n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular Factorial(long n) { for (var i = _facCache.Count; i <= n; ++i) { var fac = (int)(Math.BigMul(_facCache.Last(), i) % _mod); _facCache.Add(fac); } return _facCache[(int)n]; } public static Modular Combination(long n, long r) { Modular ans = 1; for (var i = 0; i < r; i++) { ans *= n - i; } for (var i = 1; i <= r; i++) { ans /= i; } return ans; } public override string ToString() { return Value.ToString(); } } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22]]
8
759
12
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { var n = Read().Int(); var r = ReadSplit(); var l = new long[n]; for (int i = 0; i < n; i++) { l[i] = r[i].Long(); } var ans = 0D; for (int i = 0; i <= 60; i++) { var x = 0D; var y = 0D; for (int j = 0; j < n; j++) { if ((l[j] >> i & 1) == 1) { x++; } else y++; } ans += ((x * y) % mod) * (Math.Pow(2, i) % mod) % mod; } WriteRead(ans % mod); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { // var N = Read().ToInt64(); // var l = new List<long>(); // var r = ReadSplit(); // for (int i = 0; i < N; i++) //{ // l.Add(r[i].ToInt64()); //} // var mod = 1000000007; // double ans = 0; // for (int i = 0; i < 60; i++) //{ // double x = 0; // double y = 0; // for (int j = 0; j < N; j++) // { // if ((l[j] >> i & 1) == 1) // { // x++; // } // else y++; // } // double tmp = (x * y) % mod; // ans += (tmp * Math.Pow(2, i)) % mod; //} // WriteRead(ans % mod); var n = Read().Int(); var r = ReadSplit(); var l = new long[n]; for (int i = 0; i < n; i++) { l[i] = r[i].Long(); } var ans = 0D; for (int i = 0; i < 60; i++) { var x = 0D; var y = 0D; for (int j = 0; j < n; j++) { if ((l[j] >> i & 1) == 1) { x++; } else y++; } var tmp = (x * y) % mod; ans += (tmp * Math.Pow(2, i)) % mod; } WriteRead(ans % mod); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 11, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 11, 12, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 48], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 17, 109], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 22]]
8
538
17
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var N = Sarray()[0]; var Ai = Sarray(); var ans = 0L; var mask = 1L; for (var i = 0; i < 60; ++i, mask <<= 1) { var one = 0L; var zero = 0L; foreach (var a in Ai) { if (0 == (mask & a)) ++zero; else ++one; } ans = (ans + (mask * (one * zero) % Mod) % Mod) % Mod; } WriteLine(ans); Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var N = Sarray()[0]; var Ai = Sarray(); var ans = 0L; var mask = 1L; for (var i = 0; i < 60; ++i, mask <<= 1) { var one = 0L; var zero = 0L; foreach (var a in Ai) { if (0 == (mask & a)) ++zero; else ++one; } var num = (one * zero) % Mod; var cff = mask % Mod; ans = (ans + cff * num) % Mod; } WriteLine(ans); Out.Flush(); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 31, 23, 0, 16, 12, 16, 31, 23, 0, 24], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["-", 31, 23, 0, 16, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 12, 22]]
8
260
24
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var A = sc.ReadLongArray(N); ModInt ans = 0; for (int k = 0; k <= 60; k++) { long x0 = 0; long x1 = 0; for (int i = 0; i < N; i++) { var x = (A[i] >> k) & 1; if (x == 0) x0++; else x1++; } var p = (long)Math.Pow(2, k); ans += (x0 * x1) * p; } Console.WriteLine(ans); } public struct ModInt { public const long Mod = (int)1e9 + 7; public long num; public ModInt(long n) { num = n; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } private static List<ModInt> Facs = new List<ModInt> { 1 }; public static ModInt Fac(int n) { for (int i = Facs.Count; i <= n; i++) { Facs.Add(i * Facs[i - 1]); } return Facs[n]; } public static ModInt nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; // var res = Fac(n).num; // res /= (Fac(r).num * Fac(n - r).num); // return res % Mod; var b = new BinomialCoefficient(n); return b[n, r]; } } public class BinomialCoefficient { public ModInt[] fact, ifact; public BinomialCoefficient(int n) { fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { checked { var N = sc.ReadInt(); var A = sc.ReadLongArray(N); ModInt ans = 0; for (int k = 0; k <= 60; k++) { ModInt x0 = 0; ModInt x1 = 0; for (int i = 0; i < N; i++) { var x = (A[i] >> k) & 1; if (x == 0) x0 += 1; else x1 += 1; } ModInt p = ModInt.Pow(2, k); ans += x0 * x1 * p; } Console.WriteLine(ans); } } public struct ModInt { public const long Mod = (int)1e9 + 7; public long num; public ModInt(long n) { num = n; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; } public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } private static List<ModInt> Facs = new List<ModInt> { 1 }; public static ModInt Fac(int n) { for (int i = Facs.Count; i <= n; i++) { Facs.Add(i * Facs[i - 1]); } return Facs[n]; } public static ModInt nCr(int n, int r) { if (n < r) return 0; if (n == r) return 1; // var res = Fac(n).num; // res /= (Fac(r).num * Fac(n - r).num); // return res % Mod; var b = new BinomialCoefficient(n); return b[n, r]; } } public class BinomialCoefficient { public ModInt[] fact, ifact; public BinomialCoefficient(int n) { fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } 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; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 287, 0, 292], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 57, 75, 1, 0, 223, 0, 29], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 287, 0, 196, 0, 46]]
8
1,763
22
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { // modをかける場所がわからない int N = int.Parse(Console.ReadLine()); long[] A = new long[N]; string[] str = Console.ReadLine().Split(); for (var i = 0; i < N; i++) { A[i] = long.Parse(str[i]); } long ans = 0; int mod = (int)1e9 + 7; // bit列60桁分をすべて走査する for (int k = 0; k < 60; k++) { long x0 = 0; long x1 = 0; for (int i = 0; i < N; i++) { // k桁目をビット演算で取り出す var x = (A[i] >> k) & 1; // k桁目が 0, 1 のどちらかを数えておく if (x == 0) x0 += 1; else x1 += 1; } long p = 1; for (int i = 0; i < k; i++) { p *= 2; p %= mod; } // x0 * x1 が 0, 1 の組み合わせ数 var count = (x0 * x1) % mod; ans += count * p; ans %= mod; } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { // modをかける場所がわからない int N = int.Parse(Console.ReadLine()); long[] A = new long[N]; string[] str = Console.ReadLine().Split(); for (var i = 0; i < N; i++) { A[i] = long.Parse(str[i]); } long ans = 0; int mod = (int)1e9 + 7; // bit列60桁分をすべて走査する for (int k = 0; k < 60; k++) { long x0 = 0; long x1 = 0; for (int i = 0; i < N; i++) { // k桁目をビット演算で取り出す var x = (A[i] >> k) & 1; // k桁目が 0, 1 のどちらかを数えておく if (x == 0) x0 += 1; else x1 += 1; } long p = 1; for (int i = 0; i < k; i++) { p *= 2; p %= mod; } // x0 * x1 が 0, 1 の組み合わせ数 var count = (x0 * x1) % mod; ans += count * p; ans %= mod; } Console.WriteLine(ans); } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
237
7
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG // MyDebugger.MakeTestCase("../TextFile2.txt"); return; MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static long mod = 1000000007; static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var aa = ToIntArray(input.ReadLine(), n); var sum = 0L; for (int i = 0; i < 64; i++) { var x = 0L; for (int j = 0; j < n; j++) { x += (aa[j] >> i) % 2; } sum += (x * (n - x) << i); sum %= mod; } return sum; } static void print(long list) { var buil = new StringBuilder(); for (int i = 0; i < 64; i++) { buil.Append((list >> (63 - i)) % 2); } Debug.Write(buil); Debug.WriteLine("(" + list + ")"); } static long[] ToIntArray(string strs, int n) { var ret = new long[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = long.Parse(spl[i]); return ret; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { #if DEBUG // MyDebugger.MakeTestCase("../TextFile2.txt"); return; MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static long mod = 1000000007; static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var aa = ToIntArray(input.ReadLine(), n); var sum = 0L; for (int i = 0; i < 64; i++) { var x = 0L; for (int j = 0; j < n; j++) { x += (aa[j] >> i) % 2; } var ss = x * (n - x); for (int j = 0; j < i; j++) { ss *= 2; ss %= mod; } sum += ss; sum %= mod; } return sum; } static void print(long list) { var buil = new StringBuilder(); for (int i = 0; i < 64; i++) { buil.Append((list >> (63 - i)) % 2); } Debug.Write(buil); Debug.WriteLine("(" + list + ")"); } static long[] ToIntArray(string strs, int n) { var ret = new long[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = long.Parse(spl[i]); return ret; } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 17, 151], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 24], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 7, 0, 35], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107]]
8
345
33
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var wrong_answer = new wrong_answer(); wrong_answer.Solve(); } } public class wrong_answer { const int MOD = 1000000007; const int INF = 1 << 20; const long INFL = 1 << 62; const int MOD2 = 998244353; myinout IO = new myinout(); Math2 mmath = new Math2(); public void Solve() { //ここから var n = IO.int1; var a = IO.longm; long ans = 0; for (int i = 0; i < 62; ++i) { long cnt = 0; foreach (var x in a) cnt += (x >> i) & 1; ans += (cnt % MOD * (n - cnt) % MOD) % MOD * (1L << i) % MOD; ans %= MOD; } IO.wri(ans); } } // b-aで降順 public class Math2 { public long[] fact; // Nまでの階乗 public long[] invfact; //階乗の逆元 // Nまでの階乗をセットしておく public void factoricalmodset(long N, long MOD = 1000000007) { fact = new long[N + 1]; invfact = new long[N + 1]; fact[0] = 1; for (long i = 1; i <= N; ++i) { fact[i] = fact[i - 1] * i % MOD; } invfact[N] = pow(fact[N], MOD - 2); for (long i = N; i > 0; --i) { invfact[i - 1] = invfact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long i, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * i % MOD; i = i * i % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long gcd(long i, long y) { while (y != 0) { var r = i % y; i = y; y = r; } return i; } //最小公倍数 引数:整数x,y public long lcm(long i, long y) { return i * y / gcd(i, y); } //素因数分解 引数:整数N public Dictionary<long, int> primefactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } //約数列挙 public List<long> divisorenumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } public void swap<T>(ref T a, ref T b) { var i = a; a = b; b = i; } } class myinout { // in public string str => Console.ReadLine(); public string[] strm => str.Split(' '); public long[] longm => strm.Select(long.Parse).ToArray(); public int[] intm => strm.Select(int.Parse).ToArray(); public char[] charm => str.ToArray(); public long long1 => longm[0]; public int int1 => intm[0]; public char char1 => charm[0]; // out public void wri<T>(T i) { Console.WriteLine(i); } public void yn(bool i) { if (i) wri("Yes"); else wri("No"); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var wrong_answer = new wrong_answer(); wrong_answer.Solve(); } } public class wrong_answer { const int MOD = 1000000007; const int INF = 1 << 20; const long INFL = 1 << 62; const int MOD2 = 998244353; myinout IO = new myinout(); Math2 mmath = new Math2(); public void Solve() { //ここから var n = IO.int1; var a = IO.longm; long ans = 0; for (int i = 0; i < 62; ++i) { long cnt = 0; foreach (var x in a) cnt += (x >> i) & 1; ans += ((cnt % MOD * (n - cnt) % MOD * ((1L << i) % MOD)) % MOD); ans %= MOD; } IO.wri(ans); } } // b-aで降順 public class Math2 { public long[] fact; public long[] invfact; public void factoricalmodset(long N, long MOD = 1000000007) { fact = new long[N + 1]; invfact = new long[N + 1]; fact[0] = 1; for (long i = 1; i <= N; ++i) { fact[i] = fact[i - 1] * i % MOD; } invfact[N] = pow(fact[N], MOD - 2); for (long i = N; i > 0; --i) { invfact[i - 1] = invfact[i] * i % MOD; } } public long nCr(long n, long r, long MOD = 1000000007) { return (fact[n] * invfact[r] % MOD * invfact[n - r] % MOD); } public long pow(long i, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * i % MOD; i = i * i % MOD; n >>= 1; } return res; } public long gcd(long i, long y) { while (y != 0) { var r = i % y; i = y; y = r; } return i; } public long lcm(long i, long y) { return i * y / gcd(i, y); } public Dictionary<long, int> primefactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } public List<long> divisorenumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } public void swap<T>(ref T a, ref T b) { var i = a; a = b; b = i; } } class myinout { // in public string str => Console.ReadLine(); public string[] strm => str.Split(' '); public long[] longm => strm.Select(long.Parse).ToArray(); public int[] intm => strm.Select(int.Parse).ToArray(); public char[] charm => str.ToArray(); public long long1 => longm[0]; public int int1 => intm[0]; public char char1 => charm[0]; // out public void wri<T>(T i) { Console.WriteLine(i); } public void yn(bool i) { if (i) wri("Yes"); else wri("No"); } }
[["+", 0, 11, 12, 23, 0, 16, 31, 23, 0, 24], ["-", 12, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["-", 0, 11, 12, 16, 31, 16, 31, 16, 17, 109], ["-", 0, 11, 12, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 25], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25]]
8
873
10
using System; using System.Collections.Generic; using System.Linq; namespace ABC146_E___Rem_of_Sum_is_Num { class Program { static void Main(string[] args) { var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = NK[0]; var K = NK[1]; var A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var minus1A = A.Select(n => n - 1).ToArray(); var accumA = new long[N + 1]; accumA[0] = 0; for (int i = 1; i < N + 1; i++) accumA[i] = accumA[i - 1] + minus1A[i - 1]; accumA = accumA.Select(n => n % K).ToArray(); var dic = new Dictionary<long, long>(); for (int i = 1; i < Math.Min(K, N + 1); i++) { if (dic.ContainsKey(accumA[i])) dic[accumA[i]] += 1; else dic.Add(accumA[i], 1); } var result = 0L; result += dic.ContainsKey(0) ? dic[0] : 0; for (int i = 1; i < N + 1; i++) { if (dic.ContainsKey(accumA[i])) dic[accumA[i]] -= 1; if (N >= i + K - 1) { if (dic.ContainsKey(accumA[i + K - 1])) dic[accumA[i + K - 1]] += 1; else dic.Add(accumA[i + K - 1], 1); } result += dic.ContainsKey(accumA[i]) ? dic[accumA[i]] : 0; } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC146_E___Rem_of_Sum_is_Num { class Program { static void Main(string[] args) { Console.WriteLine(solver()); } static long solver() { var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = NK[0]; var K = NK[1]; if (K == 1) return 0; var A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var minus1A = A.Select(n => n - 1).ToArray(); var accumA = new long[N + 1]; accumA[0] = 0; for (int i = 1; i < N + 1; i++) accumA[i] = accumA[i - 1] + minus1A[i - 1]; accumA = accumA.Select(n => n % K).ToArray(); var dic = new Dictionary<long, long>(); for (int i = 1; i < Math.Min(K, N + 1); i++) { if (dic.ContainsKey(accumA[i])) dic[accumA[i]] += 1; else dic.Add(accumA[i], 1); } var result = 0L; result += dic.ContainsKey(0) ? dic[0] : 0; for (int i = 1; i < N + 1; i++) { if (dic.ContainsKey(accumA[i])) dic[accumA[i]] -= 1; if (N >= i + K - 1) { if (dic.ContainsKey(accumA[i + K - 1])) dic[accumA[i + K - 1]] += 1; else dic.Add(accumA[i + K - 1], 1); } result += dic.ContainsKey(accumA[i]) ? dic[accumA[i]] : 0; } return result; } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
410
31
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; static class CodeJam { static int Mod(long n, int K) { return (int)(((n % K) + K) % K); } static long Solve(int N, int K, int[] A) { long sum = 0; var cnts = new Dictionary<int, int>(); var S = new long[N + 1]; for (int i = 0; i < N; ++i) { S[i + 1] = S[i] + A[i]; } for (int j = 1; j <= N; ++j) { if (j >= K) { int i = j - K; int n = Mod(S[i] - i, K); if (cnts.ContainsKey(n)) { --cnts[n]; } } { int i = j - 1; int n = Mod(S[i] - i, K); if (!cnts.ContainsKey(n)) { cnts[n] = 0; } ++cnts[n]; } { int n = Mod(S[j] - j, K); if (cnts.ContainsKey(n)) { sum += cnts[n]; } } } return sum; } static void Main(string[] args) { int[] V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine(Solve(V[0], V[1], A)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Diagnostics; static class CodeJam { static int Mod(long n, int K) { return (int)(((n % K) + K) % K); } static long Solve(int N, int K, int[] A) { if (K == 1) { return 0; } long sum = 0; var cnts = new Dictionary<int, int>(); var S = new long[N + 1]; for (int i = 0; i < N; ++i) { S[i + 1] = S[i] + A[i]; } for (int j = 1; j <= N; ++j) { if (j >= K) { int i = j - K; int n = Mod(S[i] - i, K); if (cnts.ContainsKey(n)) { --cnts[n]; } } { int i = j - 1; int n = Mod(S[i] - i, K); if (!cnts.ContainsKey(n)) { cnts[n] = 0; } ++cnts[n]; } { int n = Mod(S[j] - j, K); if (cnts.ContainsKey(n)) { sum += cnts[n]; } } } return sum; } static void Main(string[] args) { int[] V = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); Console.WriteLine(Solve(V[0], V[1], A)); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
375
11
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var s = sc.Ia; var a = sc.Ia2; var r = new int[s[0] + 1]; var hs = new Dictionary<int, int>(); hs.Add(0, 1); long ans = 0; for (int i = 1; i <= s[0]; i++) { r[i] = a[i] - 1; r[i] += r[i - 1]; r[i] %= s[1]; if (hs.ContainsKey(r[i])) { ans += hs[r[i]]; hs[r[i]]++; } else { hs.Add(r[i], 1); } if (i >= s[1] - 1) { hs[r[i + 1 - s[1]]]--; } } Console.WriteLine(ans); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; static void Main() { Sc sc = new Sc(); var s = sc.Ia; var a = sc.Ia2; var r = new int[s[0] + 1]; var hs = new Dictionary<int, int>(); hs.Add(0, 1); long ans = 0; for (int i = 1; i <= s[0]; i++) { r[i] = a[i] - 1; r[i] += r[i - 1]; r[i] %= s[1]; if (hs.ContainsKey(r[i])) { ans += hs[r[i]]; hs[r[i]]++; } else { hs.Add(r[i], 1); } if (i >= s[1] - 1) { hs[r[i + 1 - s[1]]]--; } } Console.WriteLine(s[1] == 1 ? 0 : ans); } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), int.Parse); } public int[] Ia3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(int a) { return Array.ConvertAll((a.ToString() + " " + Console.ReadLine()).Split(), long.Parse); } public long[] La3(bool a, int b, bool c, int d) { return Array.ConvertAll(((a ? b.ToString() + " " : "") + Console.ReadLine() + (c ? " " + d.ToString() : "")) .Split(), long.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["+", 0, 28, 0, 41, 15, 16, 31, 204, 205, 22], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 60], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102]]
8
1,067
9
using System; using System.Collections.Generic; using System.Linq; public static class Common { public static void Increment<T>(this Dictionary<T, long> dict, T key) { if (dict.ContainsKey(key)) { dict[key]++; } else { dict[key] = 1; } } public static void Decrement<T>(this Dictionary<T, long> dict, T key) { dict[key]--; } public static long Get<T>(this Dictionary<T, long> dict, T key) { long count = 0; dict.TryGetValue(key, out count); return count; } } public class Solution { public static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = vals[0]; var K = vals[1]; var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var acc = new long[N + 1]; for (int i = 1; i <= N; i++) { acc[i] += acc[i - 1] + A[i - 1]; } var mods = new long[N + 1]; for (int i = 0; i <= N; i++) { mods[i] = (acc[i] - i) % K; } var dict = new Dictionary<long, long>(); long count = 0; for (int j = 1; j <= N; j++) { var prevLeft = j - 1 - K + 1; if (prevLeft >= 0) { dict.Decrement(mods[prevLeft]); } var i = j - 1; dict.Increment(mods[i]); count += dict.Get(mods[j]); } Console.WriteLine(count); } }
using System; using System.Collections.Generic; using System.Linq; public static class Common { public static void Increment<T>(this Dictionary<T, long> dict, T key) { if (dict.ContainsKey(key)) { dict[key]++; } else { dict[key] = 1; } } public static void Decrement<T>(this Dictionary<T, long> dict, T key) { if (dict.ContainsKey(key)) { dict[key]--; } else { dict[key] = -1; } } public static long Get<T>(this Dictionary<T, long> dict, T key) { long count = 0; dict.TryGetValue(key, out count); return count; } } public class Solution { public static void Main() { var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = vals[0]; var K = vals[1]; var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var acc = new long[N + 1]; for (int i = 1; i <= N; i++) { acc[i] += acc[i - 1] + A[i - 1]; } var mods = new long[N + 1]; for (int i = 0; i <= N; i++) { mods[i] = (acc[i] - i) % K; } var dict = new Dictionary<long, long>(); long count = 0; for (int j = 1; j <= N; j++) { var prevLeft = j - 1 - K + 1; if (prevLeft >= 0) { dict.Decrement(mods[prevLeft]); } var i = j - 1; dict.Increment(mods[i]); count += dict.Get(mods[j]); } Console.WriteLine(count); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 75, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
409
22
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; var m = nm[1]; var s = Console.ReadLine(); int last = n; SegmentTree<int> segTree = new SegmentTree<int>(n, int.MaxValue, Min); for (int i = 0; i < s.Length; i++) { if (s[i] == '1') continue; segTree[i] = i; } List<int> res = new List<int>(); while (last >= 1 && last != int.MaxValue) { var query = segTree.Query(Max(0, last - m), last - 1); res.Add(last - query); last = query; } if (last == int.MaxValue) Console.WriteLine(-1); else Console.WriteLine(string.Join(" ", res.Reverse<int>())); } } class SegmentTree<T> { public int Size { get; private set; } T Identity; T[] Data; Func<T, T, T> Merge; int LeafCount; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, T identity, Func<T, T, T> merge) { Init(size, identity, merge); for (int i = 1; i < Data.Length; i++) Data[i] = identity; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(T[] elems, T identity, Func<T, T, T> merge) { Init(elems.Length, identity, merge); elems.CopyTo(Data, LeafCount); for (int i = elems.Length + LeafCount; i < Data.Length; i++) Data[i] = identity; for (int i = LeafCount - 1; i >= 1; i--) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Init(int size, T identity, Func<T, T, T> merge) { Size = size; Identity = identity; Merge = merge; LeafCount = 1; while (LeafCount < size) LeafCount <<= 1; Data = new T[LeafCount << 1]; } public T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Data[LeafCount + index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] set { Update(index, value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int i, T x) { Data[i += LeafCount] = x; while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Operate(int i, T x) { Data[i += LeafCount] = Merge(Data[i], x); while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int l, int r) { T lRes = Identity, rRes = Identity; for (l += LeafCount, r += LeafCount; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) { if ((l & 1) == 1) lRes = Merge(lRes, Data[l]); if ((r & 1) == 0) rRes = Merge(Data[r], rRes); } return Merge(lRes, rRes); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; var m = nm[1]; var s = Console.ReadLine(); if (n == 1) { Console.WriteLine(1); return; } int last = n; SegmentTree<int> segTree = new SegmentTree<int>(n, int.MaxValue, Min); for (int i = 0; i < s.Length; i++) { if (s[i] == '1') continue; segTree[i] = i; } List<int> res = new List<int>(); while (last >= 1 && last != int.MaxValue) { var query = segTree.Query(Max(0, last - m), last - 1); res.Add(last - query); last = query; } if (last == int.MaxValue) Console.WriteLine(-1); else Console.WriteLine(string.Join(" ", res.Reverse<int>())); } } class SegmentTree<T> { public int Size { get; private set; } T Identity; T[] Data; Func<T, T, T> Merge; int LeafCount; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, T identity, Func<T, T, T> merge) { Init(size, identity, merge); for (int i = 1; i < Data.Length; i++) Data[i] = identity; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(T[] elems, T identity, Func<T, T, T> merge) { Init(elems.Length, identity, merge); elems.CopyTo(Data, LeafCount); for (int i = elems.Length + LeafCount; i < Data.Length; i++) Data[i] = identity; for (int i = LeafCount - 1; i >= 1; i--) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Init(int size, T identity, Func<T, T, T> merge) { Size = size; Identity = identity; Merge = merge; LeafCount = 1; while (LeafCount < size) LeafCount <<= 1; Data = new T[LeafCount << 1]; } public T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Data[LeafCount + index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] set { Update(index, value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int i, T x) { Data[i += LeafCount] = x; while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Operate(int i, T x) { Data[i += LeafCount] = Merge(Data[i], x); while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int l, int r) { T lRes = Identity, rRes = Identity; for (l += LeafCount, r += LeafCount; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) { if ((l & 1) == 1) lRes = Merge(lRes, Data[l]); if ((r & 1) == 0) rRes = Merge(Data[r], rRes); } return Merge(lRes, rRes); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
897
17
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { struct mint : IEquatable<mint> { // static uint mod = 998244353; static uint mod = 1000000007; uint _v; public mint(long v) : this((uint)(v % mod + mod)) {} private mint(uint v) { _v = v < mod ? v : (v - mod); } public static void SetMod(uint p) { mod = p; } public static mint operator +(mint lhs, mint rhs) { return new mint(lhs._v + rhs._v); } public static mint operator -(mint lhs, mint rhs) { return new mint(lhs._v + mod - rhs._v); } public static mint operator *(mint lhs, mint rhs) { return new mint((uint)((ulong)lhs._v * rhs._v % mod)); } public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); } public static mint operator ^(mint x, int n) { return Pow(x, n); } public static bool operator ==(mint l, mint r) { return l._v == r._v; } public static bool operator !=(mint l, mint r) { return !(l == r); } public static bool operator<(mint l, mint r) { return l._v < r._v; } public static bool operator>(mint l, mint r) { return l._v > r._v; } public static mint Pow(mint x, int n) { var r = new mint(1); while (n > 0) { if ((n & 1) > 0) r *= x; x *= x; n >>= 1; } return r; } public mint Pow(int n) { return Pow(this, n); } public mint Inv() { return Pow((int)mod - 2); } public bool Equals(mint o) { return this == o; } public override bool Equals(object obj) { if (obj is mint) return this == (mint)obj; else return false; } public override int GetHashCode() { return _v.GetHashCode(); } public override string ToString() { return _v.ToString(); } public static implicit operator mint(int i) { return new mint(i); } public static implicit operator mint(long i) { return new mint(i); } private static mint[] _fact; public static void SetFact(int n) { _fact = new mint[n + 1]; _fact[0] = 1; for (int i = 1; i < n + 1; i++) { _fact[i] = _fact[i - 1] * i; } } public static mint Fact(int n) { if (_fact == null || _fact.Length < n) { SetFact(n * 2); } return _fact[n]; } public static mint Combination(int n, int r) { return Fact(n) / (Fact(n - r) * Fact(r)); } } static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class MinHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MinHeap() : this(0) {} public MinHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c < 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) { j++; } if (_comp.Compare(_list[i], _list[j]) > 0) { Swap(i, j); i = j; } else { return result; } } } public MinHeap<T> Copy(Comparison<T> comp = null) { var c = new MinHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MinHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMul(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMul(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMul(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } class Graph<T> { private int _size; private List<T>[] _edges; public Graph(int size) { _size = size; _edges = new List<T>[size]; } public List<T> this[int i] { get { if (_edges[i] == null) _edges[i] = new List<T>(); return _edges[i]; } } } static Graph<T> NewGraph<T>(int size, T template) { return new Graph<T>(size); } static List<T> NewList<T>(T template) { return new List<T>(); } static T[] NewArray<T>(int size, T template) { return new T[size]; } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var s = Console.ReadLine(); var r = new Stack<int>(); var i = n; while (i > 0) { for (int j = m; j >= 0; j--) { if (j == 0) { i = -1; break; } var k = Math.Min(j, i); if (s[i - k] == '0') { r.Push(k); i -= k; break; } } } if (i < 0) { Console.WriteLine(-1); return; } Console.Write(r.Pop()); while (r.Any()) { Console.Write(r.Pop()); } Console.WriteLine(); //↑ } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { struct mint : IEquatable<mint> { // static uint mod = 998244353; static uint mod = 1000000007; uint _v; public mint(long v) : this((uint)(v % mod + mod)) {} private mint(uint v) { _v = v < mod ? v : (v - mod); } public static void SetMod(uint p) { mod = p; } public static mint operator +(mint lhs, mint rhs) { return new mint(lhs._v + rhs._v); } public static mint operator -(mint lhs, mint rhs) { return new mint(lhs._v + mod - rhs._v); } public static mint operator *(mint lhs, mint rhs) { return new mint((uint)((ulong)lhs._v * rhs._v % mod)); } public static mint operator /(mint lhs, mint rhs) { return lhs * rhs.Inv(); } public static mint operator ^(mint x, int n) { return Pow(x, n); } public static bool operator ==(mint l, mint r) { return l._v == r._v; } public static bool operator !=(mint l, mint r) { return !(l == r); } public static bool operator<(mint l, mint r) { return l._v < r._v; } public static bool operator>(mint l, mint r) { return l._v > r._v; } public static mint Pow(mint x, int n) { var r = new mint(1); while (n > 0) { if ((n & 1) > 0) r *= x; x *= x; n >>= 1; } return r; } public mint Pow(int n) { return Pow(this, n); } public mint Inv() { return Pow((int)mod - 2); } public bool Equals(mint o) { return this == o; } public override bool Equals(object obj) { if (obj is mint) return this == (mint)obj; else return false; } public override int GetHashCode() { return _v.GetHashCode(); } public override string ToString() { return _v.ToString(); } public static implicit operator mint(int i) { return new mint(i); } public static implicit operator mint(long i) { return new mint(i); } private static mint[] _fact; public static void SetFact(int n) { _fact = new mint[n + 1]; _fact[0] = 1; for (int i = 1; i < n + 1; i++) { _fact[i] = _fact[i - 1] * i; } } public static mint Fact(int n) { if (_fact == null || _fact.Length < n) { SetFact(n * 2); } return _fact[n]; } public static mint Combination(int n, int r) { return Fact(n) / (Fact(n - r) * Fact(r)); } } static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } static List<T> ReadObjects<T>(int n, Func<int[], T> creator) { var l = new List<T>(n); for (int i = 0; i < n; i++) { var a = ReadIntArray(); l.Add(creator(a)); } return l; } static int[,] ReadMatrix(int n, int m) { var r = new int[n, m]; for (int i = 0; i < n; i++) { var a = ReadIntArray(); for (int j = 0; j < m; j++) { r[i, j] = a[j]; } } return r; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } public class MinHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MinHeap() : this(0) {} public MinHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c < 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) > 0) { j++; } if (_comp.Compare(_list[i], _list[j]) > 0) { Swap(i, j); i = j; } else { return result; } } } public MinHeap<T> Copy(Comparison<T> comp = null) { var c = new MinHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MinHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMul(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMul(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMul(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } class Graph<T> { private int _size; private List<T>[] _edges; public Graph(int size) { _size = size; _edges = new List<T>[size]; } public List<T> this[int i] { get { if (_edges[i] == null) _edges[i] = new List<T>(); return _edges[i]; } } } static Graph<T> NewGraph<T>(int size, T template) { return new Graph<T>(size); } static List<T> NewList<T>(T template) { return new List<T>(); } static T[] NewArray<T>(int size, T template) { return new T[size]; } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var s = Console.ReadLine(); var r = new Stack<int>(); var i = n; while (i > 0) { for (int j = m; j >= 0; j--) { if (j == 0) { i = -1; break; } var k = Math.Min(j, i); if (s[i - k] == '0') { r.Push(k); i -= k; break; } } } if (i < 0) { Console.WriteLine(-1); return; } Console.Write(r.Pop()); while (r.Any()) { Console.Write(" "); Console.Write(r.Pop()); } Console.WriteLine(); //↑ } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
8
3,604
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); long x = sc.NextLong(); long y = sc.NextLong(); long answer = 0; answer += (4 - x) * 100000; answer += (4 - y) * 100000; if (x == 1 && y == 1) { answer += 400000; } 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 x = sc.NextLong(); long y = sc.NextLong(); long answer = 0; answer += Math.Max(0, (4 - x) * 100000); answer += Math.Max(0, (4 - y) * 100000); if (x == 1 && y == 1) { answer += 400000; } 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, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24]]
8
400
14
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { public class Solver { private readonly IInputReader _inputReader; private readonly IOutputWriter _outputWriter; public Solver(IInputReader inputReader, IOutputWriter outputWriter) { _inputReader = inputReader; _outputWriter = outputWriter; } public void Solve() { var numbers = _inputReader.ReadLine().ToIntArray(); var X = numbers[0]; var Y = numbers[1]; var prise = 0; if (X == 3) { prise += 10000; } else if (X == 2) { prise += 20000; } else if (X == 1) { prise += 30000; } if (Y == 3) { prise += 10000; } else if (Y == 2) { prise += 20000; } else if (Y == 1) { prise += 30000; } if (X == 1 && Y == 1) { prise += 40000; } _outputWriter.WriteLine(prise.ToString()); } } internal class Program { static void Main(string[] args) { var reader = new ConsoleInputReader(); var writer = new ConsoleOutputWriter(); new Solver(reader, writer).Solve(); } } public interface IInputReader { string ReadLine(); } public interface IOutputWriter { void WriteLine(string output); } internal class ConsoleInputReader : IInputReader { public string ReadLine() => Console.ReadLine(); } internal class ConsoleOutputWriter : IOutputWriter { public void WriteLine(string output) => Console.WriteLine(output); } public static class StringExtensions { public static char ToChar(this string text) => text[0]; public static int ToInt(this string text) => int.Parse(text); public static int[] ToIntArray(this string text) => text.Split(' ').Select(txt => txt.ToInt()).ToArray(); public static long ToLong(this string text) => long.Parse(text); public static long[] ToLongArray(this string text) => text.Split(' ').Select(txt => txt.ToLong()).ToArray(); } public struct ModLong : IEquatable<ModLong> { private const long Mod = 1000000007; private readonly long _value; public ModLong(long value) { _value = (value % Mod + Mod) % Mod; } public bool Equals(ModLong other) { return _value == other._value; } public override bool Equals(object obj) { return obj is ModLong other && Equals(other); } public override int GetHashCode() { return _value.GetHashCode(); } public static bool operator ==(ModLong left, ModLong right) { return left.Equals(right); } public static bool operator !=(ModLong left, ModLong right) { return !left.Equals(right); } public static ModLong operator +(ModLong left, ModLong right) { return (ModLong)(left._value + right._value); } public static ModLong operator -(ModLong left, ModLong right) { return (ModLong)(left._value - right._value); } public static ModLong operator *(ModLong left, ModLong right) { return (ModLong)(left._value * right._value); } public static ModLong operator /(ModLong left, ModLong right) { return (ModLong)(left._value * Util.ModInv(right._value, Mod)); } public static explicit operator long(ModLong num) { return num._value; } public static explicit operator ModLong(long num) { return new ModLong(num); } public override string ToString() => _value.ToString(); } public class Util { /// <summary> /// a^n mod を計算する /// </summary> /// <param name="a"></param> /// <param name="n"></param> /// <param name="mod"></param> /// <returns></returns> public static long ModPow(long a, long n, long mod) { long res = 1; while (n > 0) { if ((n & 1) == 1) { res = res * a % mod; } a = a * a % mod; n >>= 1; } return res; } /// <summary> /// a^{-1} mod を計算する /// </summary> /// <param name="a"></param> /// <param name="mod"></param> /// <returns></returns> public static long ModInv(long a, long mod) { return ModPow(a, mod - 2, mod); } /// <summary> /// 階乗 /// </summary> /// <param name="n"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static long Factional(long n) { if (n < 0) throw new ArgumentOutOfRangeException(nameof(n)); if (n == 0) return 1; var result = 1; for (var i = 1; i <= n; i++) { result = checked(result * i); } return result; } /// <summary> /// 組み合わせ /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static long Combination(long m, long n) { if (m <= 0) throw new ArgumentOutOfRangeException(nameof(m)); if (n < 0) throw new ArgumentOutOfRangeException(nameof(n)); if (m < n) throw new ArgumentOutOfRangeException(nameof(n)); return Factional(m) / (Factional(n) * Factional(m - n)); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { public class Solver { private readonly IInputReader _inputReader; private readonly IOutputWriter _outputWriter; public Solver(IInputReader inputReader, IOutputWriter outputWriter) { _inputReader = inputReader; _outputWriter = outputWriter; } public void Solve() { var numbers = _inputReader.ReadLine().ToIntArray(); var X = numbers[0]; var Y = numbers[1]; var prise = 0; if (X == 3) { prise += 100000; } else if (X == 2) { prise += 200000; } else if (X == 1) { prise += 300000; } if (Y == 3) { prise += 100000; } else if (Y == 2) { prise += 200000; } else if (Y == 1) { prise += 300000; } if (X == 1 && Y == 1) { prise += 400000; } _outputWriter.WriteLine(prise.ToString()); } } internal class Program { static void Main(string[] args) { var reader = new ConsoleInputReader(); var writer = new ConsoleOutputWriter(); new Solver(reader, writer).Solve(); } } public interface IInputReader { string ReadLine(); } public interface IOutputWriter { void WriteLine(string output); } internal class ConsoleInputReader : IInputReader { public string ReadLine() => Console.ReadLine(); } internal class ConsoleOutputWriter : IOutputWriter { public void WriteLine(string output) => Console.WriteLine(output); } public static class StringExtensions { public static char ToChar(this string text) => text[0]; public static int ToInt(this string text) => int.Parse(text); public static int[] ToIntArray(this string text) => text.Split(' ').Select(txt => txt.ToInt()).ToArray(); public static long ToLong(this string text) => long.Parse(text); public static long[] ToLongArray(this string text) => text.Split(' ').Select(txt => txt.ToLong()).ToArray(); } public struct ModLong : IEquatable<ModLong> { private const long Mod = 1000000007; private readonly long _value; public ModLong(long value) { _value = (value % Mod + Mod) % Mod; } public bool Equals(ModLong other) { return _value == other._value; } public override bool Equals(object obj) { return obj is ModLong other && Equals(other); } public override int GetHashCode() { return _value.GetHashCode(); } public static bool operator ==(ModLong left, ModLong right) { return left.Equals(right); } public static bool operator !=(ModLong left, ModLong right) { return !left.Equals(right); } public static ModLong operator +(ModLong left, ModLong right) { return (ModLong)(left._value + right._value); } public static ModLong operator -(ModLong left, ModLong right) { return (ModLong)(left._value - right._value); } public static ModLong operator *(ModLong left, ModLong right) { return (ModLong)(left._value * right._value); } public static ModLong operator /(ModLong left, ModLong right) { return (ModLong)(left._value * Util.ModInv(right._value, Mod)); } public static explicit operator long(ModLong num) { return num._value; } public static explicit operator ModLong(long num) { return new ModLong(num); } public override string ToString() => _value.ToString(); } public class Util { /// <summary> /// a^n mod を計算する /// </summary> /// <param name="a"></param> /// <param name="n"></param> /// <param name="mod"></param> /// <returns></returns> public static long ModPow(long a, long n, long mod) { long res = 1; while (n > 0) { if ((n & 1) == 1) { res = res * a % mod; } a = a * a % mod; n >>= 1; } return res; } /// <summary> /// a^{-1} mod を計算する /// </summary> /// <param name="a"></param> /// <param name="mod"></param> /// <returns></returns> public static long ModInv(long a, long mod) { return ModPow(a, mod - 2, mod); } /// <summary> /// 階乗 /// </summary> /// <param name="n"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static long Factional(long n) { if (n < 0) throw new ArgumentOutOfRangeException(nameof(n)); if (n == 0) return 1; var result = 1; for (var i = 1; i <= n; i++) { result = checked(result * i); } return result; } /// <summary> /// 組み合わせ /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static long Combination(long m, long n) { if (m <= 0) throw new ArgumentOutOfRangeException(nameof(m)); if (n < 0) throw new ArgumentOutOfRangeException(nameof(n)); if (m < n) throw new ArgumentOutOfRangeException(nameof(n)); return Factional(m) / (Factional(n) * Factional(m - n)); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
1,005
14
using System; class ddccfinals { public static void Main() { String[] str = Console.ReadLine().Split(' '); int code = int.Parse(str[0]); int mec = int.Parse(str[1]); int result = 0; if (code > 3) { code = 0; } if (mec > 3) { mec = 0; } result = code * 100000 + mec * 100000; if (code == 1 && mec == 1) { result += 400000; } Console.WriteLine(result); } }
using System; class ddccfinals { public static void Main() { String[] str = Console.ReadLine().Split(' '); int code = int.Parse(str[0]); int mec = int.Parse(str[1]); int result = 0; if (code > 3) { code = 4; } if (mec > 3) { mec = 4; } result = (4 - code) * 100000 + (4 - mec) * 100000; if (code == 1 && mec == 1) { result += 400000; } Console.WriteLine(result); } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 11, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 31, 203], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 11, 12, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 31, 203], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 16, 31, 23, 0, 25]]
8
121
12
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var A = sc.ReadLongArray(N); var sum = new long[N]; sum[0] = A[0]; var asum = A.Sum(); for (int i = 1; i < N; i++) { sum[i] = sum[i - 1] + A[i]; if (sum[i] == asum / 2 && asum % 2 == 0) { Console.WriteLine(0); return; } } var max = asum / 2; var ans = long.MaxValue; for (int i = 0; i < N; i++) { if (sum[i] > max) { // 伸ばすとき long res1 = 0; if (i > 0) { var target = (asum + 1) / 2; var x = sum[i - 1]; if (asum % 2 == 1) { x++; res1++; } res1 += (target - x) * 2; } // 減らすとき long res2 = 0; { var target = (asum - 1) / 2; var x = sum[i]; if (asum % 2 == 1) { x--; res2++; } res2 += (x - target) * 2; } ans = Math.Min(res1, res2); break; } } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup() { return Tuple.Create(this.ReadInt(), this.ReadInt()); } public Tuple<long, long> ReadTupLong() { return Tuple.Create(this.ReadLong(), this.ReadLong()); } public Tuple<int, int, int> ReadTup3() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int, int> ReadTup4() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt(), this.ReadInt()); } 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) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(); } return array; } public Tuple<int, int>[] ReadTupArray(int n) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = sc.ReadInt(); var A = sc.ReadLongArray(N); var sum = new long[N]; sum[0] = A[0]; var asum = A.Sum(); for (int i = 1; i < N; i++) { sum[i] = sum[i - 1] + A[i]; if (sum[i] == asum / 2 && asum % 2 == 0) { Console.WriteLine(0); return; } } var max = asum / 2; var ans = long.MaxValue; for (int i = 0; i < N; i++) { if (sum[i] > max) { // 伸ばすとき long res1 = 0; if (i > 0) { var target = (asum + 1) / 2; var x = sum[i - 1]; if (asum % 2 == 1) { x++; res1++; } res1 += (target - x) * 2; } else { res1 = long.MaxValue; } // 減らすとき long res2 = 0; { var target = (asum) / 2; var x = sum[i]; if (asum % 2 == 1) { x--; res2++; } res2 += (x - target) * 2; } ans = Math.Min(res1, res2); break; } } Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup() { return Tuple.Create(this.ReadInt(), this.ReadInt()); } public Tuple<long, long> ReadTupLong() { return Tuple.Create(this.ReadLong(), this.ReadLong()); } public Tuple<int, int, int> ReadTup3() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt()); } public Tuple<int, int, int, int> ReadTup4() { return Tuple.Create(this.ReadInt(), this.ReadInt(), this.ReadInt(), this.ReadInt()); } 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) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(); } return array; } public Tuple<int, int>[] ReadTupArray(int n) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(); } return array; } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203]]
8
1,222
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int N = cin.nextInt(); long[] a = cin.ArrayLong(N, 0); long max = 0; long max2 = 0; int half = 0; long ans = 0; for (int i = 0; i < N; i++) max += a[i]; for (int i = 0; i < N; i++) { max2 += a[i]; if (max % 2 == 0 && max / 2 == max2) { ans = 0; goto just; } else if (max / 2 <= max2) { half++; break; } half++; } if ((max2 - a[half]) < (max - max2)) ans = Math.Abs((max - max2) - max2); else if ((max2 - a[half]) > (max - max2)) ans = Math.Abs(max - max2 - (max2 - a[half])); else ans = a[half]; Console.WriteLine(ans); just: if (ans == 0) Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } public void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int N = cin.nextInt(); long[] a = cin.ArrayLong(N, 0); long max = 0; long max2 = 0; int half = 0; long ans = 0; for (int i = 0; i < N; i++) max += a[i]; for (int i = 0; i < N; i++) { max2 += a[i]; if (max % 2 == 0 && max / 2 == max2) { ans = 0; goto just; } else if (max / 2 <= max2) { break; } half++; } if ((max2 - a[half]) < max - max2) ans = Math.Abs(max2 * 2 - max); else if ((max2 - a[half]) > max - max2) { ans = Math.Abs(max2 * 2 - 2 * a[half] - max); } else ans = a[half]; Console.WriteLine(ans); just: if (ans == 0) Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } public void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["-", 75, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 75, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 203], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 23, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 16, 12, 16, 31, 203], ["+", 0, 28, 0, 16, 31, 16, 12, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46]]
8
912
29
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var waaaa = new waaaa(); waaaa.Solve(); } } public class waaaa { const int MOD = 1000000007; const long INF = 1 << 63; const int MOD2 = 998244353; myinout mio = new myinout(); Math2 mmath = new Math2(); public void Solve() { //ここから var o = mio.IntM; var N = o[0]; var A = mio.LongM; long[] l = new long[N + 1]; long[] r = new long[N + 1]; for (int i = 0; i < N; ++i) { l[i + 1] = l[i] + A[i]; } for (int i = N - 1; i >= 0; i--) { r[i] = r[i + 1] + A[i]; } long ans = INF; for (int i = 0; i < N; ++i) { ans = Math.Min(ans, Math.Abs(r[i] - l[i])); } mio.wri(ans); } } // b-aで降順 public class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = pow(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long GCD(long x, long y) { while (y != 0) { var r = x % y; x = y; y = r; } return x; } //最小公倍数 引数:整数x,y public long LCM(long x, long y) { return x * y / GCD(x, y); } //素因数分解 引数:整数N public Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } //約数列挙 public List<long> divisorenumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } class myinout { // in public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; // out public void wri<T>(T x) { Console.WriteLine(x); } public void yn(bool x) { if (x) wri("Yes"); else wri("No"); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { var waaaa = new waaaa(); waaaa.Solve(); } } public class waaaa { const int MOD = 1000000007; const long INF = 1 << 62; const int MOD2 = 998244353; myinout mio = new myinout(); Math2 mmath = new Math2(); public void Solve() { //ここから var o = mio.IntM; var N = o[0]; var A = mio.LongM; long[] l = new long[N + 1]; long[] r = new long[N + 1]; for (int i = 0; i < N; ++i) { l[i + 1] = l[i] + A[i]; } for (int i = N - 1; i >= 0; i--) { r[i] = r[i + 1] + A[i]; } long ans = Math.Abs(r[0] - l[0]); for (int i = 0; i < N; ++i) { ans = Math.Min(ans, Math.Abs(r[i] - l[i])); } mio.wri(ans); } } // b-aで降順 public class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 // Nまでの階乗をセットしておく public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = pow(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } // nCr 引数:n r (mod) public long nCr(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } //階乗(O(logN)) 引数:底x n乗 (MOD) public long pow(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } //最大公約数 引数:整数x,y public long GCD(long x, long y) { while (y != 0) { var r = x % y; x = y; y = r; } return x; } //最小公倍数 引数:整数x,y public long LCM(long x, long y) { return x * y / GCD(x, y); } //素因数分解 引数:整数N public Dictionary<long, int> PrimeFactorization(long N) { var ret = new Dictionary<long, int>(); for (long i = 2; i * i <= N; ++i) { int cnt = 0; while (N % i == 0) { cnt++; N /= i; } if (cnt != 0) ret[i] = cnt; } if (N >= 2) ret[N] = 1; return ret; } //約数列挙 public List<long> divisorenumrate(long N) { var ret = new List<long>(); for (long i = 1; i * i <= N; ++i) { if (N % i == 0) { ret.Add(i); ret.Add(N / i); } } return ret; } } class myinout { // in public string Str => Console.ReadLine(); public string[] StrM => Str.Split(' '); public long[] LongM => StrM.Select(long.Parse).ToArray(); public int[] IntM => StrM.Select(int.Parse).ToArray(); public char[] CharM => Str.ToArray(); public long Long1 => LongM[0]; public int Int1 => IntM[0]; // out public void wri<T>(T x) { Console.WriteLine(x); } public void yn(bool x) { if (x) wri("Yes"); else wri("No"); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
900
17
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; namespace UtakaApp { public partial class Program { //========================================================================================= // Answer //========================================================================================= public const string SiteName = "AtCoder"; public const string ContestName = "ddcc2020-qual"; public const string ProblemName = "D"; public void Solve() { int M = cin.ReadInt; long rest = 0; long ans = 0; for (int i = 0; i < M; i++) { long d = cin.ReadLong; long c = cin.ReadLong; ans += c; rest += d * c; long addition = rest / 10; ans += addition; rest = rest % 10; } ans--; cou.WriteLine(ans); } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } //========================================================================================= // Library //========================================================================================= public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// 配列をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; namespace UtakaApp { public partial class Program { //========================================================================================= // Answer //========================================================================================= public const string SiteName = "AtCoder"; public const string ContestName = "ddcc2020-qual"; public const string ProblemName = "D"; public void Solve() { int M = cin.ReadInt; long sum = 0; long k = 0; for (int i = 0; i < M; i++) { long d = cin.ReadLong; long c = cin.ReadLong; sum += d * c; k += c; } var ans = (sum - 1) / 9 + k - 1; cou.WriteLine(ans); } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } //========================================================================================= // Library //========================================================================================= public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public static class UtakaExtentions { /// <summary> /// 配列をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; if (targetTestCaseNumber >= 0 && targetTestCaseNumber != testCaseNumber) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 195, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 16, 31, 16, 31, 16, 31, 23, 0, 24], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 31, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 212, 0, 16, 31, 16, 31, 16, 17, 85], ["+", 0, 212, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
3,163
41
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class D { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { int M = GetInt(); long[] d = new long[M]; long[] c = new long[M]; for (int i = 0; i < M; i++) { d[i] = GetLong(); c[i] = GetLong(); } long sum = 0; for (int i = 0; i < M; i++) sum += d[i] * c[i]; WriteLine(c.Sum() - 1 + sum / 9); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class D { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { int M = GetInt(); long[] d = new long[M]; long[] c = new long[M]; for (int i = 0; i < M; i++) { d[i] = GetLong(); c[i] = GetLong(); } long sum = 0; for (int i = 0; i < M; i++) sum += d[i] * c[i]; long ans = c.Sum() - 1; long rest = sum; while (rest > 9) { long q = rest / 10; ans += q; rest -= q * 9; } WriteLine(ans); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 197, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
590
37
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC145A { class Program { static void Main(string[] args) { int r, s; var word = Console.ReadLine().Split(' '); r = int.Parse(word[0]); s = int.Parse(word[1]); s = r * r; Console.WriteLine(s); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC145A { class Program { static void Main(string[] args) { int r, s; var word = Console.ReadLine().Split(' '); r = int.Parse(word[0]); s = r * r; Console.WriteLine(s); Console.ReadKey(); } } }
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32]]
8
110
12
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; var A = new long[N]; for (long i = 0; i < N; i++) { A[i] = cin.ReadLong; } var MOD = 1000000007; var ans = 0L; for (int i = 0; i < 64; i++) { var count = 0L; for (long j = 0; j < N; j++) { count += ((A[j] >> i) & 1); } ans += ((long)Pow(2, i) * count * (N - count)) % MOD; ans %= MOD; } Console.WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; var A = new long[N]; for (long i = 0; i < N; i++) { A[i] = cin.ReadLong; } var MOD = 1000000007; var ans = 0L; for (int i = 0; i < 64; i++) { var count = 0L; for (long j = 0; j < N; j++) { count += ((A[j] >> i) & 1); } var value = (long)Pow(2, i) % MOD; value = (value * count) % MOD; value = (value * (N - count)) % MOD; ans = (ans + value) % MOD; } Console.WriteLine(ans); } } 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, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22]]
8
562
29
using System; using System.Collections.Generic; // using System.Linq; using System.Diagnostics; class Program { static void Main(string[] args) { const long MOD = 1000000007; var sc = new Scanner(); long n = sc.nextLong(); var a = new long[n]; long a_max = 0; for (int i = 0; i < n; i++) { a[i] = sc.nextLong(); a_max = Math.Max(a_max, a[i]); } var count = new long[Convert.ToString(a_max, 2).Length]; for (int i = 0; i < n; i++) { string a_2 = Convert.ToString(a[i], 2); a_2 = a_2.PadLeft(Convert.ToString(a_max, 2).Length, '0'); for (int j = 0; j < a_2.Length; j++) { if (a_2[j] == '1') count[j]++; } // Debug.WriteLine("a_2=" + a_2); } long ans = 0; for (int i = 0; i < count.Length; i++) { long p = 1; for (int j = 0; j < count.Length - i - 1; j++) { p *= 2 % MOD; } // Debug.WriteLine("i:" + i + "(p)" + p + "*(count)" + count[i] + // "*(n-count)" + (n - count[i])); p = p * count[i] % MOD; ans += p * (n - count[i]) % MOD; ans %= MOD; } Console.WriteLine(ans); } } // chokudai's Scanner class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
using System; using System.Collections.Generic; // using System.Linq; using System.Diagnostics; class Program { static void Main(string[] args) { const long MOD = 1000000007; var sc = new Scanner(); int n = sc.nextInt(); var a = new long[n]; long a_max = 0; for (int i = 0; i < n; i++) { a[i] = sc.nextLong(); a_max = Math.Max(a_max, a[i]); } var count = new long[Convert.ToString(a_max, 2).Length]; for (int i = 0; i < n; i++) { string a_2 = Convert.ToString(a[i], 2); a_2 = a_2.PadLeft(Convert.ToString(a_max, 2).Length, '0'); for (int j = 0; j < a_2.Length; j++) { if (a_2[j] == '1') count[j]++; } Debug.WriteLine("a_2=" + a_2); } long ans = 0; for (int i = 0; i < count.Length; i++) { long p = 1; for (int j = 0; j < count.Length - i - 1; j++) { p *= 2 % MOD; } p %= MOD; // Debug.WriteLine("i:" + i + "(p)" + p + "*(count)" + count[i] + // "*(n-count)" + (n - count[i])); long tmp = p * count[i] % MOD; ans = ans + tmp * (n - count[i]) % MOD; ans %= MOD; } Console.WriteLine(ans); } } // chokudai's Scanner class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 11, 12, 16, 12, 16, 31, 16, 31, 22]]
8
662
26
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); var a = cin.ArrayLong(n); long ans = 0; for (int i = 0; i < 62; i++) { long val = (long)1 << i; long cnt = 0; for (int j = 0; j < n; j++) { if ((a[j] & val) != 0) { ++cnt; } } long rem = n - cnt; long temp = (cnt * rem) % MOD; temp = (temp * val) % MOD; ans = (ans + temp) % MOD; } Console.WriteLine(ans); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { var cin = new Scanner2(); int n = cin.Int(); var a = cin.ArrayLong(n); long ans = 0; for (int i = 0; i < 62; i++) { long val = (long)1 << i; long cnt = 0; for (int j = 0; j < n; j++) { if ((a[j] & val) != 0) { ++cnt; } } if (cnt == 0) { continue; } long rem = n - cnt; long temp = (cnt * rem) % MOD; long val2 = val % MOD; temp = (temp * val2) % MOD; ans = (long)((ans + temp) % MOD); } Console.WriteLine(ans); } } public class Scanner2 { private readonly char[] delimiter_ = new char[] { ' ' }; private readonly string filePath_; private string[] buf_; private int index_; Func<string> reader_; public Scanner2(string file = "") { if (string.IsNullOrWhiteSpace(file)) { reader_ = Console.ReadLine; } else { filePath_ = file; var fs = new StreamReader(file); reader_ = fs.ReadLine; } buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = reader_(); while (st == "") { st = reader_(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() => int.Parse(Next()); public long Long() => long.Parse(Next()); public double Double() => double.Parse(Next()); public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } public void Save(string text) { if (string.IsNullOrWhiteSpace(filePath_)) { return; } File.WriteAllText(filePath_ + "_output.txt", text); } } }
[["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 74, 51, 23, 0, 25]]
8
646
29
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC147D { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var AList = NNList(N); LIB_Mod ans = 0; var mask = 1L; for (var i = 0; i < 60; i++) { var zeroCnt = 0; foreach (var item in AList) { if ((item & mask) == 0) ++zeroCnt; } ans += mask * zeroCnt * (N - zeroCnt); mask <<= 1; } Console.WriteLine(ans); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { struct LIB_Mod : IEquatable<LIB_Mod>, IEquatable<long> { static public long _mod = 1000000007; long v; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator LIB_Mod(long x) => new LIB_Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(LIB_Mod x) => x.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(LIB_Mod x) { if ((v += x.v) >= _mod) v -= _mod; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Sub(LIB_Mod x) { if ((v -= x.v) < 0) v += _mod; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Mul(LIB_Mod x) => v = (v * x.v) % _mod; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Div(LIB_Mod x) => v = (v * Inverse(x.v)) % _mod; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod operator +(LIB_Mod x, LIB_Mod y) { var t = x.v + y.v; return t >= _mod ? new LIB_Mod { v = t - _mod } : new LIB_Mod { v = t }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod operator -(LIB_Mod x, LIB_Mod y) { var t = x.v - y.v; return t < 0 ? new LIB_Mod { v = t + _mod } : new LIB_Mod { v = t }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod operator *(LIB_Mod x, LIB_Mod y) => x.v * y.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod operator /(LIB_Mod x, LIB_Mod y) => x.v * Inverse(y.v); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(LIB_Mod x, LIB_Mod y) => x.v == y.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(LIB_Mod x, LIB_Mod y) => x.v != y.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(LIB_Mod x) => v == x.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(long x) => v == x; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object x) => x == null ? false : Equals((LIB_Mod)x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => v.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => v.ToString(); static List<LIB_Mod> _fact = new List<LIB_Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod Pow(LIB_Mod x, long y) { LIB_Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ABC147D { static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var N = NN; var AList = NNList(N); LIB_Mod ans = 0; LIB_Mod maskm = 1; var mask = 1L; for (var i = 0; i <= 60; i++) { var zeroCnt = 0L; foreach (var item in AList) { if ((item & mask) == 0) ++zeroCnt; } ans += maskm * zeroCnt * (N - zeroCnt); maskm *= 2; mask <<= 1; } Console.WriteLine(ans); } static class Console_ { static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { struct LIB_Mod : IEquatable<LIB_Mod>, IEquatable<long> { static public long _mod = 1000000007; long v; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LIB_Mod(long x) { if (x < _mod && x >= 0) v = x; else if ((v = x % _mod) < 0) v += _mod; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator LIB_Mod(long x) => new LIB_Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(LIB_Mod x) => x.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(LIB_Mod x) { if ((v += x.v) >= _mod) v -= _mod; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Sub(LIB_Mod x) { if ((v -= x.v) < 0) v += _mod; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Mul(LIB_Mod x) => v = (v * x.v) % _mod; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Div(LIB_Mod x) => v = (v * Inverse(x.v)) % _mod; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod operator +(LIB_Mod x, LIB_Mod y) { var t = x.v + y.v; return t >= _mod ? new LIB_Mod { v = t - _mod } : new LIB_Mod { v = t }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod operator -(LIB_Mod x, LIB_Mod y) { var t = x.v - y.v; return t < 0 ? new LIB_Mod { v = t + _mod } : new LIB_Mod { v = t }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod operator *(LIB_Mod x, LIB_Mod y) => x.v * y.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod operator /(LIB_Mod x, LIB_Mod y) => x.v * Inverse(y.v); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(LIB_Mod x, LIB_Mod y) => x.v == y.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(LIB_Mod x, LIB_Mod y) => x.v != y.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(LIB_Mod x) => v == x.v; [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(long x) => v == x; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object x) => x == null ? false : Equals((LIB_Mod)x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => v.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => v.ToString(); static List<LIB_Mod> _fact = new List<LIB_Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(long n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod Comb(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public LIB_Mod Pow(LIB_Mod x, long y) { LIB_Mod a = 1; while (y != 0) { if ((y & 1) == 1) a.Mul(x); x.Mul(x); y >>= 1; } return a; } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203]]
8
1,746
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>(); static void Main(string[] args) { var n = ReadLong(); var ll = ReadLongArr(); BitArr[] b = new BitArr[n]; for (int i = 0; i < n; i++) { b[i] = new BitArr(ll[i]); } long mod = 1000000007; long res = 0; long order = 1; for (int i = 0; i < 64; i++) { int bitcnt = 0; for (int j = 0; j < n; j++) { if (b[j].bitArr[i]) { bitcnt++; } } res += (n - bitcnt) * bitcnt * order; res = res % mod; order = order * 2; } Console.WriteLine(res); } class BitArr { public bool[] bitArr = new bool[64]; public BitArr(long l) { var ll = l; for (int i = 0; i < 64; i++) { bitArr[i] = (ll % 2) == 1; ll = ll / 2; } } } public static int Digit(long num) { // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。 return (num == 0) ? 1 : ((int)Math.Log10(num) + 1); } public static long nCm(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; var a = n * nCm(n - 1, m - 1) / m; return a % 1000000007; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } public class Class1 { static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, long>, long>(); static void Main(string[] args) { var n = ReadLong(); var ll = ReadLongArr(); BitArr[] b = new BitArr[n]; for (int i = 0; i < n; i++) { b[i] = new BitArr(ll[i]); } long mod = 1000000007; long res = 0; long order = 1; for (int i = 0; i < 64; i++) { int bitcnt = 0; for (int j = 0; j < n; j++) { if (b[j].bitArr[i]) { bitcnt++; } } res += (((n - bitcnt) * bitcnt) % mod) * (order % mod); res = res % mod; order = order * 2; } Console.WriteLine(res); } class BitArr { public bool[] bitArr = new bool[64]; public BitArr(long l) { var ll = l; for (int i = 0; i < 64; i++) { bitArr[i] = (ll % 2) == 1; ll = ll / 2; } } } public static int Digit(long num) { // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。 return (num == 0) ? 1 : ((int)Math.Log10(num) + 1); } public static long nCm(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; var a = n * nCm(n - 1, m - 1) / m; return a % 1000000007; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } } }
[["+", 12, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 109], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 109], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
8
535
10
using System; namespace D { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var result = 0L; long MOD = 1000000007; for (int d = 0; d < 60; d++) { var count = 0L; for (int i = 0; i < N; i++) { if ((A[i] & (1L << d)) > 0) count++; } long sub = count * (N - count); sub %= MOD; result += (1L << d) * sub; result %= MOD; } Console.WriteLine(result); } } }
using System; namespace D { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var result = 0L; long MOD = 1000000007; for (int d = 0; d < 60; d++) { var count = 0L; for (int i = 0; i < N; i++) { if ((A[i] & (1L << d)) > 0) count++; } long sub = count * (N - count); sub %= MOD; long sub2 = (1L << d) % MOD; result += sub2 * sub; result %= MOD; } Console.WriteLine(result); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22]]
8
164
11
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; class Solver { Scanner sc = new Scanner(); // public void Solve() { var N = sc.Int; var A = sc.ArrLong; var ctr = Create(61, () => new int[N + 1]); for (var k = 0; k < 61; k++) for (var i = N - 1; i >= 0; i--) { ctr[k][i] = ctr[k][i + 1]; if ((1 & A[i] >> k) == 1) ctr[k][i]++; } var sum = 0L; var m = (int)1e9 + 7; for (var k = 0; k < 61; k++) for (var i = 0; i < N; i++) { var c = N - ctr[k][i + 1] - i - 1; if ((1 & A[i] >> k) == 1) sum += c * (1L << k); else sum += ctr[k][i + 1] * (1L << k); sum %= m; } WriteLine(sum); } } #region Template public class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>()); public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>()); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Tie(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; class Solver { Scanner sc = new Scanner(); // public void Solve() { var N = sc.Int; var A = sc.ArrLong; var ctr = Create(61, () => new int[N + 1]); for (var k = 0; k < 61; k++) for (var i = N - 1; i >= 0; i--) { ctr[k][i] = ctr[k][i + 1]; if ((1 & A[i] >> k) == 1) ctr[k][i]++; } var sum = 0L; var m = (int)1e9 + 7; for (var k = 0; k < 61; k++) for (var i = 0; i < N; i++) { var mask = (1L << k) % m; var c = N - ctr[k][i + 1] - i - 1; if ((1 & A[i] >> k) == 1) sum += c * mask; else sum += ctr[k][i + 1] * mask; sum %= m; } WriteLine(sum); } } #region Template public class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>()); public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>()); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Tie(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; } } #endregion
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 31, 203], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 151], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 0, 7, 8, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 64, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 31, 203], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 17, 151], ["-", 0, 11, 12, 16, 12, 23, 0, 16, 12, 22], ["-", 64, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 22], ["-", 75, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 75, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 12, 22]]
8
1,716
23
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var hw = Console.ReadLine().Split().Select(int.Parse).ToArray(); int h = hw[0]; int w = hw[1]; List<int>[] graph = Enumerable.Repeat(0, h * w).Select(_ => new List<int>()).ToArray(); for (int i = 0; i < h - 1; i++) for (int j = 0; j < w; j++) { var id = i * w + j; graph[id].Add(id + w); } for (int i = 0; i < h; i++) for (int j = 0; j < w - 1; j++) { var id = i * w + j; graph[id].Add(id + 1); } var arrived = new bool[h * w]; var a = Enumerable.Repeat(0, h) .SelectMany(_ => Console.ReadLine().Split().Select(int.Parse)) .ToArray() .Zip(Enumerable.Repeat(0, h) .SelectMany( _ => Console.ReadLine().Split().Select(int.Parse)) .ToArray(), (x, y) => Abs(x - y)) .ToArray(); var offset = 160 * 160; BitArray[] diffs = Enumerable.Repeat(0, h * w) .Select(_ => new BitArray(offset * 2 + 1)) .ToArray(); Queue<int> queue = new Queue<int>(); queue.Enqueue(0); diffs[0].SetTrue(offset); while (queue.Count != 0) { var last = queue.Dequeue(); var newBitArray = new BitArray(diffs[last]); diffs[last].ShiftPositive(a[last]); newBitArray.ShiftNegative(a[last]); diffs[last].Or(newBitArray); foreach (var next in graph[last]) { diffs[next].Or(diffs[last]); if (arrived[next]) continue; arrived[next] = true; queue.Enqueue(next); } } var min = int.MaxValue; var lastDiff = diffs.Last(); for (int i = 0; i < lastDiff.Length; i++) { if (!lastDiff.Get(i)) continue; min = Min(min, Abs(offset - i)); } Console.WriteLine(min); } } class BitArray { public readonly int Length; private readonly ulong LastMask; ulong[] data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BitArray(int length) { data = new ulong[((length - 1) >> 6) + 1]; Length = length; LastMask = (~0UL) >> ((~length) & 63); } public BitArray(BitArray bitArray) { data = new ulong[Length = bitArray.data.Length]; bitArray.data.CopyTo(data, 0); LastMask = bitArray.LastMask; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Get(int index) => (data[index >> 6] >> (index & 63) & 1) == 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetTrue(int index) => data[index >> 6] |= (1UL << (index & 63)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetFalse(int index) => data[index >> 6] &= ~(1UL << (index & 63)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Or(BitArray bitArray) { for (int i = 0; i < data.Length; i++) data[i] |= bitArray.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void And(BitArray bitArray) { for (int i = 0; i < data.Length; i++) data[i] &= bitArray.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Xor(BitArray bitArray) { for (int i = 0; i < data.Length; i++) data[i] ^= bitArray.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ShiftPositive(int width) { var blockShiftLength = width >> 6; var bitShiftLengtha = width & 63; var bitShiftLengthb = 64 - bitShiftLengtha; for (int i = 0; i < data.Length; i++) { data[i] = ((0 <= i - blockShiftLength ? data[i - blockShiftLength] << bitShiftLengtha : 0) | (bitShiftLengthb != 64 && 0 <= i - blockShiftLength - 1 ? data[i - blockShiftLength - 1] >> bitShiftLengthb : 0)); } data[data.Length - 1] &= LastMask; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ShiftNegative(int width) { var blockShiftLength = width >> 6; var bitShiftLengtha = width & 63; var bitShiftLengthb = 64 - bitShiftLengtha; for (int i = 0; i < data.Length; i++) { data[i] = ((i + blockShiftLength < data.Length ? data[i + blockShiftLength] >> bitShiftLengtha : 0) | (bitShiftLengthb != 64 && i + blockShiftLength + 1 < data.Length ? data[i + blockShiftLength + 1] << bitShiftLengthb : 0)); } data[data.Length - 1] &= LastMask; } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { var hw = Console.ReadLine().Split().Select(int.Parse).ToArray(); int h = hw[0]; int w = hw[1]; List<int>[] graph = Enumerable.Repeat(0, h * w).Select(_ => new List<int>()).ToArray(); for (int i = 0; i < h - 1; i++) for (int j = 0; j < w; j++) { var id = i * w + j; graph[id].Add(id + w); } for (int i = 0; i < h; i++) for (int j = 0; j < w - 1; j++) { var id = i * w + j; graph[id].Add(id + 1); } var arrived = new bool[h * w]; var a = Enumerable.Repeat(0, h) .SelectMany(_ => Console.ReadLine().Split().Select(int.Parse)) .ToArray() .Zip(Enumerable.Repeat(0, h) .SelectMany( _ => Console.ReadLine().Split().Select(int.Parse)) .ToArray(), (x, y) => Abs(x - y)) .ToArray(); var offset = 160 * 160; BitArray[] diffs = Enumerable.Repeat(0, h * w) .Select(_ => new BitArray(offset * 2 + 1)) .ToArray(); Queue<int> queue = new Queue<int>(); queue.Enqueue(0); diffs[0].SetTrue(offset); while (queue.Count != 0) { var last = queue.Dequeue(); var newBitArray = new BitArray(diffs[last]); diffs[last].ShiftPositive(a[last]); newBitArray.ShiftNegative(a[last]); diffs[last].Or(newBitArray); foreach (var next in graph[last]) { diffs[next].Or(diffs[last]); if (arrived[next]) continue; arrived[next] = true; queue.Enqueue(next); } } var min = int.MaxValue; var lastDiff = diffs.Last(); for (int i = 0; i < lastDiff.Length; i++) { if (!lastDiff.Get(i)) continue; min = Min(min, Abs(offset - i)); } Console.WriteLine(min); } } class BitArray { public readonly int Length; private readonly ulong LastMask; ulong[] data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BitArray(int length) { data = new ulong[((length - 1) >> 6) + 1]; Length = length; LastMask = (~0UL) >> ((~length) & 63); } public BitArray(BitArray bitArray) { data = new ulong[Length = bitArray.data.Length]; bitArray.data.CopyTo(data, 0); LastMask = bitArray.LastMask; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Get(int index) => (data[index >> 6] >> (index & 63) & 1) == 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetTrue(int index) => data[index >> 6] |= (1UL << (index & 63)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetFalse(int index) => data[index >> 6] &= ~(1UL << (index & 63)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Or(BitArray bitArray) { for (int i = 0; i < data.Length; i++) data[i] |= bitArray.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void And(BitArray bitArray) { for (int i = 0; i < data.Length; i++) data[i] &= bitArray.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Xor(BitArray bitArray) { for (int i = 0; i < data.Length; i++) data[i] ^= bitArray.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ShiftPositive(int width) { var blockShiftLength = width >> 6; var bitShiftLengtha = width & 63; var bitShiftLengthb = 64 - bitShiftLengtha; for (int i = data.Length - 1; i >= 0; i--) { data[i] = ((0 <= i - blockShiftLength ? data[i - blockShiftLength] << bitShiftLengtha : 0) | (bitShiftLengthb != 64 && 0 <= i - blockShiftLength - 1 ? data[i - blockShiftLength - 1] >> bitShiftLengthb : 0)); } data[data.Length - 1] &= LastMask; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ShiftNegative(int width) { var blockShiftLength = width >> 6; var bitShiftLengtha = width & 63; var bitShiftLengthb = 64 - bitShiftLengtha; for (int i = 0; i < data.Length; i++) { data[i] = ((i + blockShiftLength < data.Length ? data[i + blockShiftLength] >> bitShiftLengtha : 0) | (bitShiftLengthb != 64 && i + blockShiftLength + 1 < data.Length ? data[i + blockShiftLength + 1] << bitShiftLengthb : 0)); } data[data.Length - 1] &= LastMask; } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 68]]
8
1,227
12
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var h = ni(); var w = ni(); var a = new int[h, w]; var b = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { a[i, j] = ni(); } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { b[i, j] = ni(); } } var dp = new bool[h, w, 6410]; dp[0, 0, Math.Abs(a[0, 0] - b[0, 0])] = true; int ans = int.MaxValue; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { for (int k = 0; k < 6410; k++) { if (dp[i, j, k]) { var next1 = Math.Abs(k + a[i, j] - b[i, j]); if (next1 < 6410) { if (i + 1 < h) dp[i + 1, j, next1] = true; if (j + 1 < w) dp[i, j + 1, next1] = true; } var next2 = Math.Abs(k - a[i, j] + b[i, j]); if (next2 < 6410) { if (i + 1 < h) dp[i + 1, j, next2] = true; if (j + 1 < w) dp[i, j + 1, next2] = true; } if (i == h - 1 && j == w - 1) { ans = Math.Min(next1, ans); ans = Math.Min(next2, ans); } } } } } cout.WriteLine(ans); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)); new Solver(Console.In, Console.Out).Run(); #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { public static T Dump<T>(this T obj) { #if LOCAL return LINQPad.Extensions.Dump(obj); #else return obj; #endif } } public class Scanner { private readonly TextReader Reader; private readonly Queue<string> TokenQueue = new Queue<string>(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return int.Parse(Next(), ci); } public long NextLong() { return long.Parse(Next(), ci); } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (TokenQueue.Count == 0) { if (!StockTokens()) { throw new InvalidOperationException(); } } return TokenQueue.Dequeue(); } public bool HasNext() { if (TokenQueue.Count > 0) { return true; } return StockTokens(); } private static readonly char[] _separator = new[] { ' ', '\t' }; private bool StockTokens() { while (true) { string line = Reader.ReadLine(); if (line == null) { return false; } string[] tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { continue; } foreach (string token in tokens) { TokenQueue.Enqueue(token); } return true; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using E = System.Linq.Enumerable; internal partial class Solver { public void Run() { var h = ni(); var w = ni(); var a = new int[h, w]; var b = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { a[i, j] = ni(); } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { b[i, j] = ni(); } } var dp = new bool[h, w, 6410]; dp[0, 0, 0] = true; int ans = int.MaxValue; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { for (int k = 0; k < 6410; k++) { if (dp[i, j, k]) { var next1 = Math.Abs(k + a[i, j] - b[i, j]); if (next1 < 6410) { if (i + 1 < h) dp[i + 1, j, next1] = true; if (j + 1 < w) dp[i, j + 1, next1] = true; } var next2 = Math.Abs(k - a[i, j] + b[i, j]); if (next2 < 6410) { if (i + 1 < h) dp[i + 1, j, next2] = true; if (j + 1 < w) dp[i, j + 1, next2] = true; } if (i == h - 1 && j == w - 1) { ans = Math.Min(next1, ans); ans = Math.Min(next2, ans); } } } } } cout.WriteLine(ans); } } // PREWRITEN CODE BEGINS FROM HERE internal partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL byte[] inputBuffer = new byte[1000000]; var inputStream = Console.OpenStandardInput(inputBuffer.Length); Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)); new Solver(Console.In, Console.Out).Run(); #else Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver(Console.In, Console.Out).Run(); Console.Out.Flush(); #endif } #pragma warning disable IDE0052 private readonly TextReader cin; private readonly TextWriter cout; #pragma warning restore IDE0052 public Solver(TextReader reader, TextWriter writer) : base(reader) { cin = reader; cout = writer; } public Solver(string input, TextWriter writer) : this(new StringReader(input), writer) {} #pragma warning disable IDE1006 #pragma warning disable IDE0051 private int ni() { return NextInt(); } private int[] ni(int n) { return NextIntArray(n); } private long nl() { return NextLong(); } private long[] nl(int n) { return NextLongArray(n); } private double nd() { return NextDouble(); } private double[] nd(int n) { return NextDoubleArray(n); } private string ns() { return Next(); } private string[] ns(int n) { return NextArray(n); } #pragma warning restore IDE1006 #pragma warning restore IDE0051 } internal static class LinqPadExtension { public static T Dump<T>(this T obj) { #if LOCAL return LINQPad.Extensions.Dump(obj); #else return obj; #endif } } public class Scanner { private readonly TextReader Reader; private readonly Queue<string> TokenQueue = new Queue<string>(); private readonly CultureInfo ci = CultureInfo.InvariantCulture; public Scanner() : this(Console.In) {} public Scanner(TextReader reader) { Reader = reader; } public int NextInt() { return int.Parse(Next(), ci); } public long NextLong() { return long.Parse(Next(), ci); } public double NextDouble() { return double.Parse(Next(), ci); } public string[] NextArray(int size) { string[] array = new string[size]; for (int i = 0; i < size; i++) { array[i] = Next(); } return array; } public int[] NextIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = NextInt(); } return array; } public long[] NextLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = NextLong(); } return array; } public double[] NextDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = NextDouble(); } return array; } public string Next() { if (TokenQueue.Count == 0) { if (!StockTokens()) { throw new InvalidOperationException(); } } return TokenQueue.Dequeue(); } public bool HasNext() { if (TokenQueue.Count > 0) { return true; } return StockTokens(); } private static readonly char[] _separator = new[] { ' ', '\t' }; private bool StockTokens() { while (true) { string line = Reader.ReadLine(); if (line == null) { return false; } string[] tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) { continue; } foreach (string token in tokens) { TokenQueue.Enqueue(token); } return true; } } }
[["-", 206, 207, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 206, 207, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 206, 207, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 206, 207, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 21], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 21], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 206, 207, 0, 28, 0, 213, 3, 4, 0, 25]]
8
1,332
17
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif //#define TOPCODER using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "abc147"; public const string ProblemName = "E"; public int[] dx = { -1, 0, 1, 0 }; public int[] dy = { 0, 1, 0, -1 }; public int H; public int W; public int[][] A; public int[][] B; public int[][] G; public void Solve() { H = cin.ReadInt; W = cin.ReadInt; A = JagArray2D<int>(H, W); B = JagArray2D<int>(H, W); G = JagArray2D<int>(H, W); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i][j] = cin.ReadInt; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { B[i][j] = cin.ReadInt; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { G[i][j] = Math.Abs(A[i][j] - B[i][j]); } } const int MaxV = 6400; BitSet[][] dp = new BitSet[H][]; for (int i = 0; i < H; i++) { dp[i] = new BitSet[W]; for (int j = 0; j < W; j++) { dp[i][j] = new BitSet(MaxV * 2 + 1); } } int initV = G[0][0]; dp[0][0].SetTrue(initV + MaxV); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (j < W - 1) { int rv = G[i][j + 1]; var newBitSet1 = new BitSet(dp[i][j]); newBitSet1.ShiftPositive(rv); var newBitSet2 = new BitSet(dp[i][j]); newBitSet2.ShiftNegative(rv); dp[i][j + 1].Or(newBitSet1); dp[i][j + 1].Or(newBitSet2); } if (i < H - 1) { int bv = G[i + 1][j]; var newBitSet1 = new BitSet(dp[i][j]); newBitSet1.ShiftPositive(bv); var newBitSet2 = new BitSet(dp[i][j]); newBitSet2.ShiftNegative(bv); dp[i + 1][j].Or(newBitSet1); dp[i + 1][j].Or(newBitSet2); } } } int ans = int.MaxValue; for (int i = 0; i <= MaxV; i++) { if (dp[H - 1][W - 1].Get(i)) { ans = Math.Min(ans, Math.Abs(MaxV - i)); } } cou.WriteLine(ans); } public void Solve2() { H = cin.ReadInt; W = cin.ReadInt; A = JagArray2D<int>(H, W); B = JagArray2D<int>(H, W); G = JagArray2D<int>(H, W); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i][j] = cin.ReadInt; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { B[i][j] = cin.ReadInt; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { G[i][j] = Math.Abs(A[i][j] - B[i][j]); } } const int MaxV = 6400; // dp[i][j][k] : [i行][j列][値があるかどうか] bool[][][] dp = JagArray3D<bool>(H, W, MaxV + 1); var initV = G[0][0]; dp[0][0][initV] = true; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k <= MaxV; k++) { if (dp[i][j][k]) { // 右 if (j < W - 1) { var nv = G[i][j + 1]; var v1 = nv + k; if (Math.Abs(v1) <= MaxV) { dp[i][j + 1][Math.Abs(v1)] = true; } var v2 = nv - k; if (Math.Abs(v2) <= MaxV) { dp[i][j + 1][Math.Abs(v2)] = true; } } // 下 if (i < H - 1) { var nv = G[i + 1][j]; var v1 = nv + k; if (Math.Abs(v1) <= MaxV) { dp[i + 1][j][Math.Abs(v1)] = true; } var v2 = nv - k; if (Math.Abs(v2) <= MaxV) { dp[i + 1][j][Math.Abs(v2)] = true; } } } } } } for (int i = 0; i <= MaxV; i++) { if (dp[H - 1][W - 1][i]) { cou.WriteLine(i); return; } } } } public class BitSet { public readonly int Length; public readonly ulong LastMask; private ulong[] data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BitSet(int length) { data = new ulong[((length - 1) >> 6) + 1]; Length = length; LastMask = (~0UL) >> ((~length) & 63); } public BitSet(BitSet bitSet) { Length = bitSet.data.Length; data = new ulong[Length]; bitSet.data.CopyTo(data, 0); LastMask = bitSet.LastMask; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Get(int index) => (data[index >> 6] >> (index & 63) & 1) == 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetTrue(int index) => data[index >> 6] |= (1UL << (index & 63)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetFalse(int index) => data[index >> 6] &= ~(1UL << (index & 63)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Or(BitSet bitSet) { for (int i = 0; i < data.Length; i++) data[i] |= bitSet.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void And(BitSet bitSet) { for (int i = 0; i < data.Length; i++) data[i] &= bitSet.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Xor(BitSet bitSet) { for (int i = 0; i < data.Length; i++) data[i] ^= bitSet.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ShiftPositive(int width) { var blockShiftLength = width >> 6; var bitShiftLengtha = width & 63; var bitShiftLengthb = 64 - bitShiftLengtha; for (int i = data.Length - 1; i >= 0; i--) { data[i] = ((0 <= i - blockShiftLength ? data[i - blockShiftLength] << bitShiftLengtha : 0) | (bitShiftLengthb != 64 && 0 <= i - blockShiftLength - 1 ? data[i - blockShiftLength - 1] >> bitShiftLengthb : 0)); } data[data.Length - 1] &= LastMask; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ShiftNegative(int width) { var blockShiftLength = width >> 6; var bitShiftLengtha = width & 63; var bitShiftLengthb = 64 - bitShiftLengtha; for (int i = 0; i < data.Length; i++) { data[i] = ((i + blockShiftLength < data.Length ? data[i + blockShiftLength] >> bitShiftLengtha : 0) | (bitShiftLengthb != 64 && i + blockShiftLength + 1 < data.Length ? data[i + blockShiftLength + 1] << bitShiftLengthb : 0)); } data[data.Length - 1] &= LastMask; } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } #if !TOPCODER public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } #endif //========================================================================================= // Library //========================================================================================= public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public class IntLargeComparer : IComparer<int> { public static IntLargeComparer Instance = new IntLargeComparer(); public int Compare(int x, int y) { return y - x; } } public class LongLargeComparer : IComparer<long> { public static LongLargeComparer Instance = new LongLargeComparer(); public int Compare(long x, long y) { if (x > y) return -1; if (x < y) return 1; return 0; } } public static class UtakaExtentions { /// <summary> /// 配列をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
// ReSharper disable ArrangeTypeMemberModifiers // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable FunctionRecursiveOnAllPaths // ReSharper disable InconsistentNaming // ReSharper disable InlineOutVariableDeclaration // ReSharper disable InvertIf // ReSharper disable JoinDeclarationAndInitializer // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable MemberCanBeMadeStatic.Local // ReSharper disable NonReadonlyMemberInGetHashCode // ReSharper disable PossibleNullReferenceException // ReSharper disable RedundantUsingDirective // ReSharper disable SuggestVarOrType_BuiltInTypes // ReSharper disable SuggestVarOrType_Elsewhere // ReSharper disable TailRecursiveCall // ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Local // ReSharper disable UseObjectOrCollectionInitializert #if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif //#define TOPCODER using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Numerics; using System.Runtime.InteropServices; using System.Security.Cryptography; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "abc147"; public const string ProblemName = "E"; public int[] dx = { -1, 0, 1, 0 }; public int[] dy = { 0, 1, 0, -1 }; public int H; public int W; public int[][] A; public int[][] B; public int[][] G; public void Solve() { H = cin.ReadInt; W = cin.ReadInt; A = JagArray2D<int>(H, W); B = JagArray2D<int>(H, W); G = JagArray2D<int>(H, W); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i][j] = cin.ReadInt; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { B[i][j] = cin.ReadInt; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { G[i][j] = Math.Abs(A[i][j] - B[i][j]); } } const int MaxV = 6400; BitSet[][] dp = new BitSet[H][]; for (int i = 0; i < H; i++) { dp[i] = new BitSet[W]; for (int j = 0; j < W; j++) { dp[i][j] = new BitSet(MaxV * 2 + 1); } } int initV = G[0][0]; dp[0][0].SetTrue(MaxV + initV); dp[0][0].SetTrue(MaxV - initV); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (j < W - 1) { int rv = G[i][j + 1]; var newBitSet1 = new BitSet(dp[i][j]); newBitSet1.ShiftPositive(rv); var newBitSet2 = new BitSet(dp[i][j]); newBitSet2.ShiftNegative(rv); dp[i][j + 1].Or(newBitSet1); dp[i][j + 1].Or(newBitSet2); } if (i < H - 1) { int bv = G[i + 1][j]; var newBitSet1 = new BitSet(dp[i][j]); newBitSet1.ShiftPositive(bv); var newBitSet2 = new BitSet(dp[i][j]); newBitSet2.ShiftNegative(bv); dp[i + 1][j].Or(newBitSet1); dp[i + 1][j].Or(newBitSet2); } } } int ans = int.MaxValue; for (int i = 0; i <= MaxV; i++) { if (dp[H - 1][W - 1].Get(i)) { ans = Math.Min(ans, Math.Abs(MaxV - i)); } } cou.WriteLine(ans); } public void Solve2() { H = cin.ReadInt; W = cin.ReadInt; A = JagArray2D<int>(H, W); B = JagArray2D<int>(H, W); G = JagArray2D<int>(H, W); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { A[i][j] = cin.ReadInt; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { B[i][j] = cin.ReadInt; } } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { G[i][j] = Math.Abs(A[i][j] - B[i][j]); } } const int MaxV = 6400; // dp[i][j][k] : [i行][j列][値があるかどうか] bool[][][] dp = JagArray3D<bool>(H, W, MaxV + 1); var initV = G[0][0]; dp[0][0][initV] = true; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k <= MaxV; k++) { if (dp[i][j][k]) { // 右 if (j < W - 1) { var nv = G[i][j + 1]; var v1 = nv + k; if (Math.Abs(v1) <= MaxV) { dp[i][j + 1][Math.Abs(v1)] = true; } var v2 = nv - k; if (Math.Abs(v2) <= MaxV) { dp[i][j + 1][Math.Abs(v2)] = true; } } // 下 if (i < H - 1) { var nv = G[i + 1][j]; var v1 = nv + k; if (Math.Abs(v1) <= MaxV) { dp[i + 1][j][Math.Abs(v1)] = true; } var v2 = nv - k; if (Math.Abs(v2) <= MaxV) { dp[i + 1][j][Math.Abs(v2)] = true; } } } } } } for (int i = 0; i <= MaxV; i++) { if (dp[H - 1][W - 1][i]) { cou.WriteLine(i); return; } } } } public class BitSet { public readonly int Length; public readonly ulong LastMask; private ulong[] data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BitSet(int length) { data = new ulong[((length - 1) >> 6) + 1]; Length = length; LastMask = (~0UL) >> ((~length) & 63); } public BitSet(BitSet bitSet) { Length = bitSet.data.Length; data = new ulong[Length]; bitSet.data.CopyTo(data, 0); LastMask = bitSet.LastMask; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Get(int index) => (data[index >> 6] >> (index & 63) & 1) == 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetTrue(int index) => data[index >> 6] |= (1UL << (index & 63)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetFalse(int index) => data[index >> 6] &= ~(1UL << (index & 63)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Or(BitSet bitSet) { for (int i = 0; i < data.Length; i++) data[i] |= bitSet.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void And(BitSet bitSet) { for (int i = 0; i < data.Length; i++) data[i] &= bitSet.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Xor(BitSet bitSet) { for (int i = 0; i < data.Length; i++) data[i] ^= bitSet.data[i]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ShiftPositive(int width) { var blockShiftLength = width >> 6; var bitShiftLengtha = width & 63; var bitShiftLengthb = 64 - bitShiftLengtha; for (int i = data.Length - 1; i >= 0; i--) { data[i] = ((0 <= i - blockShiftLength ? data[i - blockShiftLength] << bitShiftLengtha : 0) | (bitShiftLengthb != 64 && 0 <= i - blockShiftLength - 1 ? data[i - blockShiftLength - 1] >> bitShiftLengthb : 0)); } data[data.Length - 1] &= LastMask; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ShiftNegative(int width) { var blockShiftLength = width >> 6; var bitShiftLengtha = width & 63; var bitShiftLengthb = 64 - bitShiftLengtha; for (int i = 0; i < data.Length; i++) { data[i] = ((i + blockShiftLength < data.Length ? data[i + blockShiftLength] >> bitShiftLengtha : 0) | (bitShiftLengthb != 64 && i + blockShiftLength + 1 < data.Length ? data[i + blockShiftLength + 1] << bitShiftLengthb : 0)); } data[data.Length - 1] &= LastMask; } } //========================================================================================= // Debug IO //========================================================================================= public partial class Program { //========================================================================================= // Main //========================================================================================= private readonly ConsoleInput cin; private readonly IConsole cou; public Program(ConsoleInput cin, IConsole cou) { this.cin = cin; this.cou = cou; } #if !TOPCODER public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var cin = new ConsoleInput(System.Console.In); var console = new MyConsole(); new Program(cin, console).Solve(); console.Flush(); #endif } #endif //========================================================================================= // Library //========================================================================================= public static T[] Array1D<T>(int a, T defaultValue) where T : struct { var ret = new T[a]; for (int i = 0; i < a; i++) { ret[i] = defaultValue; } return ret; } public static T[] Array1D<T>(int a) where T : struct { var ret = new T[a]; return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされた配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[,] Array2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a, b]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { ret[i, j] = defaultValue; } } return ret; } public static T[,,] Array3D<T>(int a, int b, int c, T defaultValue) where T : struct { T[,,] ret = new T[a, b, c]; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < c; k++) { ret[i, j, k] = defaultValue; } } } return ret; } /// <summary> /// 要素数 (a, b) の、defaultValue で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>指定した条件で初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b, T defaultValue) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { var row = new T[b]; ret[i] = row; for (int j = 0; j < b; j++) { row[j] = defaultValue; } } return ret; } /// <summary> /// 要素数 (a, b) のdefault値で満たされたJag配列を作成します。 /// </summary> /// <typeparam name="T">配列の型</typeparam> /// <param name="a">1次元の要素数</param> /// <param name="b">2次元の要素数</param> /// <returns>初期化された配列</returns> public static T[][] JagArray2D<T>(int a, int b) where T : struct { var ret = new T[a][]; for (int i = 0; i < a; i++) { ret[i] = new T[b]; } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c, T defaultValue) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; for (int k = 0; k < c; k++) { bRow[k] = defaultValue; } } } return ret; } public static T[][][] JagArray3D<T>(int a, int b, int c) where T : struct { var ret = new T[a][][]; for (int i = 0; i < a; i++) { T[][] aRow = new T[b][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[] bRow = new T[c]; aRow[j] = bRow; } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d, T defaultValue) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; for (int l = 0; l < d; l++) { cRow[l] = defaultValue; } } } } return ret; } public static T[][][][] JagArray4D<T>(int a, int b, int c, int d) where T : struct { var ret = new T[a][][][]; for (int i = 0; i < a; i++) { T[][][] aRow = new T[b][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][] bRow = new T[c][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[] cRow = new T[d]; bRow[k] = cRow; } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e, T defaultValue) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; for (int m = 0; m < e; m++) { dRow[m] = defaultValue; } } } } } return ret; } public static T[][][][][] JagArray5D<T>(int a, int b, int c, int d, int e) where T : struct { var ret = new T[a][][][][]; for (int i = 0; i < a; i++) { T[][][][] aRow = new T[b][][][]; ret[i] = aRow; for (int j = 0; j < b; j++) { T[][][] bRow = new T[c][][]; aRow[j] = bRow; for (int k = 0; k < c; k++) { T[][] cRow = new T[d][]; bRow[k] = cRow; for (int l = 0; l < d; l++) { T[] dRow = new T[e]; cRow[l] = dRow; } } } } return ret; } /// <summary> /// ジャグ配列をコピーして返す。 /// </summary> public static T[][] CopyJagArray2D<T>(T[][] source) where T : struct { int len = source.Length; T[][] dest = new T[len][]; for (int i = 0; i < len; i++) { T[] inner = source[i]; int innerLength = inner.Length; T[] newer = new T[innerLength]; Array.Copy(inner, newer, innerLength); dest[i] = newer; } return dest; } } public class IntLargeComparer : IComparer<int> { public static IntLargeComparer Instance = new IntLargeComparer(); public int Compare(int x, int y) { return y - x; } } public class LongLargeComparer : IComparer<long> { public static LongLargeComparer Instance = new LongLargeComparer(); public int Compare(long x, long y) { if (x > y) return -1; if (x < y) return 1; return 0; } } public static class UtakaExtentions { /// <summary> /// 配列をコピーします /// </summary> public static T[] Copy<T>(this IList<T> a) { T[] ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } public class ConsoleInput { private readonly char _separator = ' '; private readonly TextReader _stream; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var i = 0; i < tmp.Length; ++i) { inputStream.Enqueue(tmp[i]); } return inputStream.Dequeue(); } } public string ReadLine => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) { ret[i] = Read; } return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadInt; } return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) { ret[i] = ReadLong; } return ret; } } public interface IConsole { void Flush(); void Write(object obj); void Write(string str); void WriteLine(object obj); void WriteLine(string str); void WriteLine(); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { Console.Write(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { Console.WriteLine(str); } public void WriteLine() { Console.WriteLine(); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(object obj) { Write(obj.ToString()); } public void Write(string str) { mSb.Append(str); } public void WriteLine(object obj) { WriteLine(obj.ToString()); } public void WriteLine(string str) { mSb.AppendLine(str); } public void WriteLine() { mSb.AppendLine(); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var cin = new ConsoleInput(inputStream); var debugConsoleWriter = new DebugConsole(); new Program(cin, debugConsoleWriter).Solve(); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems(int targetTestCaseNumber = -1) { if (targetTestCaseNumber >= 0) { Console.WriteLine( $"!!!!!!!!!!!! Check TestCase {targetTestCaseNumber} !!!!!!!!!!"); } bool isSuccessAll = true; int testCaseNumber = 0; while (true) { testCaseNumber++; bool foundTargetTest = targetTestCaseNumber == testCaseNumber; if (targetTestCaseNumber >= 0 && !foundTargetTest) { continue; } var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine("Success"); } else { isSuccessAll = false; Console.WriteLine("Failure *****"); } if (foundTargetTest) { break; } } if (isSuccessAll) { Console.WriteLine("!!!!!!!!! All Success !!!!!!!!!"); } } } #endif public static class Dbg { [Conditional("UTAKA_DEBUG")] public static void WriteLine(string str) { Console.WriteLine(str); } [Conditional("UTAKA_DEBUG")] public static void WriteLine() { Console.WriteLine(); } [Conditional("UTAKA_DEBUG")] public static void Write(string str) { Console.Write(str); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 213, 63, 214, 205, 204, 205, 204, 205, 22], ["+", 63, 214, 205, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 63, 214, 205, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
5,026
17
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { const int T = 25600; const int X = 60; const int Y = T / X + 1; public void Solve() { long[][][] M = new long [H][][]; for (int i = 0; i < H; i++) { M[i] = new long [W][]; for (int j = 0; j < W; j++) { M[i][j] = new long[Y]; } } int[][] C = new int [H][]; for (int i = 0; i < H; i++) { C[i] = new int[W]; for (int j = 0; j < W; j++) { C[i][j] = Math.Abs(A[i][j] - B[i][j]); } } M[0][0][C[0][0] / X] |= 1L << (C[0][0] % X); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k < T; k++) { if ((M[i][j][k / X] >> (k % X)) % 2 == 0) continue; if (i + 1 < H) { int a = Math.Abs(k + C[i + 1][j]); int b = Math.Abs(k - C[i + 1][j]); if (a < X) M[i + 1][j][a / X] |= 1L << (a % X); if (b < X) M[i + 1][j][b / X] |= 1L << (b % X); } if (j + 1 < W) { int a = Math.Abs(k + C[i][j + 1]); int b = Math.Abs(k - C[i][j + 1]); if (a < X) M[i][j + 1][a / X] |= 1L << (a % X); if (b < X) M[i][j + 1][b / X] |= 1L << (b % X); } } } } for (int i = 0; i < T; i++) { if ((M[H - 1][W - 1][i / X] >> (i % X)) % 2 == 1) { Console.WriteLine(i); return; } } } int H, W; int[][] A; int[][] B; public Sol() { var d = ria(); H = d[0]; W = d[1]; A = new int [H][]; for (int i = 0; i < H; i++) { A[i] = ria(); } B = new int [H][]; for (int i = 0; i < H; i++) { B[i] = ria(); } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { const int T = 80 * 81; const int X = 60; const int Y = T / X + 1; public void Solve() { long[][][] M = new long [H][][]; for (int i = 0; i < H; i++) { M[i] = new long [W][]; for (int j = 0; j < W; j++) { M[i][j] = new long[Y]; } } int[][] C = new int [H][]; for (int i = 0; i < H; i++) { C[i] = new int[W]; for (int j = 0; j < W; j++) { C[i][j] = Math.Abs(A[i][j] - B[i][j]); } } M[0][0][C[0][0] / X] |= 1L << (C[0][0] % X); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k < T; k++) { if ((M[i][j][k / X] >> (k % X)) % 2 == 0) continue; if (i + 1 < H) { int a = Math.Abs(k + C[i + 1][j]); int b = Math.Abs(k - C[i + 1][j]); if (a < T) M[i + 1][j][a / X] |= 1L << (a % X); if (b < T) M[i + 1][j][b / X] |= 1L << (b % X); } if (j + 1 < W) { int a = Math.Abs(k + C[i][j + 1]); int b = Math.Abs(k - C[i][j + 1]); if (a < T) M[i][j + 1][a / X] |= 1L << (a % X); if (b < T) M[i][j + 1][b / X] |= 1L << (b % X); } } } } for (int i = 0; i < T; i++) { if ((M[H - 1][W - 1][i / X] >> (i % X)) % 2 == 1) { Console.WriteLine(i); return; } } } int H, W; int[][] A; int[][] B; public Sol() { var d = ria(); H = d[0]; W = d[1]; A = new int [H][]; for (int i = 0; i < H; i++) { A[i] = ria(); } B = new int [H][]; for (int i = 0; i < H; i++) { B[i] = ria(); } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22]]
8
969
12
using System; using System.Collections.Generic; using System.Linq; class F { struct LR { public long L, R; } static void Main() { var h = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = h[0], x = h[1], d = h[2]; if (d == 0) { Console.WriteLine(x == 0 ? 1 : n + 1); return; } if (d < 0) { d = -d; x = -x; } var map = new Dictionary<long, List<LR>>(); for (long i = 0; i <= n; i++) { var l = i * (i - 1) / 2; var r = n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2; var a = i * x; var m = a % d; if (m < 0) m += d; a = (a - m) / d; if (!map.ContainsKey(m)) map[m] = new List<LR>(); map[m].Add(new LR { L = a + l, R = a + r }); } var c = 0L; foreach (var lrs in map.Values) { var M = long.MinValue; foreach (var lr in lrs.OrderBy(s => s.L).ThenBy(s => s.R)) { c += lr.R - Math.Max(M, lr.L - 1); M = lr.R; } } Console.WriteLine(c); } }
using System; using System.Collections.Generic; using System.Linq; class F { struct LR { public long L, R; } static void Main() { var h = Console.ReadLine().Split().Select(long.Parse).ToArray(); long n = h[0], x = h[1], d = h[2]; if (d == 0) { Console.WriteLine(x == 0 ? 1 : n + 1); return; } if (d < 0) { d = -d; x = -x; } var map = new Dictionary<long, List<LR>>(); for (long i = 0; i <= n; i++) { var l = i * (i - 1) / 2; var r = l + i * (n - i); var a = i * x; var m = (a % d + d) % d; a = (a - m) / d; if (!map.ContainsKey(m)) map[m] = new List<LR>(); map[m].Add(new LR { L = a + l, R = a + r }); } var c = 0L; foreach (var lrs in map.Values) { var r = long.MinValue; foreach (var lr in lrs.OrderBy(s => s.L).Where(s => s.R > r)) { c += lr.R - Math.Max(r, lr.L - 1); r = lr.R; } } Console.WriteLine(c); } }
[["-", 0, 212, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 16, 31, 16, 31, 16, 12, 23, 0, 24], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 16, 31, 16, 31, 16, 12, 23, 0, 25], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 85], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 0, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 16, 12, 16, 31, 16, 31, 23, 0, 25], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 17, 85], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 22], ["-", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22]]
8
362
42