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; namespace B { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var nx = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); var li = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); var count = 0L; var current = 0L; for (var i = 0; i < li.Length; i++) { if (current <= nx[1]) count++; else break; current += li[i]; } Console.WriteLine(count); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace B { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var nx = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); var li = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); var count = 1; var current = 0L; for (var i = 0; i < li.Length; i++) { current += li[i]; if (current <= nx[1]) count++; else break; } Console.WriteLine(count); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 8, 196, 0, 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, 7, 8, 196, 0, 57, 75, 93, 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, 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
209
16
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var n = int.Parse(spl[0]); var x = int.Parse(spl[1]); var ary = ToIntArray(input.ReadLine(), n); int c = 0; int y = 0; while (true) { c++; y += ary[c - 1]; if (c > n) break; if (y > x) break; } return c; } static int[] ToIntArray(string strs, int n) { var ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.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 { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var n = int.Parse(spl[0]); var x = int.Parse(spl[1]); var ary = ToIntArray(input.ReadLine(), n); int c = 0; int y = 0; while (true) { c++; if (c > n) break; y += ary[c - 1]; if (y > x) break; } return c; } static int[] ToIntArray(string strs, int n) { var ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
[["+", 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, 47], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 52, 8, 196, 0, 57, 64, 93, 0, 35], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 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, 47], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 25], ["-", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94]]
8
289
16
using System; using System.Linq; using System.Collections.Generic; namespace ABC130_1 { class B { static void Main(string[] args) { var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); var sum = 0; var res = 0; for (int i = 0; i < a[0]; i++) { if (a[1] < sum) break; sum += l[i]; res++; } Console.WriteLine(res); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC130_1 { class B { static void Main(string[] args) { var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); var sum = 0; var res = 1; for (int i = 1; i < a[0] + 1; i++) { sum += l[i - 1]; if (a[1] < sum) break; res++; } Console.WriteLine(res); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 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], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 93, 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, 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
139
22
using System; using System.Collections.Generic; public class AtCoderB { static void Main() { int n; int x; { var line = Console.ReadLine(); var words = line.Split(' '); n = int.Parse(words[0]); x = int.Parse(words[1]); } int answer = 0; int oldD = 0; { var line = Console.ReadLine(); var words = line.Split(' '); for (int i = 0; i < n; i++) { int newD = oldD + int.Parse(words[i]); if (newD <= x) { answer++; } } } Console.WriteLine(answer); } }
using System; using System.Collections.Generic; public class AtCoderB { static void Main() { int n; int x; { var line = Console.ReadLine(); var words = line.Split(' '); n = int.Parse(words[0]); x = int.Parse(words[1]); } int answer = 0; int oldD = 0; { var line = Console.ReadLine(); var words = line.Split(' '); if (oldD <= x) { answer++; } for (int i = 0; i < n; i++) { oldD = oldD + int.Parse(words[i]); if (oldD <= x) { answer++; } } } Console.WriteLine(answer); } }
[["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 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, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22]]
8
157
16
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! var a = Console.ReadLine().Split().Select(y => int.Parse(y)).ToArray(); int n = a[0]; int x = a[1]; var l = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray(); int counter = 0; int zahyo = 0; for (int i = 0; n != i; i++) { if (zahyo <= x) { counter++; } zahyo = zahyo + l[i]; } Console.WriteLine(counter); } }
using System; using System.Linq; public class Hello { public static void Main() { // Your code here! var a = Console.ReadLine().Split().Select(y => int.Parse(y)).ToArray(); int n = a[0]; int x = a[1]; var l = Console.ReadLine().Split().Select(z => int.Parse(z)).ToArray(); int counter = 1; int zahyo = 0; for (int i = 0; n != i; i++) { zahyo = zahyo + l[i]; if (zahyo <= x) { counter++; } } Console.WriteLine(counter); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 8, 196, 0, 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, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 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, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["-", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
149
20
using System; using System.Linq; namespace CSharp { class Program { static void Main() { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = input[0]; var X = input[1]; var L = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var sum = 0; for (int i = 0; i < N; i++) { if ((sum += L[i]) > X) { Console.WriteLine(i + 1); break; } } } } }
using System; using System.Linq; namespace CSharp { class Program { static void Main() { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = input[0]; var X = input[1]; var L = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var sum = 0; for (int i = 0; i < N; i++) { if ((sum += L[i]) > X) { Console.WriteLine(i + 1); return; } } Console.WriteLine(N + 1); } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 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, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
140
11
using System; using static System.Console; using static System.Math; using System.Collections.Generic; using System.Linq; using System.Text; namespace TemplateAlgorithm { class Program { public const long Inf = (long)1e18; public const double eps = 1e-6; public const string alfa = "abcdefghijklmnopqrstuvwxyz"; public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const int MOD = 1000000007; static void Main(string[] args) { var data = IO.ReadIntArr(); int N, X; N = data[0]; X = data[1]; long[] L; L = IO.ReadLongArr(); var D = new long[N]; { for (var i = 0; i < N - 1; i++) { D[i + 1] = D[i] + L[i]; } } WriteLine(D.Where(i => i <= X).Count()); } static int ToInt(char c) => c - '0'; #region MIN, MAX /// <summary> /// 最大値を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="vals"></param> /// <returns></returns> public static T MaxValue<T>(params T[] vals) => vals.Max(); /// <summary> /// 最小値を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="vals"></param> /// <returns></returns> public static T MinValue<T>(params T[] vals) => vals.Min(); #endregion } #region IO /// <summary> /// IO /// </summary> public class IO { public static string ReadStr(bool isTrim = false) => (isTrim) ? ReadLine().Trim() : ReadLine(); public static int ReadInt() => int.Parse(ReadStr()); public static long ReadLong() => long.Parse(ReadStr()); public static decimal ReadDecimal() => decimal.Parse(ReadStr()); public static double ReadDouble() => double.Parse(ReadStr()); public static string[] ReadStrArr(char separator = ' ') => ReadLine().Split(separator); public static int[] ReadIntArr() => Array.ConvertAll(ReadStrArr(), int.Parse); public static long[] ReadLongArr() => Array.ConvertAll(ReadStrArr(), long.Parse); public static decimal[] ReadDecimalArr() => Array.ConvertAll(ReadStrArr(), decimal.Parse); public static double[] ReadDoubleArr() => Array.ConvertAll(ReadStrArr(), double.Parse); public static void Cout<T>(T value) => WriteLine(value); public static void CoutJoin<T>(T[] values, string separator = " ") => Cout(string.Join(separator, values)); } #endregion }
using System; using static System.Console; using static System.Math; using System.Collections.Generic; using System.Linq; using System.Text; namespace TemplateAlgorithm { class Program { public const long Inf = (long)1e18; public const double eps = 1e-6; public const string alfa = "abcdefghijklmnopqrstuvwxyz"; public const string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const int MOD = 1000000007; static void Main(string[] args) { var data = IO.ReadIntArr(); int N, X; N = data[0]; X = data[1]; long[] L; L = IO.ReadLongArr(); var D = new long[N + 1]; D[0] = 0; for (var i = 0; i < N; i++) { D[i + 1] = D[i] + L[i]; } WriteLine(D.Where(i => i <= X).Count()); } static int ToInt(char c) => c - '0'; #region MIN, MAX /// <summary> /// 最大値を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="vals"></param> /// <returns></returns> public static T MaxValue<T>(params T[] vals) => vals.Max(); /// <summary> /// 最小値を返す /// </summary> /// <typeparam name="T"></typeparam> /// <param name="vals"></param> /// <returns></returns> public static T MinValue<T>(params T[] vals) => vals.Min(); #endregion } #region IO /// <summary> /// IO /// </summary> public class IO { public static string ReadStr(bool isTrim = false) => (isTrim) ? ReadLine().Trim() : ReadLine(); public static int ReadInt() => int.Parse(ReadStr()); public static long ReadLong() => long.Parse(ReadStr()); public static decimal ReadDecimal() => decimal.Parse(ReadStr()); public static double ReadDouble() => double.Parse(ReadStr()); public static string[] ReadStrArr(char separator = ' ') => ReadLine().Split(separator); public static int[] ReadIntArr() => Array.ConvertAll(ReadStrArr(), int.Parse); public static long[] ReadLongArr() => Array.ConvertAll(ReadStrArr(), long.Parse); public static decimal[] ReadDecimalArr() => Array.ConvertAll(ReadStrArr(), decimal.Parse); public static double[] ReadDoubleArr() => Array.ConvertAll(ReadStrArr(), double.Parse); public static void Cout<T>(T value) => WriteLine(value); public static void CoutJoin<T>(T[] values, string separator = " ") => Cout(string.Join(separator, values)); } #endregion }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 196, 0, 45], ["+", 8, 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, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 0, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 196, 0, 7, 8, 196, 0, 46]]
8
537
13
using System; using System.Text.RegularExpressions; using System.Collections.Generic; class Program { static void Main(string[] arg) { int[] tmp1 = new int[2]; int tmpnum = 0; int count = 0; string[] x = Regex.Split(Console.ReadLine(), @"\s+"); tmp1[0] = Convert.ToInt32(x[0]); tmp1[1] = Convert.ToInt32(x[1]); foreach (string tmpstr in Regex.Split(Console.ReadLine(), @"\s+")) { if (tmpnum <= tmp1[1]) { count++; } else { break; } tmpnum += Convert.ToInt32(tmpstr); } Console.WriteLine(count); } }
using System; using System.Text.RegularExpressions; using System.Collections.Generic; class Program { static void Main(string[] arg) { int[] tmp1 = new int[2]; int tmpnum = 0; int count = 1; string[] x = Regex.Split(Console.ReadLine(), @"\s+"); tmp1[0] = Convert.ToInt32(x[0]); tmp1[1] = Convert.ToInt32(x[1]); foreach (string tmpstr in Regex.Split(Console.ReadLine(), @"\s+")) { tmpnum += Convert.ToInt32(tmpstr); if (tmpnum <= tmp1[1]) { count++; } else { break; } } Console.WriteLine(count); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
156
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] values = Console.ReadLine().Split(' '); int n = int.Parse(values[0]); int x = int.Parse(values[1]); string[] stepvalues = Console.ReadLine().Split(' '); int[] steps = new int[n]; for (int i = 0; i < n; i++) { steps[i] = int.Parse(stepvalues[i]); } int position = 0; int count = 1; for (int i = 0; i <= n; i++) { if (position < x) { position += steps[i]; count++; } } Console.WriteLine(count.ToString()); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] values = Console.ReadLine().Split(' '); int n = int.Parse(values[0]); int x = int.Parse(values[1]); string[] stepvalues = Console.ReadLine().Split(' '); int[] steps = new int[n]; for (int i = 0; i < n; i++) { steps[i] = int.Parse(stepvalues[i]); } int position = 0; int count = 1; for (int i = 0; i < n; i++) { position += steps[i]; if (position <= x) { count++; } } Console.WriteLine(count.ToString()); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 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, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45]]
8
201
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' '); var n = int.Parse(s[0]); var x = int.Parse(s[1]); var sls = Console.ReadLine().Split(' '); var ls = new int[n]; for (int i = 0; i < n; i++) { ls[i] = int.Parse(sls[i]); } bool isyesorno = false; bool yes = false; if (!isyesorno) { int place = 0; int count = 0; while (place <= x && count < n) { place += ls[count]; count++; } Console.WriteLine(count); } else { if (yes) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } #if DEBUG Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' '); var n = int.Parse(s[0]); var x = int.Parse(s[1]); var sls = Console.ReadLine().Split(' '); var ls = new int[n]; for (int i = 0; i < n; i++) { ls[i] = int.Parse(sls[i]); } bool isyesorno = false; bool yes = false; if (!isyesorno) { int place = 0; int count = 0; while (place <= x) { if (count < n) { place += ls[count]; count++; } else { count++; break; } } Console.WriteLine(count); } else { if (yes) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } #if DEBUG Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } } }
[["-", 0, 57, 64, 196, 0, 52, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 64, 196, 0, 52, 0, 25], ["+", 0, 57, 64, 196, 0, 52, 8, 196, 0, 45], ["+", 64, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 64, 196, 0, 52, 8, 196, 0, 57, 0, 95], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46]]
8
250
14
using Atcoder; using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var first = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = first[0]; var X = first[1]; var Ls = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int result = 0; int tmp = 0; for (int i = 0; i < N; i++) { if (tmp > X) { Console.Write(result); return; } tmp = tmp + Ls[i]; result++; } Console.Write(result); } // static void Main(string[] args) //{ // var temp = new Atcoder.ABC129.B(); // temp.Run(); //} } // var N = int.Parse(Console.ReadLine()); // var S = Console.ReadLine(); // var K = Console.ReadLine().Split(' '); // var N = int.Parse((K[0])); // var M = int.Parse((K[1])); // var firstLine = Console.ReadLine().Split(' ').Select(int.Parse); }
using Atcoder; using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var first = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = first[0]; var X = first[1]; var Ls = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int result = 1; int tmp = 0; for (int i = 0; i < N; i++) { tmp = tmp + Ls[i]; if (tmp <= X) { result++; } } Console.Write(result); } // static void Main(string[] args) //{ // var temp = new Atcoder.ABC129.B(); // temp.Run(); //} } // var N = int.Parse(Console.ReadLine()); // var S = Console.ReadLine(); // var K = Console.ReadLine().Split(' '); // var N = int.Parse((K[0])); // var M = int.Parse((K[1])); // var firstLine = Console.ReadLine().Split(' ').Select(int.Parse); }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 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], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 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, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
199
27
using System; using System.Collections.Generic; using System.Linq; namespace Paiza { class Program { public static void Main(string[] args) { if (true) { abc130_b(); } else { arc089_a(); abc085_c(); abc083_b(); abc087_b(); ABC081A(); ABC086A(); ABC081B(); } } private static void abc130_b() { var NX = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NX[0]; var X = NX[1]; var L = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); L = Enumerable.Range(0, 1).Select(x => x).Concat(L).ToArray(); var counter = 0; var D = 0; foreach (var item in L) { D += item; if (D > X) { Console.WriteLine(counter); return; } counter++; } } private static void arc089_a() { var N = int.Parse(Console.ReadLine()); var t = Enumerable.Range(0, N) .Select(x => Console.ReadLine() .Split(' ') .Select(y => int.Parse(y)) .ToArray()) .ToArray(); int[] prev = new int[] { 0, 0, 0 }; foreach (var item in t) { var dt = item[0] - prev[0]; var dist = Math.Abs(item[1] - prev[1]) + Math.Abs(item[2] - prev[2]); var parity = item[0] % 2 == 0; if (dist > Math.Abs(item[0] - prev[0])) { Console.WriteLine("No"); return; } if (dist % 2 != dt % 2) { Console.WriteLine("No"); return; } prev = item; } Console.WriteLine("Yes"); } private static void abc085_c() { var NY = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NY[0]; var Y = NY[1]; // 10000 5000 1000 for (int i = 0; i <= N; i++) { for (int j = 0; j <= N - j; j++) { var k = N - i - j; if (k >= 0) { if (i * 10000 + j * 5000 + k * 1000 == Y) { Console.WriteLine($"{i} {j} {k}"); return; } } } } Console.WriteLine("-1 -1 -1"); } private static void abc083_b() { var NAB = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); var N = NAB[0]; var A = NAB[1]; var B = NAB[2]; int sums = 0; for (int i = 1; i <= N; i++) { var sum = i.ToString() .Select(x => x.ToString()) .Select(x => int.Parse(x)) .Sum(x => x); if (A <= sum && sum <= B) { sums += i; } } Console.WriteLine(sums); } private static void abc087_b() { var ABCX = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var A = ABCX[0]; var B = ABCX[1]; var C = ABCX[2]; var X = ABCX[3]; var count = 0; for (int i = 0; i <= A; i++) { for (int j = 0; j <= B; j++) { for (int k = 0; k <= C; k++) { if (i * 500 + j * 100 + k * 50 == X) { count++; } } } } Console.WriteLine(count); } private static void ABC081B() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int c = 0; while (a.All(x => x % 2 == 0)) { a = a.Select(x => x / 2).ToArray(); c++; } Console.WriteLine(c); } private static void ABC081A() { Console.WriteLine(Console.ReadLine().Count(x => x.ToString() == "1")); } private static void ABC086A() { var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); Console.WriteLine((a[1] * a[0]) % 2 == 0 ? "Even" : "Odd"); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Paiza { class Program { public static void Main(string[] args) { if (true) { abc130_b(); } else { arc089_a(); abc085_c(); abc083_b(); abc087_b(); ABC081A(); ABC086A(); ABC081B(); } } private static void abc130_b() { var NX = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NX[0]; var X = NX[1]; var L = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); L = Enumerable.Range(0, 1).Select(x => x).Concat(L).ToArray(); var counter = 0; var D = 0; foreach (var item in L) { D += item; if (D > X) { Console.WriteLine(counter); return; } counter++; } Console.WriteLine(counter); } private static void arc089_a() { var N = int.Parse(Console.ReadLine()); var t = Enumerable.Range(0, N) .Select(x => Console.ReadLine() .Split(' ') .Select(y => int.Parse(y)) .ToArray()) .ToArray(); int[] prev = new int[] { 0, 0, 0 }; foreach (var item in t) { var dt = item[0] - prev[0]; var dist = Math.Abs(item[1] - prev[1]) + Math.Abs(item[2] - prev[2]); var parity = item[0] % 2 == 0; if (dist > Math.Abs(item[0] - prev[0])) { Console.WriteLine("No"); return; } if (dist % 2 != dt % 2) { Console.WriteLine("No"); return; } prev = item; } Console.WriteLine("Yes"); } private static void abc085_c() { var NY = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = NY[0]; var Y = NY[1]; // 10000 5000 1000 for (int i = 0; i <= N; i++) { for (int j = 0; j <= N - j; j++) { var k = N - i - j; if (k >= 0) { if (i * 10000 + j * 5000 + k * 1000 == Y) { Console.WriteLine($"{i} {j} {k}"); return; } } } } Console.WriteLine("-1 -1 -1"); } private static void abc083_b() { var NAB = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); var N = NAB[0]; var A = NAB[1]; var B = NAB[2]; int sums = 0; for (int i = 1; i <= N; i++) { var sum = i.ToString() .Select(x => x.ToString()) .Select(x => int.Parse(x)) .Sum(x => x); if (A <= sum && sum <= B) { sums += i; } } Console.WriteLine(sums); } private static void abc087_b() { var ABCX = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var A = ABCX[0]; var B = ABCX[1]; var C = ABCX[2]; var X = ABCX[3]; var count = 0; for (int i = 0; i <= A; i++) { for (int j = 0; j <= B; j++) { for (int k = 0; k <= C; k++) { if (i * 500 + j * 100 + k * 50 == X) { count++; } } } } Console.WriteLine(count); } private static void ABC081B() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int c = 0; while (a.All(x => x % 2 == 0)) { a = a.Select(x => x / 2).ToArray(); c++; } Console.WriteLine(c); } private static void ABC081A() { Console.WriteLine(Console.ReadLine().Count(x => x.ToString() == "1")); } private static void ABC086A() { var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList(); Console.WriteLine((a[1] * a[0]) % 2 == 0 ? "Even" : "Odd"); } } }
[["+", 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
1,117
7
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { var tmp = ReadIntArray(); int n = tmp[0], x = tmp[1]; int[] ls = ReadIntArray(); int i = 0; int pos = 0; while (pos <= x) { pos += ls[i++]; } WriteLine(i); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { var tmp = ReadIntArray(); int n = tmp[0], x = tmp[1]; int[] ls = ReadIntArray(); ls = ls.Concat(new int[] { 10001 }).ToArray(); int i = 0; int pos = 0; while (pos <= x) { pos += ls[i++]; } WriteLine(i); } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 3, 4, 0, 28, 0, 227, 0, 228], ["+", 0, 28, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 28, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 3, 4, 0, 28, 0, 227, 0, 229, 0, 45], ["+", 3, 4, 0, 28, 0, 227, 0, 229, 0, 203], ["+", 3, 4, 0, 28, 0, 227, 0, 229, 0, 46], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
145
19
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { var tmp = ReadIntArray(); int n = tmp[0], x = tmp[1]; int[] ls = ReadIntArray(); int i = 0; int pos = 0; while (i < n && pos <= x) { pos += ls[i++]; } WriteLine(i); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { var tmp = ReadIntArray(); int n = tmp[0], x = tmp[1]; int[] ls = ReadIntArray(); int i = 1; int pos = 0; while (i <= n && pos + ls[i - 1] <= x) { pos += ls[i - 1]; i++; } WriteLine(i); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 52, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 19], ["+", 0, 52, 15, 16, 12, 16, 31, 16, 17, 72], ["+", 15, 16, 12, 16, 31, 16, 12, 204, 205, 22], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 12, 204, 206, 207, 0, 28, 0, 223, 0, 29], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29]]
8
149
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace kyopro { class Program { static void Main(string[] args) { string[] nx = Console.ReadLine().Split(); int n = int.Parse(nx[0]); int x = int.Parse(nx[1]); string[] ln = Console.ReadLine().Split(); int zahyou = 0; int kaisuu = 0; while (zahyou <= x) { if (kaisuu > n) { break; } zahyou = zahyou + int.Parse(ln[kaisuu]); kaisuu = kaisuu + 1; } Console.WriteLine(kaisuu); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace kyopro { class Program { static void Main(string[] args) { string[] nx = Console.ReadLine().Split(); int n = int.Parse(nx[0]); int x = int.Parse(nx[1]); string[] ln = Console.ReadLine().Split(); int zahyou = 0; int kaisuu = 0; Boolean han = false; while (zahyou <= x) { if (kaisuu >= n) { han = true; break; } zahyou = zahyou + int.Parse(ln[kaisuu]); kaisuu = kaisuu + 1; } if (han) { Console.WriteLine(kaisuu + 1); } else { Console.WriteLine(kaisuu); } } } }
[["+", 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, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 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], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 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, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 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, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
157
29
using System; class B_Bounding { static void Main(string[] args) { string[] NX = Console.ReadLine().Split(' '); string[] Lstr = Console.ReadLine().Split(' '); int X = int.Parse(NX[1]); int[] L = new int[int.Parse(NX[0])]; for (int Ind = 0; Ind < int.Parse(NX[0]); Ind++) { L[Ind] = int.Parse(Lstr[Ind]); } int r = 0; int ans = 0; for (int i = 0; i < int.Parse(NX[0]); i++) { ans++; r += L[i]; if (r > X) break; } Console.WriteLine(ans); } }
using System; class B_Bounding { static void Main(string[] args) { string[] NX = Console.ReadLine().Split(' '); string[] Lstr = Console.ReadLine().Split(' '); int X = int.Parse(NX[1]); int[] L = new int[int.Parse(NX[0])]; for (int Ind = 0; Ind < int.Parse(NX[0]); Ind++) { L[Ind] = int.Parse(Lstr[Ind]); } int r = 0; int ans = 1; for (int i = 0; i < int.Parse(NX[0]); i++) { r += L[i]; if (r > X) break; ans++; } Console.WriteLine(ans); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29]]
8
184
8
using System; class Program { static void Main(string[] args) { string[] param1 = Console.ReadLine().Split(' '); // 1行目. string[] paramL = Console.ReadLine().Split(' '); int N = int.Parse(param1[0]); int X = int.Parse(param1[1]); int tmp = 0; int bound = 1; for (int i = 0; i < N; i++) { int L = int.Parse(paramL[i]); tmp += L; bound++; if (tmp >= X) break; } Console.WriteLine(bound); } }
using System; class Program { static void Main(string[] args) { string[] param1 = Console.ReadLine().Split(' '); // 1行目. string[] paramL = Console.ReadLine().Split(' '); int N = int.Parse(param1[0]); int X = int.Parse(param1[1]); int tmp = 0; int bound = 1; for (int i = 0; i < N; i++) { int L = int.Parse(paramL[i]); tmp += L; if (tmp > X) break; bound++; } Console.WriteLine(bound); } }
[["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29]]
8
142
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { //入力 string s = Console.ReadLine(); int N = int.Parse(s.Split(' ')[0]); int X = int.Parse(s.Split(' ')[1]); string t = Console.ReadLine(); //変数の割り当て int[] L = new int[N]; int sum = 0; //すべての和 for (int i = 0; i < N; i++) { L[i] = int.Parse(t.Split(' ')[i]); sum += L[i]; } //検証 //回答となる数値 int ans = 0; //現在の数直線における場所 int now_pos = 0; int index = 0; while (now_pos <= X) { ans++; now_pos += L[index]; index++; } if (sum < X) { ans++; } //出力 Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { //入力 string s = Console.ReadLine(); int N = int.Parse(s.Split(' ')[0]); int X = int.Parse(s.Split(' ')[1]); string t = Console.ReadLine(); //変数の割り当て int[] L = new int[N]; int sum = 0; //すべての和 for (int i = 0; i < N; i++) { L[i] = int.Parse(t.Split(' ')[i]); sum += L[i]; } //検証 //回答となる数値 int ans = 0; //現在の数直線における場所 int now_pos = 0; int index = 0; if (sum > X) { while (now_pos <= X) { ans++; now_pos += L[index]; index++; } } else { ans = N + 1; } //出力 Console.WriteLine(ans); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
222
20
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { /* var input = Console.ReadLine().Split(); int W = int.Parse(input[0]); int H = int.Parse(input[1]); int x = int.Parse(input[2]); int y = int.Parse(input[3]);*/ var input = Console.ReadLine().Split(); int n = int.Parse(input[0]); int x = int.Parse(input[1]); var input2 = Console.ReadLine().Split(); var l = new int[n]; for (int i = 0; i < n; i++) { l[i] = int.Parse(input2[i]); } int count = 0; int ball = 0; for (int i = 0; ball <= x && i < n; i++) { ball += l[i]; count++; } Console.WriteLine(count); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { /* var input = Console.ReadLine().Split(); int W = int.Parse(input[0]); int H = int.Parse(input[1]); int x = int.Parse(input[2]); int y = int.Parse(input[3]);*/ var input = Console.ReadLine().Split(); int n = int.Parse(input[0]); int x = int.Parse(input[1]); var input2 = Console.ReadLine().Split(); var l = new int[n]; for (int i = 0; i < n; i++) { l[i] = int.Parse(input2[i]); } int count = 0; int ball = 0; for (int i = 0; ball <= x && i < n + 1; i++) { if (i < n) ball += l[i]; count++; } Console.WriteLine(count); } }
[["+", 0, 7, 15, 16, 12, 16, 12, 16, 17, 72], ["+", 0, 7, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 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, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
8
170
8
using System; using System.Collections.Generic; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; public void Do() { cin = new Scanner(); int N = cin.nextInt(); int X = cin.nextInt(); int d = 0; for (int i = 1; i <= N; i++) { d += cin.nextInt(); if (d > X) { Console.WriteLine(i); return; } } } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; public void Do() { cin = new Scanner(); int N = cin.nextInt(); int X = cin.nextInt(); int d = 0; for (int i = 1; i <= N; i++) { d += cin.nextInt(); if (d > X) { Console.WriteLine(i); return; } } Console.WriteLine(N + 1); } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
[["+", 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, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
536
9
using System; using System.IO; namespace Sandbox { internal class Program { private static void Main(string[] args) { var scanner = new Scanner(); var n = scanner.GetNextAsInt(); var x = scanner.GetNextAsInt(); var l = scanner.ToIntArrayFromNextLine(); var count = 0; var xnow = 0; foreach (var li in l) { if (xnow <= x) { count++; } else { break; } xnow += li; } Console.WriteLine(count); } #region String Scanner public class Scanner { private const char Separator = ' '; private readonly StreamReader _Stream = new StreamReader(Console.OpenStandardInput()); private int _Pos; private string[] _Line = new string[0]; #region get a element public string GetNext() { // ReSharper disable once InvertIf if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); this._Pos = 0; } return this._Line[this._Pos++]; } public int GetNextAsInt() { return int.Parse(this.GetNext()); } public long GetNextAsLong() { return long.Parse(this.GetNext()); } public double GetNextAsDouble() { return double.Parse(this.GetNext()); } #endregion #region get array public string[] ToArrayFromNextLine() { if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); } this._Pos = this._Line.Length; return this._Line; } public int[] ToIntArrayFromNextLine() { return ToIntArray(this.ToArrayFromNextLine()); } public long[] ToLongArrayFromNextLine() { return ToLongArray(this.ToArrayFromNextLine()); } public double[] ToDoubleArrayFromNextLine() { return ToDoubleArray(this.ToArrayFromNextLine()); } #endregion #region convert array private static int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private static long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private static double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion } #endregion } }
using System; using System.IO; namespace Sandbox { internal class Program { private static void Main(string[] args) { var scanner = new Scanner(); var n = scanner.GetNextAsInt(); var x = scanner.GetNextAsInt(); var l = scanner.ToIntArrayFromNextLine(); var count = 0; var xnow = 0; foreach (var li in l) { if (xnow <= x) { count++; } else { break; } xnow += li; } if (xnow <= x) { count++; } Console.WriteLine(Math.Min(count, n + 1)); } #region String Scanner public class Scanner { private const char Separator = ' '; private readonly StreamReader _Stream = new StreamReader(Console.OpenStandardInput()); private int _Pos; private string[] _Line = new string[0]; #region get a element public string GetNext() { // ReSharper disable once InvertIf if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); this._Pos = 0; } return this._Line[this._Pos++]; } public int GetNextAsInt() { return int.Parse(this.GetNext()); } public long GetNextAsLong() { return long.Parse(this.GetNext()); } public double GetNextAsDouble() { return double.Parse(this.GetNext()); } #endregion #region get array public string[] ToArrayFromNextLine() { if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); } this._Pos = this._Line.Length; return this._Line; } public int[] ToIntArrayFromNextLine() { return ToIntArray(this.ToArrayFromNextLine()); } public long[] ToLongArrayFromNextLine() { return ToLongArray(this.ToArrayFromNextLine()); } public double[] ToDoubleArrayFromNextLine() { return ToDoubleArray(this.ToArrayFromNextLine()); } #endregion #region convert array private static int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private static long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private static double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion } #endregion } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
585
20
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { public static void Main() { var t = Console.ReadLine().Split(' '); int N = int.Parse(t[0]); int X = int.Parse(t[1]); t = Console.ReadLine().Split(' '); int[] L = new int[N]; for (int i = 0; i < N; i++) L[i] = int.Parse(t[i]); int p = 0, ctr = 0; for (int i = 0; i < N; i++) { if (p <= X) ctr++; p += L[i]; } Console.WriteLine(ctr); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { public static void Main() { var t = Console.ReadLine().Split(' '); int N = int.Parse(t[0]); int X = int.Parse(t[1]); t = Console.ReadLine().Split(' '); int[] L = new int[N]; for (int i = 0; i < N; i++) L[i] = int.Parse(t[i]); int p = 0, ctr = 0; for (int i = 0; i < N; i++) { if (p <= X) ctr++; p += L[i]; } if (p <= X) ctr++; Console.WriteLine(ctr); } }
[["+", 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, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 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]]
8
177
9
using System; using System.Linq; namespace ABC130_B { class Program { static void Main(string[] args) { var NX = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NX[0]; var X = NX[1]; var L = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ans = 0; var temp = 0; for (int i = 0; i < L.Length; i++) { temp += L[i]; ans++; if (temp > X) break; } Console.WriteLine(ans); } } }
using System; using System.Linq; namespace ABC130_B { class Program { static void Main(string[] args) { var NX = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NX[0]; var X = NX[1]; var L = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ans = 0; var temp = 0; for (int i = 0; i < L.Length; i++) { temp += L[i]; ans++; if (temp > X) break; } if (temp <= X) { ans++; } Console.WriteLine(ans); } } }
[["+", 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, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
144
11
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; namespace atcorder2 { class Program { public static long Read() { return long.Parse(ReadLine()); } public static long[] Reads() { return ReadLine().Split().Select(long.Parse).ToArray(); } public static long gcd(long x, long y) { if (y < x) gcd(y, x); while (y != 0) { var z = x % y; x = y; y = z; } return x; } public static long C(long n, long k) { long x = 1; for (long i = 1; i <= k; i++) { x *= n - i + 1; x /= i; } return x; } static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var q = Reads(); var w = q[0]; var h = q[1]; var x = q[2]; var y = q[3]; if ((decimal)w / 2 == (decimal)x / 2 && (decimal)h / 2 == (decimal)y / 2) WriteLine("{0} {1}", w * h / 2.0, 1); else WriteLine("{0} {1}", w * h / 2.0, 0); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; namespace atcorder2 { class Program { public static long Read() { return long.Parse(ReadLine()); } public static long[] Reads() { return ReadLine().Split().Select(long.Parse).ToArray(); } public static long gcd(long x, long y) { if (y < x) gcd(y, x); while (y != 0) { var z = x % y; x = y; y = z; } return x; } public static long C(long n, long k) { long x = 1; for (long i = 1; i <= k; i++) { x *= n - i + 1; x /= i; } return x; } static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var q = Reads(); var w = q[0]; var h = q[1]; var x = q[2]; var y = q[3]; if ((decimal)w / 2 == x && (decimal)h / 2 == y) WriteLine("{0} {1}", w * h / 2.0, 1); else WriteLine("{0} {1}", w * h / 2.0, 0); Console.Out.Flush(); } } }
[["-", 15, 16, 31, 16, 12, 16, 31, 74, 0, 24], ["-", 15, 16, 31, 16, 12, 16, 31, 74, 39, 199], ["-", 15, 16, 31, 16, 12, 16, 31, 74, 0, 25], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 15, 16, 12, 16, 12, 16, 31, 74, 0, 24], ["-", 15, 16, 12, 16, 12, 16, 31, 74, 39, 199], ["-", 15, 16, 12, 16, 12, 16, 31, 74, 0, 25], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
8
325
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp14 { class Class5 { static void Main() { var I = Console.ReadLine().Split().Select(int.Parse).ToArray(); double W = I[0]; double H = I[1]; double x = I[2]; double y = I[3]; //対角線上あるかどうか bool frag = W / H == x / y; int i = frag ? 1 : 0; Console.WriteLine($"{W*H/2} {i}"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp14 { class Class5 { static void Main() { var I = Console.ReadLine().Split().Select(int.Parse).ToArray(); double W = I[0]; double H = I[1]; double x = I[2]; double y = I[3]; //対角線上あるかどうか 0 のとき? // y = y/x + y0 bool frag = y == H / 2 && x == W / 2; int i = frag ? 1 : 0; Console.WriteLine($"{W*H/2} {i}"); } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 85], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 0, 212, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 212, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 212, 0, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 98], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 60], ["+", 0, 212, 0, 16, 12, 16, 12, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 22], ["+", 0, 212, 0, 16, 12, 16, 12, 16, 12, 203]]
8
138
12
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); long W = long.Parse(input[0]); long H = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); decimal Smax = H * W / 2; int judge = 0; if (H % 2 == 0 && W % 2 == 0 && W / 2 == x && H / 2 == y) { judge = 1; } Console.WriteLine("{0}" + " " + "{1}", Smax, judge); } }
using System; using System.Text; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); decimal W = decimal.Parse(input[0]); decimal H = decimal.Parse(input[1]); decimal x = decimal.Parse(input[2]); decimal y = decimal.Parse(input[3]); decimal Smax = H * W / 2; int judge = 0; if (H % 2 == 0 && W % 2 == 0 && W / 2 == x && H / 2 == y) { judge = 1; } Console.WriteLine("{0}" + " " + "{1}", Smax, judge); } }
[["-", 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, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
189
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_20190707_1 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); long W = long.Parse(s[0]); long H = long.Parse(s[1]); long x = long.Parse(s[2]); long y = long.Parse(s[3]); string answer = ""; if (W / 2 == x && H / 2 == y) { answer = "1"; } else { answer = "0"; } Console.WriteLine((W * H / 2).ToString() + " " + answer); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_20190707_1 { class Program { static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); double W = double.Parse(s[0]); double H = double.Parse(s[1]); long x = long.Parse(s[2]); long y = long.Parse(s[3]); string answer = ""; if (W == x * 2 && H == y * 2) { answer = "1"; } else { answer = "0"; } Console.WriteLine((W * H / 2).ToString() + " " + answer); } } }
[["-", 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, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 85], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
8
176
16
using System; using System.Collections.Generic; using System.IO; using System.Linq; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here long W = Cin, H = Cin, x = Cin, y = Cin; Cout((((double)W * H) / 2.0)); Cout(" "); Coutln(y * W == x * H || y * W == -H * x + H * W ? 1 : 0); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here long W = Cin, H = Cin, x = Cin, y = Cin; Cout((((double)W * H) / 2.0)); Cout(" "); Coutln(x == W / 2.0 && y == H / 2.0 ? 1 : 0); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
[["+", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 0, 41, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 41, 15, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 41, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 28, 0, 41, 15, 16, 31, 16, 17, 60], ["-", 0, 41, 15, 16, 31, 16, 12, 16, 17, 48], ["-", 0, 41, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 106], ["-", 0, 41, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 41, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 41, 15, 16, 31, 16, 17, 60], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 41, 15, 16, 31, 16, 12, 16, 12, 250], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 31, 22], ["-", 12, 16, 12, 16, 31, 16, 31, 241, 0, 33], ["-", 12, 16, 12, 16, 31, 16, 31, 241, 0, 22], ["-", 15, 16, 12, 16, 12, 16, 31, 16, 17, 48], ["-", 15, 16, 12, 16, 12, 16, 31, 16, 12, 22], ["-", 0, 41, 15, 16, 12, 16, 12, 16, 17, 72], ["-", 15, 16, 12, 16, 12, 16, 12, 16, 17, 48], ["-", 15, 16, 12, 16, 12, 16, 12, 16, 12, 22], ["+", 0, 41, 15, 16, 12, 16, 12, 16, 17, 85], ["+", 0, 41, 15, 16, 12, 16, 12, 16, 12, 250]]
8
1,706
30
using System; class Ho { static void Main() { var b = Console.ReadLine().Split(); var W = double.Parse(b[0]); var H = double.Parse(b[1]); var x = double.Parse(b[2]); var y = double.Parse(b[3]); double saidai = W * H / 2; double kotae = x * H; if (2 * x == W && 2 * y == H) { Console.WriteLine(kotae + " " + "1"); } else { Console.WriteLine(kotae + " " + "0"); } } }
using System; class Ho { static void Main() { var b = Console.ReadLine().Split(); var W = double.Parse(b[0]); var H = double.Parse(b[1]); var x = double.Parse(b[2]); var y = double.Parse(b[3]); double kotae = W * H / 2; if (2 * x == W && 2 * y == H) { Console.WriteLine(kotae + " " + "1"); } else { Console.WriteLine(kotae + " " + "0"); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 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, 48], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22]]
8
144
9
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long[] whxy = Console.ReadLine().Split().Select(long.Parse).ToArray(); double res = whxy[0] * whxy[1] / 2; bool isCenter = whxy[2] * 2 == whxy[0] && whxy[3] * 2 == whxy[1]; Console.WriteLine("{0} {1}", res, isCenter ? 1 : 0); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long[] whxy = Console.ReadLine().Split().Select(long.Parse).ToArray(); double res = ((double)whxy[0] * (double)whxy[1]) / 2; bool isCenter = whxy[2] * 2 == whxy[0] && whxy[3] * 2 == whxy[1]; Console.WriteLine("{0} {1}", res, isCenter ? 1 : 0); } } }
[["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 74, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 74, 39, 199], ["+", 0, 16, 31, 23, 0, 16, 31, 74, 0, 25], ["+", 0, 16, 31, 23, 0, 16, 12, 74, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 16, 31, 23, 0, 16, 12, 74, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25]]
8
124
8
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class AtCoderC { private static int w; private static int h; private static int x; private static int y; static void Main() { { string line = Console.ReadLine(); var words = line.Split(' '); w = int.Parse(words[0]); h = int.Parse(words[1]); x = int.Parse(words[2]); y = int.Parse(words[3]); } bool hasManyAnswer = (x == w / 2) && (y == h / 2); double answer = w * h / 2d; Console.WriteLine(answer + " " + (hasManyAnswer ? "1" : "0")); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class AtCoderC { private static double w; private static double h; private static double x; private static double y; static void Main() { { string line = Console.ReadLine(); var words = line.Split(' '); w = double.Parse(words[0]); h = double.Parse(words[1]); x = double.Parse(words[2]); y = double.Parse(words[3]); } bool hasManyAnswer = (x == w / 2) && (y == h / 2); double answer = w * h / 2d; Console.WriteLine(answer + " " + (hasManyAnswer ? "1" : "0")); } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
174
16
using System; namespace MyProgram { class AtCoder { static void Main(string[] args) { long[] input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long W = input[0]; long H = input[1]; double x = (double)input[2]; double y = (double)input[3]; int method = 0; if (input[0] / 2 == input[2] && input[1] / 2 == input[3]) { method = 1; } Console.WriteLine("{0} {1}", (double)(W * H) / 2, method); } } }
using System; namespace MyProgram { class AtCoder { static void Main(string[] args) { long[] input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); long W = input[0]; long H = input[1]; double x = (double)input[2]; double y = (double)input[3]; int method = 0; if ((double)input[0] / 2 == (double)input[2] && (double)input[1] / 2 == (double)input[3]) { method = 1; } Console.WriteLine("{0} {1}", (double)(W * H) / 2, method); } } }
[["+", 15, 16, 31, 16, 31, 16, 31, 74, 0, 24], ["+", 15, 16, 31, 16, 31, 16, 31, 74, 39, 199], ["+", 15, 16, 31, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 57, 15, 16, 31, 16, 12, 74, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 12, 74, 39, 199], ["+", 0, 57, 15, 16, 31, 16, 12, 74, 0, 25], ["+", 15, 16, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 15, 16, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 15, 16, 12, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 0, 24], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 39, 199], ["+", 0, 57, 15, 16, 12, 16, 12, 74, 0, 25]]
8
146
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var p = Input(); var w = p[0].ToLong(); var h = p[1].ToLong(); var x = p[2].ToLong(); var y = p[3].ToLong(); Console.WriteLine("{0} {1}", w * h / 2.0, w / 2 == x && h / 2 == y ? 1 : 0); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public static void Main(string[] args) { var p = Input(); var w = p[0].ToLong(); var h = p[1].ToLong(); var x = p[2].ToLong(); var y = p[3].ToLong(); Console.WriteLine("{0} {1}", w * h / 2.0, ((w / 2.0) == (double)x && (h / 2.0 == (double)y)) ? 1 : 0); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(' '); } public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt(); return r; } }
[["+", 3, 4, 0, 28, 0, 41, 15, 23, 0, 24], ["+", 15, 23, 0, 16, 31, 16, 31, 23, 0, 24], ["-", 0, 41, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 250], ["+", 15, 23, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 15, 23, 0, 16, 31, 16, 12, 74, 0, 24], ["+", 15, 23, 0, 16, 31, 16, 12, 74, 39, 199], ["+", 15, 23, 0, 16, 31, 16, 12, 74, 0, 25], ["+", 0, 41, 15, 23, 0, 16, 12, 23, 0, 24], ["-", 0, 41, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 250], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 39, 199], ["+", 0, 16, 12, 23, 0, 16, 12, 74, 0, 25], ["+", 0, 41, 15, 23, 0, 16, 12, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 41, 15, 23, 0, 25]]
8
355
16
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 W = cin.ReadInt; var H = cin.ReadInt; var x = cin.ReadInt; var y = cin.ReadInt; long ans1 = W * H / 2; int ans2 = (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) ? 1 : 0; Console.WriteLine(ans1 + " " + ans2); } } 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 W = cin.ReadInt; var H = cin.ReadInt; var x = cin.ReadInt; var y = cin.ReadInt; double ans1 = (double)W * (double)H / 2.0; int ans2 = (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) ? 1 : 0; Console.WriteLine(ans1 + " " + ans2); } } 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, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 212, 0, 16, 31, 16, 12, 74, 0, 24], ["+", 0, 212, 0, 16, 31, 16, 12, 74, 39, 199], ["+", 0, 212, 0, 16, 31, 16, 12, 74, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250]]
8
507
10
using System; using System.Linq; using static System.Math; namespace C { class Program { static void Main(string[] args) { var WHxy = Console.ReadLine().Split().Select(long.Parse).ToArray(); long s = WHxy[0] * WHxy[1] / 2; bool isAbleToDivideMany = false; if (WHxy[0] / 2 == WHxy[2] && WHxy[1] / 2 == WHxy[3]) { isAbleToDivideMany = true; } Console.WriteLine("{0} {1}", s, isAbleToDivideMany ? "1" : "0"); } } }
using System; using System.Linq; using static System.Math; namespace C { class Program { static void Main(string[] args) { var WHxy = Console.ReadLine().Split().Select(double.Parse).ToArray(); double s = WHxy[0] * WHxy[1] / 2; bool isAbleToDivideMany = false; double q = WHxy[0] / 2; if (WHxy[0] / 2 == WHxy[2] && WHxy[1] / 2 == WHxy[3]) { isAbleToDivideMany = true; } Console.WriteLine("{0} {1}", s, isAbleToDivideMany ? "1" : "0"); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["+", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
130
14
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("2 3 1 2"); // 3.000000 0 } else if (InputPattern == "Input2") { WillReturn.Add("2 2 1 1"); // 2.000000 1 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray(); int W = wkArr[0]; int H = wkArr[1]; int x = wkArr[2]; int y = wkArr[3]; int Menseki = W * H; if (W / 2 == x && H / 2 == y) { Console.WriteLine("{0} {1}", (decimal)W * (decimal)H / 2M, 1); } else { Console.WriteLine("{0} {1}", (decimal)W * (decimal)H / 2M, 0); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("2 3 1 2"); // 3.000000 0 } else if (InputPattern == "Input2") { WillReturn.Add("2 2 1 1"); // 2.000000 1 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray(); int W = wkArr[0]; int H = wkArr[1]; int x = wkArr[2]; int y = wkArr[3]; int Menseki = W * H; if (W == x * 2 && H == y * 2) { Console.WriteLine("{0} {1}", (decimal)W * (decimal)H / 2M, 1); } else { Console.WriteLine("{0} {1}", (decimal)W * (decimal)H / 2M, 0); } } }
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 85], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 48], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
8
273
8
#if true //#if false #define UTAKA_DEBUG #endif using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using System.IO; namespace UtakaApp { public partial class Program { public const string ContestName = "abc130"; public const string ProblemName = "C"; public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var console = new MyConsole(); new Program().Solve(System.Console.In, console); console.Flush(); #endif var sw = new StreamWriter( System.Console.OpenStandardOutput()) { AutoFlush = false }; } public void Solve(TextReader textReader, IConsole console) { var cin = new ConsoleInput(textReader, ' '); int W = cin.ReadInt; int H = cin.ReadInt; int x = cin.ReadInt; int y = cin.ReadInt; double ans = (double)W * H / 2; bool multi = x == W / 2 && y == H / 2; string multiStr = multi ? "1" : "0"; console.WriteLine($"{ans} {multiStr}"); } } public partial class Program { public const int ModLarge = 1000000007; void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } } public class ConsoleInput { private readonly TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(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 => _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(string str); void WriteLine(string str); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter( System.Console.OpenStandardOutput()) { AutoFlush = false }; System.Console.SetOut(sw); } public void Flush() { System.Console.Out.Flush(); } public void Write(string str) { System.Console.Write(str); } public void WriteLine(string str) { System.Console.WriteLine(str); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(string str) { mSb.Append(str); } public void WriteLine(string str) { mSb.AppendLine(str); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string DirectoryPath => $"../../../../{Program.ContestName}/{Program.ProblemName}"; private string GetInputFilePath(int testCaseNumber) { // return $"{DirectoryPath}/sample-{testCaseNumber}.in"; return $"{DirectoryPath}/in_{testCaseNumber}.txt"; } private string GetOutputFilePath(int testCaseNumber) { // return $"{DirectoryPath}/sample-{testCaseNumber}.out"; return $"{DirectoryPath}/out_{testCaseNumber}.txt"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var debugConsoleWriter = new DebugConsole(); new Program().Solve(inputStream, debugConsoleWriter); 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() { var isSuccessAll = true; var testCaseNumber = 1; while (true) { var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } System.Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { System.Console.WriteLine($"Success"); } else { isSuccessAll = false; System.Console.WriteLine($"Failure *****"); } testCaseNumber++; } if (isSuccessAll) { System.Console.WriteLine($"!!!!!!!!! All Success !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL public static class Dbg { public static void WriteLine(string str) { System.Console.WriteLine(str); } public static void Write(string str) { System.Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
#if true //#if false #define UTAKA_DEBUG #endif using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using System.IO; namespace UtakaApp { public partial class Program { public const string ContestName = "abc130"; public const string ProblemName = "C"; public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var console = new MyConsole(); new Program().Solve(System.Console.In, console); console.Flush(); #endif var sw = new StreamWriter( System.Console.OpenStandardOutput()) { AutoFlush = false }; } public void Solve(TextReader textReader, IConsole console) { var cin = new ConsoleInput(textReader, ' '); int W = cin.ReadInt; int H = cin.ReadInt; int x = cin.ReadInt; int y = cin.ReadInt; double ans = (double)W * H / 2; bool multi = (x * 2 == W) && (y * 2 == H); string multiStr = multi ? "1" : "0"; console.WriteLine($"{ans} {multiStr}"); } } public partial class Program { public const int ModLarge = 1000000007; void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } } public class ConsoleInput { private readonly TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(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 => _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(string str); void WriteLine(string str); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter( System.Console.OpenStandardOutput()) { AutoFlush = false }; System.Console.SetOut(sw); } public void Flush() { System.Console.Out.Flush(); } public void Write(string str) { System.Console.Write(str); } public void WriteLine(string str) { System.Console.WriteLine(str); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(string str) { mSb.Append(str); } public void WriteLine(string str) { mSb.AppendLine(str); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string DirectoryPath => $"../../../../{Program.ContestName}/{Program.ProblemName}"; private string GetInputFilePath(int testCaseNumber) { // return $"{DirectoryPath}/sample-{testCaseNumber}.in"; return $"{DirectoryPath}/in_{testCaseNumber}.txt"; } private string GetOutputFilePath(int testCaseNumber) { // return $"{DirectoryPath}/sample-{testCaseNumber}.out"; return $"{DirectoryPath}/out_{testCaseNumber}.txt"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var debugConsoleWriter = new DebugConsole(); new Program().Solve(inputStream, debugConsoleWriter); 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() { var isSuccessAll = true; var testCaseNumber = 1; while (true) { var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } System.Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { System.Console.WriteLine($"Success"); } else { isSuccessAll = false; System.Console.WriteLine($"Failure *****"); } testCaseNumber++; } if (isSuccessAll) { System.Console.WriteLine($"!!!!!!!!! All Success !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL public static class Dbg { public static void WriteLine(string str) { System.Console.WriteLine(str); } public static void Write(string str) { System.Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
[["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 212, 0, 16, 31, 16, 12, 16, 17, 85], ["-", 0, 212, 0, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 24], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 48], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 212, 0, 16, 12, 16, 12, 16, 17, 85], ["-", 0, 212, 0, 16, 12, 16, 12, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 23, 0, 25]]
8
1,187
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, ' ')); return; } public void Solve(ConsoleInput cin) { var W = cin.ReadInt; var H = cin.ReadInt; var x = cin.ReadInt; var y = cin.ReadInt; double Area = (double)W * (double)H / 2.0; int MultiWays; if (x == W / 2 && y == H / 2) { MultiWays = 1; } else { MultiWays = 0; } Console.WriteLine("{0} {1}", Area, MultiWays); } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } 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, ' ')); return; } public void Solve(ConsoleInput cin) { var W = cin.ReadLong; var H = cin.ReadLong; var x = cin.ReadLong; var y = cin.ReadLong; double Area = (double)W * (double)H / 2.0; int MultiWays; if (W == x * 2 && H == y * 2) { MultiWays = 1; } else { MultiWays = 0; } Console.WriteLine("{0} {1}", Area, MultiWays); } } public static class Extensions { public static string Reverse(this string sourse) { char[] chrAry = sourse.ToCharArray(); Array.Reverse(chrAry); return new string(chrAry); } } 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, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["+", 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, 48], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 48]]
8
554
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] values = Console.ReadLine().Split(' '); double W = double.Parse(values[0]); double H = double.Parse(values[1]); double x = double.Parse(values[2]); double y = double.Parse(values[3]); double solution = (W * H) / 2; int uniqueness = 0; if (W / 2 == x && H / 2 == y) { uniqueness = 1; } Console.WriteLine(solution.ToString("N6") + " " + uniqueness); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] values = Console.ReadLine().Split(' '); double W = double.Parse(values[0]); double H = double.Parse(values[1]); double x = double.Parse(values[2]); double y = double.Parse(values[3]); double solution = (W * H) / 2; int uniqueness = 0; if (W / 2 == x && H / 2 == y) { uniqueness = 1; } Console.WriteLine(solution + " " + uniqueness); } }
[["-", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["-", 31, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 31, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25]]
8
168
7
using System; using System.Collections.Generic; using System.Linq; using System.Diagnostics; class Program { static void Main(string[] args) { var sc = new Scanner(); var w = sc.nextInt(); var h = sc.nextInt(); var x = sc.nextInt(); var y = sc.nextInt(); int ans = 0; if (x == w / 2 && y == h / 2) ans = 1; Console.WriteLine("{0} {1}", (double)w * h / 2, 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) { var sc = new Scanner(); var w = sc.nextInt(); var h = sc.nextInt(); var x = sc.nextInt(); var y = sc.nextInt(); int ans = 0; if (x * 2 == w && y * 2 == h) ans = 1; Console.WriteLine("{0} {1}", (double)w * h / 2.0, 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, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 250]]
8
473
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { public class Program { static void Main(string[] args) { int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); int w = vs[0]; int h = vs[1]; int x = vs[2]; int y = vs[3]; double area = w * h / 2; int f = w % 2 == 0 && h % 2 == 0 && (w / 2) == x && (h / 2) == y ? 1 : 0; Console.WriteLine($"{area} {f}"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { public class Program { static void Main(string[] args) { int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray(); int w = vs[0]; int h = vs[1]; int x = vs[2]; int y = vs[3]; double area = ((double)w) * ((double)h) / 2.0; int f = w % 2 == 0 && h % 2 == 0 && (w / 2) == x && (h / 2) == y ? 1 : 0; Console.WriteLine($"{area} {f}"); } } }
[["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 74, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 74, 39, 199], ["+", 0, 16, 31, 16, 31, 23, 0, 74, 0, 25], ["+", 0, 212, 0, 16, 31, 16, 31, 23, 0, 25], ["+", 0, 212, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 23, 0, 74, 0, 24], ["+", 0, 16, 31, 16, 12, 23, 0, 74, 39, 199], ["+", 0, 16, 31, 16, 12, 23, 0, 74, 0, 25], ["+", 0, 212, 0, 16, 31, 16, 12, 23, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250]]
8
162
12
using System; using System.Linq; namespace abc130_c { static class Program { static void Main(string[] args) { var input = Console.ReadLine(); var items = input.Split(' '); var w = items.ParseInt(0); var h = items.ParseInt(1); var x = items.ParseInt(2); var y = items.ParseInt(3); var face = w * h / 2; var hasPattern = (x == w / 2 && y == h / 2) ? 1 : 0; Console.WriteLine($"{face} {hasPattern}"); } static int ParseInt(this string[] items, int index) { var ret = 0; if ((items?.Length ?? 0) > index) { if (!int.TryParse(items[index], out ret)) { ret = 0; } } return ret; } } }
using System; using System.Linq; namespace abc130_c { static class Program { static void Main(string[] args) { var input = Console.ReadLine(); var items = input.Split(' '); var w = items.ParseDouble(0); var h = items.ParseDouble(1); var x = items.ParseDouble(2); var y = items.ParseDouble(3); var face = w * h / 2; var hasPattern = (x == w / 2 && y == h / 2) ? 1 : 0; Console.WriteLine($"{face} {hasPattern}"); } static double ParseDouble(this string[] items, int index) { var ret = 0d; if ((items?.Length ?? 0) > index) { if (!double.TryParse(items[index], out ret)) { ret = 0; } } return ret; } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["-", 0, 57, 15, 241, 0, 213, 63, 214, 205, 199], ["+", 0, 57, 15, 241, 0, 213, 63, 214, 205, 199]]
8
194
16
using System; using System.Collections.Generic; using System.Text; using System.Numerics; namespace SolutionCS { class Program { static void Main(string[] args) { string[] strs = Console.ReadLine().Split(' '); int W = int.Parse(strs[0]); int H = int.Parse(strs[1]); int x = int.Parse(strs[2]); int y = int.Parse(strs[3]); double ans0 = (double)W * (double)H; ans0 /= 2; int ans1 = 0; if (x == W / 2 && y == H / 2) { ans1 = 1; } Console.WriteLine("{0} {1}", ans0, ans1); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; namespace SolutionCS { class Program { static void Main(string[] args) { string[] strs = Console.ReadLine().Split(' '); int W = int.Parse(strs[0]); int H = int.Parse(strs[1]); int x = int.Parse(strs[2]); int y = int.Parse(strs[3]); double ans0 = (double)W * (double)H; ans0 /= 2; int ans1 = 0; if (x * 2 == W && y * 2 == H) { ans1 = 1; } Console.WriteLine("{0} {1}", ans0, ans1); } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
8
164
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Q3 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); int W = int.Parse(strs[0]); int H = int.Parse(strs[1]); int x = int.Parse(strs[2]); int y = int.Parse(strs[3]); bool OK = false; if (W / (double)x == 2.0 && H / (double)y == 2.0) { OK = true; } double menseki = W * H / 2.0; Console.WriteLine(menseki + " " + (OK ? 1 : 0)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Q3 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); double W = double.Parse(strs[0]); double H = double.Parse(strs[1]); double x = double.Parse(strs[2]); double y = double.Parse(strs[3]); bool OK = false; if (x * 2 == W && y * 2 == H) { OK = true; } double menseki = W * H / 2.0; Console.WriteLine(menseki + " " + (OK ? 1 : 0)); } } }
[["-", 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, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 85], ["-", 15, 16, 31, 16, 31, 16, 12, 74, 39, 199], ["-", 15, 16, 31, 16, 31, 16, 12, 74, 0, 25], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 250], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 17, 85], ["-", 15, 16, 12, 16, 31, 16, 12, 74, 0, 24], ["-", 15, 16, 12, 16, 31, 16, 12, 74, 39, 199], ["-", 15, 16, 12, 16, 31, 16, 12, 74, 0, 25], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 250], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
180
34
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); long W = long.Parse(input[0]); long H = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); //面積が実数になる場合がある double ans = (double)W * (double)H / 2; int plural; //答えが複数あるか ある=1 ない=0 if (W / 2 == x && H / 2 == y) { //与えられた点が中央にあるとき plural = 1; } else { //与えられた点が中央にないとき plural = 0; } Console.WriteLine(ans + " " + plural); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); long W = long.Parse(input[0]); long H = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); //面積が実数になる場合がある double ans = (double)W * (double)H / 2; int plural; //答えが複数あるか ある=1 ない=0 // WとHは整数型なので偶数の時だけOKにする if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) { //与えられた点が中央にあるとき plural = 1; } else { //与えられた点が中央にないとき plural = 0; } Console.WriteLine(ans + " " + plural); } } }
[["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 60], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22]]
8
175
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); long W = long.Parse(input[0]); long H = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); double ans; //面積が実数になる場合がある int plural; if (x == W / 2 && H / 2 == y) { //与えられた点が中央にあるとき ans = W * H / 2; plural = 1; } else { //与えられた点が中央にないとき ans = (double)W * (double)H / 2; plural = 0; } Console.WriteLine(ans + " " + plural); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); long W = long.Parse(input[0]); long H = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); double ans; //面積が実数になる場合がある int plural; //答えが複数あるか ある=1 ない=0 if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) { //与えられた点が中央にあるとき ans = W * H / 2; plural = 1; } else { //与えられた点が中央にないとき ans = (double)W * (double)H / 2; plural = 0; } Console.WriteLine(ans + " " + plural); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22]]
8
184
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); long W = long.Parse(input[0]); long H = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); long ans; int plural; if (W % 2 == 0 && x == W / 2 && H % 2 == 0 && H / 2 == y) { //与えられた点が中央にあるとき ans = W * H / 2; plural = 1; } else { //与えられた点が中央にないとき ans = W * H / 2; plural = 0; } Console.WriteLine(ans + " " + plural); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC130C { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); long W = long.Parse(input[0]); long H = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); double ans; int plural; if (W % 2 == 0 && x == W / 2 && H % 2 == 0 && H / 2 == y) { //与えられた点が中央にあるとき ans = W * H / 2; plural = 1; } else { //与えられた点が中央にないとき ans = (double)W * (double)H / 2; plural = 0; } Console.WriteLine(ans + " " + plural); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 11, 12, 16, 31, 16, 12, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 12, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 12, 74, 0, 25]]
8
189
8
using System; class Program { static void Main(string[] args) { string[] a1 = Console.ReadLine().Split(' '); int W = int.Parse(a1[0]); int H = int.Parse(a1[1]); int x = int.Parse(a1[2]); int y = int.Parse(a1[3]); int rtn2 = 0; double rtn1 = W * H / 2; if (x == W / 2 && y == H / 2) { rtn2 = 1; } else { rtn2 = 0; } // Console.WriteLine(ans); Console.WriteLine(rtn1 + " " + rtn2); } }
using System; class Program { static void Main(string[] args) { string[] a1 = Console.ReadLine().Split(' '); double W = double.Parse(a1[0]); double H = double.Parse(a1[1]); double x = double.Parse(a1[2]); double y = double.Parse(a1[3]); int rtn2 = 0; double rtn1 = W * H / 2; if (x == W / 2 && y == H / 2) { rtn2 = 1; } else { rtn2 = 0; } // Console.WriteLine(ans); Console.WriteLine(rtn1 + " " + rtn2); } }
[["-", 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, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 11], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 31, 22, 0, 202], ["-", 0, 1, 0, 11, 31, 22, 0, 202, 12, 203]]
8
144
17
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { public static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); long W = long.Parse(s[0]); long H = long.Parse(s[1]); long x = long.Parse(s[2]); long y = long.Parse(s[3]); double area = (double)W / 2.0 * (double)H; bool flag = false; if (x == W / 2 && y == H / 2) flag = true; int l = (flag) ? 1 : 0; Console.WriteLine("{0:f9} 1", area, l); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; class Program { public static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); long W = long.Parse(s[0]); long H = long.Parse(s[1]); long x = long.Parse(s[2]); long y = long.Parse(s[3]); double area = (double)W / 2.0 * (double)H; bool flag = false; if ((x + x == W) && (y + y == H)) flag = true; int l = (flag) ? 1 : 0; Console.WriteLine("{0:f6} {1}", area, l); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 72], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
168
14
using System; using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { double[] WHxy = ReadLine().Split(' ').Select(double.Parse).ToArray(); double W = WHxy[0]; double H = WHxy[1]; double x = WHxy[2]; double y = WHxy[3]; if (W / 2 == x && H / 2 == y) { WriteLine($"{W * H / 2} 1"); } else if (y == (H - 2 * y) * x / (W - 2 * x) || y == (2 * y - H) * (W - x) / (W - 2 * x) || H - y == (H - 2 * y) * x / (W - 2 * x) || H - y == (2 * y - H) * (W - x) / (W - 2 * x) || x == W / 2 || y == H / 2) { WriteLine($"{W * H / 2} 0"); } } }
using System.Linq; using System.Collections.Generic; using System.Text; using static System.Console; using static System.Math; class Program { static void Main(string[] args) { double[] WHxy = ReadLine().Split(' ').Select(double.Parse).ToArray(); double W = WHxy[0]; double H = WHxy[1]; double x = WHxy[2]; double y = WHxy[3]; if (W / 2 == x && H / 2 == y) { WriteLine($"{W * H / 2} 1"); } else if (y == (H - 2 * y) * x / (W - 2 * x) || y == (2 * y - H) * (W - x) / (W - 2 * x) || H - y == (H - 2 * y) * x / (W - 2 * x) || H - y == (2 * y - H) * (W - x) / (W - 2 * x) || x == W / 2 || y == H / 2) { WriteLine($"{W * H / 2} 0"); } else { WriteLine($"{W * H / 2} 0"); } } }
[["-", 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], ["+", 75, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 75, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["+", 75, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 295], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 45], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 31, 22], ["+", 0, 283, 0, 284, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 283, 0, 284, 0, 46], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 296], ["+", 0, 213, 3, 4, 0, 28, 0, 283, 0, 62], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
8
259
20
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(); double W = double.Parse(input[0]); double H = double.Parse(input[1]); double x = double.Parse(input[2]); double y = double.Parse(input[3]); if (0 < x && x < W && 0 < y && y < H && W == H) { Console.WriteLine((W * H / 2).ToString("F") + " " + 1); } else { Console.WriteLine((W * H / 2).ToString("F") + " " + 0); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(); double W = double.Parse(input[0]); double H = double.Parse(input[1]); double x = double.Parse(input[2]); double y = double.Parse(input[3]); if (x == W / 2 && y == H / 2) { Console.WriteLine((W * H / 2).ToString("F") + " " + 1); } else { Console.WriteLine((W * H / 2).ToString("F") + " " + 0); } } }
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 31, 203], ["-", 31, 16, 31, 16, 31, 16, 31, 16, 17, 18], ["-", 31, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 98], ["-", 31, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 31, 203], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 17, 18], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 18], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
8
174
18
namespace ABC130.C { using System; using System.Collections.Generic; using System.Linq; using static System.Console; public class Program { public static void Main(string[] args) { var l = ReadInputsAsInt().ToList(); var w = l[0]; var h = l[1]; var x = l[2]; var y = l[3]; WriteLine(Solve(h, w, x, y)); } public static string Solve(int h, int w, int x, int y) { return $"{MaxArea(h, w)} {(IsCenter(h, w, x, y) ? 1 : 0)}"; throw new NotImplementedException(); } public static double MaxArea(int h, int w) => h * w / 2.0; public static bool IsCenter(int h, int w, int x, int y) { if (x == w / 2 && y == h / 2) return true; return false; } static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x)); } }
namespace ABC130.C { using System; using System.Collections.Generic; using System.Linq; using static System.Console; public class Program { public static void Main(string[] args) { var l = ReadInputsAsInt().ToList(); var w = l[0]; var h = l[1]; var x = l[2]; var y = l[3]; WriteLine(Solve(h, w, x, y)); } public static string Solve(int h, int w, int x, int y) { return $"{MaxArea(h, w)} {(IsCenter(h, w, x, y) ? 1 : 0)}"; } public static double MaxArea(int h, int w) => (double)h * (double)w / 2.0; public static bool IsCenter(int h, int w, int x, int y) => (w % 2 == 0 && x == w / 2) && (h % 2 == 0 && y == h / 2); static IEnumerable<int> ReadInputsAsInt() => ReadLine().Split(' ').Select(x => int.Parse(x)); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 293, 0, 294], ["-", 0, 195, 8, 196, 0, 293, 0, 230, 0, 228], ["-", 0, 195, 8, 196, 0, 293, 0, 230, 39, 22], ["-", 8, 196, 0, 293, 0, 230, 3, 4, 0, 24], ["-", 8, 196, 0, 293, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 293, 0, 35], ["+", 8, 306, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 8, 306, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 8, 306, 0, 16, 31, 16, 31, 74, 0, 25], ["+", 8, 306, 0, 16, 31, 16, 12, 74, 0, 24], ["+", 8, 306, 0, 16, 31, 16, 12, 74, 39, 199], ["+", 8, 306, 0, 16, 31, 16, 12, 74, 0, 25], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 0, 235, 8, 201, 0, 195, 8, 306, 0, 221], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 17, 109], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 60], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 8, 306, 0, 16, 31, 23, 0, 16, 17, 98], ["+", 0, 195, 8, 306, 0, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 306, 0, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 12, 23, 0, 16, 31, 16, 31, 16, 17, 109], ["+", 12, 23, 0, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["+", 8, 306, 0, 16, 12, 23, 0, 16, 17, 98], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 37, 0, 211, 0, 146], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 0, 195, 8, 196, 0, 37, 0, 211, 0, 147], ["-", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46]]
8
246
35
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); long w = long.Parse(input[0]); long h = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); double answer = w * h / (double)2; int memo = 0; if (x == w / 2 && y == h / 2) memo = 1; Console.WriteLine(answer + " " + memo); } }
using System; using System.Linq; //リストの使用 using System.Collections.Generic; using System.Text; //テキストの高速出力に必要 class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); long w = long.Parse(input[0]); long h = long.Parse(input[1]); long x = long.Parse(input[2]); long y = long.Parse(input[3]); double answer = w * h / (double)2; int memo = 0; if (2 * x == w && 2 * y == h) memo = 1; Console.WriteLine(answer + " " + memo); } }
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 17, 85], ["-", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203]]
8
151
8
using System; using System.Linq; namespace ECommonSubsequence { class Program { static void Main(string[] args) { // 入力の取得 var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = inputs[0]; var m = inputs[1]; var sNumbers = Console.ReadLine().Split().Select(int.Parse).ToArray(); var tNumbers = Console.ReadLine().Split().Select(int.Parse).ToArray(); var dp = new mInt[n + 1, m + 1]; for (var i = 0; i < n + 1; i++) dp[i, 0] = new mInt(1); for (var i = 0; i < m + 1; i++) dp[0, i] = new mInt(1); for (var i = 1; i < n + 1; i++) { for (var j = 1; j < m + 1; j++) { dp[i, j] = dp[i - 1, j] + dp[i, j - 1]; if (sNumbers[i - 1] != tNumbers[j - 1]) dp[i, j] -= dp[i - 1, j - 1]; } } // 解答の出力 Console.WriteLine(dp[n, m].X); } struct mInt { const int M = 1000000007; public int X { get; } public mInt(int x) { X = x % M; } public static mInt operator +(mInt a, mInt b) { return new mInt(a.X + b.X); } public static mInt operator +(mInt a, int num) { return new mInt(a.X + num); } public static mInt operator -(mInt a, mInt b) { return new mInt(a.X - b.X); } } } }
using System; using System.Linq; namespace ECommonSubsequence { class Program { static void Main(string[] args) { // 入力の取得 var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = inputs[0]; var m = inputs[1]; var sNumbers = Console.ReadLine().Split().Select(int.Parse).ToArray(); var tNumbers = Console.ReadLine().Split().Select(int.Parse).ToArray(); var dp = new mInt[n + 1, m + 1]; for (var i = 0; i < n + 1; i++) dp[i, 0] = new mInt(1); for (var i = 0; i < m + 1; i++) dp[0, i] = new mInt(1); for (var i = 1; i < n + 1; i++) { for (var j = 1; j < m + 1; j++) { dp[i, j] = dp[i - 1, j] + dp[i, j - 1]; if (sNumbers[i - 1] != tNumbers[j - 1]) dp[i, j] -= dp[i - 1, j - 1]; } } // 解答の出力 Console.WriteLine(dp[n, m].X); } struct mInt { const int M = 1000000007; public int X { get; } public mInt(int x) { X = x % M; } public static mInt operator +(mInt a, mInt b) { return new mInt(a.X + b.X); } public static mInt operator +(mInt a, int num) { return new mInt(a.X + num); } public static mInt operator -(mInt a, mInt b) { var diff = a.X - b.X; while (diff < 0) diff += M; return new mInt(diff); } } } }
[["-", 8, 201, 0, 315, 8, 196, 0, 37, 0, 38], ["-", 0, 315, 8, 196, 0, 37, 0, 230, 0, 228], ["-", 0, 315, 8, 196, 0, 37, 0, 230, 39, 22], ["-", 8, 196, 0, 37, 0, 230, 3, 4, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 315, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 315, 8, 196, 0, 52, 0, 89], ["+", 8, 201, 0, 315, 8, 196, 0, 52, 0, 24], ["+", 0, 315, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 315, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 315, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 8, 201, 0, 315, 8, 196, 0, 52, 0, 25], ["+", 8, 196, 0, 52, 8, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 52, 8, 1, 0, 11, 12, 22], ["+", 0, 315, 8, 196, 0, 52, 8, 1, 0, 35], ["+", 8, 201, 0, 315, 8, 196, 0, 37, 0, 38], ["+", 0, 315, 8, 196, 0, 37, 0, 230, 0, 228], ["+", 0, 315, 8, 196, 0, 37, 0, 230, 39, 22], ["+", 8, 196, 0, 37, 0, 230, 3, 4, 0, 24], ["+", 0, 37, 0, 230, 3, 4, 0, 28, 0, 22]]
8
409
23
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[,] A = new int[N, 2]; string[] S = new string[N]; for (var i = 0; i < N; i++) { string[] str = Console.ReadLine().Split(); A[i, 0] = int.Parse(str[0]); A[i, 1] = int.Parse(str[1]); S[i] = str[2]; } double uymax = -999999999; double uymin = 999999999; double dymax = -999999999; double dymin = 999999999; double oymax = -999999999; double oymin = 999999999; double rxmax = -999999999; double rxmin = 999999999; double lxmax = -999999999; double lxmin = 999999999; double oxmax = -999999999; double oxmin = 999999999; for (var i = 0; i < N; i++) { if (S[i] == "U") { uymax = Math.Max(uymax, A[i, 1]); uymin = Math.Min(uymin, A[i, 1]); } else if (S[i] == "D") { dymax = Math.Max(dymax, A[i, 1]); dymin = Math.Min(dymin, A[i, 1]); } else { oymax = Math.Max(oymax, A[i, 1]); oymin = Math.Min(oymin, A[i, 1]); } if (S[i] == "R") { rxmax = Math.Max(rxmax, A[i, 0]); rxmin = Math.Min(rxmin, A[i, 0]); } else if (S[i] == "L") { lxmax = Math.Max(lxmax, A[i, 0]); lxmin = Math.Min(lxmin, A[i, 0]); } else { oxmax = Math.Max(oxmax, A[i, 0]); oxmin = Math.Min(oxmin, A[i, 0]); } } var list = new List<double>(); list.Add(0); if (dymax > oymax) { list.Add(dymax - oymax); } if (oymax > uymax) { list.Add(oymax - uymax); } if (dymax > uymax) { list.Add((dymax - uymax) / 2); } if (uymin > oymin) { list.Add(uymin - oymin); } if (oymin > dymin) { list.Add(oymin - dymin); } if (uymin > dymin) { list.Add((uymin - dymin) / 2); } if (lxmax > oxmax) { list.Add(lxmax - oxmax); } if (oxmax > rxmax) { list.Add(oxmax - rxmax); } if (lxmax > rxmax) { list.Add((lxmax - rxmax) / 2); } if (rxmin > oxmin) { list.Add(rxmin - oxmin); } if (oxmin > lxmin) { list.Add(oxmin - lxmin); } if (rxmin > lxmin) { list.Add((rxmin - lxmin) / 2); } double ans = 999999999999999999; for (var i = 0; i < list.Count; i++) { double t = list[i]; double xmax = -999999999; double xmin = 999999999; double ymax = -999999999; double ymin = 999999999; for (var j = 0; j < N; j++) { double x = A[j, 0]; double y = A[j, 1]; if (S[j] == "U") { y += t; } else if (S[j] == "D") { y -= t; } else if (S[j] == "R") { x += t; } else { x -= t; } xmax = Math.Max(xmax, x); xmin = Math.Min(xmin, x); ymax = Math.Max(ymax, y); ymin = Math.Min(ymin, y); } ans = Math.Min(ans, (xmax - xmin) * (ymax - ymin)); Console.Error.WriteLine(t); } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[,] A = new int[N, 2]; string[] S = new string[N]; for (var i = 0; i < N; i++) { string[] str = Console.ReadLine().Split(); A[i, 0] = int.Parse(str[0]); A[i, 1] = int.Parse(str[1]); S[i] = str[2]; } double uymax = -999999999; double uymin = 999999999; double dymax = -999999999; double dymin = 999999999; double oymax = -999999999; double oymin = 999999999; double rxmax = -999999999; double rxmin = 999999999; double lxmax = -999999999; double lxmin = 999999999; double oxmax = -999999999; double oxmin = 999999999; for (var i = 0; i < N; i++) { if (S[i] == "U") { uymax = Math.Max(uymax, A[i, 1]); uymin = Math.Min(uymin, A[i, 1]); } else if (S[i] == "D") { dymax = Math.Max(dymax, A[i, 1]); dymin = Math.Min(dymin, A[i, 1]); } else { oymax = Math.Max(oymax, A[i, 1]); oymin = Math.Min(oymin, A[i, 1]); } if (S[i] == "R") { rxmax = Math.Max(rxmax, A[i, 0]); rxmin = Math.Min(rxmin, A[i, 0]); } else if (S[i] == "L") { lxmax = Math.Max(lxmax, A[i, 0]); lxmin = Math.Min(lxmin, A[i, 0]); } else { oxmax = Math.Max(oxmax, A[i, 0]); oxmin = Math.Min(oxmin, A[i, 0]); } } var list = new List<double>(); list.Add(0); if (dymax > oymax) { list.Add(dymax - oymax); } if (oymax > uymax) { list.Add(oymax - uymax); } if (dymax > uymax) { list.Add((dymax - uymax) / 2); } if (dymin > oymin) { list.Add(dymin - oymin); } if (oymin > uymin) { list.Add(oymin - uymin); } if (dymin > uymin) { list.Add((dymin - uymin) / 2); } if (lxmax > oxmax) { list.Add(lxmax - oxmax); } if (oxmax > rxmax) { list.Add(oxmax - rxmax); } if (lxmax > rxmax) { list.Add((lxmax - rxmax) / 2); } if (lxmin > oxmin) { list.Add(lxmin - oxmin); } if (oxmin > rxmin) { list.Add(oxmin - rxmin); } if (lxmin > rxmin) { list.Add((lxmin - rxmin) / 2); } double ans = 999999999999999999; for (var i = 0; i < list.Count; i++) { double t = list[i]; double xmax = -999999999; double xmin = 999999999; double ymax = -999999999; double ymin = 999999999; for (var j = 0; j < N; j++) { double x = A[j, 0]; double y = A[j, 1]; if (S[j] == "U") { y += t; } else if (S[j] == "D") { y -= t; } else if (S[j] == "R") { x += t; } else { x -= t; } xmax = Math.Max(xmax, x); xmin = Math.Min(xmin, x); ymax = Math.Max(ymax, y); ymin = Math.Min(ymin, y); } ans = Math.Min(ans, (xmax - xmin) * (ymax - ymin)); Console.Error.WriteLine(t); } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22]]
8
941
32
using System; using System.IO; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using E = System.Linq.Enumerable; partial class Solver { public int[] dx = new int[] { 0, 1, 0, -1 }; public int[] dy = new int[] { 1, 0, -1, 0 }; public string ds = "URDL"; public void Run() { var N = ni(); var x = new long[N]; var y = new long[N]; var d = new string[N]; for (int i = 0; i < N; i++) { x[i] = ni(); y[i] = ni(); d[i] = ns(); } double ans = 0; double lower = 0, upper = 1e15; for (int _ = 0; _ < 200; _++) { var left = (lower + lower + upper) / 3.0; var right = (lower + upper + upper) / 3.0; double areaL = GetAreaAt(N, x, y, d, left); double areaR = GetAreaAt(N, x, y, d, right); // cout.WriteLine("{0} {1}", areaL, areaR); ans = areaL; if (areaL > areaR) { lower = left; } else { upper = right; } } cout.WriteLine("{0:F9}", ans); } private double GetAreaAt(int N, long[] x, long[] y, string[] d, double mid) { double xmin = 1e100; double ymin = 1e100; double xmax = -1e100; double ymax = -1e100; for (int i = 0; i < N; i++) { var dindex = ds.IndexOf(d[i][0]); var nx = x[i] + dx[dindex] * mid; var ny = y[i] + dy[dindex] * mid; xmin = Math.Min(xmin, nx); ymin = Math.Min(ymin, ny); xmax = Math.Max(xmax, nx); ymax = Math.Max(ymax, ny); } return (ymax - ymin) * (xmax - xmin); } } // PREWRITEN CODE BEGINS FROM HERE partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL 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) { this.cin = reader; this.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 } public static class LinqPadExtension { static public 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) { this.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) { var array = new string[size]; for (int i = 0; i < size; i++) array[i] = Next(); return array; } public int[] NextIntArray(int size) { var array = new int[size]; for (int i = 0; i < size; i++) array[i] = NextInt(); return array; } public long[] NextLongArray(int size) { var array = new long[size]; for (int i = 0; i < size; i++) array[i] = NextLong(); return array; } public double[] NextDoubleArray(int size) { var 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(); } static readonly char[] _separator = new[] { ' ' }; private bool StockTokens() { while (true) { var line = Reader.ReadLine(); if (line == null) return false; var tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) continue; foreach (var token in tokens) TokenQueue.Enqueue(token); return true; } } }
using System; using System.IO; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using E = System.Linq.Enumerable; partial class Solver { public int[] dx = new int[] { 0, 1, 0, -1 }; public int[] dy = new int[] { 1, 0, -1, 0 }; public string ds = "URDL"; public void Run() { var N = ni(); var x = new long[N]; var y = new long[N]; var d = new string[N]; for (int i = 0; i < N; i++) { x[i] = ni(); y[i] = ni(); d[i] = ns(); } double ans = 1e100; double lower = 0, upper = 1e15; for (int _ = 0; _ < 300; _++) { var left = (lower + lower + upper) / 3.0; var right = (lower + upper + upper) / 3.0; double areaL = GetAreaAt(N, x, y, d, left); double areaR = GetAreaAt(N, x, y, d, right); // cout.WriteLine("{0} {1}", areaL, areaR); ans = Math.Min(ans, areaL); if (areaL > areaR) { lower = left; } else { upper = right; } } if (ans < 0) ans = 0; cout.WriteLine("{0:0.0000000000000}", ans); } private double GetAreaAt(int N, long[] x, long[] y, string[] d, double mid) { double xmin = 1e100; double ymin = 1e100; double xmax = -1e100; double ymax = -1e100; for (int i = 0; i < N; i++) { var dindex = ds.IndexOf(d[i][0]); var nx = x[i] + dx[dindex] * mid; var ny = y[i] + dy[dindex] * mid; xmin = Math.Min(xmin, nx); ymin = Math.Min(ymin, ny); xmax = Math.Max(xmax, nx); ymax = Math.Max(ymax, ny); } return (ymax - ymin) * (xmax - xmin); } } // PREWRITEN CODE BEGINS FROM HERE partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL 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) { this.cin = reader; this.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 } public static class LinqPadExtension { static public 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) { this.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) { var array = new string[size]; for (int i = 0; i < size; i++) array[i] = Next(); return array; } public int[] NextIntArray(int size) { var array = new int[size]; for (int i = 0; i < size; i++) array[i] = NextInt(); return array; } public long[] NextLongArray(int size) { var array = new long[size]; for (int i = 0; i < size; i++) array[i] = NextLong(); return array; } public double[] NextDoubleArray(int size) { var 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(); } static readonly char[] _separator = new[] { ' ' }; private bool StockTokens() { while (true) { var line = Reader.ReadLine(); if (line == null) return false; var tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) continue; foreach (var token in tokens) TokenQueue.Enqueue(token); return true; } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
1,253
23
using System; using System.IO; namespace Contest { struct S { public int X, Y; public S(int x, int y) { X = x; Y = y; } } class Program { private Scanner sc; public void Solve() { sc = new Scanner(); int N = sc.NextInt(); int K = sc.NextInt(); Console.WriteLine(N - K); } static void Main() => new Program().Solve(); } } class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; _separator = ' '; } private readonly char _separator; private readonly StreamReader _stream; private int _pos; private string[] _line; #region get a element public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(_separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region convert array private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region get array public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(_separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; using System.IO; using System.Runtime.InteropServices; namespace Contest { struct S { public int X, Y; public S(int x, int y) { X = x; Y = y; } } class Program { private Scanner sc; public void Solve() { sc = new Scanner(); int N = sc.NextInt(); int K = sc.NextInt(); if (K == 1) { Console.WriteLine(0); return; } Console.WriteLine(N - K); } static void Main() => new Program().Solve(); } } class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; _separator = ' '; } private readonly char _separator; private readonly StreamReader _stream; private int _pos; private string[] _line; #region get a element public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(_separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region convert array private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region get array public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(_separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 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
542
24
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; public class Solver { public void Solve() { Write(ri - ri); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const int mod = 1000000007; long Reverse(long n) { return Pow(n, mod - 2); } long Pow(long n, long p) { long t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p /= 2; } return q; } int PowUpper(int n, int b) { int p = 1; while (p <= n) { p *= b; } return p; } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); 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); 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 long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; public class Solver { public void Solve() { int n = ri, k = ri; Write(k == 1 ? 0 : n - k); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const int mod = 1000000007; long Reverse(long n) { return Pow(n, mod - 2); } long Pow(long n, long p) { long t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p /= 2; } return q; } int PowUpper(int n, int b) { int p = 1; while (p <= n) { p *= b; } return p; } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); 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); 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 long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
[["+", 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], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 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], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 12, 22]]
8
1,047
19
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Collections; using System.Linq.Expressions; using Pair = System.Tuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using static _20200215.Cin; using static _20200215.Util; namespace _20200215 { public class Program { public static void Main(string[] args) { DontAutoFlush(); // ABC036_C(); 13m // AGC038_A(); 140m // Tenka1_2017_C(); 60m // ARC067_D(); 20m Diverta2019_2_B(); Flush(); } public static void Diverta2019_2_B() { long N = rl; long[] a, b; ReadCols(out a, out b, N); var hm = new HashMap<long, HashMap<long, long>>(); for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { var da = Math.Abs(a[j] - a[i]); var db = Math.Abs(b[j] - b[i]); hm[da][db]++; } } long max = 0; foreach (var da in hm.Keys) { foreach (var db in hm[da].Keys) { ChMax(ref max, hm[da][db]); } } long ans = N - max; Console.WriteLine(ans); } /// <summary> /// D - Walk and Teleport /// </summary> public static void ARC067_D() { long N = rl; long A = rl; long B = rl; long[] X = rla; long ans = 0; for (int i = 1; i < N; i++) { long diff = X[i] - X[i - 1]; ans += Math.Min(diff * A, B); } Console.WriteLine(ans); } /// <summary> /// C - 4/N /// </summary> public static void Tenka1_2017_C() { long N = rl; for (int h = 1; h <= 3500; h++) { for (int n = 1; n <= 3500; n++) { long hnN = h * n * N; long bunbo = 4 * h * n - n * N - h * N; if (bunbo <= 0) continue; if (hnN % bunbo == 0) { Console.WriteLine("{0} {1} {2}", h, n, hnN / bunbo); return; } } } } /// <summary> /// A - 01 Matrix /// </summary> public static void AGC038_A() { long H = rl; long W = rl; long A = rl; long B = rl; string s1 = new string('1', (int)A) + new string('0', (int)(W - A)); string s2 = new string('0', (int)A) + new string('1', (int)(W - A)); for (int i = 0; i < B; i++) { Console.WriteLine(s1); } for (int i = 0; i < H - B; i++) { Console.WriteLine(s2); } } /// <summary> /// C - 座圧 /// </summary> public static void ABC036_C() { long N = rl; long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = rl; } var sorted = A.OrderBy(a => a).Distinct().ToArray(); Dictionary<long, long> dic = new Dictionary<long, long>(); for (int i = 0; i < sorted.Length; i++) { dic[sorted[i]] = i; } foreach (var a in A) { Console.WriteLine(dic[a]); } } } public class HashMap<K, V> : Dictionary<K, V> { V i; static Func<V> j = Expression.Lambda<Func<V>>(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 static void DontAutoFlush() { var a = new 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 int GCD(int a, int b) { return (b == 0) ? a : GCD(b, 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 long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } 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 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 int ReadInt() { return int.Parse(k()); } public static long ReadLong() { return long.Parse(k()); } public static double ReadDouble() { return double.Parse(k()); } public static string ReadString() { return k(); } public static int[] ReadIntArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } 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) { i = null; int[][] b = new int [a][]; for (int c = 0; c < a; c++) b[c] = ReadIntArray(); return b; } public static long[][] ReadLongTable(long a) { i = null; long[][] b = new long [a][]; for (long c = 0; c < a; c++) b[c] = ReadLongArray(); return b; } static string[] i { get; set; } static int j { get; set; } static string k() { if (i == null || i.Length <= j) { i = Console.ReadLine().Split(' '); j = 0; } return i[j++]; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Collections; using System.Linq.Expressions; using Pair = System.Tuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using static _20200215.Cin; using static _20200215.Util; namespace _20200215 { public class Program { public static void Main(string[] args) { DontAutoFlush(); // ABC036_C(); 13m // AGC038_A(); 140m // Tenka1_2017_C(); 60m // ARC067_D(); 20m Diverta2019_2_B(); Flush(); } public static void Diverta2019_2_B() { long N = rl; long[] a, b; ReadCols(out a, out b, N); var hm = new HashMap<long, HashMap<long, long>>(); for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { var da = a[j] - a[i]; var db = b[j] - b[i]; // var x = ((a[i], b[i]), (a[j], b[j])); hm[da][db]++; hm[-da][-db]++; } } long max = 0; foreach (var da in hm.Keys) { foreach (var db in hm[da].Keys) { if (max < hm[da][db]) { max = hm[da][db]; } } } long ans = N - max; Console.WriteLine(ans); } /// <summary> /// D - Walk and Teleport /// </summary> public static void ARC067_D() { long N = rl; long A = rl; long B = rl; long[] X = rla; long ans = 0; for (int i = 1; i < N; i++) { long diff = X[i] - X[i - 1]; ans += Math.Min(diff * A, B); } Console.WriteLine(ans); } /// <summary> /// C - 4/N /// </summary> public static void Tenka1_2017_C() { long N = rl; for (int h = 1; h <= 3500; h++) { for (int n = 1; n <= 3500; n++) { long hnN = h * n * N; long bunbo = 4 * h * n - n * N - h * N; if (bunbo <= 0) continue; if (hnN % bunbo == 0) { Console.WriteLine("{0} {1} {2}", h, n, hnN / bunbo); return; } } } } /// <summary> /// A - 01 Matrix /// </summary> public static void AGC038_A() { long H = rl; long W = rl; long A = rl; long B = rl; string s1 = new string('1', (int)A) + new string('0', (int)(W - A)); string s2 = new string('0', (int)A) + new string('1', (int)(W - A)); for (int i = 0; i < B; i++) { Console.WriteLine(s1); } for (int i = 0; i < H - B; i++) { Console.WriteLine(s2); } } /// <summary> /// C - 座圧 /// </summary> public static void ABC036_C() { long N = rl; long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = rl; } var sorted = A.OrderBy(a => a).Distinct().ToArray(); Dictionary<long, long> dic = new Dictionary<long, long>(); for (int i = 0; i < sorted.Length; i++) { dic[sorted[i]] = i; } foreach (var a in A) { Console.WriteLine(dic[a]); } } } public class HashMap<K, V> : Dictionary<K, V> { V i; static Func<V> j = Expression.Lambda<Func<V>>(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 static void DontAutoFlush() { var a = new 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 int GCD(int a, int b) { return (b == 0) ? a : GCD(b, 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 long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } 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 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 int ReadInt() { return int.Parse(k()); } public static long ReadLong() { return long.Parse(k()); } public static double ReadDouble() { return double.Parse(k()); } public static string ReadString() { return k(); } public static int[] ReadIntArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } 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) { i = null; int[][] b = new int [a][]; for (int c = 0; c < a; c++) b[c] = ReadIntArray(); return b; } public static long[][] ReadLongTable(long a) { i = null; long[][] b = new long [a][]; for (long c = 0; c < a; c++) b[c] = ReadLongArray(); return b; } static string[] i { get; set; } static int j { get; set; } static string k() { if (i == null || i.Length <= j) { i = Console.ReadLine().Split(' '); j = 0; } return i[j++]; } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 223, 0, 204, 205, 204, 205, 22], ["+", 0, 223, 0, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 241, 0, 33], ["+", 205, 204, 206, 207, 0, 28, 0, 241, 0, 22], ["+", 0, 223, 0, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 223, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 241, 0, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 241, 0, 22], ["+", 0, 1, 0, 223, 0, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 210, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 275], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 210, 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, 1, 0, 11, 12, 204, 205, 204, 205, 22], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
8
2,266
37
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Modular { private const int M = 1000003; private long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { return new Modular((a % M + M) % 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 Pow(Modular a, int 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 operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; public static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / Fac(r) / Fac(n - r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Program { private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static Modular Pi(int x, int n) { return (x > 0 && n < 1000003) ? Modular.Fac(x + n) / Modular.Fac(x - 1) : 0; } static int Solve(int x, int d, int n) { var X = new Modular(x) / d; return (int)(Modular.Pow(d, n) * Pi((int)X, n - 1)); } static void Main(string[] args) { int Q = ReadInt(); for (int i = 0; i < Q; ++i) { int[] V = ReadInts(); Console.WriteLine(Solve(V[0], V[1], V[2])); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace AtCoder { class Modular { private const int M = 1000003; private long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { return new Modular((a % M + M) % 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 Pow(Modular a, int 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 operator /(Modular a, Modular b) { return a * Pow(b, M - 2); } private static readonly List<int> facs = new List<int> { 1 }; public static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % M)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / Fac(r) / Fac(n - r); } public static explicit operator int(Modular a) { return (int)a.value; } } class Program { private static string Read() { return Console.ReadLine(); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } static Modular Pi(int x, int n) { return (x > 0 && n < 1000002) ? Modular.Fac(x + n) / Modular.Fac(x - 1) : 0; } static int Solve(int x, int d, int n) { if (d == 0) { return (int)Modular.Pow(x, n); } else { var X = new Modular(x) / d; return (int)(Modular.Pow(d, n) * Pi((int)X, n - 1)); } } static void Main(string[] args) { int Q = ReadInt(); for (int i = 0; i < Q; ++i) { int[] V = ReadInts(); Console.WriteLine(Solve(V[0], V[1], V[2])); } } } }
[["-", 0, 41, 15, 23, 0, 16, 12, 16, 12, 203], ["+", 0, 41, 15, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["+", 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, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 37, 0, 74, 0, 24], ["+", 0, 57, 64, 196, 0, 37, 0, 74, 0, 25], ["+", 0, 37, 0, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 37, 0, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 37, 0, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 37, 0, 74, 51, 213, 3, 4, 0, 24], ["+", 0, 74, 51, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 37, 0, 74, 51, 213, 3, 4, 0, 21], ["+", 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, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
700
26
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = (int)1e6 + 3; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var ncr = new BinomialCoefficient(mod - 1); int T = cin.nextint; ModInt minus = 0; minus -= 1; for (int t = 0; t < T; t++) { ModInt a = cin.nextint; ModInt d = cin.nextint; int n = cin.nextint; if (d.num == 0) { WriteLine(a * n); continue; } if (a.num == 0) { WriteLine((n - 1) * d * n * ModInt.Inverse(2)); continue; } if (mod <= n) { WriteLine(0); continue; } // var ans = ModInt.Pow(d, n); ////WriteLine(ans); ////a_par_d, a_pard+1, ....a_pard+n-1の積 // var a_par_d = (int)(a * ModInt.Inverse(d)).num; // var facter = ncr.fact[a_par_d + n - 1]; // if (a_par_d > 0) //{ // var ifacter = ncr.fact[a_par_d - 1]; // facter = facter * ModInt.Inverse(ifacter); //} // else //{ // ans = 0; //} // WriteLine(a_par_d + " " + facter + " " + ifacter + " " + ret); // ans *= facter; // WriteLine(ans); var ans = ModInt.Pow(minus * d, n) * ncr.fact[n]; // WriteLine(ans); var p = minus * a * ModInt.Inverse(d); ans *= ncr[(int)p.num, n]; WriteLine(ans); } } } /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> /// <OriginalAuthor>camypaper</OriginalAuthor> struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e6 + 3; /// <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); } } 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 class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using System.Numerics; using static System.Math; using pair = Pair<int, int>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = (int)1e6 + 3; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { var ncr = new BinomialCoefficient(mod - 1); int T = cin.nextint; ModInt minus = 0; minus -= 1; for (int t = 0; t < T; t++) { ModInt a = cin.nextint; ModInt d = cin.nextint; int n = cin.nextint; if (d.num == 0) { WriteLine(ModInt.Pow(a, n)); continue; } if (a.num == 0) { WriteLine(0); continue; } if (mod <= n) { WriteLine(0); continue; } // var ans = ModInt.Pow(d, n); ////WriteLine(ans); ////a_par_d, a_pard+1, ....a_pard+n-1の積 // var a_par_d = (int)(a * ModInt.Inverse(d)).num; // var facter = ncr.fact[a_par_d + n - 1]; // if (a_par_d > 0) //{ // var ifacter = ncr.fact[a_par_d - 1]; // facter = facter * ModInt.Inverse(ifacter); //} // else //{ // ans = 0; //} // WriteLine(a_par_d + " " + facter + " " + ifacter + " " + ret); // ans *= facter; // WriteLine(ans); var ans = ModInt.Pow(minus * d, n) * ncr.fact[n]; // WriteLine(ans); var p = minus * a * ModInt.Inverse(d); ans *= ncr[(int)p.num, n]; WriteLine(ans); } } } /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> /// <OriginalAuthor>camypaper</OriginalAuthor> struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e6 + 3; /// <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); } } 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 class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 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, 28, 0, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 28, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
1,615
24
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using static System.Math; class Program { static long mod = (long)1e6 + 3; static long[] f = new long[mod]; //階乗 static long[] invf = new long[mod]; //階乗の逆元 static void Main() { f[0] = 1; invf[0] = 1; for (int i = 1; i < mod; i++) { f[i] = f[i - 1] * i % mod; invf[i] = inv(f[i]); } int q = int.Parse(Console.ReadLine()); for (int i = 0; i < q; i++) { long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray(); Console.WriteLine(Ans(input[0], input[1], input[2])); } } static long Ans(long x, long d, long n) { if (x == 0) return 0; if (n == 1) return x % mod; long y = x * inv(d) % mod; long r = (y + n - 1 + mod) % mod; long l = (y - 1 + mod) % mod; if (n >= mod || l >= r) return 0; long ans = pow(d, n); return ans * f[r] % mod * invf[l] % mod; } static long pow(long a, long k) { if (k == 0) return 1; if (k == 1) return a % mod; long t = pow(a, k / 2); if (k % 2 == 0) return t * t % mod; return t * t % mod * a % mod; } static long inv(long k) { return pow(k, mod - 2); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using static System.Math; class Program { static long mod = (long)1e6 + 3; static long[] f = new long[mod]; //階乗 static long[] invf = new long[mod]; //階乗の逆元 static void Main() { f[0] = 1; invf[0] = 1; for (int i = 1; i < mod; i++) { f[i] = f[i - 1] * i % mod; invf[i] = inv(f[i]); } int q = int.Parse(Console.ReadLine()); for (int i = 0; i < q; i++) { long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray(); Console.WriteLine(Ans(input[0], input[1], input[2])); } } static long Ans(long x, long d, long n) { x %= mod; if (x == 0) return 0; if (n == 1) return x; if (d == 0) return pow(x, n); long y = x * inv(d) % mod; long r = (y + n - 1 + mod) % mod; long l = (y - 1 + mod) % mod; if (n >= mod || l > r) return 0; long ans = pow(d, n); return ans * f[r] % mod * invf[l] % mod; } static long pow(long a, long k) { if (k == 0) return 1; if (k == 1) return a % mod; long t = pow(a, k / 2); if (k % 2 == 0) return t * t % mod; return t * t % mod * a % mod; } static long inv(long k) { return pow(k, mod - 2); } }
[["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 37, 0, 16, 17, 109], ["-", 8, 196, 0, 57, 64, 37, 0, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 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], ["+", 8, 196, 0, 57, 64, 37, 0, 213, 63, 22], ["+", 0, 57, 64, 37, 0, 213, 3, 4, 0, 24], ["+", 64, 37, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 64, 37, 0, 213, 3, 4, 0, 21], ["+", 0, 57, 64, 37, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47]]
8
421
22
using System; using System.IO; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using E = System.Linq.Enumerable; partial class Solver { const int Mod = 1000003; public void Run() { var Q = ni(); var MulTable = new long[Mod + 120]; MulTable[1] = 1; for (int i = 2; i < MulTable.Length; i++) { MulTable[i] = (MulTable[i - 1] * i) % Mod; } for (int _ = 0; _ < Q; _++) { var x = nl(); var d = nl(); var n = nl(); // a = x / d var a = x * Inverse(d, Mod) % Mod; var dn = ModPow2(d, n, Mod); // a * (a+1) * ... * (a+n-1) long ans = 0; if (a + n - 1 >= Mod) { ans = 0; } else { ans = MulTable[a + n - 1]; if (a - 1 >= 0) { ans = (ans * Inverse(MulTable[a - 1], Mod)) % Mod; } } ans *= dn; ans %= Mod; cout.WriteLine(ans); } } static public long ModPow2(long x, long n, long mod) { long t = x, ret = 1; while (n > 0) { if ((n & 1) != 0) { ret = (t * ret) % mod; } t = t * t % mod; n >>= 1; } return ret; } static public long ExtendedGcd(long a, long b, ref long x, ref long y) { if (b == 0) { x = 1; y = 0; return a; } else { long d = ExtendedGcd(b, a % b, ref y, ref x); y -= a / b * x; return d; } } static public long Inverse(long a, long mod) { long x = 0, y = 0; if (ExtendedGcd(a, mod, ref x, ref y) == 1) return (x + mod) % mod; else return -1; } } // PREWRITEN CODE BEGINS FROM HERE partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL 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) { this.cin = reader; this.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 } 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) { this.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) { var array = new string[size]; for (int i = 0; i < size; i++) array[i] = Next(); return array; } public int[] NextIntArray(int size) { var array = new int[size]; for (int i = 0; i < size; i++) array[i] = NextInt(); return array; } public long[] NextLongArray(int size) { var array = new long[size]; for (int i = 0; i < size; i++) array[i] = NextLong(); return array; } public double[] NextDoubleArray(int size) { var 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(); } static readonly char[] _separator = new[] { ' ' }; private bool StockTokens() { while (true) { var line = Reader.ReadLine(); if (line == null) return false; var tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) continue; foreach (var token in tokens) TokenQueue.Enqueue(token); return true; } } }
using System; using System.IO; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using E = System.Linq.Enumerable; partial class Solver { const int Mod = 1000003; public void Run() { var Q = ni(); var MulTable = new long[Mod + 120]; MulTable[1] = 1; for (int i = 2; i < MulTable.Length; i++) { MulTable[i] = (MulTable[i - 1] * i) % Mod; } for (int _ = 0; _ < Q; _++) { var x = nl(); var d = nl(); var n = nl(); long ans = 0; if (d == 0) { ans = ModPow2(x, n, Mod); } else { // a = x / d var a = x * Inverse(d, Mod) % Mod; var dn = ModPow2(d, n, Mod); // a * (a+1) * ... * (a+n-1) if (a + n - 1 >= Mod) { ans = 0; } else { ans = MulTable[a + n - 1]; if (a - 1 > 0) { ans = (ans * Inverse(MulTable[a - 1], Mod)) % Mod; } } ans *= dn; ans %= Mod; } cout.WriteLine(ans); } } static public long ModPow2(long x, long n, long mod) { long t = x, ret = 1; while (n > 0) { if ((n & 1) != 0) { ret = (t * ret) % mod; } t = t * t % mod; n >>= 1; } return ret; } static public long ExtendedGcd(long a, long b, ref long x, ref long y) { if (b == 0) { x = 1; y = 0; return a; } else { long d = ExtendedGcd(b, a % b, ref y, ref x); y -= a / b * x; return d; } } static public long Inverse(long a, long mod) { long x = 0, y = 0; if (ExtendedGcd(a, mod, ref x, ref y) == 1) return (x + mod) % mod; else return -1; } } // PREWRITEN CODE BEGINS FROM HERE partial class Solver : Scanner { public static void Main(string[] args) { #if LOCAL 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) { this.cin = reader; this.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 } 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) { this.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) { var array = new string[size]; for (int i = 0; i < size; i++) array[i] = Next(); return array; } public int[] NextIntArray(int size) { var array = new int[size]; for (int i = 0; i < size; i++) array[i] = NextInt(); return array; } public long[] NextLongArray(int size) { var array = new long[size]; for (int i = 0; i < size; i++) array[i] = NextLong(); return array; } public double[] NextDoubleArray(int size) { var 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(); } static readonly char[] _separator = new[] { ' ' }; private bool StockTokens() { while (true) { var line = Reader.ReadLine(); if (line == null) return false; var tokens = line.Split(_separator, StringSplitOptions.RemoveEmptyEntries); if (tokens.Length == 0) continue; foreach (var token in tokens) TokenQueue.Enqueue(token); return true; } } }
[["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 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], ["+", 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, 213, 63, 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, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 75, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,202
34
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; using static System.Console; using static System.Math; using static Func; class Z { static void Main() => new K(); } class K { int F => int.Parse(Str); long FL => long.Parse(Str); int[] G => Strs.Select(int.Parse).ToArray(); uint[] GU => Strs.Select(uint.Parse).ToArray(); decimal[] GD => Strs.Select(decimal.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; } static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; } static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; } static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; } static ulong One(int k) => 1ul << k; static ulong All(int k) => One(k) - 1; static bool Has(ulong s, int k) => (s & One(k)) != 0; const int MOD = 1000003; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var Q = F; var fact = new long[MOD]; fact[0] = 1; for (var i = 1; i < MOD; i++) fact[i] = fact[i - 1] * i % MOD; var ifact = new long[MOD]; ifact[MOD - 1] = Inverse(fact[MOD - 1], MOD); for (var i = MOD - 2; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1) % MOD; for (var q = 0; q < Q; q++) { var I = G; int x = I[0], d = I[1], n = I[2]; var y = Inverse(d, MOD) * x % MOD; if (y == 0 || y + n - 1 >= MOD) WriteLine(0); else WriteLine(Pow(d, n, MOD) * fact[y + n - 1] % MOD * ifact[y - 1] % MOD); } } } static class Func { public static long Inverse(long a, long mod) { if (a < 0) { a %= mod; if (a < 0) a += mod; } var t = SolveLinear(a, mod); return t.Item1 > 0 ? t.Item1 : t.Item1 + mod; } public static Tuple<long, long> SolveLinear(long n, long m) { if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); } if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); } if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); } long a = 1, b = 0, c = 0, d = 1; while (m > 0) { var r = n % m; var q = n / m; n = m; m = r; var tmp = a; a = -a * q + b; b = tmp; tmp = c; c = -c * q + d; d = tmp; } return n != 1 ? null : new Tuple<long, long>(d, b); } public static long Pow(long a, long b, long mod) { var p = 1L; var x = a; while (b > 0) { if ((b & 1) == 1) p = (p * x) % mod; b >>= 1; x = (x * x) % mod; } return p; } }
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; using static System.Console; using static System.Math; using static Func; class Z { static void Main() => new K(); } class K { int F => int.Parse(Str); long FL => long.Parse(Str); int[] G => Strs.Select(int.Parse).ToArray(); uint[] GU => Strs.Select(uint.Parse).ToArray(); decimal[] GD => Strs.Select(decimal.Parse).ToArray(); long[] GL => Strs.Select(long.Parse).ToArray(); string Str => ReadLine(); string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; } static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; } static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; } static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; } static ulong One(int k) => 1ul << k; static ulong All(int k) => One(k) - 1; static bool Has(ulong s, int k) => (s & One(k)) != 0; const int MOD = 1000003; public K() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } void Solve() { var Q = F; var fact = new long[MOD]; fact[0] = 1; for (var i = 1; i < MOD; i++) fact[i] = fact[i - 1] * i % MOD; var ifact = new long[MOD]; ifact[MOD - 1] = Inverse(fact[MOD - 1], MOD); for (var i = MOD - 2; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1) % MOD; for (var q = 0; q < Q; q++) { var I = G; int x = I[0], d = I[1], n = I[2]; if (d == 0) WriteLine(Pow(x, n, MOD)); else { var y = Inverse(d, MOD) * x % MOD; if (y == 0 || y + n - 1 >= MOD) WriteLine(0); else WriteLine(Pow(d, n, MOD) * fact[y + n - 1] % MOD * ifact[y - 1] % MOD); } } } } static class Func { public static long Inverse(long a, long mod) { if (a < 0) { a %= mod; if (a < 0) a += mod; } var t = SolveLinear(a, mod); return t.Item1 > 0 ? t.Item1 : t.Item1 + mod; } public static Tuple<long, long> SolveLinear(long n, long m) { if (n < 0) { var p = SolveLinear(-n, m); return p == null ? p : new Tuple<long, long>(-p.Item1, p.Item2); } if (m < 0) { var p = SolveLinear(n, -m); return p == null ? p : new Tuple<long, long>(p.Item1, -p.Item2); } if (n < m) { var p = SolveLinear(m, n); return p == null ? p : new Tuple<long, long>(p.Item2, p.Item1); } long a = 1, b = 0, c = 0, d = 1; while (m > 0) { var r = n % m; var q = n / m; n = m; m = r; var tmp = a; a = -a * q + b; b = tmp; tmp = c; c = -c * q + d; d = tmp; } return n != 1 ? null : new Tuple<long, long>(d, b); } public static long Pow(long a, long b, long mod) { var p = 1L; var x = a; while (b > 0) { if ((b & 1) == 1) p = (p * x) % mod; b >>= 1; x = (x * x) % mod; } return p; } }
[["+", 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], ["+", 8, 196, 0, 57, 64, 1, 0, 213, 63, 22], ["+", 0, 57, 64, 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], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,183
21
using System; public class Program { public static void Main() { int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp)); int totalApplePieceAmount = ar[0] * 3 + ar[1]; Console.WriteLine(Math.Floor(totalApplePieceAmount / 3.0)); } }
using System; public class Program { public static void Main() { int[] ar = Array.ConvertAll(Console.ReadLine().Split(' '), arTemp => Convert.ToInt32(arTemp)); double totalApplePieceAmount = (double)(ar[0] * 3 + ar[1]); Console.WriteLine(Math.Floor(totalApplePieceAmount / 2.0)); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 0, 200, 0, 212, 0, 74, 51, 23, 0, 24], ["+", 0, 200, 0, 212, 0, 74, 51, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 250], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 250]]
8
77
9
using System; namespace AtCoder { class Class1 { static void Main(string[] args) { byte A, P; string[] input = Console.ReadLine().Split(' '); A = byte.Parse(input[0]); P = byte.Parse(input[1]); A = (byte)(A * 3); P = (byte)(P + A); Console.WriteLine(P / 2); } } }
using System; namespace AtCoder { class Class1 { static void Main(string[] args) { int A, P; string[] input = Console.ReadLine().Split(' '); A = int.Parse(input[0]); P = int.Parse(input[1]); A = A * 3; P = P + A; Console.WriteLine(P / 2); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 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
100
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int N = int.Parse(input); List<Sample> sampleList = new List<Sample>(); for (int i = 0; i < N; i++) { input = Console.ReadLine(); String[] temp = input.Split(' '); sampleList.Add(new Sample() { city = temp[0], point = int.Parse(temp[1]), rate = sampleList.Count + 1 }); for (int j = 0; j < i; j++) { Sample smp = sampleList.Find(m => m.rate == j + 1); if (string.Compare(temp[0], smp.city) < 0) { sampleList[i].rate = j + 1; for (int k = 0; k < sampleList.Count - 1; k++) { if (sampleList[k].rate >= sampleList[i].rate) { sampleList[k].rate++; } } break; } else if (string.Compare(temp[0], smp.city) == 0) { if (sampleList[i].point > smp.point) { sampleList[i].rate = j + 1; for (int k = 0; k < sampleList.Count - 1; k++) { if (sampleList[k].rate >= sampleList[i].rate) { sampleList[k].rate++; } } break; } } } } foreach (Sample smp in sampleList) { Console.WriteLine(smp.rate); } return; } private class Sample { public String city { set; get; } public int point { set; get; } public int rate { set; get; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { class Program { static void Main(string[] args) { string input = Console.ReadLine(); int N = int.Parse(input); List<Sample> sampleList = new List<Sample>(); for (int i = 0; i < N; i++) { input = Console.ReadLine(); String[] temp = input.Split(' '); sampleList.Add(new Sample() { city = temp[0], point = int.Parse(temp[1]), rate = sampleList.Count + 1, raw = i + 1 }); for (int j = 0; j < i; j++) { Sample smp = sampleList.Find(m => m.rate == j + 1); if (string.Compare(temp[0], smp.city) < 0) { sampleList[i].rate = j + 1; for (int k = 0; k < sampleList.Count - 1; k++) { if (sampleList[k].rate >= sampleList[i].rate) { sampleList[k].rate++; } } break; } else if (string.Compare(temp[0], smp.city) == 0) { if (sampleList[i].point > smp.point) { sampleList[i].rate = j + 1; for (int k = 0; k < sampleList.Count - 1; k++) { if (sampleList[k].rate >= sampleList[i].rate) { sampleList[k].rate++; } } break; } } } } sampleList.Sort((a, b) => a.rate - b.rate); foreach (Sample smp in sampleList) { Console.WriteLine(smp.raw); } return; } private class Sample { public String city { set; get; } public int point { set; get; } public int rate { set; get; } public int raw { set; get; } } } }
[["+", 3, 4, 0, 28, 0, 230, 10, 229, 0, 21], ["+", 0, 28, 0, 230, 10, 229, 0, 11, 31, 22], ["+", 0, 230, 10, 229, 0, 11, 0, 202, 0, 32], ["+", 0, 230, 10, 229, 0, 11, 12, 16, 31, 22], ["+", 0, 230, 10, 229, 0, 11, 12, 16, 17, 72], ["+", 0, 230, 10, 229, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 33], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 205, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 0, 131], ["+", 0, 28, 0, 218, 8, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 235, 8, 201, 0, 277, 278, 279, 0, 45], ["+", 8, 201, 0, 277, 278, 279, 0, 280, 141, 282], ["+", 8, 201, 0, 277, 278, 279, 0, 280, 0, 35], ["+", 8, 201, 0, 277, 278, 279, 0, 280, 141, 281], ["+", 0, 235, 8, 201, 0, 277, 278, 279, 0, 46], ["+", 0, 235, 8, 201, 0, 277, 0, 251, 0, 259], ["+", 8, 201, 0, 235, 8, 201, 0, 277, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 277, 141, 22]]
8
415
36
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace ABC128 { class PP : IComparable<PP> { public string S; public int P; public int idx; public PP(string s, int p, int id) { S = s; P = p; idx = id; } public int CompareTo(PP p) { if (S.CompareTo(p.S) < 0) { return 1; } else if (S.CompareTo(p.S) == 0) { if (P > p.P) { return 1; } else if (P == p.P) { return 0; } else { return -1; } } else { return -1; } } } class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); PP[] SP = new PP[N]; for (int i = 0; i < N; i++) { string[] s = Console.ReadLine().Split(' '); SP[i] = new PP(s[0], int.Parse(s[1]), i + 1); Console.WriteLine(SP[i].S); } Array.Sort(SP); Array.Reverse(SP); for (int i = 0; i < N; i++) { Console.WriteLine(SP[i].idx); } } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; namespace ABC128 { class PP : IComparable<PP> { public string S; public int P; public int idx; public PP(string s, int p, int id) { S = s; P = p; idx = id; } public int CompareTo(PP p) { if (S.CompareTo(p.S) < 0) { return 1; } else if (S.CompareTo(p.S) == 0) { if (P > p.P) { return 1; } else if (P == p.P) { return 0; } else { return -1; } } else { return -1; } } } class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); PP[] SP = new PP[N]; for (int i = 0; i < N; i++) { string[] s = Console.ReadLine().Split(' '); SP[i] = new PP(s[0], int.Parse(s[1]), i + 1); } Array.Sort(SP); Array.Reverse(SP); for (int i = 0; i < N; i++) { Console.WriteLine(SP[i].idx); } } } }
[["-", 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, 214, 205, 204, 205, 22], ["-", 0, 28, 0, 214, 205, 204, 206, 207, 0, 70], ["-", 0, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 214, 205, 204, 206, 207, 0, 73], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
311
12
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; var m = nm[1]; int[][] sw = new int [m][]; for (int i = 0; i < m; i++) { sw[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); } int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ans = 0; // bit全探索 for (int i = 0; i < Math.Pow(2, n); i++) { var katei = new bool[n]; for (int j = 0; j < n; j++) { var x = (i >> j) & 1; if (x == 1) katei[j] = true; } var flag = true; var on = 0; for (int j = 0; j < m; j++) { for (int k = 1; k < sw[j].Length; k++) { if (katei[sw[j][k] - 1]) on++; } if (on % 2 != p[j]) { flag = false; break; } } if (flag) ans++; } // 出力 Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; class Program { static void Main(string[] args) { // 入力 // var s = Console.ReadLine(); // var n = int.Parse(Console.ReadLine()); int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = nm[0]; var m = nm[1]; int[][] sw = new int [m][]; for (int i = 0; i < m; i++) { sw[i] = Console.ReadLine().Split().Select(int.Parse).ToArray(); } int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ans = 0; // bit全探索 for (int i = 0; i < Math.Pow(2, n); i++) { var katei = new bool[n]; for (int j = 0; j < n; j++) { var x = (i >> j) & 1; if (x == 1) katei[j] = true; } var flag = true; for (int j = 0; j < m; j++) { var on = 0; for (int k = 1; k < sw[j].Length; k++) { if (katei[sw[j][k] - 1]) on++; } if (on % 2 != p[j]) { flag = false; break; } } if (flag) ans++; } // 出力 Console.WriteLine(ans); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 141, 22, 0, 316], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 197, 0, 198, 0, 200, 141, 22, 0, 316], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35]]
8
345
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128_C { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var N = int.Parse(input[0]); var M = int.Parse(input[1]); var s = new int [M][]; var p = new int[M]; for (int i = 0; i < M; i++) { var inputsw = Console.ReadLine().Split(' '); var k = int.Parse(inputsw[0]); s[i] = new int[k]; for (int j = 1; j <= k; j++) { s[i][j - 1] = int.Parse(inputsw[j]) - 1; } } var inputp = Console.ReadLine().Split(' '); for (int i = 0; i < M; i++) { p[i] = int.Parse(inputp[i]); } var ans = 0; for (int bit = 0; bit < (1 << N); bit++) { var ok = true; for (int i = 0; i < M; i++) { var c = 0; foreach (var item in s[i]) { if ((bit >> item & 1) != 0) { c++; } } c %= 2; if (c != p[i]) { ok = false; } } if (ok) { ans++; } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128_C { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); var N = int.Parse(input[0]); var M = int.Parse(input[1]); var s = new int [M][]; var p = new int[M]; for (int i = 0; i < M; i++) { var inputsw = Console.ReadLine().Split(' '); var k = int.Parse(inputsw[0]); s[i] = new int[k]; for (int j = 1; j <= k; j++) { s[i][j - 1] = int.Parse(inputsw[j]) - 1; } } var inputp = Console.ReadLine().Split(' '); for (int i = 0; i < M; i++) { p[i] = int.Parse(inputp[i]); } var ans = 0; for (int bit = 0; bit < (1 << N); bit++) { var ok = true; for (int i = 0; i < M; i++) { var c = 0; foreach (var item in s[i]) { if ((bit >> item & 1) != 0) { c++; } } c %= 2; if (c != p[i]) { ok = false; } } if (ok) { ans++; } } 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
357
7
using System; using System.Linq; namespace AtCoder { class Program { public static void Main() { int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = input[0]; int m = input[1]; int[][] s = new int [m][]; for (int i = 0; i < m; i++) { s[i] = Console.ReadLine().Split(' ').Select(int.Parse).Skip(1).ToArray(); } int[] p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Console.WriteLine(Count(n, m, s, p, new bool[0])); } static int Count(int n, int m, int[][] s, int[] p, bool[] sw) { int result; if (sw.Length == n) { result = 0; int count = s.Where((x, i) => x.Where((_, j) => sw[j]).Count() % 2 == p[i]) .Count(); return count == m ? 1 : 0; } bool[] nsw = new bool[sw.Length + 1]; Array.Copy(sw, nsw, sw.Length); nsw[nsw.Length - 1] = true; result = Count(n, m, s, p, nsw); nsw[nsw.Length - 1] = false; result += Count(n, m, s, p, nsw); return result; } } }
using System; using System.Linq; namespace AtCoder { class Program { public static void Main() { int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = input[0]; int m = input[1]; int[][] s = new int [m][]; for (int i = 0; i < m; i++) { s[i] = Console.ReadLine().Split(' ').Select(int.Parse).Skip(1).ToArray(); } int[] p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); Console.WriteLine(Count(n, m, s, p, new bool[0])); } static int Count(int n, int m, int[][] s, int[] p, bool[] sw) { int result; if (sw.Length == n) { result = 0; int count = s.Where((x, i) => x.Where((_, j) => sw[s[i][j] - 1]).Count() % 2 == p[i]) .Count(); return count == m ? 1 : 0; } bool[] nsw = new bool[sw.Length + 1]; Array.Copy(sw, nsw, sw.Length); nsw[nsw.Length - 1] = true; result = Count(n, m, s, p, nsw); nsw[nsw.Length - 1] = false; result += Count(n, m, s, p, nsw); return result; } } }
[["+", 0, 28, 0, 16, 31, 204, 205, 204, 205, 22], ["+", 0, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 8, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
368
8
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace competitive_programming { class Program { static void Main(string[] args) { int[] input = Console.ReadLine() .Split(' ') .Select(value => int.Parse(value)) .ToArray(); int n = input[0]; int m = input[1]; string[] swinfo = new string[m]; for (int i = 0; i < m; i++) { swinfo[i] = Console.ReadLine(); } int[] ps = Console.ReadLine() .Split(' ') .Select(value => int.Parse(value)) .ToArray(); var lamps = new lamp[m]; for (int i = 0; i < m; i++) { var info = swinfo[i].Split(' ').Select(value => int.Parse(value)).ToArray(); var sw = new int[info.Count() - 1]; for (int j = 0; j < sw.Length; j++) sw[j] = info[j + 1]; // Console.WriteLine("sw" + sw.Length); lamps[i] = new lamp(ps[i], sw); } check(1, lamps, n); Console.WriteLine(count); } static int count = 0; public static bool check(int swNum, lamp[] lamps, int n) { // Console.WriteLine(swNum); if (swNum == n + 1) { foreach (var lamp in lamps) { // Console.WriteLine(lamp.check); if (lamp.check) continue; else return false; } count++; // Console.WriteLine("goal"); return true; } if (check(swNum + 1, lamps, n)) { return true; } var nlamps = lamps; for (int i = 0; i < nlamps.Length; i++) { // Console.WriteLine(i + "番目の最初は" + nlamps[i].switches[0]); ; if (nlamps[i].switches.Contains(swNum)) { // Console.WriteLine(i +" contain " + nlamps[i].check); nlamps[i].check = !nlamps[i].check; } } if (check(swNum + 1, nlamps, n)) { return true; } return false; } } struct lamp { public lamp(int p, int[] switches) { this.p = p; this.switches = switches; if (p == 0) check = true; else check = false; } public bool check; public int p; public int[] switches; } struct Vector2 { public Vector2(int x, int y) { this.x = x; this.y = y; } public int x; public int y; } struct Vector3 { public int x; public int y; public int z; } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace competitive_programming { class Program { static void Main(string[] args) { var main = new Program(); main.solve(); } void solve() { int[] input = Console.ReadLine() .Split(' ') .Select(value => int.Parse(value)) .ToArray(); int n = input[0]; int m = input[1]; string[] swinfo = new string[m]; for (int i = 0; i < m; i++) { swinfo[i] = Console.ReadLine(); } int[] ps = Console.ReadLine() .Split(' ') .Select(value => int.Parse(value)) .ToArray(); var lamps = new lamp[m]; for (int i = 0; i < m; i++) { var info = swinfo[i].Split(' ').Select(value => int.Parse(value)).ToArray(); var sw = new int[info.Count() - 1]; for (int j = 0; j < sw.Length; j++) sw[j] = info[j + 1]; // Console.WriteLine("sw" + sw.Length); lamps[i] = new lamp(ps[i], sw); } check(1, lamps, n); Console.WriteLine(count); } static int count = 0; public bool check(int swNum, lamp[] lamps, int n) { // Console.WriteLine(swNum); if (swNum == n + 1) { foreach (var lamp in lamps) { // Console.WriteLine(lamp.check); if (lamp.check) continue; else return false; } count++; // Console.WriteLine("goal"); return true; } if (check(swNum + 1, lamps, n)) { // if(swNum != 1) return true; } var nlamps = lamps; for (int i = 0; i < nlamps.Length; i++) { // Console.WriteLine(i + "番目の最初は" + nlamps[i].switches[0]); ; if (nlamps[i].switches.Contains(swNum)) { // Console.WriteLine(i +" contain " + nlamps[i].check); nlamps[i].check = !nlamps[i].check; } } if (check(swNum + 1, nlamps, n)) { // if (swNum != 1) return true; } return false; } } struct lamp { public lamp(int p, int[] switches) { this.p = p; this.switches = switches; if (p == 0) check = true; else check = false; } public bool check; public int p; public int[] switches; } struct Vector2 { public Vector2(int x, int y) { this.x = x; this.y = y; } public int x; public int y; } struct Vector3 { public int x; public int y; public int z; } }
[["+", 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, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 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], ["-", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 0, 57, 64, 196, 0, 37, 0, 211, 0, 146], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
8
561
27
using System; using System.Linq; using System.Collections.Generic; namespace ABC128 { class C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int[] k = new int[M]; int[,] s = new int[M, 10]; for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(' '); k[i] = int.Parse(input[0]); for (int j = 1; j <= k[i]; j++) { s[i, j] = int.Parse(input[j]); // Console.WriteLine("---"); // Console.WriteLine(s[i, j]); } } input = Console.ReadLine().Split(' '); int[] p = new int[M]; for (int i = 0; i < M; i++) { p[i] = int.Parse(input[i]); } int[] a = new int[N]; CalcSw(N, a, M, k, s, p); Console.WriteLine(count); } static int count = 0; static void CalcSw(int N, int[] a, int M, int[] k, int[,] s, int[] p) { if (N == 0) { // foreach (var x in a) { Console.Write(x); } // Console.WriteLine(); // 一番下まできたら、Mとkでループして、 // 電気がついているかどうかを確認する // 計算したらメモ化再帰のでカウントする int c = 0; for (int i = 0; i < M; i++) { c = 0; // Console.WriteLine("------"); for (int j = 1; j <= k[i]; j++) { // Console.WriteLine(s[i, j]); if (a[s[i, j] - 1] == 1) { c++; } } // Console.WriteLine(); // Console.WriteLine("------"); if ((c % 2) != p[i]) { return; } } count++; return; } //ここでスイッチの状態を固定する処理を書く N--; a[N] = 0; CalcSw(N, a, M, k, s, p); a[N] = 1; CalcSw(N, a, M, k, s, p); } } }
using System; namespace ABC128 { class C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int[] k = new int[M]; int[,] s = new int[M, 20]; for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(' '); k[i] = int.Parse(input[0]); for (int j = 1; j <= k[i]; j++) { s[i, j] = int.Parse(input[j]); } } input = Console.ReadLine().Split(' '); int[] p = new int[M]; for (int i = 0; i < M; i++) { p[i] = int.Parse(input[i]); } int[] a = new int[N]; CalcSw(N, a, M, k, s, p); Console.WriteLine(count); } static int count = 0; static void CalcSw(int N, int[] a, int M, int[] k, int[,] s, int[] p) { if (N == 0) { int c = 0; for (int i = 0; i < M; i++) { c = 0; for (int j = 1; j <= k[i]; j++) { if (a[s[i, j] - 1] == 1) { c++; } } if ((c % 2) != p[i]) { return; } } count++; return; } N--; a[N] = 0; CalcSw(N, a, M, k, s, p); a[N] = 1; CalcSw(N, a, M, k, s, p); } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
8
468
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { C(); } public static void C() { Scanner cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); List<int>[] f = new List<int>[n]; for (int i = 0; i < n; i++) { int t = cin.Int(); f[i] = new List<int>(); for (int j = 0; j < t; j++) { f[i].Add(cin.Int()); } } int[] p = new int[m]; for (int i = 0; i < m; i++) { p[i] = cin.Int(); } int ans = 0; int l = (int)Math.Pow(2, n); for (int k = 0; k < l; k++) { bool ok = true; for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 0; j < f[i].Count; j++) { if ((f[i][j] & i) != 0) { ++cnt; } } if (cnt % 2 != p[i]) { ok = false; break; } } if (ok) { ++ans; } } Console.WriteLine(ans); } } public class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { C(); } public static void C() { Scanner cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); List<int>[] f = new List<int>[m]; for (int i = 0; i < m; i++) { int t = cin.Int(); f[i] = new List<int>(); for (int j = 0; j < t; j++) { f[i].Add(1 << (cin.Int() - 1)); } } int[] p = new int[m]; for (int i = 0; i < m; i++) { p[i] = cin.Int(); } int ans = 0; int l = (int)Math.Pow(2, n); for (int k = 0; k < l; k++) { bool ok = true; for (int i = 0; i < m; i++) { int cnt = 0; for (int j = 0; j < f[i].Count; j++) { if ((f[i][j] & k) != 0) { ++cnt; } } if (cnt % 2 != p[i]) { ok = false; break; } } if (ok) { ++ans; } } Console.WriteLine(ans); } } public class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 151], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 57, 15, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 12, 22]]
8
698
14
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var S = new int [M][]; var maxS = 0; for (int i = 0; i < M; i++) { var K = sc.ReadInt(); S[i] = new int[K]; for (int k = 0; k < K; k++) { S[i][k] = sc.ReadInt(); maxS = Math.Max(S[i][k], maxS); } } var P = sc.ReadIntArray(M); var ans = 0; for (int x = 0; x < (int)Math.Pow(2, maxS); x++) { var res = true; for (int i = 0; i < M; i++) { var count = 0; foreach (var s in S[i]) { count += x >> (s - 1) & 1; } if (count % 2 != P[i]) res = false; } if (res == true) ans += 1; } Console.WriteLine(ans); } } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); 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; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } 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 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 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; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } } 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]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Array[n].CompareTo(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; } } } private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static Scanner sc = new Scanner(); static void Main(string[] args) { var N = sc.ReadInt(); var M = sc.ReadInt(); var S = new int [M][]; for (int i = 0; i < M; i++) { var K = sc.ReadInt(); S[i] = new int[K]; for (int k = 0; k < K; k++) { S[i][k] = sc.ReadInt(); } } var P = sc.ReadIntArray(M); var ans = 0; for (int x = 0; x < (int)Math.Pow(2, N); x++) { var res = true; for (int i = 0; i < M; i++) { var count = 0; foreach (var s in S[i]) { count += x >> (s - 1) & 1; } if (count % 2 != P[i]) res = false; } if (res == true) ans += 1; } Console.WriteLine(ans); } } class Modulo { public readonly int MOD; private readonly List<int> Facs = new List<int>() { 1 }; public Modulo(int mod = 1000000007) { this.MOD = mod; } public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % MOD); } public int Div(int a, int b) { return Mul(a, Pow(b, MOD - 2)); } public int Pow(int a, int n) { switch (n) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, n / 2); int p2 = Mul(p1, p1); return ((n % 2) == 0) ? p2 : Mul(p2, a); } } public int Fac(int n) { for (int i = this.Facs.Count; i <= n; i++) { this.Facs.Add(Mul(i, Facs[i - 1])); } return this.Facs[n]; } public int nPr(int n, int r) => Div(Fac(n), Fac(n - r)); 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; } } class Debug { public static void Dump<T>(T[,] array) { Console.WriteLine(); var h = array.GetLength(0); var w = array.GetLength(1); for (int r = 0; r < h; r++) { for (int c = 0; c < w; c++) { Console.Write(array[r, c]); Console.Write(" "); } Console.WriteLine(); } Console.WriteLine(); } public static void Dump<T>(T[] array) { Console.WriteLine(); Console.WriteLine(string.Join(" ", array)); Console.WriteLine(); } } 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 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 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; } } class HashMap<K, V> : Dictionary<K, V> where V : new() { private V DefaltValue = new V(); public HashMap() {} public HashMap(V defaultValue) { this.DefaltValue = new V(); } new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = this.DefaltValue; } set { base[i] = value; } } } 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]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Array[n].CompareTo(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; } } } private int Compare(T a, T b) { var c = a.CompareTo(b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 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, 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], ["-", 3, 4, 0, 28, 0, 204, 205, 204, 205, 22], ["-", 0, 28, 0, 204, 205, 204, 206, 207, 0, 70], ["-", 0, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 28, 0, 204, 205, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 12, 74, 51, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 74, 51, 213, 3, 4, 0, 28, 0, 22]]
8
1,727
24
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class Program { static void Main() { var N = int.Parse(ReadLine()); var x = new long[N]; var y = new long[N]; for (int i = 0; i < N; i++) { var xy = ReadLine().Split().Select(long.Parse).ToArray(); x[i] = xy[0]; y[i] = xy[1]; } if (N == 1) { WriteLine(1); return; } var ans = int.MaxValue; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == j) continue; var a = Abs(x[i] - x[j]); var b = Abs(y[i] - y[j]); var uf = new UnionFind(N); for (int k = 0; k < N; k++) { for (int l = 0; l < N; l++) { if (k == l) continue; if (Abs(x[k] - x[l]) == a && Abs(y[k] - y[l]) == b) { uf.Unite(k, l); } } } ans = Min(ans, uf.Count); } } WriteLine(ans); } } public class UnionFind { int[] parent; int count; public int Count => count; public UnionFind(int length) { parent = new int[length]; for (int i = 0; i < parent.Length; i++) { parent[i] = -1; } count = length; } int Root(int x) => parent[x] < 0 ? x : parent[x] = Root(parent[x]); public bool Same(int x, int y) => Root(x) == Root(y); public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return false; count--; if (parent[x] < parent[y]) { parent[x] += parent[y]; parent[y] = x; } else { parent[y] += parent[x]; parent[x] = y; } return true; } public int Size(int x) => -parent[Root(x)]; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class Program { static void Main() { var N = int.Parse(ReadLine()); var x = new long[N]; var y = new long[N]; for (int i = 0; i < N; i++) { var xy = ReadLine().Split().Select(long.Parse).ToArray(); x[i] = xy[0]; y[i] = xy[1]; } if (N == 1) { WriteLine(1); return; } var ans = int.MaxValue; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i == j) continue; var a = x[i] - x[j]; var b = y[i] - y[j]; var uf = new UnionFind(N); for (int k = 0; k < N; k++) { for (int l = 0; l < N; l++) { if (k == l) continue; if (x[k] - x[l] == a && y[k] - y[l] == b) { uf.Unite(k, l); } } } ans = Min(ans, uf.Count); } } WriteLine(ans); } } public class UnionFind { int[] parent; int count; public int Count => count; public UnionFind(int length) { parent = new int[length]; for (int i = 0; i < parent.Length; i++) { parent[i] = -1; } count = length; } int Root(int x) => parent[x] < 0 ? x : parent[x] = Root(parent[x]); public bool Same(int x, int y) => Root(x) == Root(y); public bool Unite(int x, int y) { x = Root(x); y = Root(y); if (x == y) return false; count--; if (parent[x] < parent[y]) { parent[x] += parent[y]; parent[y] = x; } else { parent[y] += parent[x]; parent[x] = y; } return true; } public int Size(int x) => -parent[Root(x)]; }
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 31, 213, 63, 22], ["-", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 57, 15, 16, 12, 16, 31, 213, 63, 22], ["-", 15, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["-", 15, 16, 12, 16, 31, 213, 3, 4, 0, 25]]
8
552
12
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var N = ReadInt(); var x = new long[N]; var y = new long[N]; for (int i = 0; i < N; i++) { var input = ReadArrayInt(); x[i] = input[0]; y[i] = input[1]; } var len = new List<long[]>(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { var xL = Math.Abs(x[i] - x[j]); var yL = Math.Abs(y[i] - y[j]); if (!(xL == 0 && yL == 0)) len.Add(new long[] { xL, yL }); } } len = len.Distinct().ToList(); var ans = N; for (int i = 0; i < len.Count(); i++) { var costs = N; for (int j = 0; j < N; j++) { var xP = x[j] - len[i][0]; var yP = y[j] - len[i][1]; for (int k = 0; k < N; k++) { if (k == j) continue; if (xP == x[k] && yP == y[k]) { costs--; break; } } } if (costs < ans) ans = costs; } Console.WriteLine(ans); Console.ReadLine(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var N = ReadLong(); var x = new long[N]; var y = new long[N]; for (int i = 0; i < N; i++) { var input = ReadArrayLong(); x[i] = input[0]; y[i] = input[1]; } var len = new List<long[]>(); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { var xL = x[i] - x[j]; var yL = y[i] - y[j]; if (!(xL == 0 && yL == 0)) len.Add(new long[] { xL, yL }); } } len = len.Distinct().ToList(); var ans = N; for (int i = 0; i < len.Count(); i++) { var costs = N; for (int j = 0; j < N; j++) { var xP = x[j] - len[i][0]; var yP = y[j] - len[i][1]; for (int k = 0; k < N; k++) { if (k == j) continue; if (xP == x[k] && yP == y[k]) { costs--; break; } } } if (costs < ans) ans = costs; } Console.WriteLine(ans); Console.ReadLine(); } static string Read() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(Read()); } static long ReadLong() { return long.Parse(Read()); } static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); } static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 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], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
493
14
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; public class ABC { public static void Main() { var read = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = read[0]; SortedDictionary<string, long> balls = new SortedDictionary<string, long>(); bool[] collected = new bool[N]; Tuple<long, long>[] balls_tuple = new Tuple<long, long>[N]; for (long i = 0; i < N; i++) { string readline = Console.ReadLine(); long[] split = readline.Split().Select(long.Parse).ToArray(); balls[readline] = i; balls_tuple[i] = new Tuple<long, long>(split[0], split[1]); collected[i] = false; } long minimum_cost = long.MaxValue; if (N == 1) { Console.WriteLine(1); return; } else for (long firstball = 0; firstball < N - 1; firstball++) { for (long lastball = firstball + 1; lastball < N; lastball++) { long p = balls_tuple[firstball].Item1 - balls_tuple[lastball].Item1; long q = balls_tuple[firstball].Item2 - balls_tuple[lastball].Item2; bool[] thisTime_collected = new bool[N]; collected.CopyTo(thisTime_collected, 0); long n_collected = 0; long cost = 0; bool isDAME = false; for (long lookingyounger = 0; lookingyounger < N - 1; lookingyounger++) { //回収する珠のスタートを選ぶ if (thisTime_collected[lookingyounger] == true) continue; else { cost++; if (cost > minimum_cost) { isDAME = true; break; } long x = balls_tuple[lookingyounger].Item1; long y = balls_tuple[lookingyounger].Item2; thisTime_collected[lookingyounger] = true; n_collected++; while (balls.ContainsKey((longs2key(x - p, y - q)))) { long key_nextball = balls[longs2key(x - p, y - q)]; thisTime_collected[key_nextball] = true; n_collected++; x -= p; y -= q; } while (balls.ContainsKey((longs2key(x + p, y + q)))) { long key_nextball = balls[longs2key(x + p, y + q)]; thisTime_collected[key_nextball] = true; n_collected++; x += p; y += q; } } } if (isDAME == false) { if (minimum_cost > cost) { minimum_cost = cost; } } } } Console.WriteLine(minimum_cost); } public static string longs2key(long x, long y) { return x + " " + y; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; public class ABC { public static void Main() { var read = Console.ReadLine().Split().Select(long.Parse).ToArray(); long N = read[0]; SortedDictionary<string, long> balls = new SortedDictionary<string, long>(); bool[] collected = new bool[N]; Tuple<long, long>[] balls_tuple = new Tuple<long, long>[N]; for (long i = 0; i < N; i++) { string readline = Console.ReadLine(); long[] split = readline.Split().Select(long.Parse).ToArray(); balls[readline] = i; balls_tuple[i] = new Tuple<long, long>(split[0], split[1]); collected[i] = false; } long minimum_cost = long.MaxValue; if (N == 1) { Console.WriteLine(1); return; } else for (long firstball = 0; firstball < N - 1; firstball++) { for (long lastball = firstball + 1; lastball < N; lastball++) { long p = balls_tuple[firstball].Item1 - balls_tuple[lastball].Item1; long q = balls_tuple[firstball].Item2 - balls_tuple[lastball].Item2; bool[] thisTime_collected = new bool[N]; collected.CopyTo(thisTime_collected, 0); long n_collected = 0; long cost = 0; bool isDAME = false; for (long lookingyounger = 0; lookingyounger < N; lookingyounger++) { //回収する珠のスタートを選ぶ if (thisTime_collected[lookingyounger] == true) continue; else { cost++; if (cost > minimum_cost) { isDAME = true; break; } long x = balls_tuple[lookingyounger].Item1; long y = balls_tuple[lookingyounger].Item2; thisTime_collected[lookingyounger] = true; n_collected++; while (balls.ContainsKey((longs2key(x - p, y - q)))) { long key_nextball = balls[longs2key(x - p, y - q)]; thisTime_collected[key_nextball] = true; n_collected++; x -= p; y -= q; } x = balls_tuple[lookingyounger].Item1; y = balls_tuple[lookingyounger].Item2; while (balls.ContainsKey((longs2key(x + p, y + q)))) { long key_nextball = balls[longs2key(x + p, y + q)]; thisTime_collected[key_nextball] = true; n_collected++; x += p; y += q; } } } if (isDAME == false) { if (minimum_cost > cost) { minimum_cost = cost; } } } } Console.WriteLine(minimum_cost); } public static string longs2key(long x, long y) { return x + " " + y; } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 214, 205, 204, 205, 22], ["+", 0, 11, 12, 214, 205, 204, 206, 207, 0, 70], ["+", 12, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 214, 205, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 11, 12, 214, 141, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
8
590
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static void Main() { int N = Console.ReadLine().ToInt(); var xyList = ReadLines(N) .Select(line => line.ToIntArray()) .Select(arr => new { x = arr[0], y = arr[1] }) .ToArray(); if (N == 1) { Console.WriteLine(1); return; } var candList = xyList.Take(0).ToList(); for (int i = 0; i < xyList.Length; i++) { for (int j = i + 1; j < xyList.Length; j++) { var xy1 = xyList[i]; var xy2 = xyList[j]; var x = xy1.x - xy2.x; var y = xy1.y - xy2.y; if (x != 0 && y != 0) { candList.Add(new { x, y }); } } } int min = int.MaxValue; foreach (var cand in candList) { var val = 0; foreach (var xy in xyList) { var x = xy.x - cand.x; var y = xy.y - cand.y; var ddd = new { x, y }; if (xyList.Contains(ddd) == false) { val += 1; } } min = Math.Min(val, min); } Console.WriteLine(min); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static void Main() { int N = Console.ReadLine().ToInt(); var xyList = ReadLines(N) .Select(line => line.ToIntArray()) .Select(arr => new { x = arr[0], y = arr[1] }) .ToArray(); if (N == 1) { Console.WriteLine(1); return; } var candList = xyList.Take(0).ToList(); for (int i = 0; i < xyList.Length; i++) { for (int j = i + 1; j < xyList.Length; j++) { var xy1 = xyList[i]; var xy2 = xyList[j]; var x = xy1.x - xy2.x; var y = xy1.y - xy2.y; candList.Add(new { x, y }); } } int min = int.MaxValue; foreach (var cand in candList) { var val = 0; foreach (var xy in xyList) { var x = xy.x - cand.x; var y = xy.y - cand.y; var ddd = new { x, y }; if (xyList.Contains(ddd) == false) { val += 1; } } min = Math.Min(val, min); } Console.WriteLine(min); } }
[["-", 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, 79], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
584
12
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; namespace Program { public static class DIVERTA2019_2B { static public void Solve() { var N = NextInt; var list = new List<Tuple<int, int>>(); for (int i = 0; i < N; ++i) { var x = NextInt; var y = NextInt; list.Add(Tuple.Create(x, y)); } var diff = new Dictionary<Tuple<int, int>, int>(); for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { var key = Tuple.Create(Abs(list[i].Item1 - list[j].Item1), Abs(list[i].Item2 - list[j].Item2)); if (diff.ContainsKey(key)) { diff[key]++; } else { diff[key] = 1; } } } Console.WriteLine(N - diff.Values.Max()); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { private static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); static List<int> NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList(); static List<long> NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList(); static List<double> NextDoubleList(int N) => Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList(); static List<string> NextStringList(int N) => Enumerable.Repeat(0, N).Select(_ => NextString).ToList(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); static IEnumerable<T> Repeat<T>(T v, int n) => Enumerable.Repeat<T>(v, n); static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } static List<T> Sort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, comp); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => comp(y, x)); return tmp.ToList(); } static IEnumerable<long> Prime(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; public Tuple<TKey, TValue> Pop() => q.Pop(); } class Mod { static public long _mod = 1000000007; private long _val = 0; public Mod(long x) { _val = x % _mod; } static public implicit operator Mod(long x) => new Mod(x); static public explicit operator long(Mod x) => x._val; static public Mod operator +(Mod x) => x._val; static public Mod operator -(Mod x) => -x._val; static public Mod operator ++(Mod x) => x._val + 1; static public Mod operator --(Mod x) => x._val - 1; static public Mod operator +(Mod x, Mod y) => (x._val + y._val) % _mod; static public Mod operator -(Mod x, Mod y) => ((((x._val - y._val) % _mod) + _mod) % _mod); static public Mod operator *(Mod x, Mod y) => (x._val * y._val) % _mod; static public Mod operator /(Mod x, Mod y) => (x._val * Inverse(y._val)) % _mod; static public bool operator ==(Mod x, Mod y) => x._val == y._val; static public bool operator !=(Mod x, Mod y) => x._val != y._val; static public bool operator<(Mod x, Mod y) => x._val < y._val; static public bool operator>(Mod x, Mod y) => x._val > y._val; static public bool operator <=(Mod x, Mod y) => x._val <= y._val; static public bool operator >=(Mod x, Mod y) => x._val >= y._val; static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } 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; } override public bool Equals(object obj) => obj == null ? false : _val == ((Mod)obj)._val; public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; public override int GetHashCode() => _val.GetHashCode(); public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>(); static private List<Mod> _ifact = new List<Mod>(); static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) { _fact.Add(1); _ifact.Add(1); } else { _fact.Add(_fact[i - 1] * i); _ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2)); } } static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _ifact[n - k] * _ifact[k] * _fact[n]; } } class Mat<T> { private T[,] m; public Mat(T[,] v) { m = (T[,])v.Clone(); } static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return new Mat<T>(tm); } static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return new Mat<T>(tm); } static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return new Mat<T>(tm); } static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); static Mod Pow(Mod x, long y) => Mod.Pow(x, y); static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>(); static void _Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) _fact.Add(1); else _fact.Add(_fact[i - 1] * i); } static long Comb(int n, int k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; namespace Program { public static class DIVERTA2019_2B { static public void Solve() { var N = NextInt; var list = new List<Tuple<int, int>>(); for (int i = 0; i < N; ++i) { var x = NextInt; var y = NextInt; list.Add(Tuple.Create(x, y)); } if (N == 1) { Console.WriteLine(1); return; } var diff = new Dictionary<Tuple<int, int>, int>(); for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (i == j) continue; var key = Tuple.Create(list[i].Item1 - list[j].Item1, list[i].Item2 - list[j].Item2); if (diff.ContainsKey(key)) { diff[key]++; } else { diff[key] = 1; } } } Console.WriteLine(N - diff.Values.Max()); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { private static Queue<string> param = new Queue<string>(); public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); static List<int> NextIntList(int N) => Enumerable.Repeat(0, N).Select(_ => NextInt).ToList(); static List<long> NextLongList(int N) => Enumerable.Repeat(0, N).Select(_ => NextLong).ToList(); static List<double> NextDoubleList(int N) => Enumerable.Repeat(0, N).Select(_ => NextDouble).ToList(); static List<string> NextStringList(int N) => Enumerable.Repeat(0, N).Select(_ => NextString).ToList(); static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); static IEnumerable<T> Repeat<T>(T v, int n) => Enumerable.Repeat<T>(v, n); static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } static List<T> Sort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, comp); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } static List<T> RevSort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => comp(y, x)); return tmp.ToList(); } static IEnumerable<long> Prime(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; public Tuple<TKey, TValue> Pop() => q.Pop(); } class Mod { static public long _mod = 1000000007; private long _val = 0; public Mod(long x) { _val = x % _mod; } static public implicit operator Mod(long x) => new Mod(x); static public explicit operator long(Mod x) => x._val; static public Mod operator +(Mod x) => x._val; static public Mod operator -(Mod x) => -x._val; static public Mod operator ++(Mod x) => x._val + 1; static public Mod operator --(Mod x) => x._val - 1; static public Mod operator +(Mod x, Mod y) => (x._val + y._val) % _mod; static public Mod operator -(Mod x, Mod y) => ((((x._val - y._val) % _mod) + _mod) % _mod); static public Mod operator *(Mod x, Mod y) => (x._val * y._val) % _mod; static public Mod operator /(Mod x, Mod y) => (x._val * Inverse(y._val)) % _mod; static public bool operator ==(Mod x, Mod y) => x._val == y._val; static public bool operator !=(Mod x, Mod y) => x._val != y._val; static public bool operator<(Mod x, Mod y) => x._val < y._val; static public bool operator>(Mod x, Mod y) => x._val > y._val; static public bool operator <=(Mod x, Mod y) => x._val <= y._val; static public bool operator >=(Mod x, Mod y) => x._val >= y._val; static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } 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; } override public bool Equals(object obj) => obj == null ? false : _val == ((Mod)obj)._val; public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; public override int GetHashCode() => _val.GetHashCode(); public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>(); static private List<Mod> _ifact = new List<Mod>(); static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) { _fact.Add(1); _ifact.Add(1); } else { _fact.Add(_fact[i - 1] * i); _ifact.Add(_ifact[i - 1] * Mod.Pow(i, _mod - 2)); } } static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _ifact[n - k] * _ifact[k] * _fact[n]; } } class Mat<T> { private T[,] m; public Mat(T[,] v) { m = (T[,])v.Clone(); } static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return new Mat<T>(tm); } static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return new Mat<T>(tm); } static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return new Mat<T>(tm); } static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return new Mat<T>(tm); } static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); static Mod Pow(Mod x, long y) => Mod.Pow(x, y); static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>(); static void _Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) if (i == 0L) _fact.Add(1); else _fact.Add(_fact[i - 1] * i); } static long Comb(int n, int k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
[["+", 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], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 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, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35], ["-", 0, 200, 0, 212, 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, 25], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24]]
8
3,719
35
using System; using System.Collections.Generic; public class S { private const char BLANK = '.'; private const char ROCK = '#'; public static void Main() { // diverta 2 C // 負数を1個作り(正数最小値-正数最大値)、ひたすら正数をそこに減算していく。 // 負数は1個以外すべて最大値に対して減算する。 var N = int.Parse(Console.ReadLine()); var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var list = new List<int>(); foreach (var tgt in input) { list.Add(tgt); } list.Sort(); input = list.ToArray(); int max = input[N - 1]; int? hoge = null; int focusIndex = -1; for (int i = 0; i < N - 1; i++) { if (input[i] < 0) { if (input[i + 1] >= 0 && i != N - 2) { focusIndex = i; hoge = input[i]; } else { max -= input[i]; } } else { if (focusIndex == -1) { focusIndex = i; hoge = input[i]; } else { hoge -= input[i]; } } } Console.WriteLine(max - hoge); max = input[N - 1]; focusIndex = -1; hoge = null; for (int i = 0; i < N - 1; i++) { if (input[i] < 0) { if (input[i + 1] >= 0 && i + 1 != N - 1) { focusIndex = i; hoge = input[i]; } else { Console.WriteLine(max + " " + input[i]); max -= input[i]; } } else { if (focusIndex == -1) { focusIndex = i; hoge = input[i]; } else { Console.WriteLine(hoge + " " + input[i]); hoge -= input[i]; } } } if (hoge != null) Console.WriteLine(max + " " + hoge); } }
using System; using System.Collections.Generic; public class S { private const char BLANK = '.'; private const char ROCK = '#'; public static void Main() { // diverta 2 C // 負数を1個作り(正数最小値-正数最大値)、ひたすら正数をそこに減算していく。 // 負数は1個以外すべて最大値に対して減算する。 var N = long.Parse(Console.ReadLine()); var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var list = new List<long>(); foreach (var tgt in input) { list.Add(tgt); } list.Sort(); input = list.ToArray(); long max = input[N - 1]; long? hoge = null; long focusIndex = -1; for (long i = 0; i < N - 1; i++) { if (input[i] < 0) { if (input[i + 1] >= 0 && i != N - 2) { focusIndex = i; hoge = input[i]; } else { max -= input[i]; } } else { if (focusIndex == -1) { focusIndex = i; hoge = input[i]; } else { hoge -= input[i]; } } } if (hoge != null) { Console.WriteLine(max - hoge); } else { Console.WriteLine(max); } max = input[N - 1]; focusIndex = -1; hoge = null; for (long i = 0; i < N - 1; i++) { if (input[i] < 0) { if (input[i + 1] >= 0 && i + 1 != N - 1) { focusIndex = i; hoge = input[i]; } else { Console.WriteLine(max + " " + input[i]); max -= input[i]; } } else { if (focusIndex == -1) { focusIndex = i; hoge = input[i]; } else { Console.WriteLine(hoge + " " + input[i]); hoge -= input[i]; } } } if (hoge != null) Console.WriteLine(max + " " + hoge); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 317, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 317, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 215], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
430
34
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp3 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var numbers = Console.ReadLine().Split(' '); var nega = from num in numbers where int.Parse(num)<0 orderby int.Parse(num) select int.Parse(num); var other = from num in numbers where int.Parse(num) >= 0 orderby int.Parse(num) select int.Parse(num); var negativeList = nega.ToList<int>(); var otherList = other.ToList<int>(); // 0以上のみ // 最小 -x .... -最大手前 → 最大 - (最小 -x .... -最大手前) // 全体の最小から 0以上 の要素を 最大の手前まで引いていく // 全体の最大から 負の要素と↑を引いて終わり(負) // 要素が重複しないように注意 int min = 0; int max = 0; // 0以上のみ if (negativeList.Count == 0) { min = otherList.First(); max = otherList.Last(); int m = otherList.Sum() - min * 2; Console.WriteLine(m); int newNum = min; for (int i = 1; i < n - 1; i++) { Console.WriteLine("{0} {1}", newNum, otherList[i]); newNum -= otherList[i]; } Console.WriteLine("{0} {1}", max, newNum); return; } // 負のみ else if (otherList.Count == 0) { min = negativeList.First(); max = negativeList.Last(); int m = negativeList.Sum() - max * 2; m *= -1; Console.WriteLine(m); int newNum = max; for (int i = 0; i < n - 1; i++) { Console.WriteLine("{0} {1}", newNum, negativeList[i]); } return; } // 混合 else { min = negativeList.First(); max = otherList.Last(); int m = otherList.Sum() - negativeList.Sum(); Console.WriteLine(m); int newNum = min; for (int i = 0; i < otherList.Count - 1; i++) { Console.WriteLine("{0} {1}", newNum, otherList[i]); newNum -= otherList[i]; } negativeList[0] = newNum; newNum = max; for (int i = 0; i < negativeList.Count; i++) { Console.WriteLine("{0} {1}", newNum, negativeList[i]); } return; } } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp3 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var numbers = Console.ReadLine().Split(' '); var nega = from num in numbers where int.Parse(num)<0 orderby int.Parse(num) select int.Parse(num); var other = from num in numbers where int.Parse(num) >= 0 orderby int.Parse(num) select int.Parse(num); var negativeList = nega.ToList<int>(); var otherList = other.ToList<int>(); int min = 0; int max = 0; // 0以上のみ if (negativeList.Count == 0) { min = otherList.First(); max = otherList.Last(); int m = otherList.Sum() - min * 2; Console.WriteLine(m); int newNum = min; for (int i = 1; i < n - 1; i++) { Console.WriteLine("{0} {1}", newNum, otherList[i]); newNum -= otherList[i]; } Console.WriteLine("{0} {1}", max, newNum); return; } // 負のみ else if (otherList.Count == 0) { min = negativeList.First(); max = negativeList.Last(); int m = negativeList.Sum() - max * 2; m *= -1; Console.WriteLine(m); int newNum = max; for (int i = 0; i < n - 1; i++) { Console.WriteLine("{0} {1}", newNum, negativeList[i]); newNum -= negativeList[i]; } return; } // 混合 else { min = negativeList.First(); max = otherList.Last(); int m = otherList.Sum() - negativeList.Sum(); Console.WriteLine(m); int newNum = min; for (int i = 0; i < otherList.Count - 1; i++) { Console.WriteLine("{0} {1}", newNum, otherList[i]); newNum -= otherList[i]; } negativeList[0] = newNum; newNum = max; for (int i = 0; i < negativeList.Count; i++) { Console.WriteLine("{0} {1}", newNum, negativeList[i]); newNum -= negativeList[i]; } return; } } } }
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 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], ["+", 64, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
504
14
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } private const int MOD = 1000000007; static void Solve() { var n = Input.NextInt(); var a = Input.NextInt(n); a.Sort(); var p = new List<int>(); var q = new List<int>(); q.Add(a[0]); p.Add(a[n - 1]); for (int i = 1; i < n - 1; ++i) { var ai = a[i]; if (ai >= 0) { p.Add(ai); } else { q.Add(ai); } } int ans = 0; var ansList = new List<int>(); if (p.Count >= 2) { ans = q[0]; for (int i = 1; i < p.Count; ++i) { ansList.Add(ans); ansList.Add(p[i]); ans = ans - p[i]; } } ansList.Add(p[0]); ansList.Add(ans); ans = p[0] - ans; if (q.Count >= 2) { for (int i = 1; i < q.Count; ++i) { ansList.Add(ans); ansList.Add(q[i]); ans = ans - q[i]; } } Console.WriteLine(ans); for (int i = 0; i < ansList.Count; i += 2) { Console.WriteLine($"{ansList[i]} {ansList[i+1]}"); } } #region よく使う便利関数 static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static void Swap<T>(ref T x, ref T y) { T t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } private const int MOD = 1000000007; static void Solve() { var n = Input.NextInt(); var a = Input.NextInt(n); a.Sort(); var p = new List<int>(); var q = new List<int>(); q.Add(a[0]); p.Add(a[n - 1]); for (int i = 1; i < n - 1; ++i) { var ai = a[i]; if (ai >= 0) { p.Add(ai); } else { q.Add(ai); } } int ans = q[0]; var ansList = new List<int>(); if (p.Count >= 2) { for (int i = 1; i < p.Count; ++i) { ansList.Add(ans); ansList.Add(p[i]); ans = ans - p[i]; } } ansList.Add(p[0]); ansList.Add(ans); ans = p[0] - ans; if (q.Count >= 2) { for (int i = 1; i < q.Count; ++i) { ansList.Add(ans); ansList.Add(q[i]); ans = ans - q[i]; } } Console.WriteLine(ans); for (int i = 0; i < ansList.Count; i += 2) { Console.WriteLine($"{ansList[i]} {ansList[i+1]}"); } } #region よく使う便利関数 static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static void Swap<T>(ref T x, ref T y) { T t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 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, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
1,829
10
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; // using Edge = Pair<long, int>; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var num = Input.num; var ar = Input.ar.OrderBy(v => v).ToArray(); if (num == 2) { WriteLine($"{ar[1] - ar[0]}\n{ar[1]} {ar[0]}"); return; } var res = new List<string>(num - 1); var r = 0; if (ar[0] <= 0 && ar[num - 1] > 0) { r = ar[0]; var i = num - 2; for (i = num - 2; i >= 0; i--) { if (ar[i] <= 0) break; res.Add($"{r} {ar[i]}"); r -= ar[i]; } res.Add($"{ar[num - 1]} {r}"); r = -r + ar[num - 1]; while (i - 1 >= 0) { res.Add($"{r} {ar[i]}"); r -= ar[i]; i--; } } else if (ar[num - 1] <= 0) { r = ar[num - 1] - ar[0]; res.Add($"{ar[num - 1]} {ar[0]}"); for (var i = 1; i < num - 1; i++) { res.Add($"{r} {ar[i]}"); r -= ar[i]; } } else { r = ar[0] - ar[num - 1]; res.Add($"{ar[0]} {ar[num-1]}"); for (var i = 1; i < num - 2; i++) { res.Add($"{r} {ar[i]}"); r -= ar[i]; } res.Add($"{ar[num - 2]} {r}"); } WriteLine($"{r}\n{string.Join("\n", res)}"); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[] ar1D(int n) => Enumerable.Repeat(0, n).Select(_ => num).ToArray(); public static long[] arL1D(int n) => Enumerable.Repeat(0, n).Select(_ => numL).ToArray(); public static string[] strs(int n) => Enumerable.Repeat(0, n).Select(_ => read).ToArray(); public static int[][] ar2D(int n) => Enumerable.Repeat(0, n).Select(_ => ar).ToArray(); public static long[][] arL2D(int n) => Enumerable.Repeat(0, n).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static string[] Make<T1, T2>(out T1 v1, out T2 v2) { var r = read.Split(' '); v1 = getValue<T1>(r[0]); v2 = getValue<T2>(r[1]); return r; } public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { var r = Make(out v1, out v2); v3 = getValue<T3>(r[2]); return r; } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; // using Edge = Pair<long, int>; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var num = Input.num; var ar = Input.ar.OrderBy(v => v).ToArray(); if (num == 2) { WriteLine($"{ar[1] - ar[0]}\n{ar[1]} {ar[0]}"); return; } var res = new List<string>(num - 1); var r = 0; if (ar[0] <= 0 && ar[num - 1] > 0) { r = ar[0]; var i = num - 2; for (i = num - 2; i >= 0; i--) { if (ar[i] <= 0) break; res.Add($"{r} {ar[i]}"); r -= ar[i]; } res.Add($"{ar[num - 1]} {r}"); r = -r + ar[num - 1]; while (i - 1 >= 0) { res.Add($"{r} {ar[i]}"); r -= ar[i]; i--; } } else if (ar[num - 1] <= 0) { r = ar[num - 1] - ar[0]; res.Add($"{ar[num - 1]} {ar[0]}"); for (var i = 1; i < num - 1; i++) { res.Add($"{r} {ar[i]}"); r -= ar[i]; } } else { r = ar[0] - ar[num - 1]; res.Add($"{ar[0]} {ar[num-1]}"); for (var i = 1; i < num - 2; i++) { res.Add($"{r} {ar[i]}"); r -= ar[i]; } res.Add($"{ar[num - 2]} {r}"); r = -r + ar[num - 2]; } WriteLine($"{r}\n{string.Join("\n", res)}"); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[] ar1D(int n) => Enumerable.Repeat(0, n).Select(_ => num).ToArray(); public static long[] arL1D(int n) => Enumerable.Repeat(0, n).Select(_ => numL).ToArray(); public static string[] strs(int n) => Enumerable.Repeat(0, n).Select(_ => read).ToArray(); public static int[][] ar2D(int n) => Enumerable.Repeat(0, n).Select(_ => ar).ToArray(); public static long[][] arL2D(int n) => Enumerable.Repeat(0, n).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static string[] Make<T1, T2>(out T1 v1, out T2 v2) { var r = read.Split(' '); v1 = getValue<T1>(r[0]); v2 = getValue<T2>(r[1]); return r; } public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { var r = Make(out v1, out v2); v3 = getValue<T3>(r[2]); return r; } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["+", 75, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 241, 0, 33], ["+", 0, 1, 0, 11, 12, 16, 31, 241, 0, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35]]
8
1,129
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; static class Program { class Rate { public readonly int g; public readonly int s; public readonly int b; public Rate(int[] args) { g = args[0]; s = args[1]; b = args[2]; } } static long Search(long N, Rate A, Rate B) { var dp = new long[N + 1]; for (int i = 1; i <= N; ++i) { if (i >= A.g) { dp[i] = Math.Max(dp[i - A.g] + B.g, dp[i]); } if (i >= A.s) { dp[i] = Math.Max(dp[i - A.s] + B.s, dp[i]); } if (i >= A.b) { dp[i] = Math.Max(dp[i - A.b] + B.b, dp[i]); } } return dp[N]; } static long Solve(int N, Rate A, Rate B) { long X = Search(N, A, B); long Y = Search(X, B, A); return Y; } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var A = new Rate(Array.ConvertAll(Console.ReadLine().Split(), int.Parse)); var B = new Rate(Array.ConvertAll(Console.ReadLine().Split(), int.Parse)); Console.WriteLine(Solve(N, A, B)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; static class Program { class Rate { public readonly int g; public readonly int s; public readonly int b; public Rate(int[] args) { g = args[0]; s = args[1]; b = args[2]; } } static long Search(long N, Rate A, Rate B) { var dp = new long[N + 1]; for (int i = 1; i <= N; ++i) { dp[i] = i; if (i >= A.g) { dp[i] = Math.Max(dp[i - A.g] + B.g, dp[i]); } if (i >= A.s) { dp[i] = Math.Max(dp[i - A.s] + B.s, dp[i]); } if (i >= A.b) { dp[i] = Math.Max(dp[i - A.b] + B.b, dp[i]); } } return dp[N]; } static long Solve(int N, Rate A, Rate B) { long X = Search(N, A, B); long Y = Search(X, B, A); return Y; } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var A = new Rate(Array.ConvertAll(Console.ReadLine().Split(), int.Parse)); var B = new Rate(Array.ConvertAll(Console.ReadLine().Split(), int.Parse)); Console.WriteLine(Solve(N, A, B)); } }
[["+", 8, 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], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
370
7
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; // using Edge = Pair<long, int>; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var num = Input.num; var agsb = Input.ar; var bgsb = Input.ar; var dp = new int[4, num + 1]; for (var i = 1; i <= 3; i++) for (var j = 0; j <= num; j++) if (j - agsb[i - 1] >= 0) dp[i, j] = Max(dp[i - 1, j], dp[i, j - agsb[i - 1]] + bgsb[i - 1]); else dp[i, j] = dp[i - 1, j]; var max = 0; for (var i = 0; i <= num; i++) max = Max(max, dp[3, i]); dp = new int[4, max + 1]; for (var i = 1; i <= 3; i++) for (var j = 0; j <= max; j++) if (j - bgsb[i - 1] >= 0) dp[i, j] = Max(dp[i - 1, j], dp[i, j - bgsb[i - 1]] + agsb[i - 1]); else dp[i, j] = dp[i - 1, j]; var m = max; for (var i = 0; i <= m; i++) max = Max(max, dp[3, i]); WriteLine(max); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[] ar1D(int n) => Enumerable.Repeat(0, n).Select(_ => num).ToArray(); public static long[] arL1D(int n) => Enumerable.Repeat(0, n).Select(_ => numL).ToArray(); public static string[] strs(int n) => Enumerable.Repeat(0, n).Select(_ => read).ToArray(); public static int[][] ar2D(int n) => Enumerable.Repeat(0, n).Select(_ => ar).ToArray(); public static long[][] arL2D(int n) => Enumerable.Repeat(0, n).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static string[] Make<T1, T2>(out T1 v1, out T2 v2) { var r = read.Split(' '); v1 = getValue<T1>(r[0]); v2 = getValue<T2>(r[1]); return r; } public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { var r = Make(out v1, out v2); v3 = getValue<T3>(r[2]); return r; } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Convert; using static System.Math; // using Debug; // using static System.Globalization.CultureInfo; // using Edge = Pair<long, int>; using System.Text; class Program { static void Main(string[] args) { Solve(); // WriteLine(Solve()); } static void Solve() { var num = Input.num; var agsb = Input.arL; var bgsb = Input.arL; var dp = new long[4, num + 1]; for (var i = 1; i <= 3; i++) for (var j = 0; j <= num; j++) if (j - agsb[i - 1] >= 0) dp[i, j] = Max(dp[i - 1, j], dp[i, j - agsb[i - 1]] + bgsb[i - 1]); else dp[i, j] = dp[i - 1, j]; var max = 0L; for (var i = 0; i <= num; i++) max = Max(max, dp[3, i] + num - i); dp = new long[4, max + 1]; for (var i = 1; i <= 3; i++) for (var j = 0; j <= max; j++) if (j - bgsb[i - 1] >= 0) dp[i, j] = Max(dp[i - 1, j], dp[i, j - bgsb[i - 1]] + agsb[i - 1]); else dp[i, j] = dp[i - 1, j]; var m = max; for (var i = 0; i <= m; i++) max = Max(max, dp[3, i] + m - i); WriteLine(max); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static char[][] gred(int h) => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray(); public static int[] ar1D(int n) => Enumerable.Repeat(0, n).Select(_ => num).ToArray(); public static long[] arL1D(int n) => Enumerable.Repeat(0, n).Select(_ => numL).ToArray(); public static string[] strs(int n) => Enumerable.Repeat(0, n).Select(_ => read).ToArray(); public static int[][] ar2D(int n) => Enumerable.Repeat(0, n).Select(_ => ar).ToArray(); public static long[][] arL2D(int n) => Enumerable.Repeat(0, n).Select(_ => arL).ToArray(); public static T getValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object) int.Parse(g); if (t == typeof(long)) return (T)(object) long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object) char.Parse(g); if (t == typeof(double)) return (T)(object) double.Parse(g); if (t == typeof(bool)) return (T)(object) bool.Parse(g); return default(T); } public static string[] Make<T1, T2>(out T1 v1, out T2 v2) { var r = read.Split(' '); v1 = getValue<T1>(r[0]); v2 = getValue<T2>(r[1]); return r; } public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { var r = Make(out v1, out v2); v3 = getValue<T3>(r[2]); return r; } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["+", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199]]
8
981
18
using System; namespace ABC129A { class Program { static void Main(string[] args) { int p, q, r; string[] ss = Console.ReadLine().Split(' '); p = int.Parse(ss[0]); q = int.Parse(ss[1]); r = int.Parse(ss[2]); if (p > q && q > r) Console.WriteLine(q + r); else if (p > r && r > q) Console.WriteLine(r + q); else if (q > p && p > r) Console.WriteLine(p + r); else if (q > r && r > p) Console.WriteLine(r + p); else if (r > p && p > q) Console.WriteLine(p + q); else if (r > q && q > p) Console.WriteLine(q + p); if (p == q && p > r) Console.WriteLine(p + r); else if (p == q && p < r) Console.WriteLine(p + q); else if (q == r && q > p) Console.WriteLine(q + p); else if (q == r && q < p) Console.WriteLine(q + r); else if (p == r && p > q) Console.WriteLine(p + q); else if (p == r && p < q) Console.WriteLine(p + r); Console.ReadKey(); } } }
using System; namespace ABC129A { class Program { static void Main(string[] args) { int p, q, r; string[] ss = Console.ReadLine().Split(' '); p = int.Parse(ss[0]); q = int.Parse(ss[1]); r = int.Parse(ss[2]); if (p > q && q > r) Console.WriteLine(q + r); else if (p > r && r > q) Console.WriteLine(r + q); else if (q > p && p > r) Console.WriteLine(p + r); else if (q > r && r > p) Console.WriteLine(r + p); else if (r > p && p > q) Console.WriteLine(p + q); else if (r > q && q > p) Console.WriteLine(q + p); if (p == q && p > r) Console.WriteLine(p + r); else if (p == q && p < r) Console.WriteLine(p + q); else if (q == r && q > p) Console.WriteLine(q + p); else if (q == r && q < p) Console.WriteLine(q + r); else if (p == r && p > q) Console.WriteLine(p + q); else if (p == r && p < q) Console.WriteLine(p + r); if (p == q && q == r) Console.WriteLine(p + q); Console.ReadKey(); } } }
[["+", 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, 60], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 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
327
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcider { class Program { static void Main(string[] args) { string[] x = Console.ReadLine().Split(' '); int P = int.Parse(x[0]); int Q = int.Parse(x[1]); int R = int.Parse(x[2]); int a = P + Q; int b = Q + R; int c = R + P; int[] kyori = { a, b, c }; int min = 100; for (int i = 0; i < kyori.Length; i++) if (kyori[i] < min) { min = kyori[i]; } Console.WriteLine(min); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcider { class Program { static void Main(string[] args) { string[] x = Console.ReadLine().Split(' '); int P = int.Parse(x[0]); int Q = int.Parse(x[1]); int R = int.Parse(x[2]); int[] kyori = { P + Q, Q + R, R + P }; int min = kyori[0]; for (int i = 0; i < kyori.Length; i++) if (kyori[i] < min) { min = kyori[i]; } Console.WriteLine(min); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 229, 0, 45], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 229, 0, 21], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 45], ["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 21], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73]]
8
183
32
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int n = sc.intarr[0]; int[] ws = sc.intarr; int small = ws[0]; int big = ws[n - 1]; for (int i = 1; i < n - 1; i++) { if (small <= big) { small += ws[i]; } else { big += ws[i]; } } wr.wri(Math.Abs(big - small)); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int n = sc.intarr[0]; int[] ws = sc.intarr; int small = ws[0]; int big = ws[n - 1]; int back_index = 2; for (int i = 1; i <= n - back_index; i++) { if (small <= big) { small += ws[i]; } else { big += ws[n - back_index]; back_index++; i--; } } wr.wri(Math.Abs(big - small)); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 68]]
8
317
19
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var a = int.Parse(Console.ReadLine()); var b = Console.ReadLine().Split(); var ret = new List<int>(); for (int i = 1; i < b.Length; i++) { int valA = 0; for (int j = 0; j < i; j++) { valA += (int.Parse(b[j])); } int valB = 0; for (int j = i + 1; j < a; j++) { valB += int.Parse(b[j]); } var retVal = valA - valB; ret.Add(Math.Abs(retVal)); } var min = ret.Min(); Console.WriteLine(Array.IndexOf(ret.ToArray(), min)); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var a = int.Parse(Console.ReadLine()); var b = Console.ReadLine().Split(); var ret = new List<int>(); for (int i = 1; i < b.Length; i++) { int valA = 0; for (int j = 0; j < i; j++) { valA += (int.Parse(b[j])); } int valB = 0; for (int j = i; j < a; j++) { valB += int.Parse(b[j]); } var retVal = valA - valB; ret.Add(Math.Abs(retVal)); } Console.WriteLine(ret.Min()); } } }
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 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, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 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, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22]]
8
206
20
using System; namespace ConsoleApp1 { class Class1 { static void Main(string[] args) { string N = Console.ReadLine(); int numN = int.Parse(N); string W = Console.ReadLine(); string[] WList = W.Split(' '); int min = 0, S1 = 0, S2 = 0, j, k; for (int i = 1; i < numN; i++) { for (j = 0; j < i; j++) { S1 += int.Parse(WList[j]); } for (k = j + 1; k < numN; k++) { S2 += int.Parse(WList[k]); } if (i == 1) { min = Math.Abs(S1 + S2); } else if (Math.Abs(S1 + S2) < min) { min = S1 + S2; } if (min == 0) { break; } } Console.WriteLine(min); } } }
using System; namespace ConsoleApp1 { class Class1 { static void Main(string[] args) { string N = Console.ReadLine(); int numN = int.Parse(N); string W = Console.ReadLine(); string[] WList = W.Split(' '); int min = 0, S1, S2, j, k; for (int i = 1; i < numN; i++) { S1 = 0; S2 = 0; for (j = 0; j < i; j++) { S1 += int.Parse(WList[j]); } for (k = j; k < numN; k++) { S2 += int.Parse(WList[k]); } if (i == 1) { min = Math.Abs(S1 - S2); } else if (Math.Abs(S1 - S2) < min) { min = Math.Abs(S1 - S2); } if (min == 0) { break; } } Console.WriteLine(min); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 10, 11, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 10, 11, 12, 16, 12, 203], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 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], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
211
25
using System; using System.Collections.Generic; using System.Linq; public static partial class Program { public static void Main() { var n = CRL().ToInt(); var wis = CRL().ArrayInts(); var min = int.MaxValue; for (int i = 1; i <= 100; i++) { var s = wis.Where(x => x <= i).Sum(); var b = wis.Where(x => x > i).Sum(); min = Math.Min(min, Diff(s, b)); } CWL(min); } } public static partial class Program { //テンプレここから public static int Sigma(int n, int next = 1, int val = 0) => next > n? val : Sigma(n, next + 1, val + next); public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b); public static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b); public static long LCM(long a, long b) => a * b / GCD(a, b); public static int LCM(int a, int b) => a * b / GCD(a, b); public static string CRL() => Console.ReadLine(); public static void CWL(object obj) => Console.WriteLine(obj); public static int ToInt(this double d) => (int)d; public static long ToLong(this double d) => (long)d; public static int ToInt(this string str) => int.Parse(str); public static long ToLong(this string str) => long.Parse(str); public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray(); public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray(); public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong(); public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt(); public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static long Sign(this long i) => Math.Sign(i); public static bool IsEven(this long i) => i % 2 == 0; public static bool IsEven(this int i) => i % 2 == 0; public static readonly int[] Dx = new[] { 0, -1, 0, 1 }; public static readonly int[] Dy = new[] { -1, 0, 1, 0 }; public const int Mod = 1000000007; public static string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static long ToLong(this char c) => c.ToString().ToLong(); public static int ToInt(this char c) => c.ToString().ToInt(); public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray(); public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray(); public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray(); public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray(); public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array); public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array); public static string JoinToStr(this IEnumerable<int> array, string sep = "") => array.Select(x => x.ToString()).Join(sep); //テンプレここまで }
using System; using System.Collections.Generic; using System.Linq; public static partial class Program { public static void Main() { var n = CRL().ToInt(); var wis = CRL().ArrayInts(); var min = int.MaxValue; for (int i = 1; i <= n; i++) { var s = wis.Take(i).Sum(); var b = wis.Skip(i).Take(n - i).Sum(); min = Math.Min(min, Diff(s, b)); } CWL(min); } } public static partial class Program { //テンプレここから public static int Sigma(int n, int next = 1, int val = 0) => next > n? val : Sigma(n, next + 1, val + next); public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b); public static int GCD(int a, int b) => b == 0 ? a : GCD(b, a % b); public static long LCM(long a, long b) => a * b / GCD(a, b); public static int LCM(int a, int b) => a * b / GCD(a, b); public static string CRL() => Console.ReadLine(); public static void CWL(object obj) => Console.WriteLine(obj); public static int ToInt(this double d) => (int)d; public static long ToLong(this double d) => (long)d; public static int ToInt(this string str) => int.Parse(str); public static long ToLong(this string str) => long.Parse(str); public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray(); public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray(); public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong(); public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt(); public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b)); public static long Sign(this long i) => Math.Sign(i); public static bool IsEven(this long i) => i % 2 == 0; public static bool IsEven(this int i) => i % 2 == 0; public static readonly int[] Dx = new[] { 0, -1, 0, 1 }; public static readonly int[] Dy = new[] { -1, 0, 1, 0 }; public const int Mod = 1000000007; public static string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static long ToLong(this char c) => c.ToString().ToLong(); public static int ToInt(this char c) => c.ToString().ToInt(); public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray(); public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray(); public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray(); public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray(); public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array); public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array); public static string JoinToStr(this IEnumerable<int> array, string sep = "") => array.Select(x => x.ToString()).Join(sep); //テンプレここまで }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 19], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 205, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
916
21
using System; using System.Collections.Generic; using System.Globalization; using System.IO.Pipes; namespace cswork { class Program { public Program() {} Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); void Omame() { cin = new Scanner(); int n = cin.nextInt(); int m = cin.nextInt(); HashSet<int> a = new HashSet<int>(); for (int i = 0; i < m; i++) { a.Add(cin.nextInt() - 1); } long[] count = new long[n]; if (a.Contains(0)) { count[0] = 0; } else { count[0] = 1; } if (n > 1) { if (a.Contains(1)) { count[1] = 0; } else { count[1] = count[0] + 1; } } for (int i = 2; i < n; i++) { if (a.Contains(i)) { count[i] = 0; } else { count[i] = count[i - 1] + count[i - 2]; } } Console.WriteLine(count[n - 1] % 1000000007); } static void Main(string[] args) { new Program().Omame(); } public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO.Pipes; namespace cswork { class Program { public Program() {} Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); void Omame() { cin = new Scanner(); int n = cin.nextInt(); int m = cin.nextInt(); HashSet<int> a = new HashSet<int>(); for (int i = 0; i < m; i++) { a.Add(cin.nextInt() - 1); } long[] count = new long[n]; if (a.Contains(0)) { count[0] = 0; } else { count[0] = 1; } if (n > 1) { if (a.Contains(1)) { count[1] = 0; } else { count[1] = count[0] + 1; } } for (int i = 2; i < n; i++) { if (a.Contains(i)) { count[i] = 0; } else { count[i] = count[i - 1] + count[i - 2]; count[i] %= 1000000007; } } Console.WriteLine(count[n - 1]); } static void Main(string[] args) { new Program().Omame(); } public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } }
[["+", 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, 132], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
590
9
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; namespace AtCoder_Beginner_Contest_129 { class Program { static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); } static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); } static void Main(string[] args) { var NM = Sarray(); var N = NM[0]; var M = NM[1]; var am = new int[N]; for (var i = 0; i < M; ++i) { am[Sarray()[0] - 1] = 1; } var num = new long[N]; if (0 == am[0]) num[0] = 1; if (0 == am[1]) num[1] = 1 + num[0]; if (num[0] == 0 & num[1] == 0) { WriteLine(0); return; } for (var i = 2; i < N; ++i) { if (0 != am[i]) { if (0 != am[i - 1]) { WriteLine(0); return; } continue; } num[i] = (num[i - 1] + num[i - 2]) % 1000000007; } WriteLine(num[N - 1]); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; namespace AtCoder_Beginner_Contest_129 { class Program { static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); } static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); } static void Main(string[] args) { var NM = Sarray(); var N = NM[0]; var M = NM[1]; var am = new int[N]; for (var i = 0; i < M; ++i) { am[Sarray()[0] - 1] = 1; } var num = new long[N]; if (N == 1) // 1の場合 { WriteLine(1); return; } if (0 == am[0]) num[0] = 1; if (0 == am[1]) num[1] = 1 + num[0]; if (num[0] == 0 & num[1] == 0) { WriteLine(0); return; } for (var i = 2; i < N; ++i) { if (0 != am[i]) { continue; } num[i] = (num[i - 1] + num[i - 2]) % 1000000007; } WriteLine(num[N - 1]); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 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, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 79], ["-", 64, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 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], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
321
35
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = input[0], m = input[1]; int[] a = new int[m], b = new int[m + 1]; for (int i = 0; i < m; i++) a[i] = int.Parse(Console.ReadLine()); b[0] = a[0]; for (int i = 1; i < m; i++) b[i] = a[i] - a[i - 1] - 1; b[m] = n - a[m - 1]; ModInt pro = 1; for (int i = 0; i < m + 1; i++) pro *= ModInt.Fib(b[i]); Console.WriteLine((int)pro); } } struct ModInt { const int MOD = 1000000007; long value; static List<ModInt> fib = new List<ModInt> { 0, 1 }; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) => new ModInt(a % MOD + (a < 0 ? MOD : 0)); public static explicit operator int(ModInt a) => (int)a.value; public static ModInt operator +(ModInt a, ModInt b) => a.value + b.value; public static ModInt operator *(ModInt a, ModInt b) => a.value * b.value; public static ModInt Fib(int n) { for (int i = fib.Count(); i <= n; i++) fib.Add(fib[i - 2] + fib[i - 1]); return fib[n]; } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int n = input[0], m = input[1]; if (m == 0) { Console.WriteLine((int)ModInt.Fib(n + 1)); return; } int[] a = new int[m], b = new int[m + 1]; for (int i = 0; i < m; i++) a[i] = int.Parse(Console.ReadLine()); b[0] = a[0]; for (int i = 1; i < m; i++) b[i] = a[i] - a[i - 1] - 1; b[m] = n - a[m - 1]; ModInt pro = 1; for (int i = 0; i < m + 1; i++) pro *= ModInt.Fib(b[i]); Console.WriteLine((int)pro); } } struct ModInt { const int MOD = 1000000007; long value; static List<ModInt> fib = new List<ModInt> { 0, 1 }; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) => new ModInt(a % MOD + (a < 0 ? MOD : 0)); public static explicit operator int(ModInt a) => (int)a.value; public static ModInt operator +(ModInt a, ModInt b) => a.value + b.value; public static ModInt operator *(ModInt a, ModInt b) => a.value * b.value; public static ModInt Fib(int n) { for (int i = fib.Count(); i <= n; i++) fib.Add(fib[i - 2] + fib[i - 1]); return fib[n]; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 0, 28, 0, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 74, 51, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 74, 51, 213, 3, 4, 0, 24], ["+", 51, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 51, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 51, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 28, 0, 74, 51, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199]]
8
406
27
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] nm = ReadLineIntArray(); int wk = -1; int index = 0; long rtn = 0; long wk_rtn = 0; long wk_up1 = 0; long wk_up2 = 0; for (int i = 0; i < nm[1]; i++) { int next = ReadLineInt(); if (wk == next - 1) { Console.WriteLine(0); return; } if (nm[0] == next) { Console.WriteLine(0); return; } wk = next; wk_rtn = 0; for (int j = index; j < next - 1; j++) { wk_up2 = wk_up1; wk_up1 = wk_rtn; if (j == index) { wk_up1 = 1; wk_up2 = 1; wk_rtn = wk_up2; } else { wk_rtn = (wk_rtn + wk_up2) % 1000000007; } } index = next + 1; if (rtn == 0) { rtn = wk_rtn % 1000000007; } else { rtn = (rtn * wk_rtn) % 1000000007; } } wk_rtn = 0; wk_up1 = 0; wk_up2 = 0; for (int j = index; j < nm[0]; j++) { wk_up2 = wk_up1; wk_up1 = wk_rtn; if (j == index) { wk_up1 = 1; wk_up2 = 1; wk_rtn = wk_up2; } else { wk_rtn = (wk_rtn + wk_up2) % 1000000007; } } if (rtn == 0) { rtn = wk_rtn % 1000000007; } else { rtn = (rtn * wk_rtn) % 1000000007; } Console.WriteLine(rtn); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } }
using System; using System.Collections.Generic; using static System.Math; using System.Linq; using System.Text; class DandA { static void Main(string[] args) { int[] nm = ReadLineIntArray(); int wk = -1; int index = 0; long rtn = 0; long wk_rtn = 0; long wk_up1 = 0; long wk_up2 = 0; for (int i = 0; i < nm[1]; i++) { int next = ReadLineInt(); if (wk == next - 1) { Console.WriteLine(0); return; } if (nm[0] == next) { Console.WriteLine(0); return; } wk = next; wk_rtn = 0; for (int j = index; j < next - 1; j++) { wk_up2 = wk_up1; wk_up1 = wk_rtn; if (j == index) { wk_up1 = 1; wk_up2 = 1; wk_rtn = wk_up2; } else { wk_rtn = (wk_rtn + wk_up2) % 1000000007; } } if (wk_rtn == 0) { wk_rtn = 1; } index = next + 1; if (rtn == 0) { rtn = wk_rtn % 1000000007; } else { rtn = (rtn * wk_rtn) % 1000000007; } } wk_rtn = 0; wk_up1 = 0; wk_up2 = 0; for (int j = index; j < nm[0]; j++) { wk_up2 = wk_up1; wk_up1 = wk_rtn; if (j == index) { wk_up1 = 1; wk_up2 = 1; wk_rtn = wk_up2; } else { wk_rtn = (wk_rtn + wk_up2) % 1000000007; } } if (wk_rtn == 0) { wk_rtn = 1; } if (rtn == 0) { rtn = wk_rtn % 1000000007; } else { rtn = (rtn * wk_rtn) % 1000000007; } Console.WriteLine(rtn); } static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"; static string[] strAry = new string[] { "L", "R", "U", "D" }; static int[] intArray = new int[10]; static List<int> intList = new List<int>(); static Dictionary<string, int> myTable = new Dictionary<string, int>(); static HashSet<int>[] rtnArrAb = null; static HashSet<int>[] rtnArrCd = null; static private string ReadLineStr() { return Console.ReadLine(); } static private int ReadLineInt() { return int.Parse(Console.ReadLine()); } static private long ReadLineLong() { return long.Parse(Console.ReadLine()); } static private double ReadLineDouble() { return double.Parse(Console.ReadLine()); } static private string[] ReadLineStrArray() { return Console.ReadLine().Trim().Split(); } static private int[] ReadLineIntArray() { return Console.ReadLine() .Trim() .Split() .Select(a => int.Parse(a)) .ToArray(); } static private long[] ReadLineLongArray() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToArray(); } static private double[] ReadLineDoubleArray() { return Console.ReadLine() .Trim() .Split() .Select(a => double.Parse(a)) .ToArray(); } static private decimal[] ReadLineDecimalArray() { return Console.ReadLine() .Trim() .Split() .Select(a => decimal.Parse(a)) .ToArray(); } static private List<int> ReadLineIntList() { return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList(); } static private List<long> ReadLineLongList() { return Console.ReadLine() .Trim() .Split() .Select(a => long.Parse(a)) .ToList(); } static private string[][] ReadMLineStrArray(int arg) { return new int [arg].Select(_ => Console.ReadLine().Split()).ToArray(); } static private int[][] ReadMLineIntArray(int arg) { return new int [arg] .Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()) .ToArray(); } static private bool IsPrime(int num) { if (num < 2) return false; if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } static private string IntToNString(int x, int n) { var nstring = ""; var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; int r = 1; int q = x; while (q > 0) { r = q % n; nstring += numbers[r]; q = q / n; } return string.Join("", nstring.Reverse()); } static private long Gcd(long m, long n) { long temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } }
[["+", 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], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 75, 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, 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
1,163
24
using System; public class ABC129C { public static void Main(string[] args) { var str = Console.ReadLine().Split(); int n = int.Parse(str[0]); int m = int.Parse(str[1]); int[] a = new int[m]; long[] dp = new long[n + 1]; long mod = 1000000007; for (int i = 0; i < n + 1; i++) { dp[i] = 100001; } dp[0] = 1; dp[1] = 1; for (int i = 0; i < m; i++) { var str2 = Console.ReadLine(); a[i] = int.Parse(str2); dp[a[i]] = 0; } for (int i = 2; i < n + 1; i++) { if (dp[i] == 0) { continue; } else { dp[i] = dp[i - 1] + dp[i - 2]; } } Console.WriteLine(dp[n] % mod); } }
using System; public class ABC129C { public static void Main(string[] args) { var str = Console.ReadLine().Split(); int n = int.Parse(str[0]); int m = int.Parse(str[1]); int[] a = new int[m]; long[] dp = new long[n + 1]; long mod = 1000000007; for (int i = 0; i < n + 1; i++) { dp[i] = 100001; } dp[0] = 1; dp[1] = 1; for (int i = 0; i < m; i++) { var str2 = Console.ReadLine(); a[i] = int.Parse(str2); dp[a[i]] = 0; } for (int i = 2; i < n + 1; i++) { if (dp[i] == 0) { continue; } else { dp[i] = dp[i - 1] + dp[i - 2]; dp[i] = dp[i] % mod; } } Console.WriteLine(dp[n] % mod); } }
[["+", 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], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
8
239
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp86 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = st[0]; int M = st[1]; int mod = 1000000007; var a = new int[M + 3]; a[0] = -1; a[1] = 0; a[2] = 0; for (int i = 1; i <= M; i++) { a[i] = int.Parse(Console.ReadLine()); } a[M + 1] = N + 1; var X = new int[N + 1]; X[0] = 1; X[1] = 1; for (int i = 2; i < N; i++) { X[i] = (X[i - 2] % mod + X[i - 1] % mod) % mod; } // Console.WriteLine("Xの配列は" + string.Join(" ", X)); // Console.WriteLine("aの配列は" + string.Join(" ", a)); long ans = 1; if (N == 1) { Console.WriteLine(1); return; } if (N == 2) { if (M == 0) { Console.WriteLine(2); return; } else if (M == 1) { Console.WriteLine(1); return; } else { } } for (int i = 1; i <= M + 1; i++) { // Console.WriteLine("X[" + (a[i] - a[i - 1] - 1) + "] = " + X[a[i] - a[i // - 1] - 1] + "を掛けました"); if (a[i] - a[i - 1] >= 2) { ans *= X[a[i] - a[i - 1] - 2]; ans %= mod; } if (a[i] - a[i - 1] == 1) { ans *= 0; Console.WriteLine(0); return; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp86 { class Program { static void Main(string[] args) { var st = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = st[0]; int M = st[1]; int mod = 1000000007; var a = new int[M + 3]; a[0] = -1; a[1] = 0; a[2] = 0; for (int i = 1; i <= M; i++) { a[i] = int.Parse(Console.ReadLine()); } a[M + 1] = N + 1; var X = new int[N + 1]; X[0] = 1; X[1] = 1; for (int i = 2; i <= N; i++) { X[i] = (X[i - 2] % mod + X[i - 1] % mod) % mod; } // Console.WriteLine("Xの配列は" + string.Join(" ", X)); // Console.WriteLine("aの配列は" + string.Join(" ", a)); long ans = 1; if (M == 0) { Console.WriteLine(X[N]); return; } if (N == 1) { Console.WriteLine(1); return; } if (N == 2) { if (M == 0) { Console.WriteLine(2); return; } else if (M == 1) { Console.WriteLine(1); return; } else { } } for (int i = 1; i <= M + 1; i++) { // Console.WriteLine("X[" + (a[i] - a[i - 1] - 1) + "] = " + X[a[i] - a[i // - 1] - 1] + "を掛けました"); if (a[i] - a[i - 1] >= 2) { ans *= X[a[i] - a[i - 1] - 2]; ans %= mod; } if (a[i] - a[i - 1] == 1) { ans *= 0; Console.WriteLine(0); return; } } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
404
22
using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Typical_Stairs2 { class Program { static void Main(string[] args) { //以下入力時の処理 string input = ReadLine(); string[] array = input.Split(' '); var totalStep = ulong.Parse(array[0]); //零段目を抜いた段数の総数なので+1 var totalBrokenStep = ulong.Parse(array[1]); //壊れた段の総数 var step = new ulong[totalStep + 1]; //零段目も含めた段数分の箱を用意 var brokenStep = new ulong[totalBrokenStep + 2]; //壊れた階段用の箱を用意 for (ulong i = 0; i < totalBrokenStep; i++) { brokenStep[i] = ulong.Parse(ReadLine()); //一行ずつ読み込み } //壊れた階段段数を記録 step[0] = 1; // 0段目は一通りなので //以下」一段目以降の処理// ulong count = 0; //壊れた階段==処理中の段数となったときに比較する壊れた段数を次に移すために使う for (ulong j = 1; j < totalStep + 1; j++) { if (j < 2) { step[j] = step[j - 1]; // totalStep==1の時step[j-2]は存在しない } else { step[j] = step[j - 1] + step[j - 2]; //一つ前への行き方と二つ前への生き方の総和を代入 } if (j == brokenStep[count]) { // j段目の値==壊れた階段の時にstep[j]=0を代入 step[j] = 0; count++; //処理する段数を次に移すうつす } } ulong N = 1000000007; ///定数 WriteLine(step[totalStep] % N); //結果を表示 ReadKey(); } } }
using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Typical_Stairs2 { class Program { static void Main(string[] args) { //以下入力時の処理 string input = ReadLine(); string[] array = input.Split(' '); var totalStep = int.Parse(array[0]); //零段目を抜いた段数の総数なので+1 var totalBrokenStep = int.Parse(array[1]); //壊れた段の総数 var step = new long[totalStep + 1]; //零段目も含めた段数分の箱を用意 var brokenStep = new int[totalBrokenStep + 2]; //壊れた階段用の箱を用意 for (int i = 0; i < totalBrokenStep; i++) { brokenStep[i] = int.Parse(ReadLine()); //一行ずつ読み込み } //壊れた階段段数を記録 step[0] = 1; // 0段目は一通りなので //以下」一段目以降の処理// int N = 1000000007; ///定数 int count = 0; //壊れた階段==処理中の段数となったときに比較する壊れた段数を次に移すために使う for (int j = 1; j < totalStep + 1; j++) { if (j < 2) { step[j] = step[j - 1]; // totalStep==1の時step[j-2]は存在しない } else { step[j] = step[j - 1] + step[j - 2] % N; //一つ前への行き方と二つ前への生き方の総和を代入 } if (j == brokenStep[count]) { // j段目の値==壊れた階段の時にstep[j]=0を代入 step[j] = 0; count++; //処理する段数を次に移すうつす } } WriteLine(step[totalStep] % N); //結果を表示 ReadKey(); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 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, 1, 0, 11, 12, 16, 12, 16, 17, 109], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 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]]
8
276
28
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static int[] stairs; static void Main(string[] args) { //入力を受け取る int[] NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = NM[0]; int M = NM[1]; stairs = new int[N + 1]; stairs[0] = 1; stairs[1] = 1; for (int i = 2; i < N + 1; i++) { stairs[i] = -1; } for (int i = 1; i < M + 1; i++) { var num = int.Parse(Console.ReadLine()); stairs[num] = 0; } Console.WriteLine(CountWay(N)); } static int CountWay(int dan) { if (stairs[dan] != -1) { return stairs[dan]; } else { stairs[dan] = CountWay(dan - 1) + CountWay(dan - 2); return stairs[dan]; } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using E = System.Linq.Enumerable; class Program { static long[] stairs; const long beki = 1000000007; static void Main(string[] args) { //入力を受け取る int[] NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int N = NM[0]; int M = NM[1]; stairs = new long[N + 1]; stairs[0] = 1; stairs[1] = 1; for (int i = 2; i < N + 1; i++) { stairs[i] = -1; } for (int i = 1; i < M + 1; i++) { var num = int.Parse(Console.ReadLine()); stairs[num] = 0; } Console.WriteLine(CountWay(N)); } static long CountWay(long dan) { if (stairs[dan] != -1) { return stairs[dan] % beki; } else { stairs[dan] = CountWay(dan - 1) + CountWay(dan - 2); return stairs[dan] % beki; } } }
[["-", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 251, 0, 154], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 208, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["+", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["-", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 0, 57, 64, 196, 0, 37, 0, 16, 17, 109], ["+", 0, 57, 64, 196, 0, 37, 0, 16, 12, 22], ["+", 0, 57, 75, 196, 0, 37, 0, 16, 17, 109], ["+", 0, 57, 75, 196, 0, 37, 0, 16, 12, 22]]
8
257
18