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 static System.Console; using System.Linq; namespace AtCoder { public class sora { static void Main(string[] args) { int N = int.Parse(ReadLine()); long[] A = ReadLine().Split(' ').Select(long.Parse).ToArray(); long check = 1; long ans = 1; for (int i = 0; i < N; i++) { if (A[i] == 0) { ans = 0; break; } } for (int i = 0; i < N; i++) { ans *= A[i]; if (ans / A[i] != check || 1000000000000000000 < ans) { ans = -1; break; } check *= A[i]; } WriteLine(ans); } } }
using System; using static System.Console; using System.Linq; namespace AtCoder { public class sora { static void Main(string[] args) { int N = int.Parse(ReadLine()); long[] A = ReadLine().Split(' ').Select(long.Parse).ToArray(); long check = 1; long ans = 1; for (int i = 0; i < N; i++) { if (A[i] == 0) { ans = 0; break; } } if (ans != 0) { for (int i = 0; i < N; i++) { ans *= A[i]; if (ans / A[i] != check || 1000000000000000000 < ans) { ans = -1; break; } check *= A[i]; } } 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, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46]]
8
175
8
//解けなかった using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { int N = int.Parse(ReadLine()); long[] A = ReadLine().Split(' ').Select(long.Parse).ToArray(); long ans = 1; if (Array.IndexOf(A, 0) != -1) { WriteLine(0); return; } try { for (int i = 0; i < N; i++) { checked { ans *= A[i]; } } } catch (OverflowException ex) { WriteLine(-1); return; } WriteLine(ans); } } }
//解けなかった using System; using static System.Console; using System.Linq; namespace AC { public class shiokara { static void Main(string[] args) { int N = int.Parse(ReadLine()); long[] A = ReadLine().Split(' ').Select(long.Parse).ToArray(); long ans = 1; if (Array.IndexOf(A, 0) != -1) { WriteLine(0); return; } try { for (int i = 0; i < N; i++) { checked { ans *= A[i]; } } } catch (OverflowException ex) { WriteLine(-1); return; } if (ans >= 1000000000000000001) WriteLine(-1); else 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, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 213, 63, 22]]
8
151
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { long limit = 1000000000000000000; long sum = 1; long n = long.Parse(Console.ReadLine()); long[] arr = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); if (arr.Contains(0)) { Console.WriteLine(0); return; } for (int i = 0; i < n; i++) { sum *= arr[i]; if (sum > limit) { sum = -1; break; } } Console.WriteLine(sum); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { long limit = 1000000000000000000; long sum = 1; long n = long.Parse(Console.ReadLine()); long[] arr = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); if (arr.Contains(0)) { Console.WriteLine(0); return; } for (int i = 0; i < n; i++) { if (sum > limit / arr[i]) { sum = -1; break; } sum *= arr[i]; } Console.WriteLine(sum); } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 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], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 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]]
8
158
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static System.Array; class Program { public static void Main() { ReadLine(); var n = ReadLine().Split().Select(long.Parse).ToArray(); if (n.Where(x => x == 0).Count() > 0) { WriteLine("0"); return; } long result = 1; for (int i = 0; i < n.Length; i++) { try { result *= n[i]; if (1000000000000000000L < result) { WriteLine("-1"); return; } } catch (OverflowException e) { WriteLine("-1"); return; } } WriteLine($"{result}"); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static System.Array; class Program { public static void Main() { ReadLine(); var n = ReadLine().Split().Select(long.Parse).ToArray(); Sort(n); if (n[0] == 0) { WriteLine("0"); return; } long result = 1; for (int i = 0; i < n.Length; i++) { try { checked { result *= n[i]; if (1000000000000000000L < result) { WriteLine("-1"); return; } } } catch { WriteLine("-1"); return; } } WriteLine($"{result}"); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 31, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 31, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 31, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 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, 60], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 141, 22], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 0, 25]]
8
181
28
using System; class Class2 { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); long calc = 1; long max = (long)Math.Pow(10, 18); for (int i = 1; i <= N; i++) { long a = long.Parse(input[i - 1]); if (a == 0) { calc = 0; break; } if (calc == -1) { continue; } calc = calc * a; if (calc > max) { calc = -1; } } Console.WriteLine((calc).ToString()); } }
using System; class Class2 { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); long calc = 1; long max = (long)Math.Pow(10, 18); for (int i = 0; i < N; i++) { long a = long.Parse(input[i]); if (a == 0) { calc = 0; break; } if (calc == -1) { continue; } try { checked { calc = calc * a; } } catch (OverflowException) { calc = -1; } if (calc > max) { calc = -1; } } Console.WriteLine((calc).ToString()); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 25], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 0, 248, 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, 241, 0, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 46]]
8
158
23
using System; using System.Collections.Generic; using System.Linq; namespace easy_Atcoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] A = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long sum = A[0]; bool flag = true; for (int i = 1; i < N; i++) { try { checked { sum = sum * A[i]; } } catch { flag = false; break; } } if (sum > 1000000000000000000) { flag = false; } Console.WriteLine(flag ? sum : -1); // int[] AB = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // Console.WriteLine(AB[0]*AB[1]); } // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse); // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // long N = NK[0]; // long K = NK[1]; // long K = long.Parse(Console.ReadLine()); // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // string S = Console.ReadLine(); // int x = int.Parse(Console.ReadLine()); // int b = int.Parse(Console.ReadLine()); // int N = int.Parse(Console.ReadLine()); // float N = float.Parse(Console.ReadLine()); // string c = Console.ReadLine(); // string B = Console.ReadLine(); // string[] s = Console.ReadLine().Split(); // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), // Console.ReadLine() }).Select(float.Parse); float[] a = // Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X = // Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new // int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[] // s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new // Dictionary<long,long>(); for(int i=0;i<s[0];i++){ // long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];} // else{hs.Add(q[0],q[1]);} // } // //最小公倍数 // static long Lcm(long a, long b) // { // return a/Gcd(a,b)*b; // } // //最大公約数 // static long Gcd(long m, long n) // { // if(n==0)return m; // return Gcd(n,m%n); // } } }
using System; using System.Collections.Generic; using System.Linq; namespace easy_Atcoder { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] A = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long sum = A[0]; bool flag = true; if (A.Count(x => x == 0) > 0) { sum = 0; } else { for (int i = 1; i < N; i++) { try { checked { sum = sum * A[i]; } } catch { flag = false; break; } } if (sum > 1000000000000000000) { flag = false; } } Console.WriteLine(flag ? sum : -1); // int[] AB = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // Console.WriteLine(AB[0]*AB[1]); } // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse); // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // long N = NK[0]; // long K = NK[1]; // long K = long.Parse(Console.ReadLine()); // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse); // string S = Console.ReadLine(); // int x = int.Parse(Console.ReadLine()); // int b = int.Parse(Console.ReadLine()); // int N = int.Parse(Console.ReadLine()); // float N = float.Parse(Console.ReadLine()); // string c = Console.ReadLine(); // string B = Console.ReadLine(); // string[] s = Console.ReadLine().Split(); // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), // Console.ReadLine() }).Select(float.Parse); float[] a = // Array.ConvertAll(Console.ReadLine().Split(),float.Parse); var X = // Console.ReadLine(); int[,] abcd = new int[NMQ[2],4]; int[] A = new // int[NMQ[0]]; int[] A_num = new int[NMQ[0]]; long[] // s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); var hs=new // Dictionary<long,long>(); for(int i=0;i<s[0];i++){ // long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse); // if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];} // else{hs.Add(q[0],q[1]);} // } // //最小公倍数 // static long Lcm(long a, long b) // { // return a/Gcd(a,b)*b; // } // //最大公約数 // static long Gcd(long m, long n) // { // if(n==0)return m; // return Gcd(n,m%n); // } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 31, 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, 60], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 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, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
8
187
24
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Math; using static System.Console; using static exMath; using static exReadLine; class Program { static void Main(string[] args) { int N; intReadLine(out N); long[] A; longArrayReadLine(out A); long ans = A[0]; long t = (long)Pow(10, 18); if (A.Contains(0)) { ans = 0; } else { for (long i = 1; i < N; i++) { ans *= A[i]; if (ans > t) { ans = -1; break; } } } WriteLine(ans); } } static class exReadLine { public static void intReadLine(out int a) { a = int.Parse(ReadLine()); } public static void intReadLine(out int a, out int b) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); a = input[0]; b = input[1]; } public static void intReadLine(out int a, out int b, out int c) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); a = input[0]; b = input[1]; c = input[2]; } public static void intReadLine(out int a, out int b, out int c, out int d) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void longReadLine(out long a) { a = long.Parse(ReadLine()); } public static void longReadLine(out long a, out long b) { long[] input = ReadLine().Split().Select(long.Parse).ToArray(); a = input[0]; b = input[1]; } public static void longReadLine(out long a, out long b, out long c) { long[] input = ReadLine().Split().Select(long.Parse).ToArray(); a = input[0]; b = input[1]; c = input[2]; } public static void longReadLine(out long a, out long b, out long c, out long d) { long[] input = ReadLine().Split().Select(long.Parse).ToArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void intArrayReadLine(out int[] a) { a = ReadLine().Split().Select(int.Parse).ToArray(); } public static void longArrayReadLine(out long[] a) { a = ReadLine().Split().Select(long.Parse).ToArray(); } public static void intListReadLine(out List<int> a) { a = ReadLine().Split().Select(int.Parse).ToList(); } public static void longListReadLine(out List<long> a) { a = ReadLine().Split().Select(long.Parse).ToList(); } } static class exMath { // 最大公約数 public static int Gcd(int a, int b) { if (a < b) return Gcd(b, a); while (b != 0) { var r = a % b; a = b; b = r; } return a; } public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); while (b != 0) { var r = a % b; a = b; b = r; } return a; } // 最小公倍数 public static long Lcm(int a, int b) { return BigMul(a, b) / Gcd(a, b); } public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Math; using static System.Console; using static exMath; using static exReadLine; class Program { static void Main(string[] args) { int N; intReadLine(out N); long[] A; longArrayReadLine(out A); long ans = A[0]; long t = (long)Pow(10, 18); if (A.Contains(0)) { ans = 0; } else { for (long i = 1; i < N; i++) { try { checked { ans *= A[i]; if (ans > t) { ans = -1; break; } } } catch { ans = -1; break; } } } WriteLine(ans); } } static class exReadLine { public static void intReadLine(out int a) { a = int.Parse(ReadLine()); } public static void intReadLine(out int a, out int b) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); a = input[0]; b = input[1]; } public static void intReadLine(out int a, out int b, out int c) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); a = input[0]; b = input[1]; c = input[2]; } public static void intReadLine(out int a, out int b, out int c, out int d) { int[] input = ReadLine().Split().Select(int.Parse).ToArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void longReadLine(out long a) { a = long.Parse(ReadLine()); } public static void longReadLine(out long a, out long b) { long[] input = ReadLine().Split().Select(long.Parse).ToArray(); a = input[0]; b = input[1]; } public static void longReadLine(out long a, out long b, out long c) { long[] input = ReadLine().Split().Select(long.Parse).ToArray(); a = input[0]; b = input[1]; c = input[2]; } public static void longReadLine(out long a, out long b, out long c, out long d) { long[] input = ReadLine().Split().Select(long.Parse).ToArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void intArrayReadLine(out int[] a) { a = ReadLine().Split().Select(int.Parse).ToArray(); } public static void longArrayReadLine(out long[] a) { a = ReadLine().Split().Select(long.Parse).ToArray(); } public static void intListReadLine(out List<int> a) { a = ReadLine().Split().Select(int.Parse).ToList(); } public static void longListReadLine(out List<long> a) { a = ReadLine().Split().Select(long.Parse).ToList(); } } static class exMath { // 最大公約数 public static int Gcd(int a, int b) { if (a < b) return Gcd(b, a); while (b != 0) { var r = a % b; a = b; b = r; } return a; } public static long Gcd(long a, long b) { if (a < b) return Gcd(b, a); while (b != 0) { var r = a % b; a = b; b = r; } return a; } // 最小公倍数 public static long Lcm(int a, int b) { return BigMul(a, b) / Gcd(a, b); } public static long Lcm(long a, long b) { return a * b / Gcd(a, b); } }
[["+", 75, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 287, 0, 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, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 287, 0, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249]]
8
899
16
using System; using System.Linq; namespace ProblemB { class Program { static void Main() { long N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long ans = 1; if (A.Contains(0)) { Console.WriteLine(0); return; } for (int i = 0; i < N; i++) { if (Math.Log10(ans) + Math.Log10(A[i]) >= 18 && ans * A[i] > (long)Math.Pow(10, 18)) { Console.WriteLine(-1); return; } else { ans *= A[i]; } } if (Math.Log10(ans) >= 18 && ans > (long)Math.Pow(10, 18)) { Console.WriteLine(-1); return; } else { Console.WriteLine(ans); } } } }
using System; using System.Linq; namespace ProblemB { class Program { static void Main() { long N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long ans = 1; if (A.Contains(0)) { Console.WriteLine(0); return; } for (int i = 0; i < N; i++) { if (Math.Log10(ans) + Math.Log10(A[i]) > 18 || ans * A[i] > (long)Math.Pow(10, 18)) { Console.WriteLine(-1); return; } else { ans *= A[i]; } } if (ans > (long)Math.Pow(10, 18)) { Console.WriteLine(-1); return; } else { Console.WriteLine(ans); } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 15, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["-", 15, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["-", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["-", 15, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["-", 31, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["-", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
8
214
13
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Threading; namespace ForATCODER { public class Program { /// template /// /// String[] s = Console.ReadLine().Split(' '); /// long[] nk = s2larray(Console.ReadLine().Split(' ')); /// public static void Main(string[] args) { long n = s2i(Console.ReadLine()); long[] nm = s2larray(Console.ReadLine().Split(" ")); ulong er = (ulong)Math.Pow(10, 18); ulong result = (ulong)nm[0]; // zero check for (long i = 0; i < n; i++) { if (nm[i] == 0) { RESULT(0); return; }; } for (long i = 1; i < n; i++) { result *= (ulong)nm[i]; if (result < 0 || result > er) { RESULT(-1); return; }; } RESULT(result); } class TreeNode<T> { List<TreeNode<T>> Children; T Item { get; set; } public TreeNode(T item) { Item = item; } public TreeNode<T> AddChild(T item) { TreeNode<T> nodeItem = new TreeNode<T>(item); Children.Add(nodeItem); return nodeItem; } public void AddChildRelative(TreeNode<T> item) { Children.Add(item); } public List<TreeNode<T>> GetChildren(T val) { if (val.Equals(Item)) { var l = new List<TreeNode<T>>(); l.Add(this); return l; } return Children.FindAll(x => x.Item.Equals(val)); } } static void addarray(long[] arr, int start, int end) { for (int i = start; i <= end; i++) { arr[i]++; } } public static decimal Sqrt(decimal x) { decimal sqrt_x = (decimal)Math.Sqrt((long)x); for (int i = 0; i < 10; ++i) sqrt_x = 0.5m * (sqrt_x + x / sqrt_x); return sqrt_x; } static long summ(long s) { if (s == 1) return 1; return s + summ(s - 1); } public static bool checka(int[] a, int m) { int back = 1; for (int i = 0; i < a.Length; i++) { if (a[i] >= 1 && a[i] <= m) { if (a[i] >= back) { back = a[i]; } else { return false; } } else { return false; } } return true; } public static ulong pow(int a, int b) { ulong res = 1; for (int i = 0; i < b; i++) { res *= (ulong)a; } return res; } static int s2i(String s) { return Convert.ToInt32(s); } static long s2l(String s) { return Convert.ToInt64(s); } static void RESULT(double res) { Console.WriteLine(res); } static void RESULT(long res) { Console.WriteLine(res); } static void RESULT(ulong res) { Console.WriteLine(res); } static void RESULT(int res) { Console.WriteLine(res); } static void RESULT(String res) { Console.WriteLine(res); } static String[] ReadLineAll(int count) { String[] res = new String[count]; for (int i = 0; i < count; i++) { res[i] = Console.ReadLine(); } return res; } static int[] s2iarray(String[] src) { int len = src.Length; int[] res = new int[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt32(src[i]); } return res; } static long[] s2larray(String[] src) { int len = src.Length; long[] res = new long[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt64(src[i]); } return res; } static ulong[] s2larray2(String[] src) { int len = src.Length; ulong[] res = new ulong[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToUInt64(src[i]); } return res; } static long C(int n, int r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } static long C(long n, long r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } static ulong C(ulong n, ulong r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) ulong ans = 1; ulong i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Threading; namespace ForATCODER { public class Program { /// template /// /// String[] s = Console.ReadLine().Split(' '); /// long[] nk = s2larray(Console.ReadLine().Split(' ')); /// public static void Main(string[] args) { long n = s2i(Console.ReadLine()); long[] nm = s2larray(Console.ReadLine().Split(" ")); ulong er = (ulong)Math.Pow(10, 18); ulong result = (ulong)nm[0]; // zero check for (long i = 0; i < n; i++) { if (nm[i] == 0) { RESULT(0); return; }; } for (long i = 1; i < n; i++) { // check ulong sub = er - result; double nn = sub / result; if (nn + 10 < (ulong)nm[i]) { RESULT(-1); return; }; result *= (ulong)nm[i]; if (result < 0 || result > er) { RESULT(-1); return; }; } RESULT(result); } class TreeNode<T> { List<TreeNode<T>> Children; T Item { get; set; } public TreeNode(T item) { Item = item; } public TreeNode<T> AddChild(T item) { TreeNode<T> nodeItem = new TreeNode<T>(item); Children.Add(nodeItem); return nodeItem; } public void AddChildRelative(TreeNode<T> item) { Children.Add(item); } public List<TreeNode<T>> GetChildren(T val) { if (val.Equals(Item)) { var l = new List<TreeNode<T>>(); l.Add(this); return l; } return Children.FindAll(x => x.Item.Equals(val)); } } static void addarray(long[] arr, int start, int end) { for (int i = start; i <= end; i++) { arr[i]++; } } public static decimal Sqrt(decimal x) { decimal sqrt_x = (decimal)Math.Sqrt((long)x); for (int i = 0; i < 10; ++i) sqrt_x = 0.5m * (sqrt_x + x / sqrt_x); return sqrt_x; } static long summ(long s) { if (s == 1) return 1; return s + summ(s - 1); } public static bool checka(int[] a, int m) { int back = 1; for (int i = 0; i < a.Length; i++) { if (a[i] >= 1 && a[i] <= m) { if (a[i] >= back) { back = a[i]; } else { return false; } } else { return false; } } return true; } public static ulong pow(int a, int b) { ulong res = 1; for (int i = 0; i < b; i++) { res *= (ulong)a; } return res; } static int s2i(String s) { return Convert.ToInt32(s); } static long s2l(String s) { return Convert.ToInt64(s); } static void RESULT(double res) { Console.WriteLine(res); } static void RESULT(long res) { Console.WriteLine(res); } static void RESULT(ulong res) { Console.WriteLine(res); } static void RESULT(int res) { Console.WriteLine(res); } static void RESULT(String res) { Console.WriteLine(res); } static String[] ReadLineAll(int count) { String[] res = new String[count]; for (int i = 0; i < count; i++) { res[i] = Console.ReadLine(); } return res; } static int[] s2iarray(String[] src) { int len = src.Length; int[] res = new int[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt32(src[i]); } return res; } static long[] s2larray(String[] src) { int len = src.Length; long[] res = new long[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToInt64(src[i]); } return res; } static ulong[] s2larray2(String[] src) { int len = src.Length; ulong[] res = new ulong[len]; for (int i = 0; i < len; i++) { res[i] = Convert.ToUInt64(src[i]); } return res; } static long C(int n, int r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } static long C(long n, long r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } static ulong C(ulong n, ulong r) { if (n <= 1) return 0; if (r > n - r) r = n - r; // because C(n, r) == C(n, n - r) ulong ans = 1; ulong i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } } }
[["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 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, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 39, 199], ["+", 8, 196, 0, 57, 15, 16, 12, 74, 0, 25], ["+", 0, 57, 15, 16, 12, 74, 51, 204, 205, 22], ["+", 15, 16, 12, 74, 51, 204, 206, 207, 0, 70], ["+", 12, 74, 51, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 74, 51, 204, 206, 207, 0, 73], ["+", 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, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 260, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22]]
8
1,195
39
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ABC169B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine().Trim()); List<ulong> x = new List<ulong>(); var t = Console.ReadLine().Trim().Split(' '); for (int i = 0; i < N; i++) { x.Add(ulong.Parse(t[i])); if (ulong.Parse(t[i]) == 0) { Console.WriteLine("0"); return; } } ulong c = 1ul; double c2 = 0.0; foreach (var k in x) { c *= k; c2 += Math.Log10((double)k); if (c2 > 18.0 || c > 1000000000000000000ul) { Console.WriteLine("-1"); return; } } Console.WriteLine(c); Console.WriteLine(c2); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ABC169B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine().Trim()); List<ulong> x = new List<ulong>(); var t = Console.ReadLine().Trim().Split(' '); for (int i = 0; i < N; i++) { x.Add(ulong.Parse(t[i])); if (ulong.Parse(t[i]) == 0) { Console.WriteLine("0"); return; } } ulong c = 1ul; double c2 = 0.0; foreach (var k in x) { c2 += Math.Log10((double)k); if (c2 > 18.0) { Console.WriteLine("-1"); return; } c *= k; if (c > 1000000000000000000ul) { Console.WriteLine("-1"); return; } } Console.WriteLine(c); // Console.WriteLine(c2); } } }
[["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 210, 8, 196, 0, 46], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
221
30
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; namespace AtCoder_1 { class Program { static void Main(string[] args) { var N = CinL(); var A = CinLAr(); long q = 1; try { checked { for (int i = 0; i < N; i++) { q *= A[i]; if (q > 1000000000000000000L) { q = -1; break; } } } } catch { q = -1; } Cout(q); Cin(); } // main static readonly int MOD10_9_7 = (1000000000 + 7); static Random Rand = new Random(); static readonly string[] AlphabetTable = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; static int GetDigits(long num) { return (int)Floor(Log10(num)) + 1; } static int GetNumByDigit(long num, int digit) { return (int)((num / ((int)Pow(10, digit - 1))) % 10); } static int Loop(int num, int max) { if (num > max) { return num % max - 1; } else if (num < 0) { return max - (-num) % max + 1; } else { return num; } } static long GCD(long a, long b) { if (a < b) { return GCD(b, a); } if (a % b == 0) { return b; } else { return GCD(b, a % b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void SwapArE<T>(T[] a, int i, int j) { T t = a[i]; a[i] = a[j]; a[j] = t; } static void SwapLiE<T>(List<T> a, int i, int j) { T t = a[i]; a[i] = a[j]; a[j] = t; } static bool IsInt(double d) { return (int)d == d; } static string Cin() { return ReadLine(); } static string[] CinAr() { return ReadLine().Split(' '); } static int CinT() { return S2i(Cin()); } static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); } static long CinL() { return S2L(Cin()); } static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); } static double CinD() { return S2D(Cin()); } static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); } static int S2i(string s) { return int.Parse(s); } static long S2L(string s) { return long.Parse(s); } static double S2D(string s) { return double.Parse(s); } static void Cout(object s) { WriteLine(s); } static string RevStr(string s) { return new string(s.Reverse().ToArray()); } static long[] Divisor(long n) { if (n == 1) { return new long[] { 1 }; } List<long> res = new List<long>() { 1 }; for (long i = 2; i <= n / 2 + 1; i++) { if (n % i == 0) { res.Add(i); } } res.Add(n); return res.ToArray(); } static bool IsPrime(long num) { if (num == 1) { return false; } for (long i = 2; i <= Sqrt(num) + 1; i++) { if (num % i == 0) { return false; } } return true; } static void CoutAr<Type>(IEnumerable<Type> types) { Cout(string.Join(" ", types)); } public static long nCr(int n, int r) { return nPr(n, r) / Factorial(r); } public static long nPr(int n, int r) { return FactorialDivision(n, n - r); } private static long FactorialDivision(int topFactorial, int divisorFactorial) { long r = 1; for (int i = topFactorial; i > divisorFactorial; i--) { r *= i; } return r; } private static long Factorial(int i) { if (i <= 1) { return 1; } return i * Factorial(i - 1); } public static void CoutMemPairAr<Type>(IEnumerable<Pair<Type>> pairs) { var ar = pairs.ToArray(); for (int i = 0; i < ar.Length; i++) { Write($"({ar[i].a}, {ar[i].b}, {ar[i].c}), "); } Cout(""); } } public struct Pair<T> { public T a, b, c; public Pair(T _a, T _b, T _c = default(T)) { a = _a; b = _b; c = _c; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; namespace AtCoder_1 { class Program { static void Main(string[] args) { var N = CinL(); var A = CinLAr(); long q = 1; Array.Sort(A); try { checked { for (int i = 0; i < N; i++) { q *= A[i]; if (q > 1000000000000000000L) { q = -1; break; } } } } catch { q = -1; } Cout(q); Cin(); } // main static readonly int MOD10_9_7 = (1000000000 + 7); static Random Rand = new Random(); static readonly string[] AlphabetTable = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; static int GetDigits(long num) { return (int)Floor(Log10(num)) + 1; } static int GetNumByDigit(long num, int digit) { return (int)((num / ((int)Pow(10, digit - 1))) % 10); } static int Loop(int num, int max) { if (num > max) { return num % max - 1; } else if (num < 0) { return max - (-num) % max + 1; } else { return num; } } static long GCD(long a, long b) { if (a < b) { return GCD(b, a); } if (a % b == 0) { return b; } else { return GCD(b, a % b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static void SwapArE<T>(T[] a, int i, int j) { T t = a[i]; a[i] = a[j]; a[j] = t; } static void SwapLiE<T>(List<T> a, int i, int j) { T t = a[i]; a[i] = a[j]; a[j] = t; } static bool IsInt(double d) { return (int)d == d; } static string Cin() { return ReadLine(); } static string[] CinAr() { return ReadLine().Split(' '); } static int CinT() { return S2i(Cin()); } static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); } static long CinL() { return S2L(Cin()); } static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); } static double CinD() { return S2D(Cin()); } static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); } static int S2i(string s) { return int.Parse(s); } static long S2L(string s) { return long.Parse(s); } static double S2D(string s) { return double.Parse(s); } static void Cout(object s) { WriteLine(s); } static string RevStr(string s) { return new string(s.Reverse().ToArray()); } static long[] Divisor(long n) { if (n == 1) { return new long[] { 1 }; } List<long> res = new List<long>() { 1 }; for (long i = 2; i <= n / 2 + 1; i++) { if (n % i == 0) { res.Add(i); } } res.Add(n); return res.ToArray(); } static bool IsPrime(long num) { if (num == 1) { return false; } for (long i = 2; i <= Sqrt(num) + 1; i++) { if (num % i == 0) { return false; } } return true; } static void CoutAr<Type>(IEnumerable<Type> types) { Cout(string.Join(" ", types)); } public static long nCr(int n, int r) { return nPr(n, r) / Factorial(r); } public static long nPr(int n, int r) { return FactorialDivision(n, n - r); } private static long FactorialDivision(int topFactorial, int divisorFactorial) { long r = 1; for (int i = topFactorial; i > divisorFactorial; i--) { r *= i; } return r; } private static long Factorial(int i) { if (i <= 1) { return 1; } return i * Factorial(i - 1); } public static void CoutMemPairAr<Type>(IEnumerable<Pair<Type>> pairs) { var ar = pairs.ToArray(); for (int i = 0; i < ar.Length; i++) { Write($"({ar[i].a}, {ar[i].b}, {ar[i].c}), "); } Cout(""); } } public struct Pair<T> { public T a, b, c; public Pair(T _a, T _b, T _c = default(T)) { a = _a; b = _b; c = _c; } } }
[["+", 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,318
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemB { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long res = As[0]; bool exceedLimit = false; if (As.Contains(0)) Console.WriteLine(0); else if (res > 1000000000000000000) Console.WriteLine(-1); else { for (int i = 1; i < As.Length; i++) { res *= As[i]; if (res > 1000000000000000000) { exceedLimit = true; break; } } Console.WriteLine(exceedLimit ? -1 : res); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemB { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var As = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long res = As[0]; bool exceedLimit = false; if (As.Contains(0)) Console.WriteLine(0); else if (res > 1000000000000000000) Console.WriteLine(-1); else { for (int i = 1; i < As.Length; i++) { if (As[i] > 1000000000000000000 / res) { exceedLimit = true; break; } else res *= As[i]; } Console.WriteLine(exceedLimit ? -1 : res); } } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 75, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 75, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 75, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 57, 75, 1, 0, 11, 12, 204, 205, 22], ["+", 75, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 75, 1, 0, 35]]
8
190
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long N = inputArray[0]; var numArray = retreiveLongArray(); // 0を含む場合は0を返す if (numArray.Contains(0)) { Console.WriteLine(0); return; } long ans = 1; var log10Ans = Math.Log10(ans); for (int i = 0; i < N; i++) { var log10I = Math.Log10(numArray[i]); if (log10Ans + log10I > 18) { Console.WriteLine(-1); return; } ans = ans * numArray[i]; if (ans > 1000000000000000000) { Console.WriteLine(-1); return; } } //答えの出力 Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long N = inputArray[0]; var numArray = retreiveLongArray(); // 0を含む場合は0を返す if (numArray.Contains(0)) { Console.WriteLine(0); return; } long ans = 1; var log10Ans = Math.Log10(ans); for (int i = 0; i < N; i++) { var log10I = Math.Log10(numArray[i]); if (log10Ans + log10I > 18) { Console.WriteLine(-1); return; } ans = ans * numArray[i]; if (ans > 1000000000000000000) { Console.WriteLine(-1); return; } log10Ans = Math.Log10(ans); } //答えの出力 Console.WriteLine(ans); } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } } }
[["+", 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], ["+", 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, 7, 8, 196, 0, 1, 0, 35]]
8
302
9
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var n = IO.RInt; var a = IO.RSLong; if (a.Contains(0)) { WriteLine(0); return; } long ans = 1; for (int i = 0; i < n; i++) { ans *= a[i]; if (ans > 1000000000000000000) { WriteLine(-1); return; } } WriteLine(ans); } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using static System.Console; using static System.Math; namespace Atcoder { class Program { static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; static void Main(string[] args) { try { SetOut(sw); Solve.Answer(); Out.Flush(); } catch (Exception ex) { WriteLine(ex.ToString()); } } } public class Solve { public static void Answer() { var n = IO.RInt; var a = IO.RSLong; if (a.Contains(0)) { WriteLine(0); return; } long ans = 1; for (int i = 0; i < n; i++) { try { checked { ans *= a[i]; if (ans > 1000000000000000000) { WriteLine(-1); return; } } } catch (OverflowException ex) { WriteLine(-1); return; } } WriteLine(ans); } public class IO { #region Input public static int RInt => int.Parse(ReadLine()); public static long RLong => long.Parse(ReadLine()); public static double RDouble => double.Parse(ReadLine()); public static string[] RSString => ReadLine().Split(); public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray(); public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray(); public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray(); #endregion #region Output public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list)); public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No"); public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO"); #endregion } public class Mod { #region private readonly static long M = 1000000007; public static long Add(long a, long b) => (a * b) % M; public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M; public static long Multi(long a, long b) => (a * b) % M; #endregion } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 8, 196, 0, 287, 0, 196, 0, 57, 0, 25], ["+", 0, 287, 0, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 287, 0, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 141, 22]]
8
545
21
using System; class Program { static void Main(string[] args) { int i; int n = int.Parse(Console.ReadLine()); Int64[] a = new Int64[n]; string[] strInput = Console.ReadLine().Split(' '); for (i = 0; i < n; i++) { a[i] = Int64.Parse(strInput[i]); if (a[i] == 0) { Console.WriteLine(0); return; } } Int64 result = 1; for (i = 0; i < n; i++) { result *= a[i]; if (result > 1000000000000000000) { result = -1; break; } } Console.WriteLine(result); return; } }
using System; class Program { static void Main(string[] args) { int i; int n = int.Parse(Console.ReadLine()); Int64[] a = new Int64[n]; string[] strInput = Console.ReadLine().Split(' '); for (i = 0; i < n; i++) { a[i] = Int64.Parse(strInput[i]); if (a[i] == 0) { Console.WriteLine(0); return; } } Int64 result = 1; try { for (i = 0; i < n; i++) { checked { result *= a[i]; } if (result > 1000000000000000000 || result < 0) { result = -1; break; } } } catch (OverflowException ex) { result = -1; } Console.WriteLine(result); return; } }
[["+", 8, 201, 0, 195, 8, 196, 0, 246, 0, 247], ["+", 0, 195, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 287, 0, 292], ["+", 0, 7, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 246, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 141, 22], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 25], ["+", 8, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 0, 248, 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, 241, 0, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35]]
8
165
22
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using System.Text; using static System.Math; class MainClass { public static void Main(string[] args) { var N = LnInt(); var _ = LnLngs(); var resu = 1L; _ = _.OrderBy(x => x).ToArray(); foreach (var i in _) { resu *= i; } print(resu > (long)Pow(10, 18) ? -1 : resu); } public static long SumAtoB(long a, long b) { var length = b - a + 1; return (a + b) * (length / 2) + (length % 2 == 1 ? (a + b) / 2 : 0); } public static long PowLite(long n, long p, long mod = (long)1e9 + 7) { long ans = 1; long now = n; for (; p > 0; p >>= 1) { if ((p & 1) == 1) { ans *= now; ans %= mod; } now *= now; now %= mod; } return ans; } public static void print(object obj) { Console.WriteLine(obj); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable { var a = new List<T>(array).ToArray(); var res = new List<T[]>(); res.Add(new List<T>(a).ToArray()); var n = a.Length; var next = true; while (next) { next = false; int i; for (i = n - 2; i >= 0; i--) { if (a[i].CompareTo(a[i + 1]) < 0) break; } if (i < 0) break; var j = n; do { j--; } while (a[i].CompareTo(a[j]) > 0); if (a[i].CompareTo(a[j]) < 0) { var tmp = a[i]; a[i] = a[j]; a[j] = tmp; Array.Reverse(a, i + 1, n - i - 1); res.Add(new List<T>(a).ToArray()); next = true; } } return res; } }
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using System.Text; using static System.Math; class MainClass { public static void Main(string[] args) { var N = LnInt(); var _ = LnLngs(); var resu = 1L; _ = _.OrderBy(x => x).ToArray(); foreach (var i in _) { if (Log10(resu) + Log10(i) > 18) { print(-1); return; } resu *= i; } print(resu > (long)Pow(10, 18) ? -1 : resu); } public static long SumAtoB(long a, long b) { var length = b - a + 1; return (a + b) * (length / 2) + (length % 2 == 1 ? (a + b) / 2 : 0); } public static long PowLite(long n, long p, long mod = (long)1e9 + 7) { long ans = 1; long now = n; for (; p > 0; p >>= 1) { if ((p & 1) == 1) { ans *= now; ans %= mod; } now *= now; now %= mod; } return ans; } public static void print(object obj) { Console.WriteLine(obj); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable { var a = new List<T>(array).ToArray(); var res = new List<T[]>(); res.Add(new List<T>(a).ToArray()); var n = a.Length; var next = true; while (next) { next = false; int i; for (i = n - 2; i >= 0; i--) { if (a[i].CompareTo(a[i + 1]) < 0) break; } if (i < 0) break; var j = n; do { j--; } while (a[i].CompareTo(a[j]) > 0); if (a[i].CompareTo(a[j]) < 0) { var tmp = a[i]; a[i] = a[j]; a[j] = tmp; Array.Reverse(a, i + 1, n - i - 1); res.Add(new List<T>(a).ToArray()); next = true; } } return res; } }
[["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 210, 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, 24], ["+", 31, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 31, 16, 12, 213, 63, 22], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 31, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
8
959
24
using System; using System.Collections.Generic; using System.Text; using System.Linq; using System.Numerics; using System.IO; 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; private const int MAX = 1000001; static long[] fac = new long[MAX]; static long[] finv = new long[MAX]; static long[] inv = new long[MAX]; static void Solve() { var n = Input.NextInt(); var a = Input.NextLong(n); long limit = 1; for (int i = 0; i < 18; i++) { limit *= 10; } long ans = 1; if (a.Contains(0)) { ans = 0; } else { foreach (var ai in a) { ans *= ai; if (ans > limit) { ans = -1; break; } } } Console.WriteLine(ans); } #region よく使う便利関数 private static Dictionary<long, int> Factorize(long n) { var dic = new Dictionary<long, int>(); for (long i = 2; i * i <= n; ++i) { while (n % i == 0) { if (!dic.ContainsKey(i)) { dic.Add(i, 0); } dic[i]++; n /= i; } } if (n != 1) { dic.Add(n, 1); } return dic; } static void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long COM(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } 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]; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; using System.Numerics; using System.IO; 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; private const int MAX = 1000001; static long[] fac = new long[MAX]; static long[] finv = new long[MAX]; static long[] inv = new long[MAX]; static void Solve() { var n = Input.NextInt(); var a = Input.NextLong(n); long limit = 1; for (int i = 0; i < 18; i++) { limit *= 10; } decimal ans = 1; if (a.Contains(0)) { ans = 0; } else { foreach (var ai in a) { decimal safe = limit / ans + 100; if (ai > safe) { ans = -1; break; } ans *= ai; if (ans > limit) { ans = -1; break; } } } Console.WriteLine(ans); } #region よく使う便利関数 private static Dictionary<long, int> Factorize(long n) { var dic = new Dictionary<long, int>(); for (long i = 2; i * i <= n; ++i) { while (n % i == 0) { if (!dic.ContainsKey(i)) { dic.Add(i, 0); } dic[i]++; n /= i; } } if (n != 1) { dic.Add(n, 1); } return dic; } static void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long COM(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } 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]; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 57, 75, 196, 0, 210, 0, 25], ["+", 0, 57, 75, 196, 0, 210, 8, 196, 0, 45], ["+", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 200, 0, 212, 0, 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, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 75, 196, 0, 210, 8, 196, 0, 197, 0, 35], ["+", 75, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 75, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46]]
8
2,486
26
using System; using System.Collections.Generic; using System.Linq; namespace abc169_b { class Program { static void Main(string[] args) { var N = CIn.ReadInt(); var A = CIn.ReadLongArray(N); var m = 1L; for (int i = 0; i < N; i++) { try { m = checked(m * A[i]); } catch { Console.WriteLine(-1); return; } if (m > (long)1e18) { Console.WriteLine(-1); return; } } Console.WriteLine(m); } } static class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(int n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(int n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(int n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(int n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } public static char[,] ReadCharMatrix(int h, int w) { var array = new char[h, w]; for (var i = 0; i < h; i++) { var l = Console.ReadLine().ToCharArray(); for (var j = 0; j < w; j++) { array[i, j] = l[j]; } } return array; } } }
using System; using System.Collections.Generic; using System.Linq; namespace abc169_b { class Program { static void Main(string[] args) { var N = CIn.ReadInt(); var A = CIn.ReadLongArray(N); if (A.Contains(0)) { Console.WriteLine(0); return; } var m = 1L; for (int i = 0; i < N; i++) { try { m = checked(m * A[i]); } catch { Console.WriteLine(-1); return; } if (m > (long)1e18) { Console.WriteLine(-1); return; } } Console.WriteLine(m); } } static class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(int n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(int n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(int n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(int n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } public static char[,] ReadCharMatrix(int h, int w) { var array = new char[h, w]; for (var i = 0; i < h; i++) { var l = Console.ReadLine().ToCharArray(); for (var j = 0; j < w; j++) { array[i, j] = l[j]; } } return array; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
532
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using System.IO; class readint { public readint(out int i) { i = int.Parse(Console.ReadLine()); } public readint(out int a, out int b) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readint(out int a, out int b, out int c) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readint(out int a, out int b, out int c, out int d) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class readlong { public readlong(out long i) { i = long.Parse(Console.ReadLine()); } public readlong(out long a, out long b) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readlong(out long a, out long b, out long c) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readlong(out long a, out long b, out long c, out long d) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class modMWorld { public static long M = (int)998244353; // Math.Pow(10, 9) + 7; //必要な演算は、加減乗除、nCk,n!,a^n public static long add(long a, long b) { long sum = a + b; sum += M; return sum % M; } public static long sub(long a, long b) { long dif = a - b; dif += M * 2; return dif % M; } public static long mul(long a, long b) { long product = a; product *= b; return product % M; } public static long div(long a, long b) { return mul(a, Pow(b, M - 2)); } /// <summary> /// a^m modMを求める /// </summary> /// <param name="a"></param> /// <param name="m"></param> /// <returns></returns> public static long Pow(long a, long m) { switch (m) { case 0: return 1; case 1: return a; default: long p1 = Pow(a, m / 2); long p2 = mul(p1, p1); return ((m % 2) == 0) ? p2 : mul(p2, a); } } public static long kaijou(long n) { //! long output = 1; for (int i = 0; i < n; i++) { output = mul(output, n - i); } return output; } public static long nCk(long n, long k) { long output = 1; for (int i = 1; i <= k; i++) { output = mul(output, n - (i - 1)); output = div(output, i); } return output; } } class Util { public static int[] readintarr() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static long[] readlongarr() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } /// <summary> /// nの約数を小さい順のリストで返します。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<int> make_divisor(int n) { List<int> output = new List<int>(); for (int i = 1; i <= Math.Sqrt(n) + 1; i++) { if (n % i == 0) { output.Add(i); if (i * i != n) { output.Add(n / i); } } } output.Sort(); return output; } // iの素因数分解をします public static List<int> soinsuuBunkai(int n) { //素因数分解をします List<int> output = new List<int>(); int target = n; for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) { while (target % i == 0) { target /= i; output.Add(i); } if (i == 2) i--; } if (target > 1) { output.Add(target); } return output; } public static List<long> soinsuuBunkai(long n) { List<long> output = new List<long>(); long target = n; for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) { while (target % i == 0) { target /= i; output.Add(i); } if (i == 2) i--; } if (target > 1) { output.Add(target); } return output; } /// <summary> /// 2引数の最大公約数を返します。longです。 /// </summary> /// <param name="a">long 引数1</param> /// <param name="b">long 引数2</param> /// <returns></returns> public static long GCD(long a, long b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2引数の最大公約数を返します。intです。 /// </summary> /// <param name="a">int 引数1</param> /// <param name="b">int 引数2</param> /// <returns></returns> public static int GCD(int a, int b) { // if (a < b) // swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2つの変数の中身を交換する。型はなんでもいい /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void swap<T>(ref T a, ref T b) { T temp = b; b = a; a = temp; } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(long a, long b) { return a * b / GCD(a, b); } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); } public static int M = (int)998244353; //(Math.Pow(10, 9)) + 7; private static int[] factorial_modM; public static long nCr(long n, long r) { long output = 1; for (int i = 1; i <= r; i++) { output *= (n + 1 - i); output /= (i); } return output; } /// <summary> /// 2引数の積 mod Mを求める。Mは10億7。 /// 変えられるよ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Multiple_modM(int a, int b) { return (int)(Math.BigMul(a, b) % M); } /// <summary> /// n! modMまたはnCmを求めるための準備を行う。引数は最大値。 /// </summary> /// <param name="n"></param> public static void factorial_modM_Prepare(int n) { factorial_modM = new int[n + 1]; factorial_modM[0] = 1; for (int i = 1; i <= n; ++i) { factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i); } } /// <summary> /// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int Factorial(int n) { return factorial_modM[n]; } /// <summary> /// a^m modMを求める /// </summary> /// <param name="a"></param> /// <param name="m"></param> /// <returns></returns> public static int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiple_modM(p1, p1); return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a); } } /// <summary> /// a / m Mod M を求める。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Div(int a, int b) { return Multiple_modM(a, Pow(b, M - 2)); } /// <summary> /// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <param name="r"></param> /// <returns></returns> public static int nCr_modM(int n, int r) { if (r < 0) return 0; if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Div(res, Factorial(r)); res = Div(res, Factorial(n - r)); return res; } } /// <summary> /// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。 /// おすすめとしては、UnionFind<T>[] で宣言してしまう。 /// 配列で宣言したあと、コンストラクタ使ってnewするのを忘れないでね。 /// コンストラクタのitemは、そのノード固有のIDになるので、絶対必要です /// </summary> /// <typeparam name="T">int固定でいいよね。</typeparam> class UnionFind<T> { public int tree_height; public UnionFind<T> parent; public T item { get; private set; } public UnionFind(T item) { tree_height = 0; parent = this; this.item = item; } /// <summary> /// 一番上の親を探す。 /// 探しながら繋がり方を最適化している。 /// UnionFindの頂点そのものを返すので、==での比較が可能。 /// </summary> /// <returns></returns> public UnionFind<T> FindAdam() { if (parent == this) return this; else { UnionFind<T> ParentOfParent = parent.FindAdam(); parent = ParentOfParent; //縦長な構成をつなぎ直している return ParentOfParent; } } /// <summary> /// unionfind2つを一つにつなぐ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void Unite(UnionFind<T> a, UnionFind<T> b) { UnionFind<T> ParentOfA = a.FindAdam(); UnionFind<T> ParentOfB = b.FindAdam(); if (ParentOfA.tree_height < ParentOfB.tree_height) { ParentOfA.parent = ParentOfB; ParentOfB.tree_height = Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height); } else { ParentOfB.parent = ParentOfA; ParentOfA.tree_height = Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height); } } public static string convertToBinary(int N, int length) { string binary = Convert.ToString(N, 2); while (length > binary.Length) { binary = "0" + binary; } return binary; } } // Treap 平衡二分木 class Treap<T> where T : IComparable { private class Node { private static Random g_rand = new Random(); private readonly int m_rank = g_rand.Next(); private readonly T m_value; private Node m_lch; private Node m_rch; private int m_count; public Node(T value) { m_value = value; m_count = 1; } private static int Count(Node node) { return (node != null) ? node.m_count : 0; } private Node Update() { m_count = Count(m_lch) + Count(m_rch) + 1; return this; } public static Node Merge(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } if (a.m_rank < b.m_rank) { a.m_rch = Merge(a.m_rch, b); return a.Update(); } else { b.m_lch = Merge(a, b.m_lch); return b.Update(); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) { return new Tuple<Node, Node>(null, null); } if (k <= Count(t.m_lch)) { var pair = Split(t.m_lch, k); t.m_lch = pair.Item2; return new Tuple<Node, Node>(pair.Item1, t.Update()); } else { var pair = Split(t.m_rch, k - Count(t.m_lch) - 1); t.m_rch = pair.Item1; return new Tuple<Node, Node>(t.Update(), pair.Item2); } } public int FindIndex(T value) { int L = Count(m_lch); if (value.CompareTo(m_value) < 0) { return (m_lch != null) ? m_lch.FindIndex(value) : 0; } else if (value.CompareTo(m_value) > 0) { return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1; } else { return L; } } public T this[int i] { get { int L = Count(m_lch); if (i < L) { return m_lch[i]; } else if (i > L) { return m_rch[i - L - 1]; } else { return m_value; } } } } private Node node; public void Insert(T value) { if (node != null) { int k = node.FindIndex(value); var pair = Node.Split(node, k); node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2); } else { node = new Node(value); } } public int FindIndex(T value) { return node.FindIndex(value); } public T this[int i] { get { return node[i]; } } } /// <summary> /// 使い方:Permutation.next(配列) で次の配列を返す /// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。 /// もし、次のがない場合、空の配列を返します。 /// /// </summary> /// <typeparam name="T"></typeparam> class Permutation<T> where T : IComparable { public static T[] next(T[] letters) { int pivot = -1; for (int i = letters.Length - 2; i >= 0; i--) { if (letters[i].CompareTo(letters[i + 1]) < 0) { pivot = i; break; } } if (pivot == -1) { return new T[0]; } int big_min = letters.Length - 1; T big_min_T = letters[letters.Length - 1]; for (int i = letters.Length - 1; i > pivot; i--) { // big_min_Tより小さいかつ、pivotのより大きい if (letters[pivot].CompareTo(letters[i]) > 0 && letters[pivot].CompareTo(big_min_T) < 0) { big_min_T = letters[i]; big_min = i; } } T temp = letters[pivot]; letters[pivot] = letters[big_min]; letters[big_min] = temp; Array.Sort(letters, pivot + 1, letters.Length - pivot - 1); return letters; } } /// <summary> /// 使い方 : Combination /// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数) /// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する /// /// </summary> /// <typeparam name="T"></typeparam> class Combination<T> where T : IComparable { private static bool stop = false; public static List<string> AllCombination(T[] letters, int n) { // n桁ですよね。 List<string> outlist = new List<string>(); T[] state = new T[n]; for (int i = 0; i < n; i++) { state[i] = letters[0]; } outlist.Add(String.Join(" ", state)); while (true) { next_keta(ref state, state.Length - 1, letters); if (stop) break; outlist.Add(string.Join(" ", state)); } return outlist; } public static T[] next_keta(ref T[] state, int keta, T[] letters) { if (keta == -1) { stop = true; return new T[0]; } if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) { //見た桁を最初の要素にする処理を state[keta] = letters[0]; return next_keta(ref state, keta - 1, letters); } else { int ketaindex = 0; for (int i = 0; i < letters.Length; i++) { if (state[keta].CompareTo(letters[i]) == 0) { ketaindex = i; break; } } state[keta] = letters[ketaindex + 1]; return state; } } } namespace CompLib.Collections { #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } /// <summary> /// SEGTREEは1-BASE運用でございます /// よろしくおねがいします /// あと絶対コンストラクタ使ってね /// </summary> /// <typeparam name="T"></typeparam> class Segtree<T> { int n; //高さ T[] tree; //本体 Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか T exnum; //初期値 int count; /// <summary> /// !!!WARNING!!! 1-BASEです。 /// </summary> /// <param name="m">要素の数の最大値。200001とか入れておくとよい</param> /// <param name="f">2引数の関数</param> /// <param /// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param> public Segtree(int m, Func<T, T, T> f, T ex) { this.count = 0; this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { this.count = 0; for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } /// <summary> /// j番目の値をxにする。計算し直さないので、 /// 入れ替えた後はall_update();を使おう /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } /// <summary> /// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void update(int j, T x) // j番目をxにする { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } this.count++; } /// <summary> /// 木を全部計算し直す。多分NlogN。違うかも知れないから /// よかったら教えて /// </summary> public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } /// <summary> /// j番目を消す。 /// </summary> /// <param name="j"></param> public void delete (int j) { int i = j + n - 1; tree[i] = exnum; int moved = 0; while (true) { tree[i + 1] = tree[i]; T check = tree[i]; moved++; if (moved + j + 2 > count) { break; } } all_update(); } // [s, t) /// <summary> /// s番目からt - 1 番目までの結果を返す。t番目は含まない。 /// これも当然のように1-BASE. /// </summary> /// <param name="s"></param> /// <param name="t"></param> /// <returns></returns> public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class pair<T> { public T A; public T B; public pair() {} public pair(T A, T B) { this.A = A; this.B = B; } } public class chouten { public int N; public List<int> node; public chouten(int n) { this.N = n; this.node = new List<int>(); } } public class ab { public int a, b; public ab(int a, int b) { this.a = a; this.b = b; } } public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); // CompLib.Collections.PriorityQueue<?> //文字列比較のcomparer // StringComparer.OrdinalIgnoreCase public static void Main() { int N; new readint(out N); long[] A = Util.readlongarr(); Array.Sort(A); if (A[0] == 0) { Console.WriteLine(0); return; } else { long limit = 1000000000000000000; long mul = 1; for (int i = 0; i < A.Length; i++) { mul *= A[i]; if (mul > limit) { Console.WriteLine(-1); return; } } Console.WriteLine(mul); } } } public class info { public int worst; public int value; public string kakko; public bool used; public info(int worst, int value, string kakko) { this.worst = worst; this.value = value; this.kakko = kakko; this.used = false; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using System.IO; class readint { public readint(out int i) { i = int.Parse(Console.ReadLine()); } public readint(out int a, out int b) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readint(out int a, out int b, out int c) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readint(out int a, out int b, out int c, out int d) { int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class readlong { public readlong(out long i) { i = long.Parse(Console.ReadLine()); } public readlong(out long a, out long b) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; } public readlong(out long a, out long b, out long c) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; } public readlong(out long a, out long b, out long c, out long d) { long[] sp = Console.ReadLine().Split().Select(long.Parse).ToArray(); a = sp[0]; b = sp[1]; c = sp[2]; d = sp[3]; } } class modMWorld { public static long M = (int)998244353; // Math.Pow(10, 9) + 7; //必要な演算は、加減乗除、nCk,n!,a^n public static long add(long a, long b) { long sum = a + b; sum += M; return sum % M; } public static long sub(long a, long b) { long dif = a - b; dif += M * 2; return dif % M; } public static long mul(long a, long b) { long product = a; product *= b; return product % M; } public static long div(long a, long b) { return mul(a, Pow(b, M - 2)); } /// <summary> /// a^m modMを求める /// </summary> /// <param name="a"></param> /// <param name="m"></param> /// <returns></returns> public static long Pow(long a, long m) { switch (m) { case 0: return 1; case 1: return a; default: long p1 = Pow(a, m / 2); long p2 = mul(p1, p1); return ((m % 2) == 0) ? p2 : mul(p2, a); } } public static long kaijou(long n) { //! long output = 1; for (int i = 0; i < n; i++) { output = mul(output, n - i); } return output; } public static long nCk(long n, long k) { long output = 1; for (int i = 1; i <= k; i++) { output = mul(output, n - (i - 1)); output = div(output, i); } return output; } } class Util { public static int[] readintarr() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static long[] readlongarr() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } /// <summary> /// nの約数を小さい順のリストで返します。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static List<int> make_divisor(int n) { List<int> output = new List<int>(); for (int i = 1; i <= Math.Sqrt(n) + 1; i++) { if (n % i == 0) { output.Add(i); if (i * i != n) { output.Add(n / i); } } } output.Sort(); return output; } // iの素因数分解をします public static List<int> soinsuuBunkai(int n) { //素因数分解をします List<int> output = new List<int>(); int target = n; for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) { while (target % i == 0) { target /= i; output.Add(i); } if (i == 2) i--; } if (target > 1) { output.Add(target); } return output; } public static List<long> soinsuuBunkai(long n) { List<long> output = new List<long>(); long target = n; for (int i = 2; i <= 1 + Math.Sqrt(target); i += 2) { while (target % i == 0) { target /= i; output.Add(i); } if (i == 2) i--; } if (target > 1) { output.Add(target); } return output; } /// <summary> /// 2引数の最大公約数を返します。longです。 /// </summary> /// <param name="a">long 引数1</param> /// <param name="b">long 引数2</param> /// <returns></returns> public static long GCD(long a, long b) { if (a < b) swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2引数の最大公約数を返します。intです。 /// </summary> /// <param name="a">int 引数1</param> /// <param name="b">int 引数2</param> /// <returns></returns> public static int GCD(int a, int b) { // if (a < b) // swap(ref a, ref b); if (a % b == 0) return b; return GCD(b, a % b); } /// <summary> /// 2つの変数の中身を交換する。型はなんでもいい /// </summary> /// <typeparam name="T"></typeparam> /// <param name="a"></param> /// <param name="b"></param> public static void swap<T>(ref T a, ref T b) { T temp = b; b = a; a = temp; } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(long a, long b) { return a * b / GCD(a, b); } /// <summary> /// 2引数の最大公約数を返します。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long LCM(int a, int b) { return Math.BigMul(a, b) / GCD(a, b); } public static int M = (int)998244353; //(Math.Pow(10, 9)) + 7; private static int[] factorial_modM; public static long nCr(long n, long r) { long output = 1; for (int i = 1; i <= r; i++) { output *= (n + 1 - i); output /= (i); } return output; } /// <summary> /// 2引数の積 mod Mを求める。Mは10億7。 /// 変えられるよ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Multiple_modM(int a, int b) { return (int)(Math.BigMul(a, b) % M); } /// <summary> /// n! modMまたはnCmを求めるための準備を行う。引数は最大値。 /// </summary> /// <param name="n"></param> public static void factorial_modM_Prepare(int n) { factorial_modM = new int[n + 1]; factorial_modM[0] = 1; for (int i = 1; i <= n; ++i) { factorial_modM[i] = Multiple_modM(factorial_modM[i - 1], i); } } /// <summary> /// n! mod M を返す。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <returns></returns> public static int Factorial(int n) { return factorial_modM[n]; } /// <summary> /// a^m modMを求める /// </summary> /// <param name="a"></param> /// <param name="m"></param> /// <returns></returns> public static int Pow(int a, int m) { switch (m) { case 0: return 1; case 1: return a; default: int p1 = Pow(a, m / 2); int p2 = Multiple_modM(p1, p1); return ((m % 2) == 0) ? p2 : Multiple_modM(p2, a); } } /// <summary> /// a / m Mod M を求める。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static int Div(int a, int b) { return Multiple_modM(a, Pow(b, M - 2)); } /// <summary> /// nCr mod M を求める。やる前にfactorial_modM_Prepare(n)を実行しといてね。 /// </summary> /// <param name="n"></param> /// <param name="r"></param> /// <returns></returns> public static int nCr_modM(int n, int r) { if (r < 0) return 0; if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = Div(res, Factorial(r)); res = Div(res, Factorial(n - r)); return res; } } /// <summary> /// Union-Find木を定義する。コンストラクタの指定は、頂点の番号。 /// おすすめとしては、UnionFind<T>[] で宣言してしまう。 /// 配列で宣言したあと、コンストラクタ使ってnewするのを忘れないでね。 /// コンストラクタのitemは、そのノード固有のIDになるので、絶対必要です /// </summary> /// <typeparam name="T">int固定でいいよね。</typeparam> class UnionFind<T> { public int tree_height; public UnionFind<T> parent; public T item { get; private set; } public UnionFind(T item) { tree_height = 0; parent = this; this.item = item; } /// <summary> /// 一番上の親を探す。 /// 探しながら繋がり方を最適化している。 /// UnionFindの頂点そのものを返すので、==での比較が可能。 /// </summary> /// <returns></returns> public UnionFind<T> FindAdam() { if (parent == this) return this; else { UnionFind<T> ParentOfParent = parent.FindAdam(); parent = ParentOfParent; //縦長な構成をつなぎ直している return ParentOfParent; } } /// <summary> /// unionfind2つを一つにつなぐ。 /// </summary> /// <param name="a"></param> /// <param name="b"></param> public static void Unite(UnionFind<T> a, UnionFind<T> b) { UnionFind<T> ParentOfA = a.FindAdam(); UnionFind<T> ParentOfB = b.FindAdam(); if (ParentOfA.tree_height < ParentOfB.tree_height) { ParentOfA.parent = ParentOfB; ParentOfB.tree_height = Math.Max(ParentOfA.tree_height + 1, ParentOfB.tree_height); } else { ParentOfB.parent = ParentOfA; ParentOfA.tree_height = Math.Max(ParentOfB.tree_height + 1, ParentOfA.tree_height); } } public static string convertToBinary(int N, int length) { string binary = Convert.ToString(N, 2); while (length > binary.Length) { binary = "0" + binary; } return binary; } } // Treap 平衡二分木 class Treap<T> where T : IComparable { private class Node { private static Random g_rand = new Random(); private readonly int m_rank = g_rand.Next(); private readonly T m_value; private Node m_lch; private Node m_rch; private int m_count; public Node(T value) { m_value = value; m_count = 1; } private static int Count(Node node) { return (node != null) ? node.m_count : 0; } private Node Update() { m_count = Count(m_lch) + Count(m_rch) + 1; return this; } public static Node Merge(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } if (a.m_rank < b.m_rank) { a.m_rch = Merge(a.m_rch, b); return a.Update(); } else { b.m_lch = Merge(a, b.m_lch); return b.Update(); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) { return new Tuple<Node, Node>(null, null); } if (k <= Count(t.m_lch)) { var pair = Split(t.m_lch, k); t.m_lch = pair.Item2; return new Tuple<Node, Node>(pair.Item1, t.Update()); } else { var pair = Split(t.m_rch, k - Count(t.m_lch) - 1); t.m_rch = pair.Item1; return new Tuple<Node, Node>(t.Update(), pair.Item2); } } public int FindIndex(T value) { int L = Count(m_lch); if (value.CompareTo(m_value) < 0) { return (m_lch != null) ? m_lch.FindIndex(value) : 0; } else if (value.CompareTo(m_value) > 0) { return (m_rch != null) ? m_rch.FindIndex(value) + L + 1 : L + 1; } else { return L; } } public T this[int i] { get { int L = Count(m_lch); if (i < L) { return m_lch[i]; } else if (i > L) { return m_rch[i - L - 1]; } else { return m_value; } } } } private Node node; public void Insert(T value) { if (node != null) { int k = node.FindIndex(value); var pair = Node.Split(node, k); node = Node.Merge(Node.Merge(pair.Item1, new Node(value)), pair.Item2); } else { node = new Node(value); } } public int FindIndex(T value) { return node.FindIndex(value); } public T this[int i] { get { return node[i]; } } } /// <summary> /// 使い方:Permutation.next(配列) で次の配列を返す /// 配列を受け取って、その配列の要素を全部使った組み合わせのうち、辞書順で次のものを返します。 /// もし、次のがない場合、空の配列を返します。 /// /// </summary> /// <typeparam name="T"></typeparam> class Permutation<T> where T : IComparable { public static T[] next(T[] letters) { int pivot = -1; for (int i = letters.Length - 2; i >= 0; i--) { if (letters[i].CompareTo(letters[i + 1]) < 0) { pivot = i; break; } } if (pivot == -1) { return new T[0]; } int big_min = letters.Length - 1; T big_min_T = letters[letters.Length - 1]; for (int i = letters.Length - 1; i > pivot; i--) { // big_min_Tより小さいかつ、pivotのより大きい if (letters[pivot].CompareTo(letters[i]) > 0 && letters[pivot].CompareTo(big_min_T) < 0) { big_min_T = letters[i]; big_min = i; } } T temp = letters[pivot]; letters[pivot] = letters[big_min]; letters[big_min] = temp; Array.Sort(letters, pivot + 1, letters.Length - pivot - 1); return letters; } } /// <summary> /// 使い方 : Combination /// .AllCombination(使える文字を、小さい順から配列にしたもの,ほしい文字数) /// 使える文字を、小さい順から配列にしたものを重複ありで組み合わせて、stringのlistで出力する /// /// </summary> /// <typeparam name="T"></typeparam> class Combination<T> where T : IComparable { private static bool stop = false; public static List<string> AllCombination(T[] letters, int n) { // n桁ですよね。 List<string> outlist = new List<string>(); T[] state = new T[n]; for (int i = 0; i < n; i++) { state[i] = letters[0]; } outlist.Add(String.Join(" ", state)); while (true) { next_keta(ref state, state.Length - 1, letters); if (stop) break; outlist.Add(string.Join(" ", state)); } return outlist; } public static T[] next_keta(ref T[] state, int keta, T[] letters) { if (keta == -1) { stop = true; return new T[0]; } if (state[keta].CompareTo(letters[letters.Length - 1]) == 0) { //見た桁を最初の要素にする処理を state[keta] = letters[0]; return next_keta(ref state, keta - 1, letters); } else { int ketaindex = 0; for (int i = 0; i < letters.Length; i++) { if (state[keta].CompareTo(letters[i]) == 0) { ketaindex = i; break; } } state[keta] = letters[ketaindex + 1]; return state; } } } namespace CompLib.Collections { #region PriorityQueue /// <summary> /// 指定した型のインスタンスを最も価値が低い順に取り出すことが可能な可変サイズのコレクションを表します. /// </summary> /// <typeparam name="T">優先度付きキュー内の要素の型を指定します.</typeparam> /// <remarks>内部的にはバイナリヒープによって実装されています.</remarks> public class PriorityQueue<T> { readonly List<T> heap = new List<T>(); readonly Comparison<T> cmp; /// <summary> /// デフォルトの比較子を使用してインスタンスを初期化します. /// </summary> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue() { cmp = Comparer<T>.Default.Compare; } /// <summary> /// デリゲートで表されるような比較関数を使用してインスタンスを初期化します. /// </summary> /// <param name="comparison"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(Comparison<T> comparison) { cmp = comparison; } /// <summary> /// 指定された比較子を使用してインスタンスを初期化します. /// </summary> /// <param name="comparer"></param> /// <remarks>この操作は O(1) で実行されます.</remarks> public PriorityQueue(IComparer<T> comparer) { cmp = comparer.Compare; } /// <summary> /// 優先度付きキューに要素を追加します. /// </summary> /// <param name="item">優先度付きキューに追加される要素</param> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public void Enqueue(T item) { var pos = heap.Count; heap.Add(item); while (pos > 0) { var par = (pos - 1) / 2; if (cmp(heap[par], item) <= 0) break; heap[pos] = heap[par]; pos = par; } heap[pos] = item; } /// <summary> /// 優先度付きキューから最も価値が低い要素を削除し,返します. /// </summary> /// <returns>優先度付きキューから削除された要素.</returns> /// <remarks>最悪計算量 O(log N) で実行されます.</remarks> public T Dequeue() { var ret = heap[0]; var pos = 0; var x = heap[heap.Count - 1]; while (pos * 2 + 1 < heap.Count - 1) { var lch = pos * 2 + 1; var rch = pos * 2 + 2; if (rch < heap.Count - 1 && cmp(heap[rch], heap[lch]) < 0) lch = rch; if (cmp(heap[lch], x) >= 0) break; heap[pos] = heap[lch]; pos = lch; } heap[pos] = x; heap.RemoveAt(heap.Count - 1); return ret; } /// <summary> /// 優先度付きキューに含まれる最も価値が低い要素を削除せずに返します. /// </summary> /// <returns>優先度付きキューに含まれる最も価値が低い要素.</returns> /// <remarks>この操作は O(1) で実行されます.</remarks> public T Peek() { return heap[0]; } /// <summary> /// 優先度付きキュー内の要素の数を取得します. /// </summary> /// <returns>優先度付キュー内にある要素の数</returns> /// <remarks>最悪計算量 O(1) で実行されます.</remarks> public int Count { get { return heap.Count; } } /// <summary> /// 優先度付きキュー内に要素が存在するかどうかを O(1) で判定します. /// </summary> /// <returns>優先度付キュー内にある要素が存在するならば /// true,そうでなければ false.</returns> <remarks>この操作は O(1) /// で実行されます.</remarks> public bool Any() { return heap.Count > 0; } /// <summary> /// 優先度付きキューに含まれる要素を昇順に並べて返します. /// </summary> /// <remarks>この操作は計算量 O(N log N)で実行されます.</remarks> public T[] Items { get { var ret = heap.ToArray(); Array.Sort(ret, cmp); return ret; } } } #endregion } /// <summary> /// SEGTREEは1-BASE運用でございます /// よろしくおねがいします /// あと絶対コンストラクタ使ってね /// </summary> /// <typeparam name="T"></typeparam> class Segtree<T> { int n; //高さ T[] tree; //本体 Func<T, T, T> f; //更新関数。a -> b -> ab使ったなにか T exnum; //初期値 int count; /// <summary> /// !!!WARNING!!! 1-BASEです。 /// </summary> /// <param name="m">要素の数の最大値。200001とか入れておくとよい</param> /// <param name="f">2引数の関数</param> /// <param /// name="ex">葉に書いてある値の初期値。fの関数に影響を与えない数値、零元とかにしておくべき。バグり散らかす。</param> public Segtree(int m, Func<T, T, T> f, T ex) { this.count = 0; this.f = f; this.exnum = ex; n = 1; while (n < m) n <<= 1; tree = new T[(n << 1) - 1]; for (int i = 0; i < tree.Length; i++) tree[i] = ex; } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { this.count = 0; for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; all_update(); } /// <summary> /// j番目の値をxにする。計算し直さないので、 /// 入れ替えた後はall_update();を使おう /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void assign_without_update(int j, T x) { tree[j + n - 1] = x; } /// <summary> /// j番目の値をxにする。計算し直すので、ちょっと計算時間がかかる /// </summary> /// <param name="j">番目</param> /// <param name="x">更新後の値</param> public void update(int j, T x) // j番目をxにする { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } this.count++; } /// <summary> /// 木を全部計算し直す。多分NlogN。違うかも知れないから /// よかったら教えて /// </summary> public void all_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T look(int i) { return tree[i + n - 1]; } /// <summary> /// j番目を消す。 /// </summary> /// <param name="j"></param> public void delete (int j) { int i = j + n - 1; tree[i] = exnum; int moved = 0; while (true) { tree[i + 1] = tree[i]; T check = tree[i]; moved++; if (moved + j + 2 > count) { break; } } all_update(); } // [s, t) /// <summary> /// s番目からt - 1 番目までの結果を返す。t番目は含まない。 /// これも当然のように1-BASE. /// </summary> /// <param name="s"></param> /// <param name="t"></param> /// <returns></returns> public T run(int s, int t) { return query(s, t, 0, 0, n); } T query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(query(s, t, (k << 1) + 1, l, (l + r) >> 1), query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } } public class pair<T> { public T A; public T B; public pair() {} public pair(T A, T B) { this.A = A; this.B = B; } } public class chouten { public int N; public List<int> node; public chouten(int n) { this.N = n; this.node = new List<int>(); } } public class ab { public int a, b; public ab(int a, int b) { this.a = a; this.b = b; } } public class ABC { // long[] sp = Console.ReadLine().Split().Select(long // .Parse).ToArray(); int[] sp = // Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = // int.Parse(Console.ReadLine()); // CompLib.Collections.PriorityQueue<?> //文字列比較のcomparer // StringComparer.OrdinalIgnoreCase public static void Main() { int N; new readint(out N); long[] A = Util.readlongarr(); Array.Sort(A); if (A[0] == 0) { Console.WriteLine(0); return; } else { long limit = 1000000000000000000; long mul = 1; for (int i = 0; i < A.Length; i++) { try { checked { mul *= A[i]; if (mul > limit) { Console.WriteLine(-1); return; } } } catch (OverflowException ex) { Console.WriteLine(-1); return; } } Console.WriteLine(mul); } } } public class info { public int worst; public int value; public string kakko; public bool used; public info(int worst, int value, string kakko) { this.worst = worst; this.value = value; this.kakko = kakko; this.used = false; } }
[["+", 75, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 8, 196, 0, 246, 8, 196, 0, 287, 0, 292], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 8, 196, 0, 287, 0, 196, 0, 57, 0, 25], ["+", 0, 287, 0, 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, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 287, 0, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 246, 8, 196, 0, 287, 0, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["+", 8, 196, 0, 246, 0, 248, 0, 300, 141, 22]]
8
4,553
23
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var n = rint(); long a = 1; long t = 2000000000000000000; long tt = 1000000000000000000; var list = longa(); Array.Sort(list); for (int i = 0; i < n; i++) { if (a == -1) continue; if (list[i] == 0 || a == 0) { a = 0; continue; } if (t / a < list[i]) { WriteLine(22); a = -1; continue; } a *= list[i]; if (tt < a) { WriteLine(11); a = -1; continue; } } WriteLine(a); } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { if (n < r) return 0; r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var n = rint(); long a = 1; long t = 2000000000000000000; long tt = 1000000000000000000; var list = longa(); Array.Sort(list); for (int i = 0; i < n; i++) { if (a == -1) continue; if (list[i] == 0 || a == 0) { a = 0; continue; } if (t / a < list[i]) { // WriteLine(22); a = -1; continue; } a *= list[i]; if (tt < a) { // WriteLine(11); a = -1; continue; } } WriteLine(a); } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { if (n < r) return 0; r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
[["-", 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
1,244
10
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var a = cin.ArrayLong(n); var ans = 1L; if (a.Contains(0)) { Console.WriteLine(0); return; } for (int i = 0; i < n; i++) { ans *= a[i]; if (ans > 1000000000000000000 || ans < 0) { Console.WriteLine(-1); return; } } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var n = cin.nextInt(); var a = cin.ArrayLong(n); var ans = 1L; if (a.Contains(0)) { Console.WriteLine(0); return; } for (int i = 0; i < n; i++) { checked { try { ans *= a[i]; if (ans > 1000000000000000000 || ans < 0) { Console.WriteLine(-1); return; } } catch (Exception e) { Console.WriteLine(-1); return; } } } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } 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 long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 287, 0, 292], ["+", 0, 7, 8, 196, 0, 287, 0, 196, 0, 45], ["+", 8, 196, 0, 287, 0, 196, 0, 246, 0, 247], ["+", 0, 287, 0, 196, 0, 246, 8, 196, 0, 45], ["+", 0, 246, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 287, 0, 196, 0, 246, 8, 196, 0, 46], ["+", 0, 287, 0, 196, 0, 246, 0, 248, 0, 249], ["+", 0, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["+", 0, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["+", 0, 196, 0, 246, 0, 248, 0, 300, 141, 22], ["+", 0, 196, 0, 246, 0, 248, 0, 300, 0, 25], ["+", 0, 196, 0, 246, 0, 248, 8, 196, 0, 45], ["+", 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, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 246, 0, 248, 8, 196, 0, 1, 0, 35], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 38], ["+", 0, 246, 0, 248, 8, 196, 0, 37, 0, 35], ["+", 0, 196, 0, 246, 0, 248, 8, 196, 0, 46]]
8
635
23
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { var n = Read().Int(); var r = ReadSplit(); var l = new decimal[n]; for (int i = 0; i < n; i++) { l[i] = r[i].Decimal(); } var ans = l[0]; for (int i = 1; i < n; i++) { try { ans *= l[i]; } catch (Exception) { Write(-1); return; } if (ans > 1000000000000000000) { Write(-1); return; } } WriteRead(ans); } class ModCombination { public long _mod = 1000000007; public int _max = 1000000; long[] fac; long[] finv; long[] inv; public ModCombination() : this(1000000007, 1000000) {} public ModCombination(long mod, int max) { _mod = mod; _max = max; fac = new long[max]; finv = new long[max]; inv = new long[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } public long Combination(int n, int m) { if (n < m) return 0; if (n < 0 || m < 0) return 0; return fac[n] * (finv[m] * finv[n - m] % _mod) % _mod; } } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { var n = Read().Int(); var r = ReadSplit(); var l = new decimal[n]; for (int i = 0; i < n; i++) { l[i] = r[i].Decimal(); } if (l.Min() == 0) { WriteRead(0); return; } var ans = l[0]; for (int i = 1; i < n; i++) { try { ans *= l[i]; } catch (Exception) { WriteRead(-1); return; } if (ans > 1000000000000000000) { WriteRead(-1); return; } } WriteRead(ans); } class ModCombination { public long _mod = 1000000007; public int _max = 1000000; long[] fac; long[] finv; long[] inv; public ModCombination() : this(1000000007, 1000000) {} public ModCombination(long mod, int max) { _mod = mod; _max = max; fac = new long[max]; finv = new long[max]; inv = new long[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } public long Combination(int n, int m) { if (n < m) return 0; if (n < 0 || m < 0) return 0; return fac[n] * (finv[m] * finv[n - m] % _mod) % _mod; } } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 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], ["-", 0, 248, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 0, 248, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22]]
8
751
23
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); int n = cin.NextInt(); long ans = 1; var a = cin.ArrayLong(n); bool ok = true; if (a.Contains(0)) ans = 0; for (int i = 0; i < n; i++) { try { ans *= a[i]; } catch (Exception) { ok = false; goto End; } } End: if (ok && ans <= 1000000000000000000L) Console.WriteLine(ans); else Console.WriteLine(-1); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.B { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var cin = new Scanner(); int n = cin.NextInt(); long ans = 1; var a = cin.ArrayLong(n); bool ok = true; if (a.Contains(0)) ans = 0; for (int i = 0; i < n; i++) { if (1000000000000000000.0 / ans < a[i]) { ok = false; goto End; } ans *= a[i]; } End: if (ok && ans <= 1000000000000000000L) Console.WriteLine(ans); else Console.WriteLine(-1); Console.Out.Flush(); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 246, 0, 247], ["-", 0, 7, 8, 196, 0, 246, 8, 196, 0, 45], ["+", 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, 250], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 85], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 246, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 246, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 246, 0, 248, 0, 249], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 0, 24], ["-", 8, 196, 0, 246, 0, 248, 0, 300, 39, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 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]]
8
555
20
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; namespace V { partial class Solver { public void Solve() { // var n = Read; Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var n = Read; var a = Arr(n); var res = 1L; if (a.Any(x => x == 0)) return 0; foreach (var aa in a) { res *= aa; if (res > 1000000000000000000) return -1; } return res; } public bool SolveBool() { var n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SafeAdd<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { return false; } else { ts.Add(t); return false; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SafeRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafePlus<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToDigit(this char c) => (long)(c - '0'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToStr(this IEnumerable<char> cs) => new string(cs.ToArray()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToLong(this IEnumerable<char> s) { var basis = 1L; var res = 0L; foreach (var c in s) { var d = c.ToSmallAbcIndex() + 1; res += d * basis; basis *= 27; } return res; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] // public static bool TryMin<T>(this ref T current, T newer) where T : struct, // IComparable<T> //{ // if (current.CompareTo(newer) <= 0) // return false; // current = newer; // return true; //} //[MethodImpl(MethodImplOptions.AggressiveInlining)] // public static bool TryMax<T>(this ref T current, T newer) where T : struct, // IComparable<T> //{ // if (current.CompareTo(newer) >= 0) // return false; // current = newer; // return true; //} } class C { public class SegmentTree<T> { private readonly int valueCount; private readonly int baseCount; private readonly int baseIndex; private readonly T[] nodes; private readonly Func<T, T, T> func; private readonly T defaultValue; public SegmentTree(IReadOnlyList<T> ts, Func<T, T, T> func, T filling = default(T)) { this.func = func; this.defaultValue = filling; valueCount = ts.Count; baseCount = 1; while (valueCount > baseCount) baseCount <<= 1; nodes = new T[baseCount * 2 - 1]; baseIndex = baseCount - 1; for (int i = 0; i < ts.Count; i++) nodes[baseIndex + i] = ts[i]; for (int i = ts.Count; i < baseCount; i++) nodes[baseIndex + i] = filling; for (int i = baseIndex - 1; i >= 0; i--) nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int index, T t) { var i = baseIndex + index; nodes[i] = t; while (i > 0) { i -= 1; i /= 2; nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int leftIndex, int rightNextIndex) { T left = defaultValue; T right = defaultValue; int l = leftIndex + baseCount - 1; int r = rightNextIndex + baseCount - 1; for (; l < r; l >>= 1, r >>= 1) { if ((l & 1) == 0) { left = func.Invoke(left, nodes[l]); } if ((r & 1) == 0) { r--; right = func.Invoke(right, nodes[r]); } } return func.Invoke(left, right); } } public class SegmentTree { public static SegmentTree<int> Sum(IReadOnlyList<int> values) => new SegmentTree<int>(values, (x, y) => x + y); public static SegmentTree<long> Sum(IReadOnlyList<long> values) => new SegmentTree<long>(values, (x, y) => x + y); public static SegmentTree<double> Sum(IReadOnlyList<double> values) => new SegmentTree<double>(values, (x, y) => x + y); public static SegmentTree<int> Mult(IReadOnlyList<int> values) => new SegmentTree<int>(values, (x, y) => x * y, 1); public static SegmentTree<long> Mult(IReadOnlyList<long> values) => new SegmentTree<long>(values, (x, y) => x * y, 1); public static SegmentTree<double> Mult(IReadOnlyList<double> values) => new SegmentTree<double>(values, (x, y) => x * y, 1); public static SegmentTree<int> Min(IReadOnlyList<int> values) => new SegmentTree<int>(values, Math.Min, int.MaxValue); public static SegmentTree<long> Min(IReadOnlyList<long> values) => new SegmentTree<long>(values, Math.Min, long.MaxValue); public static SegmentTree<double> Min(IReadOnlyList<double> values) => new SegmentTree<double>(values, Math.Min, double.MaxValue); public static SegmentTree<int> Max(IReadOnlyList<int> values) => new SegmentTree<int>(values, Math.Max, int.MinValue); public static SegmentTree<long> Max(IReadOnlyList<long> values) => new SegmentTree<long>(values, Math.Max, long.MinValue); public static SegmentTree<double> Max(IReadOnlyList<double> values) => new SegmentTree<double>(values, Math.Max, double.MinValue); } public class UnionFind { private int[] parents; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UnionFind(int count) { parents = Enumerable.Repeat(-1, count).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryUnite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) return false; if (parents[rootY] < parents[rootX]) { var temp = rootX; rootX = rootY; rootY = temp; } parents[rootX] += parents[rootY]; parents[rootY] = rootX; return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Find(int x, int y) => GetRoot(x) == GetRoot(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetRoot(int x) { while (parents[x] >= 0) x = parents[x]; return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long GetSize(int x) => -parents[GetRoot(x)]; } public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } /// <summary> /// 木の直径(一番長い枝)を求める /// </summary> /// <returns>木の直径(一番長い枝)</returns> public long GetDiameter() { long firstFarthest = 0; long _1 = 0; GetDiameterImpl(-1, 0, 0, ref _1, ref firstFarthest); long maxDistance = 0; long _2 = 0; GetDiameterImpl(-1, firstFarthest, 0, ref maxDistance, ref _2); return maxDistance; } private void GetDiameterImpl(long from, long current, long distance, ref long maxDistance, ref long farthest) { if (distance > maxDistance) { maxDistance = distance; farthest = current; } foreach (var to in To(current)) { if (from == to) continue; GetDiameterImpl(current, to, distance + 1, ref maxDistance, ref farthest); } } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low; if (listOrdered[high].CompareTo(x) <= 0) return high + 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid].CompareTo(x) > 0) high = mid; else low = mid + 1; } return low; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low - 1; if (listOrdered[0].CompareTo(x) >= 0) return low - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid].CompareTo(x) < 0) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(int a, int b) => Gcd((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(int a, int b) => Lcm((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(int n, int p) => Pow((long)n, (long)p); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(int n) => Divisors((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<T> Repeat<T>(T t, long n) { for (long i = 0L; i < n; i++) yield return t; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set998244353() { divider = 998244353L; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, long b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, int b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, long b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, int b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, long b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, int b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, long b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, int b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint Pow(long p) => new Mint(PowImpl(Value, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; namespace V { partial class Solver { public void Solve() { // var n = Read; Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var n = Read; var a = Arr(n); var res = 1L; if (a.Any(x => x == 0)) return 0; foreach (var aa in a) { if (aa > 1000000000000000000 / res) return -1; res *= aa; } return res; } public bool SolveBool() { var n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SafeAdd<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { return false; } else { ts.Add(t); return false; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SafeRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafePlus<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToDigit(this char c) => (long)(c - '0'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string ToStr(this IEnumerable<char> cs) => new string(cs.ToArray()); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long ToLong(this IEnumerable<char> s) { var basis = 1L; var res = 0L; foreach (var c in s) { var d = c.ToSmallAbcIndex() + 1; res += d * basis; basis *= 27; } return res; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] // public static bool TryMin<T>(this ref T current, T newer) where T : struct, // IComparable<T> //{ // if (current.CompareTo(newer) <= 0) // return false; // current = newer; // return true; //} //[MethodImpl(MethodImplOptions.AggressiveInlining)] // public static bool TryMax<T>(this ref T current, T newer) where T : struct, // IComparable<T> //{ // if (current.CompareTo(newer) >= 0) // return false; // current = newer; // return true; //} } class C { public class SegmentTree<T> { private readonly int valueCount; private readonly int baseCount; private readonly int baseIndex; private readonly T[] nodes; private readonly Func<T, T, T> func; private readonly T defaultValue; public SegmentTree(IReadOnlyList<T> ts, Func<T, T, T> func, T filling = default(T)) { this.func = func; this.defaultValue = filling; valueCount = ts.Count; baseCount = 1; while (valueCount > baseCount) baseCount <<= 1; nodes = new T[baseCount * 2 - 1]; baseIndex = baseCount - 1; for (int i = 0; i < ts.Count; i++) nodes[baseIndex + i] = ts[i]; for (int i = ts.Count; i < baseCount; i++) nodes[baseIndex + i] = filling; for (int i = baseIndex - 1; i >= 0; i--) nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int index, T t) { var i = baseIndex + index; nodes[i] = t; while (i > 0) { i -= 1; i /= 2; nodes[i] = func.Invoke(nodes[i * 2 + 1], nodes[i * 2 + 2]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int leftIndex, int rightNextIndex) { T left = defaultValue; T right = defaultValue; int l = leftIndex + baseCount - 1; int r = rightNextIndex + baseCount - 1; for (; l < r; l >>= 1, r >>= 1) { if ((l & 1) == 0) { left = func.Invoke(left, nodes[l]); } if ((r & 1) == 0) { r--; right = func.Invoke(right, nodes[r]); } } return func.Invoke(left, right); } } public class SegmentTree { public static SegmentTree<int> Sum(IReadOnlyList<int> values) => new SegmentTree<int>(values, (x, y) => x + y); public static SegmentTree<long> Sum(IReadOnlyList<long> values) => new SegmentTree<long>(values, (x, y) => x + y); public static SegmentTree<double> Sum(IReadOnlyList<double> values) => new SegmentTree<double>(values, (x, y) => x + y); public static SegmentTree<int> Mult(IReadOnlyList<int> values) => new SegmentTree<int>(values, (x, y) => x * y, 1); public static SegmentTree<long> Mult(IReadOnlyList<long> values) => new SegmentTree<long>(values, (x, y) => x * y, 1); public static SegmentTree<double> Mult(IReadOnlyList<double> values) => new SegmentTree<double>(values, (x, y) => x * y, 1); public static SegmentTree<int> Min(IReadOnlyList<int> values) => new SegmentTree<int>(values, Math.Min, int.MaxValue); public static SegmentTree<long> Min(IReadOnlyList<long> values) => new SegmentTree<long>(values, Math.Min, long.MaxValue); public static SegmentTree<double> Min(IReadOnlyList<double> values) => new SegmentTree<double>(values, Math.Min, double.MaxValue); public static SegmentTree<int> Max(IReadOnlyList<int> values) => new SegmentTree<int>(values, Math.Max, int.MinValue); public static SegmentTree<long> Max(IReadOnlyList<long> values) => new SegmentTree<long>(values, Math.Max, long.MinValue); public static SegmentTree<double> Max(IReadOnlyList<double> values) => new SegmentTree<double>(values, Math.Max, double.MinValue); } public class UnionFind { private int[] parents; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UnionFind(int count) { parents = Enumerable.Repeat(-1, count).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryUnite(int x, int y) { var rootX = GetRoot(x); var rootY = GetRoot(y); if (rootX == rootY) return false; if (parents[rootY] < parents[rootX]) { var temp = rootX; rootX = rootY; rootY = temp; } parents[rootX] += parents[rootY]; parents[rootY] = rootX; return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Find(int x, int y) => GetRoot(x) == GetRoot(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetRoot(int x) { while (parents[x] >= 0) x = parents[x]; return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long GetSize(int x) => -parents[GetRoot(x)]; } public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } /// <summary> /// 木の直径(一番長い枝)を求める /// </summary> /// <returns>木の直径(一番長い枝)</returns> public long GetDiameter() { long firstFarthest = 0; long _1 = 0; GetDiameterImpl(-1, 0, 0, ref _1, ref firstFarthest); long maxDistance = 0; long _2 = 0; GetDiameterImpl(-1, firstFarthest, 0, ref maxDistance, ref _2); return maxDistance; } private void GetDiameterImpl(long from, long current, long distance, ref long maxDistance, ref long farthest) { if (distance > maxDistance) { maxDistance = distance; farthest = current; } foreach (var to in To(current)) { if (from == to) continue; GetDiameterImpl(current, to, distance + 1, ref maxDistance, ref farthest); } } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered) where T : IComparable { return GetFirstIndexGreater(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetFirstIndexGreater<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low; if (listOrdered[high].CompareTo(x) <= 0) return high + 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid].CompareTo(x) > 0) high = mid; else low = mid + 1; } return low; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered) where T : IComparable { return GetLastIndexLess(x, listOrdered, 0, listOrdered.Count - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long GetLastIndexLess<T>(T x, IList<T> listOrdered, int low, int high) where T : IComparable { var count = listOrdered.Count; if (count == 0) return low - 1; if (listOrdered[0].CompareTo(x) >= 0) return low - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid].CompareTo(x) < 0) low = mid; else high = mid - 1; } return low; } } public static class BellmanFord { public class Vertex { public long Distance { get; set; } public Vertex() { Distance = long.MaxValue; } } public class Edge { public int From { get; private set; } public int To { get; private set; } public long Weight { get; private set; } public Edge(int from, int to, long weight) { From = from; To = to; Weight = weight; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void GetReachable(int origin, ref HashSet<int> reached, ref Dictionary<int, int[]> paths) { if (reached.Contains(origin)) return; reached.Add(origin); if (paths.ContainsKey(origin) == false) return; foreach (var p in paths[origin]) GetReachable(p, ref reached, ref paths); } /// <summary> /// null: 負の無限大 /// long.MaxValue: たどり着けない /// その他: 距離 /// </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long? RunBellmanFord(int vertexCount, List<Edge> rawEdges, int source, int dest) { var forwards = rawEdges.GroupBy(x => x.From) .ToDictionary(x => x.Key, x => x.Select(xs => xs.To).ToArray()); var reverses = rawEdges.GroupBy(x => x.To).ToDictionary( x => x.Key, x => x.Select(xs => xs.From).ToArray()); var fromSource = new HashSet<int>(); var toDest = new HashSet<int>(); GetReachable(source, ref fromSource, ref forwards); GetReachable(dest, ref toDest, ref reverses); var edges = rawEdges.Where(e => fromSource.Contains(e.From)) .Where(e => fromSource.Contains(e.To)) .Where(e => toDest.Contains(e.From)) .Where(e => toDest.Contains(e.To)) .ToArray(); // initialize distances var vertices = new List<Vertex>(); for (int i = 0; i < vertexCount; i++) vertices.Add(new Vertex()); vertices[source].Distance = 0L; // update distances for (int i = 0; i < vertices.Count; i++) { foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance == long.MaxValue) continue; var newDistance = from.Distance + e.Weight; if (to.Distance > newDistance) { to.Distance = newDistance; } } } // check negative cycle foreach (var e in edges) { var from = vertices[e.From]; var to = vertices[e.To]; if (from.Distance + e.Weight < to.Distance) return null; } return vertices[dest].Distance; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(int a, int b) => Gcd((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(int a, int b) => Lcm((long)a, (long)b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(int n, int p) => Pow((long)n, (long)p); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(int n) => Divisors((long)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IEnumerable<T> Repeat<T>(T t, long n) { for (long i = 0L; i < n; i++) yield return t; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set998244353() { divider = 998244353L; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, long b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator +(Mint a, int b) => a + new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, long b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator -(Mint a, int b) => a - new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, long b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator *(Mint a, int b) => a * new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, long b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint operator /(Mint a, int b) => a / new Mint(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mint Pow(long p) => new Mint(PowImpl(Value, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : powered * a % divider; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); [MethodImpl(MethodImplOptions.AggressiveInlining)] private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
[["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 210, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22]]
8
10,117
12
using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { var n = ReadLine(); var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray(); long answer = 1; if (line.Any(value => value == 0)) { WriteLine(0); return; } foreach (var value in line) { answer *= value; if (answer > 1000000000000000000 || answer < 0) { WriteLine(-1); return; } } WriteLine(answer); } } }
using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { var n = ReadLine(); var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray(); long answer = 1; if (line.Any(value => value == 0)) { WriteLine(0); return; } foreach (var value in line) { if (answer > 1000000000000000000 / value) { WriteLine(-1); return; } answer *= value; } WriteLine(answer); } } }
[["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
150
14
using System; using System.Linq; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); int n = sc.NextInt(); int[] a = sc.IntArray(); long target = 1000000000000000000L; long ans = 1; for (int i = 0; i < n; i++) { if (a[i] > target / ans) { Console.WriteLine("-1"); return; } ans *= a[i]; } Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Linq; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); int n = sc.NextInt(); long[] a = sc.LongArray(); if (a.Contains(0)) { Console.WriteLine("0"); return; } long target = 1000000000000000000L; long ans = 1; for (int i = 0; i < n; i++) { if (a[i] > target / ans) { Console.WriteLine("-1"); return; } ans *= a[i]; } Console.WriteLine(ans); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 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], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 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
445
26
using System; using System.Linq; class IDONTKNOWCSHARP { public static void Main() { string[] values = GetLines(); long A = long.Parse(values[0]); double B = double.Parse(values[1]); Console.WriteLine((long)(A * B)); // Console.ReadKey(); } static string[] GetLines() { return Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); } }
using System; using System.Linq; class IDONTKNOWCSHARP { public static void Main() { string[] values = GetLines(); long A = long.Parse(values[0]); int B = (int)(decimal.Parse(values[1]) * 100); // Console.WriteLine(B); // string a = ; Console.WriteLine((A * B) / 100); /// Console.ReadKey(); } static string[] GetLines() { return Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); } }
[["-", 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, 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], ["+", 51, 23, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 51, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 17, 48], ["+", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
103
16
using System; using System.Linq; namespace _169_c { internal class Multiplication3 { private static void Main(string[] args) { var ab = Console.ReadLine()?.Split(" ").ToArray(); if (ab == null) return; var a = long.Parse(ab[0]); var b = double.Parse(ab[1]); var b100 = (int)(b * 100); var result = a * b100; Console.WriteLine(result / 100); } } }
using System; using System.Linq; namespace _169_c { internal class Multiplication3 { private static void Main(string[] args) { var ab = Console.ReadLine()?.Split(" "); if (ab == null) return; var a = long.Parse(ab[0]); var b = double.Parse(ab[1]); var b100 = (long)Math.Round(b * 100); var result = a * b100; Console.WriteLine(result / 100); } } }
[["-", 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, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 205, 22], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 0, 131], ["+", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22]]
8
112
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class362 { static void Main() { var AB = Console.ReadLine().Split(); var A = long.Parse(AB[0]); var B = (long)(double.Parse(AB[1]) * 100); Console.WriteLine((A * B) / 100); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp15 { class Class362 { static void Main() { var AB = Console.ReadLine().Split(); var A = long.Parse(AB[0]); var B = (long.Parse(AB[1].Remove(AB[1].Length - 3, 1))); Console.WriteLine((A * B) / 100); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 200, 0, 212, 0, 74, 51, 23, 0, 24], ["-", 51, 23, 0, 16, 31, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 214, 205, 204, 205, 22], ["+", 0, 16, 31, 214, 205, 204, 206, 207, 0, 70], ["+", 31, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 214, 205, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 17, 48], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203], ["+", 0, 212, 0, 23, 0, 213, 3, 4, 0, 25]]
8
101
19
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { long A; string B; sc.Make(out A, out B); var res = 0L; res += A * (B[0] - '0'); res += A * (B[2] - '0') / 10; res += A * (B[3] - '0') / 100; Console.WriteLine(res); } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { public void Solve(Scanner sc) { long A; string B; sc.Make(out A, out B); var res = 0L; res += A * (B[0] - '0'); var b = A * (B[2] - '0'); res += b / 10; res += (A * (B[3] - '0') + b % 10 * 10) / 100; Console.WriteLine(res); } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } public void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 31, 23, 0, 16, 12, 16, 31, 16, 31, 22], ["+", 31, 23, 0, 16, 12, 16, 31, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 16, 31, 16, 12, 203], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 17, 48], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 12, 203]]
8
1,918
17
using System; class Program { static void Main() { String[] inline = Console.ReadLine().Split(' '); ulong a = ulong.Parse(inline[0]); double b = double.Parse(inline[1]); ulong ans = (ulong)(a * (ulong)(b * 100) / 100); Console.WriteLine(ans); } }
using System; class Program { static void Main() { String[] inline = Console.ReadLine().Split(' '); ulong a = ulong.Parse(inline[0]); decimal b = decimal.Parse(inline[1]); ulong ans = (ulong)(a * b); Console.WriteLine(ans); } }
[["-", 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], ["-", 51, 23, 0, 16, 31, 16, 12, 74, 0, 24], ["-", 51, 23, 0, 16, 31, 16, 12, 74, 39, 199], ["-", 51, 23, 0, 16, 31, 16, 12, 74, 0, 25], ["-", 0, 16, 31, 16, 12, 74, 51, 23, 0, 24], ["-", 31, 16, 12, 74, 51, 23, 0, 16, 17, 48], ["-", 31, 16, 12, 74, 51, 23, 0, 16, 12, 203], ["-", 0, 16, 31, 16, 12, 74, 51, 23, 0, 25], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 17, 85], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203]]
8
86
13
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace MultiplicationC { class Program { static void Main() { ulong A = 0; double B = 0; ulong answer = 0; string[] input = Console.ReadLine().Split(' '); try { checked { A = ulong.Parse(input[0]); B = double.Parse(input[1]); if (B > 10) { Console.WriteLine("error"); return; } answer = (ulong)Math.Truncate((A * B)); } } catch (OverflowException ex) { Console.WriteLine("error"); return; } catch (FormatException ex) { Console.WriteLine("error"); return; } Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace MultiplicationC { class Program { static void Main() { decimal A = 0m; decimal B = 0m; decimal answer = 0; string[] input = Console.ReadLine().Split(' '); try { checked { A = decimal.Parse(input[0]); B = decimal.Parse(input[1]); if (B > 10) { Console.WriteLine("error"); return; } answer = (decimal)Math.Truncate((A * B)); } } catch (OverflowException ex) { Console.WriteLine("error"); return; } catch (FormatException ex) { Console.WriteLine("error"); return; } Console.WriteLine(answer); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 250], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["+", 0, 196, 0, 1, 0, 11, 12, 74, 39, 199]]
8
183
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); long A = long.Parse(strs[0]); double B = double.Parse(strs[1]); long longB = (long)(B * 100); Console.WriteLine((A * longB) / 100); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); long A = long.Parse(strs[0]); long B = long.Parse(strs[1].Replace(".", "")); Console.WriteLine((A * B) / 100); } } }
[["-", 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, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 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], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 200, 0, 212, 0, 74, 51, 23, 0, 24], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 31, 22], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 17, 48], ["-", 0, 212, 0, 74, 51, 23, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22]]
8
120
24
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var s = stra(); var n = double.Parse(s[0]); double d = double.Parse(s[1]); n *= d; WriteLine((long)n); } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { if (n < r) return 0; r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var s = stra(); var n = long.Parse(s[0]); s[1] = s[1].Replace(".", ""); var d = long.Parse(s[1]); n *= d; WriteLine(n / 100); } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { if (n < r) return 0; r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 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, 11, 12, 213, 63, 214, 205, 204, 205, 22], ["+", 12, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 12, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 12, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 12, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 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, 1, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
1,150
31
using System; using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace Atcoder_Answer { class Program { const Int32 mod = 1000000007; static void Main(string[] args) { string[] Reader = ReadLine().Split(' '); int N = int.Parse(Reader[0]); int K = int.Parse(Reader[1]); int d1 = int.Parse(ReadLine()); List<int> HaveSunukes = new List<int>(); for (int loop = 0; loop < K; loop++) { Reader = ReadLine().Split(' '); for (int j = 0; j < Reader.Length; j++) { HaveSunukes.Add(int.Parse(Reader[j])); } } WriteLine((N - HaveSunukes.Distinct().ToArray().Length)); } #region Functions public decimal floor(float d) => Math.Floor((decimal)d); #endregion class Sunuke { public int D { get; set; } } } public static class Extension { #region 拡張 : bool #region キャスト関連 public static int ToInt(this bool Bool) { if (Bool) return 1; else return 0; } public static string ToString(this bool Bool, string TrueStr, string FalseStr) { if (Bool) return TrueStr; else return FalseStr; } #endregion #endregion #region 拡張 : int #region キャスト関連 public static char ToAlphaBets(this int Base) => (char)Base; #endregion #endregion #region 拡張 : char #region 変換関連 public static char NextAlpha(this char Char) => (char)((Char) + 1); //次の文字を取得 #endregion #endregion #region 拡張 : int[] public static long Sum(this int[] Array) { int Ret = 0; for (int loop = 0; loop < Array.Length; loop++) Ret += Array[loop]; return Ret; } #endregion #region 拡張 : string public static string Multi(this string THIS, int Value) { string RetValue = ""; for (int loop = 0; loop < Value; loop++) RetValue += THIS; return RetValue; } #endregion #region 拡張 : List < string> public static string Sum(this List<string> THIS, string Split) { string RetValue = ""; for (int loop = 0; loop < THIS.Count; loop++) { RetValue += THIS[loop]; } return RetValue; } #endregion } }
using System; using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace Atcoder_Answer { class Program { const Int32 mod = 1000000007; static void Main(string[] args) { string[] Reader = ReadLine().Split(' '); int N = int.Parse(Reader[0]); int K = int.Parse(Reader[1]); List<int> D = new List<int>(); List<int> HaveSunukes = new List<int>(); for (int loop = 0; loop < K; loop++) { D.Add(int.Parse(ReadLine())); Reader = ReadLine().Split(' '); for (int j = 0; j < Reader.Length; j++) { HaveSunukes.Add(int.Parse(Reader[j])); } } WriteLine((N - HaveSunukes.Distinct().ToArray().Length)); ReadKey(); } #region Functions public decimal floor(float d) => Math.Floor((decimal)d); #endregion class Sunuke { public int D { get; set; } } } public static class Extension { #region 拡張 : bool #region キャスト関連 public static int ToInt(this bool Bool) { if (Bool) return 1; else return 0; } public static string ToString(this bool Bool, string TrueStr, string FalseStr) { if (Bool) return TrueStr; else return FalseStr; } #endregion #endregion #region 拡張 : int #region キャスト関連 public static char ToAlphaBets(this int Base) => (char)Base; #endregion #endregion #region 拡張 : char #region 変換関連 public static char NextAlpha(this char Char) => (char)((Char) + 1); //次の文字を取得 #endregion #endregion #region 拡張 : int[] public static long Sum(this int[] Array) { int Ret = 0; for (int loop = 0; loop < Array.Length; loop++) Ret += Array[loop]; return Ret; } #endregion #region 拡張 : string public static string Multi(this string THIS, int Value) { string RetValue = ""; for (int loop = 0; loop < Value; loop++) RetValue += THIS; return RetValue; } #endregion #region 拡張 : List < string> public static string Sum(this List<string> THIS, string Split) { string RetValue = ""; for (int loop = 0; loop < THIS.Count; loop++) { RetValue += THIS[loop]; } return RetValue; } #endregion } }
[["+", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 18], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 47], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["-", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 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], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22]]
8
522
32
using System; namespace ABC166C { class Program { static void Main(string[] args) { var mo = Console.ReadLine().Split(" "); ulong n = ulong.Parse(mo[0]); ulong m = ulong.Parse(mo[1]); ulong[] h = new ulong[n + 1]; ulong[] z = new ulong[n + 1]; ulong[] a = new ulong[m + 1]; ulong[] b = new ulong[m + 1]; ulong[] d = new ulong[n + 2]; ulong y = 0; var mm = Console.ReadLine().Split(" "); for (ulong i = 1; i <= n; i++) h[i] = ulong.Parse(mm[i - 1]); ulong x = 0; for (ulong i = 1; i <= m; i++) { var aa = Console.ReadLine().Split(" "); a[i] = ulong.Parse(aa[0]); b[i] = ulong.Parse(aa[1]); } for (ulong i = 1; i <= m; i++) { if (h[a[i]] < h[b[i]]) { z[a[i]] = 1; } if (h[b[i]] < h[a[i]]) { z[b[i]] = 1; } if (h[a[i]] == h[b[i]]) { z[a[i]] = 1; z[b[i]] = 1; } // d[a[i]] = 1; // d[b[i]] = 1; } // for (ulong i = 1; i <= n; i++) //{ // y += d[i]; // Console.Write(d[i]); //} // y = n - y; // Console.WriteLine(); for (ulong i = 1; i <= n; i++) { Console.Write(z[i]); if (z[i] == 1) x += 1; } // Console.WriteLine(); // Console.WriteLine(y); Console.WriteLine(n - x); } } }
using System; namespace ABC166C { class Program { static void Main(string[] args) { var mo = Console.ReadLine().Split(" "); ulong n = ulong.Parse(mo[0]); ulong m = ulong.Parse(mo[1]); ulong[] h = new ulong[n + 1]; ulong[] z = new ulong[n + 1]; ulong[] a = new ulong[m + 1]; ulong[] b = new ulong[m + 1]; ulong[] d = new ulong[n + 2]; ulong y = 0; var mm = Console.ReadLine().Split(" "); for (ulong i = 1; i <= n; i++) h[i] = ulong.Parse(mm[i - 1]); ulong x = 0; for (ulong i = 1; i <= m; i++) { var aa = Console.ReadLine().Split(" "); a[i] = ulong.Parse(aa[0]); b[i] = ulong.Parse(aa[1]); } for (ulong i = 1; i <= m; i++) { if (h[a[i]] < h[b[i]]) { z[a[i]] = 1; } if (h[b[i]] < h[a[i]]) { z[b[i]] = 1; } if (h[a[i]] == h[b[i]]) { z[a[i]] = 1; z[b[i]] = 1; } // d[a[i]] = 1; // d[b[i]] = 1; } // for (ulong i = 1; i <= n; i++) //{ // y += d[i]; // Console.Write(d[i]); //} // y = n - y; // Console.WriteLine(); for (ulong i = 1; i <= n; i++) { // Console.Write(z[i]); if (z[i] == 1) x += 1; } // Console.WriteLine(); // Console.WriteLine(y); Console.WriteLine(n - x); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
423
10
using System.Collections.Generic; using System.Collections; using System.IO; using System.Linq; using System.Text; using System; namespace cysharp_test { class Program { static void Main(string[] args) { new Program().solve(); } void solve() { int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int N = nm[0]; int M = nm[1]; long[] heights = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); bool[] possibility = new bool[N]; for (int i = 0; i < N; i++) { possibility[i] = true; } for (int i = 0; i < M; i++) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (heights[input[0] - 1] > heights[input[1] - 1]) possibility[input[1] - 1] = false; else if (heights[input[0] - 1] < heights[input[1] - 1]) possibility[input[0] - 1] = false; } Console.WriteLine(possibility.Count(b => b)); Console.ReadKey(); } } struct Vector2 { public Vector2(long x, long y) { this.x = x; this.y = y; } public long x, y; public static Vector2 operator +(Vector2 a, Vector2 b) { return new Vector2(a.x + b.x, a.y + b.y); } public static Vector2 operator -(Vector2 a, Vector2 b) { return new Vector2(a.x - b.x, a.y - b.y); } public static Vector2 operator *(Vector2 a, long scala) { return new Vector2(a.x * scala, a.y + scala); } public static bool operator ==(Vector2 a, Vector2 b) { return (a.x == b.x) && (a.y == b.y); } public static bool operator !=(Vector2 a, Vector2 b) { return !(a.x == b.x) && (a.y == b.y); } public override int GetHashCode() { return (int)(x + y); } public override bool Equals(object obj) { if (!(obj == null) && obj is Vector2) { return (this == (Vector2)obj); } else return false; } public override string ToString() { return ("(" + x + "," + y + ")"); } } }
using System.Collections.Generic; using System.Collections; using System.IO; using System.Linq; using System.Text; using System; namespace cysharp_test { class Program { static void Main(string[] args) { new Program().solve(); } void solve() { int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int N = nm[0]; int M = nm[1]; long[] heights = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); bool[] possibility = new bool[N]; for (int i = 0; i < N; i++) { possibility[i] = true; } for (int i = 0; i < M; i++) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (heights[input[0] - 1] > heights[input[1] - 1]) possibility[input[1] - 1] = false; else if (heights[input[0] - 1] < heights[input[1] - 1]) possibility[input[0] - 1] = false; else { possibility[input[0] - 1] = false; possibility[input[1] - 1] = false; } } Console.WriteLine(possibility.Count(b => b)); Console.ReadKey(); } } struct Vector2 { public Vector2(long x, long y) { this.x = x; this.y = y; } public long x, y; public static Vector2 operator +(Vector2 a, Vector2 b) { return new Vector2(a.x + b.x, a.y + b.y); } public static Vector2 operator -(Vector2 a, Vector2 b) { return new Vector2(a.x - b.x, a.y - b.y); } public static Vector2 operator *(Vector2 a, long scala) { return new Vector2(a.x * scala, a.y + scala); } public static bool operator ==(Vector2 a, Vector2 b) { return (a.x == b.x) && (a.y == b.y); } public static bool operator !=(Vector2 a, Vector2 b) { return !(a.x == b.x) && (a.y == b.y); } public override int GetHashCode() { return (int)(x + y); } public override bool Equals(object obj) { if (!(obj == null) && obj is Vector2) { return (this == (Vector2)obj); } else return false; } public override string ToString() { return ("(" + x + "," + y + ")"); } } }
[["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 46]]
8
593
27
using System.Collections.Generic; using System.Collections; using System.IO; using System.Linq; using System.Text; using System; namespace cysharp_test { class Program { static void Main(string[] args) { new Program().solve(); } void solve() { int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = nm[0]; var M = nm[1]; var heights = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var connections = new List<int>[N]; for (int i = 0; i < N; i++) connections[i] = new List<int>(); for (int i = 0; i < M; i++) { var bridges = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); connections[bridges[0] - 1].Add(bridges[1] - 1); connections[bridges[1] - 1].Add(bridges[0] - 1); } bool[] canBe = new bool[N]; for (int i = 0; i < N; i++) canBe[i] = true; int count = 0; for (int i = 0; i < N; i++) { if (!canBe[i]) continue; if (connections[i].Count() == 0) { count++; continue; } else { foreach (var n in connections[i]) { if (heights[n] < heights[i]) { canBe[n] = false; count++; break; } } } } Console.WriteLine(count); Console.ReadKey(); } } struct Vector2 { public Vector2(long x, long y) { this.x = x; this.y = y; } public long x, y; public static Vector2 operator +(Vector2 a, Vector2 b) { return new Vector2(a.x + b.x, a.y + b.y); } public static Vector2 operator -(Vector2 a, Vector2 b) { return new Vector2(a.x - b.x, a.y - b.y); } public static Vector2 operator *(Vector2 a, long scala) { return new Vector2(a.x * scala, a.y + scala); } public static bool operator ==(Vector2 a, Vector2 b) { return (a.x == b.x) && (a.y == b.y); } public static bool operator !=(Vector2 a, Vector2 b) { return !(a.x == b.x) && (a.y == b.y); } public override int GetHashCode() { return (int)(x + y); } public override bool Equals(object obj) { if (!(obj == null) && obj is Vector2) { return (this == (Vector2)obj); } else return false; } public override string ToString() { return ("(" + x + "," + y + ")"); } } }
using System.Collections.Generic; using System.Collections; using System.IO; using System.Linq; using System.Text; using System; namespace cysharp_test { class Program { static void Main(string[] args) { new Program().solve(); } void solve() { int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var N = nm[0]; var M = nm[1]; var heights = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); var connections = new List<int>[N]; for (int i = 0; i < N; i++) connections[i] = new List<int>(); for (int i = 0; i < M; i++) { var bridges = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); connections[bridges[0] - 1].Add(bridges[1] - 1); connections[bridges[1] - 1].Add(bridges[0] - 1); } bool[] canBe = new bool[N]; for (int i = 0; i < N; i++) canBe[i] = true; int count = 0; for (int i = 0; i < N; i++) { if (!canBe[i]) continue; if (connections[i].Count() == 0) { count++; continue; } else { int c = connections[i].Count(); foreach (var n in connections[i]) { if (heights[n] < heights[i]) { canBe[n] = false; c--; continue; } else { break; } } if (c == 0) count++; } } Console.WriteLine(count); Console.ReadKey(); } } struct Vector2 { public Vector2(long x, long y) { this.x = x; this.y = y; } public long x, y; public static Vector2 operator +(Vector2 a, Vector2 b) { return new Vector2(a.x + b.x, a.y + b.y); } public static Vector2 operator -(Vector2 a, Vector2 b) { return new Vector2(a.x - b.x, a.y - b.y); } public static Vector2 operator *(Vector2 a, long scala) { return new Vector2(a.x * scala, a.y + scala); } public static bool operator ==(Vector2 a, Vector2 b) { return (a.x == b.x) && (a.y == b.y); } public static bool operator !=(Vector2 a, Vector2 b) { return !(a.x == b.x) && (a.y == b.y); } public override int GetHashCode() { return (int)(x + y); } public override bool Equals(object obj) { if (!(obj == null) && obj is Vector2) { return (this == (Vector2)obj); } else return false; } public override string ToString() { return ("(" + x + "," + y + ")"); } } }
[["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 212, 0, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 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, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 75, 196, 0, 210, 8, 196, 0, 57, 0, 95], ["+", 0, 210, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 24], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 57, 0, 25], ["+", 75, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 75, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 57, 75, 196, 0, 57, 64, 1, 0, 35]]
8
684
30
using System; namespace C { class Program { static int[] ToIntAry(string[] str) { int len = str.Length; int[] intary = new int[len]; for (int i = 0; i < len; i++) { intary[i] = int.Parse(str[i]); } return intary; } static void Main(string[] args) { int[] NM = ToIntAry(Console.ReadLine().Split(' ')); int n = NM[0], m = NM[1]; int[] input = ToIntAry(Console.ReadLine().Split(' ')); int[] Hs = new int[n + 1]; input.CopyTo(Hs, 1); int[] Score = new int[n + 1]; Score[0] = 1; for (int i = 1; i <= n; i++) { Score[i] = 0; } int Count = 0; int a, b; for (int i = 0; i < m; i++) { input = ToIntAry(Console.ReadLine().Split(' ')); a = input[0]; b = input[1]; if (Hs[a] < Hs[b]) { Score[a]++; } else { Score[b]++; } } foreach (int s in Score) { if (s < 1) { Count++; } } Console.WriteLine(Count); } } }
using System; namespace C { class Program { static int[] ToIntAry(string[] str) { int len = str.Length; int[] intary = new int[len]; for (int i = 0; i < len; i++) { intary[i] = int.Parse(str[i]); } return intary; } static void Main(string[] args) { int[] NM = ToIntAry(Console.ReadLine().Split(' ')); int n = NM[0], m = NM[1]; int[] input = ToIntAry(Console.ReadLine().Split(' ')); int[] Hs = new int[n + 1]; input.CopyTo(Hs, 1); int[] Score = new int[n + 1]; Score[0] = 1; for (int i = 1; i <= n; i++) { Score[i] = 0; } int Count = 0; int a, b; for (int i = 0; i < m; i++) { input = ToIntAry(Console.ReadLine().Split(' ')); a = input[0]; b = input[1]; Score[a] += Convert.ToInt32(Hs[a] <= Hs[b]); Score[b] += Convert.ToInt32(Hs[a] >= Hs[b]); } foreach (int s in Score) { if (s == 0) { Count++; } } Console.WriteLine(Count); } } }
[["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 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, 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, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 75, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203]]
8
323
37
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemC { class Program { static void Main(string[] args) { var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = read[0]; var M = read[1]; var Hs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var As = new int[M]; var Bs = new int[M]; var maxs = new int[N]; for (int i = 0; i < M; i++) { read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); As[i] = read[0]; Bs[i] = read[1]; maxs[As[i] - 1] = Math.Max(Hs[Bs[i] - 1], maxs[As[i] - 1]); maxs[Bs[i] - 1] = Math.Max(Hs[As[i] - 1], maxs[Bs[i] - 1]); } var goods = Hs.Select((x, i) => Hs[i] > maxs[i]); //.Where(x => x); Console.WriteLine(goods.Count()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemC { class Program { static void Main(string[] args) { var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var N = read[0]; var M = read[1]; var Hs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var As = new int[M]; var Bs = new int[M]; var maxs = new int[N]; for (int i = 0; i < M; i++) { read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); As[i] = read[0]; Bs[i] = read[1]; maxs[As[i] - 1] = Math.Max(Hs[Bs[i] - 1], maxs[As[i] - 1]); maxs[Bs[i] - 1] = Math.Max(Hs[As[i] - 1], maxs[Bs[i] - 1]); } var goods = Hs.Select((x, i) => Hs[i] > maxs[i]).Where(x => x); Console.WriteLine(goods.Count()); } } }
[["+", 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, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
326
7
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { var num = Console.ReadLine() .Trim() .Split(' ') .Select(x => long.Parse(x)) .ToArray(); var tower = Console.ReadLine() .Trim() .Split(' ') .Select(x => long.Parse(x)) .ToArray(); for (var i = 0; i < num[1]; i++) { var road = Console.ReadLine() .Trim() .Split(' ') .Select(x => long.Parse(x) - 1) .ToArray(); if (tower[road[0]] < tower[road[1]]) { tower[road[0]] = 0; } else if (tower[road[0]] == tower[road[1]]) { tower[road[0]] = 0; tower[road[1]] = 0; } else if (tower[road[0]] > tower[road[1]]) { tower[road[1]] = 0; } } var ans = tower.Where(x => x > 0).Count(); Console.Write(ans); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { var num = Console.ReadLine() .Trim() .Split(' ') .Select(x => long.Parse(x)) .ToArray(); long[] tower = Console.ReadLine() .Trim() .Split(' ') .Select(x => long.Parse(x)) .ToArray(); var ans = new int[num[0]]; for (var i = 0; i < num[1]; i++) { var road = Console.ReadLine() .Trim() .Split(' ') .Select(x => long.Parse(x) - 1) .ToArray(); if (tower[road[0]] < tower[road[1]]) { ans[road[0]] = -1; } else if (tower[road[0]] == tower[road[1]]) { ans[road[0]] = -1; ans[road[1]] = -1; } else if (tower[road[0]] > tower[road[1]]) { ans[road[1]] = -1; } } Console.Write(ans.Where(x => x >= 0).Count()); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 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], ["+", 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, 227, 0, 228], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 227, 39, 224, 225, 226, 0, 204, 205, 22], ["+", 39, 224, 225, 226, 0, 204, 206, 207, 0, 70], ["+", 225, 226, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 39, 224, 225, 226, 0, 204, 206, 207, 0, 73], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 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], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 47], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 17, 20], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
291
51
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = input1[0]; var M = input1[1]; var observatories = Console.ReadLine() .Split() .Select( h => new Observatory() { Height = int.Parse(h), Good = true }) .ToArray(); for (int i = 0; i < M; i++) { var input2 = Console.ReadLine().Split().Select(int.Parse).ToArray(); var A = input2[0] - 1; var B = input2[1] - 1; if (observatories[A].Height < observatories[B].Height) { observatories[A].Good = false; } else { observatories[B].Good = false; } } Console.WriteLine(observatories.Count(o => o.Good)); } class Observatory { public int Height { get; set; } public bool Good { get; set; } } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = input1[0]; var M = input1[1]; var observatories = Console.ReadLine() .Split() .Select( h => new Observatory() { Height = int.Parse(h), Good = true }) .ToArray(); for (int i = 0; i < M; i++) { var input2 = Console.ReadLine().Split().Select(int.Parse).ToArray(); var A = input2[0] - 1; var B = input2[1] - 1; if (observatories[A].Height < observatories[B].Height) { observatories[A].Good = false; } else if (observatories[A].Height > observatories[B].Height) { observatories[B].Good = false; } else { observatories[A].Good = false; observatories[B].Good = false; } } Console.WriteLine(observatories.Count(o => o.Good)); } class Observatory { public int Height { get; set; } public bool Good { get; set; } } } }
[["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 214, 205, 204, 205, 22], ["+", 15, 16, 31, 214, 205, 204, 206, 207, 0, 70], ["+", 31, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 15, 16, 31, 214, 0, 131], ["+", 0, 57, 75, 57, 15, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 75, 57, 15, 16, 12, 214, 205, 204, 205, 22], ["+", 15, 16, 12, 214, 205, 204, 206, 207, 0, 70], ["+", 12, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 57, 15, 16, 12, 214, 0, 131], ["+", 0, 57, 75, 57, 15, 16, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 1, 0, 11, 31, 214, 205, 204, 205, 22], ["+", 0, 11, 31, 214, 205, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 214, 205, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 31, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 11, 31, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 11, 31, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35]]
8
252
37
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Text; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var Hs = Console.ReadLine().Split().Select(int.Parse).ToArray(); bool[] ret = new bool[NM[0]]; for (int i = 0; i < NM[1]; i++) { var AB = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); if (Hs[AB[0]] < Hs[AB[1]]) { ret[AB[0]] = true; } else if ((Hs[AB[0]] > Hs[AB[1]])) { ret[AB[1]] = true; } } Console.WriteLine(ret.Count(x => x == false)); } } }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Text; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var Hs = Console.ReadLine().Split().Select(int.Parse).ToArray(); bool[] batList = new bool[NM[0]]; for (int i = 0; i < NM[1]; i++) { var AB = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray(); if (Hs[AB[0]] < Hs[AB[1]]) { batList[AB[0]] = true; } else if ((Hs[AB[1]] < Hs[AB[0]])) { batList[AB[1]] = true; } else { batList[AB[0]] = true; batList[AB[1]] = true; } } Console.WriteLine(batList.Count(x => x == false)); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 75, 57, 15, 23, 0, 16, 17, 47], ["+", 0, 57, 75, 57, 15, 23, 0, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22]]
8
266
37
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionC { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // int n = int.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 var inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int N = inputintArray[0]; int M = inputintArray[1]; var H = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int[] E = Enumerable.Repeat<int>(1, N).ToArray(); int j; for (j = 0; j < M; j++) { var Road = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); if (H[Road[0] - 1] >= H[Road[1] - 1]) { E[Road[1] - 1] = 0; // Console.WriteLine(Road[1]+"yes"); } else if (H[Road[0] - 1] <= H[Road[1] - 1]) { E[Road[0] - 1] = 0; // Console.WriteLine(Road[0]+"no"); } } List<int> listE = new List<int>(E); Console.WriteLine(listE.Count(x => x == 1)); // int[] array = listE.ToArray(); // Console.WriteLine("=== array ==="); // foreach (var x in array) //{ // Console.WriteLine(x); //} Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionC { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 // string s = Console.ReadLine(); // 整数の入力 // int n = int.Parse(Console.ReadLine()); // 文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); // 整数配列の入力 var inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int N = inputintArray[0]; int M = inputintArray[1]; var H = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int[] E = Enumerable.Repeat<int>(1, N).ToArray(); int j; for (j = 0; j < M; j++) { var Road = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); if (H[Road[0] - 1] > H[Road[1] - 1]) { E[Road[1] - 1] = 0; // Console.WriteLine(Road[1]+"yes"); } else if (H[Road[0] - 1] < H[Road[1] - 1]) { E[Road[0] - 1] = 0; // Console.WriteLine(Road[0]+"no"); } else { E[Road[1] - 1] = 0; E[Road[0] - 1] = 0; } } List<int> listE = new List<int>(E); Console.WriteLine(listE.Count(x => x == 1)); // int[] array = listE.ToArray(); // Console.WriteLine("=== array ==="); // foreach (var x in array) //{ // Console.WriteLine(x); //} Console.Out.Flush(); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35]]
8
356
31
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Abc166C { public static void Main() { var nm = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var n = nm[0]; var m = nm[1]; var h = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var check = new bool[n]; for (int i = 0; i < m; i++) { var ab = Console.ReadLine().Split(' ').Select(j => int.Parse(j) - 1).ToArray(); if (h[ab[0]] < h[ab[1]]) check[ab[0]] = true; } Console.WriteLine(check.Count(i => !i)); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Abc166C { public static void Main() { var nm = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var n = nm[0]; var m = nm[1]; var h = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); var check = new bool[n]; for (int i = 0; i < m; i++) { var ab = Console.ReadLine().Split(' ').Select(j => int.Parse(j) - 1).ToArray(); if (h[ab[0]] <= h[ab[1]]) check[ab[0]] = true; if (h[ab[0]] >= h[ab[1]]) check[ab[1]] = true; } Console.WriteLine(check.Count(i => !i)); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 211, 0, 146], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 8, 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, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["+", 64, 1, 0, 11, 31, 204, 206, 207, 0, 70]]
8
213
30
using System; class Program { static void Main(string[] args) { var observatory = Console.ReadLine().Split(' '); var elevation = Console.ReadLine().Split(' '); bool[] goodObservatory = new bool[int.Parse(observatory[0])]; for (int idx = 0; idx < goodObservatory.Length; idx++) { goodObservatory[idx] = true; } for (int idx = 0; idx < int.Parse(observatory[1]); idx++) { var road = Console.ReadLine().Split(' '); if (int.Parse(elevation[int.Parse(road[0]) - 1]) == int.Parse(elevation[int.Parse(road[1]) - 1])) { goodObservatory[int.Parse(road[0]) - 1] = false; goodObservatory[int.Parse(road[1]) - 1] = false; continue; } if (int.Parse(elevation[int.Parse(road[0]) - 1]) > int.Parse(elevation[int.Parse(road[1]) - 1])) { goodObservatory[int.Parse(road[0]) - 1] = true; goodObservatory[int.Parse(road[1]) - 1] = false; } else { goodObservatory[int.Parse(road[0]) - 1] = false; goodObservatory[int.Parse(road[1]) - 1] = true; } } int count = 0; for (int idx = 0; idx < goodObservatory.Length; idx++) { if (goodObservatory[idx]) count++; } Console.WriteLine(count.ToString()); } }
using System; class Program { static void Main(string[] args) { var observatory = Console.ReadLine().Split(' '); var elevation = Console.ReadLine().Split(' '); bool[] goodObservatory = new bool[int.Parse(observatory[0])]; for (int idx = 0; idx < goodObservatory.Length; idx++) { goodObservatory[idx] = true; } for (int idx = 0; idx < int.Parse(observatory[1]); idx++) { var road = Console.ReadLine().Split(' '); if (int.Parse(elevation[int.Parse(road[0]) - 1]) == int.Parse(elevation[int.Parse(road[1]) - 1])) { goodObservatory[int.Parse(road[0]) - 1] = false; goodObservatory[int.Parse(road[1]) - 1] = false; continue; } if (int.Parse(elevation[int.Parse(road[0]) - 1]) > int.Parse(elevation[int.Parse(road[1]) - 1])) { goodObservatory[int.Parse(road[1]) - 1] = false; } else { goodObservatory[int.Parse(road[0]) - 1] = false; } } int count = 0; for (int idx = 0; idx < goodObservatory.Length; idx++) { if (goodObservatory[idx]) count++; } Console.WriteLine(count.ToString()); } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 25], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 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], ["-", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 205, 199], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 31, 213, 3, 4, 0, 24], ["-", 31, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 196, 0, 1, 0, 11, 12, 211, 0, 146]]
8
373
34
using System; using System.Collections.Generic; using System.Linq; class abc166_c { public static void Main() { String[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int m = int.Parse(str[1]); int[] h = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); List<int>[] to = new List<int>[n]; for (int i = 0; i < n; i++) { to[i] = new List<int>(); } for (int i = 0; i < m; i++) { int[] ab = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); to[ab[0] - 1].Add(ab[1] - 1); to[ab[1] - 1].Add(ab[0] - 1); } int count = 0; bool flag = true; for (int i = 0; i < n; i++) { List<int> t = to[i]; flag = true; for (int j = 0; j < t.Count; j++) { int cmp = t[j]; if (h[i] < h[cmp]) { flag = false; break; } } if (flag && t.Count != 0) { count++; } } Console.WriteLine(count); } }
using System; using System.Collections.Generic; using System.Linq; class abc166_c { public static void Main() { String[] str = Console.ReadLine().Split(' '); int n = int.Parse(str[0]); int m = int.Parse(str[1]); int[] h = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); List<int>[] to = new List<int>[n]; for (int i = 0; i < n; i++) { to[i] = new List<int>(); } for (int i = 0; i < m; i++) { int[] ab = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); to[ab[0] - 1].Add(ab[1] - 1); to[ab[1] - 1].Add(ab[0] - 1); } int count = 0; bool flag = true; for (int i = 0; i < n; i++) { List<int> t = to[i]; flag = true; for (int j = 0; j < t.Count; j++) { int cmp = t[j]; if (h[i] <= h[cmp]) { flag = false; break; } } if (flag) { count++; } } Console.WriteLine(count); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
350
8
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); var inp2 = Console.ReadLine().Split(' '); bool[] isHillGood = new bool[int.Parse(inp[0])]; for (int i = 0; i < isHillGood.Length; i++) { isHillGood[i] = true; } for (int i = 0; i < int.Parse(inp[1]); i++) { var inpAB = Console.ReadLine().Split(' '); int a = int.Parse(inpAB[0]) - 1; int b = int.Parse(inpAB[1]) - 1; if (int.Parse(inp2[a]) > int.Parse(inp2[b])) { isHillGood[b] = false; } else if (int.Parse(inp2[a]) < int.Parse(inp2[b])) { isHillGood[a] = false; } } int cnt = 0; for (int i = 0; i < isHillGood.Length; i++) { if (isHillGood[i]) cnt++; } Console.WriteLine(cnt); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var inp = Console.ReadLine().Split(' '); var inp2 = Console.ReadLine().Split(' '); bool[] isHillGood = new bool[int.Parse(inp[0])]; for (int i = 0; i < isHillGood.Length; i++) { isHillGood[i] = true; } for (int i = 0; i < int.Parse(inp[1]); i++) { var inpAB = Console.ReadLine().Split(' '); int a = int.Parse(inpAB[0]) - 1; int b = int.Parse(inpAB[1]) - 1; if (int.Parse(inp2[a]) > int.Parse(inp2[b])) { isHillGood[b] = false; } else if (int.Parse(inp2[a]) < int.Parse(inp2[b])) { isHillGood[a] = false; } else { isHillGood[a] = false; isHillGood[b] = false; } } int cnt = 0; for (int i = 0; i < isHillGood.Length; i++) { if (isHillGood[i]) cnt++; } Console.WriteLine(cnt); } }
[["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
279
17
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] NM = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); int[] H = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); bool[] NGs = new bool[NM[0]]; List<int>[] Roads = new List<int>[NM[0]]; for (int i = 0; i < NM[1]; i++) { int[] v = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); if (!(NGs[v[0] - 1])) { if (H[v[0] - 1] > H[v[1] - 1]) { Roads[v[0] - 1].Add(v[1] - 1); } else { NGs[v[0] - 1] = true; } } if (!(NGs[v[1] - 1])) { if (H[v[1] - 1] > H[v[0] - 1]) { Roads[v[1] - 1].Add(v[0] - 1); } else { NGs[v[1] - 1] = true; } } } int res = 0; for (int i = 0; i < NM[0]; i++) { if (!(NGs[i])) { bool t = true; for (int j = 0; j < Roads[i].Count; j++) { if (H[i] <= H[Roads[i][j]]) { t = false; break; } } if (t) { res += 1; } } } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] NM = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); int[] H = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); bool[] NGs = new bool[NM[0]]; List<int>[] Roads = new List<int>[NM[0]]; for (int i = 0; i < Roads.Length; i++) { Roads[i] = new List<int>(); } for (int i = 0; i < NM[1]; i++) { int[] v = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); if (!(NGs[v[0] - 1])) { if (H[v[0] - 1] > H[v[1] - 1]) { Roads[v[0] - 1].Add(v[1] - 1); } else { NGs[v[0] - 1] = true; } } if (!(NGs[v[1] - 1])) { if (H[v[1] - 1] > H[v[0] - 1]) { Roads[v[1] - 1].Add(v[0] - 1); } else { NGs[v[1] - 1] = true; } } } int res = 0; for (int i = 0; i < NM[0]; i++) { if (!(NGs[i])) { bool t = true; for (int j = 0; j < Roads[i].Count; j++) { if (H[i] <= H[Roads[i][j]]) { t = false; break; } } if (t) { res += 1; } } } Console.WriteLine(res); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 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, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 230, 0, 228], ["+", 0, 1, 0, 11, 12, 230, 39, 236, 141, 22], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 11, 12, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
8
436
31
using System; using System.Collections.Generic; class Program { struct tenbodaiSt { public int h; public List<int> route; } static void Main(string[] args) { int i, j; string[] strInput = Console.ReadLine().Split(' '); int n = int.Parse(strInput[0]); int m = int.Parse(strInput[1]); tenbodaiSt[] tenbodai = new tenbodaiSt[n]; strInput = Console.ReadLine().Split(' '); for (i = 0; i < n; i++) { tenbodai[i].h = int.Parse(strInput[i]); tenbodai[i].route = new List<int>(); } for (i = 0; i < m; i++) { strInput = Console.ReadLine().Split(' '); int a = int.Parse(strInput[0]) - 1; int b = int.Parse(strInput[1]) - 1; tenbodai[a].route.Add(b); tenbodai[b].route.Add(a); } int result = 0; for (i = 0; i < n; i++) { for (j = 0; j < tenbodai[i].route.Count; j++) { int k = tenbodai[i].route[j]; if (tenbodai[i].h < tenbodai[k].h) { break; } else if (j == tenbodai[i].route.Count - 1) { result++; } } } Console.WriteLine(result); return; } }
using System; using System.Collections.Generic; class Program { struct tenbodaiSt { public int h; public List<int> route; } static void Main(string[] args) { int i, j; string[] strInput = Console.ReadLine().Split(' '); int n = int.Parse(strInput[0]); int m = int.Parse(strInput[1]); tenbodaiSt[] tenbodai = new tenbodaiSt[n]; strInput = Console.ReadLine().Split(' '); for (i = 0; i < n; i++) { tenbodai[i].h = int.Parse(strInput[i]); tenbodai[i].route = new List<int>(); } for (i = 0; i < m; i++) { strInput = Console.ReadLine().Split(' '); int a = int.Parse(strInput[0]) - 1; int b = int.Parse(strInput[1]) - 1; tenbodai[a].route.Add(b); tenbodai[b].route.Add(a); } int result = 0; for (i = 0; i < n; i++) { if (tenbodai[i].route.Count == 0) { result++; } else { for (j = 0; j < tenbodai[i].route.Count; j++) { int k = tenbodai[i].route[j]; if (tenbodai[i].h <= tenbodai[k].h) { break; } else if (j == tenbodai[i].route.Count - 1) //最後のルート? { result++; } } } } Console.WriteLine(result); return; } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 15, 16, 31, 214, 205, 214, 205, 204, 205, 22], ["+", 31, 214, 205, 214, 205, 204, 206, 207, 0, 70], ["+", 205, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 214, 205, 214, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 31, 214, 205, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 214, 205, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 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, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46]]
8
351
23
using System; using System.Linq; using System.Collections; namespace C { class Program { static void Main(string[] args) { var foo = Console.ReadLine().Trim().Split(' '); var N = int.Parse(foo[0]); var M = int.Parse(foo[1]); var bar = Console.ReadLine().Trim().Split(' '); var H = bar.Select(x => int.Parse(x)).ToArray(); var todai = new bool[H.Length]; for (int i = 0; i < todai.Length; i++) { todai[i] = true; } var sumOfWays = new ArrayList(); while (M > 0) { var ways = (Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x))) .ToArray(); var a = ways[0] - 1; var b = ways[1] - 1; sumOfWays.Add(a); sumOfWays.Add(b); todai[a] = H[a] > H[b]; todai[b] = H[b] > H[a]; M--; } Console.WriteLine(todai.Where(x => x).Count()); Console.ReadLine(); } } }
using System; using System.Linq; using System.Collections; namespace C { class Program { static void Main(string[] args) { var foo = Console.ReadLine().Trim().Split(' '); var N = int.Parse(foo[0]); var M = int.Parse(foo[1]); var bar = Console.ReadLine().Trim().Split(' '); var H = bar.Select(x => int.Parse(x)).ToArray(); var todai = new bool[H.Length]; for (int i = 0; i < todai.Length; i++) { todai[i] = true; } var sumOfWays = new ArrayList(); while (M > 0) { var ways = (Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x))) .ToArray(); var a = ways[0] - 1; var b = ways[1] - 1; sumOfWays.Add(a); sumOfWays.Add(b); todai[a] = todai[a] && H[a] > H[b]; todai[b] = todai[b] && H[b] > H[a]; M--; } Console.WriteLine(todai.Where(x => x).Count()); Console.ReadLine(); } } }
[["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 98]]
8
300
10
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public static void Main() { String[] input = Console.ReadLine().Split(); long N = long.Parse(input[0]); long M = long.Parse(input[1]); long[] H = new long[N]; input = Console.ReadLine().Split(); bool[] flag = new bool[N + 1]; for (int i = 0; i < N; i++) { H[i] = long.Parse(input[i]); flag[i] = true; } for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(); long first = long.Parse(input[0]); long second = long.Parse(input[1]); if (H[first - 1] >= H[second - 1]) { flag[second] = false; } if (H[first - 1] <= H[second - 1]) { flag[second] = false; } } long ans = 0; for (int i = 1; i < N + 1; i++) { if (flag[i] == true) ans++; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public static void Main() { String[] input = Console.ReadLine().Split(); long N = long.Parse(input[0]); long M = long.Parse(input[1]); long[] H = new long[N]; input = Console.ReadLine().Split(); bool[] flag = new bool[N + 1]; for (int i = 0; i < N; i++) { H[i] = long.Parse(input[i]); flag[i] = true; } flag[N] = true; for (int i = 0; i < M; i++) { input = Console.ReadLine().Split(); long first = long.Parse(input[0]); long second = long.Parse(input[1]); if (H[first - 1] >= H[second - 1]) { flag[second] = false; } if (H[first - 1] <= H[second - 1]) { flag[first] = false; } } long ans = 0; for (int i = 1; i < N + 1; i++) { if (flag[i] == true) ans++; } Console.WriteLine(ans); } }
[["+", 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], ["+", 8, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22]]
8
293
9
using System; using System.Collections; using System.Collections.Generic; class Program { static Graph G; public struct Graph { public HashSet<int>[] points; public Graph(int n) { points = new HashSet<int>[n]; for (int i = 0; i < n; i++) { points[i] = new HashSet<int>(); } } public void AddLine(int a, int b) { points[a].Add(b); points[b].Add(a); } public void AddDirectionalLine(int a, int b) { points[a].Add(b); } } static void Main(string[] args) { string[] S = Console.ReadLine().Split(' '); int N = int.Parse(S[0]); int M = int.Parse(S[1]); string[] Hstr = Console.ReadLine().Split(' '); int[] Hlist = new int[N]; for (int i = 0; i < N; i++) { Hlist[i] = int.Parse(Hstr[i]); } G = new Graph(N); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split(' '); int temp1 = int.Parse(temp[0]) - 1; int temp2 = int.Parse(temp[1]) - 1; if (Hlist[temp1] < Hlist[temp2]) { G.AddDirectionalLine(temp1, temp2); } else { G.AddDirectionalLine(temp2, temp1); } } int ans = 0; foreach (HashSet<int> pointset in G.points) { if (pointset.Count == 0) { ans++; } } Console.WriteLine(ans); } }
using System; using System.Collections; using System.Collections.Generic; class Program { static Graph G; public struct Graph { public HashSet<int>[] points; public Graph(int n) { points = new HashSet<int>[n]; for (int i = 0; i < n; i++) { points[i] = new HashSet<int>(); } } public void AddLine(int a, int b) { points[a].Add(b); points[b].Add(a); } public void AddDirectionalLine(int a, int b) { points[a].Add(b); } } static void Main(string[] args) { string[] S = Console.ReadLine().Split(' '); int N = int.Parse(S[0]); int M = int.Parse(S[1]); string[] Hstr = Console.ReadLine().Split(' '); int[] Hlist = new int[N]; for (int i = 0; i < N; i++) { Hlist[i] = int.Parse(Hstr[i]); } G = new Graph(N); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split(' '); int temp1 = int.Parse(temp[0]) - 1; int temp2 = int.Parse(temp[1]) - 1; if (Hlist[temp1] < Hlist[temp2]) { G.AddDirectionalLine(temp1, temp2); } else if (Hlist[temp1] > Hlist[temp2]) { G.AddDirectionalLine(temp2, temp1); } else { G.AddLine(temp1, temp2); } } int ans = 0; foreach (HashSet<int> pointset in G.points) { if (pointset.Count == 0) { ans++; } } Console.WriteLine(ans); } }
[["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 204, 205, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 47], ["+", 0, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 21]]
8
398
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { double a = 0; double b = 0; double x = double.Parse(Console.ReadLine()); for (double i = -118; i <= 119; i++) { for (double j = -118; j <= 119; j++) { if (Math.Pow(i, 5) - Math.Pow(j, 5) == Math.Pow(x, 5)) { a = i; b = j; break; } } } Console.WriteLine("{0} {1}", a, b); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { double a = 0; double b = 0; double x = double.Parse(Console.ReadLine()); for (double i = -118; i <= 119; i++) { for (double j = -118; j <= 119; j++) { if (Math.Pow(i, 5) - Math.Pow(j, 5) == x) { a = i; b = j; break; } } } Console.WriteLine("{0} {1}", a, b); } }
[["-", 0, 57, 15, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 21], ["-", 15, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 12, 213, 3, 4, 0, 25]]
8
147
7
using System; namespace abc166 { class Program { static void Main() { var n = long.Parse(Console.ReadLine()); var a = new long[2000]; for (var i = 0; i < a.Length; ++i) { a[i] = (long)Math.Pow(i, 5); } for (var i = 0; i < a.Length; ++i) { for (var j = 0; j < a.Length; ++j) { if (a[i] - a[j] == n) { Console.WriteLine((i + 1) + " " + (j + 1)); return; } else if (a[i] + a[j] == n) { Console.WriteLine((i + 1) + " " + (-j + 1)); return; } } } } } }
using System; namespace abc166 { class Program { static void Main() { var n = long.Parse(Console.ReadLine()); var a = new long[6207]; for (var i = 0; i < a.Length; ++i) { a[i] = (long)Math.Pow(i, 5); } for (var i = 0; i < a.Length; ++i) { for (var j = 0; j < a.Length; ++j) { if (a[i] - a[j] == n) { Console.WriteLine(i + " " + j); return; } else if (a[i] + a[j] == n) { Console.WriteLine(j + " " + (-i)); return; } } } } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 28, 0, 16, 31, 16, 31, 23, 0, 24], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 31, 16, 31, 23, 0, 25], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 0, 16, 12, 23, 0, 16, 31, 241, 0, 22], ["+", 0, 28, 0, 16, 12, 23, 0, 241, 0, 22]]
8
192
20
using System; using System.Collections.Generic; using System.Linq; namespace contest_Csharp { class Program { static long power(long a, long b, long modulo) { long result = 1; long buff = a; for (long i = 1; i <= b; i *= 2) { result = result * ((b / i % (2) == 1) ? buff : 1) % modulo; buff = (buff * buff) % modulo; } return result % modulo; } static void Main(string[] args) { var vals = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); long ansA = 0, ansB = 0; var X = vals[0]; var A = Enumerable.Range(0, 1000) .Select(x => power((long)x, 5, (long)1e12)) .ToList(); var B = Enumerable.Range(0, 1000) .Select(x => power((long)x, 5, (long)1e12)) .ToList(); for (int i = 0; i < 300; i++) { for (int k = i; k < 300; k++) { if (A[i] + A[k] == X) { (ansA, ansB) = (A[i], -A[k]); } } } for (int i = 0; i < 1000; i++) { for (int k = i - 1; k >= 0; k--) { if (A[i] - A[k] == X) { (ansA, ansB) = (A[i], A[k]); } } } Console.WriteLine(ansA + " " + ansB); } } class PriorityQueue<T> where T : IComparable<T> { private List<T> heap = new List<T>(); private int lastindex = -1; private void swap(int n, int m) { T wait = heap[n]; heap[n] = heap[m]; heap[m] = wait; } public int Count() { return lastindex + 1; } public void Enqueue(T data) { int p; if (lastindex + 1 < heap.Count()) { heap[lastindex + 1] = data; } else { heap.Add(data); } lastindex++; p = lastindex; while (true) { if (p > 0 && heap[p].CompareTo(heap[(p - 1) / 2]) <= -1) { swap(p, (p - 1) / 2); p = (p - 1) / 2; } else { break; } } } public T Peek() { return heap[0]; } public T Dequeue() { T result = Peek(); heap[0] = default(T); swap(0, lastindex); lastindex--; int p = 0; while (true) { int np; if (2 * p + 1 > lastindex) { break; } else { np = ((2 * p + 1 == lastindex) || heap[2 * p + 1].CompareTo(heap[2 * p + 2]) <= -1) ? (2 * p + 1) : (2 * p + 2); } if (heap[p].CompareTo(heap[np]) >= 1) { swap(p, np); p = np; } else { break; } } return result; } } }
using System; using System.Collections.Generic; using System.Linq; namespace contest_Csharp { class Program { static long power(long a, long b, long modulo) { long result = 1; long buff = a; for (long i = 1; i <= b; i *= 2) { result = result * ((b / i % (2) == 1) ? buff : 1) % modulo; buff = (buff * buff) % modulo; } return result % modulo; } static void Main(string[] args) { var vals = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); long ansA = 0, ansB = 0; var X = vals[0]; var A = Enumerable.Range(0, 1000) .Select(x => power((long)x, 5, (long)1e12)) .ToList(); var B = Enumerable.Range(0, 1000) .Select(x => power((long)x, 5, (long)1e12)) .ToList(); for (int i = 0; i < 300; i++) { for (int k = i; k < 300; k++) { if (A[i] + A[k] == X) { (ansA, ansB) = (i, -k); } } } for (int i = 0; i < 1000; i++) { for (int k = i - 1; k >= 0; k--) { if (A[i] - A[k] == X) { (ansA, ansB) = (i, k); } } } Console.WriteLine(ansA + " " + ansB); } } class PriorityQueue<T> where T : IComparable<T> { private List<T> heap = new List<T>(); private int lastindex = -1; private void swap(int n, int m) { T wait = heap[n]; heap[n] = heap[m]; heap[m] = wait; } public int Count() { return lastindex + 1; } public void Enqueue(T data) { int p; if (lastindex + 1 < heap.Count()) { heap[lastindex + 1] = data; } else { heap.Add(data); } lastindex++; p = lastindex; while (true) { if (p > 0 && heap[p].CompareTo(heap[(p - 1) / 2]) <= -1) { swap(p, (p - 1) / 2); p = (p - 1) / 2; } else { break; } } } public T Peek() { return heap[0]; } public T Dequeue() { T result = Peek(); heap[0] = default(T); swap(0, lastindex); lastindex--; int p = 0; while (true) { int np; if (2 * p + 1 > lastindex) { break; } else { np = ((2 * p + 1 == lastindex) || heap[2 * p + 1].CompareTo(heap[2 * p + 2]) <= -1) ? (2 * p + 1) : (2 * p + 2); } if (heap[p].CompareTo(heap[np]) >= 1) { swap(p, np); p = np; } else { break; } } return result; } } }
[["-", 0, 11, 12, 288, 0, 28, 0, 204, 205, 22], ["-", 12, 288, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 12, 288, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 12, 288, 0, 28, 0, 241, 0, 204, 205, 22], ["-", 0, 28, 0, 241, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 241, 0, 204, 206, 207, 0, 73]]
8
755
12
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; 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"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var x = long.Parse(input.ReadLine()); var dic = new Dictionary<long, long>(); long ra = 0; long rb = 0; for (long i = -(x / 2) - 1; i < x / 2 + 1; i++) { var a = i; var a5 = (long)Math.Pow(a, 5); dic.Add(a5, a); var b5 = a5 - x; if (dic.ContainsKey(b5)) { ra = a; rb = dic[b5]; break; } } return ra + " " + rb; } // static long Pow(long x, long n) { // long ans = 1; // while (n > 0) { // if (n % 2 == 1) { // ans = ans * x; // } // x = x * x; // n /= 2; // } // return ans; //} }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; 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"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } static object process(TextReader input) { var x = long.Parse(input.ReadLine()); var dic = new Dictionary<long, long>(); long ra = 0; long rb = 0; long z = 6000; for (long i = -z; i < z; i++) { var a = i; var a5 = (long)Math.Pow(a, 5); dic.Add(a5, a); var b5 = a5 - x; if (dic.ContainsKey(b5)) { ra = a; rb = dic[b5]; break; } } return ra + " " + rb; } // static long Pow(long x, long n) { // long ans = 1; // while (n > 0) { // if (n % 2 == 1) { // ans = ans * x; // } // x = x * x; // n /= 2; // } // return ans; //} }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 212, 0, 16, 31, 241, 0, 23, 0, 24], ["-", 0, 16, 31, 241, 0, 23, 0, 16, 31, 22], ["-", 0, 16, 31, 241, 0, 23, 0, 16, 17, 85], ["-", 0, 16, 31, 241, 0, 23, 0, 16, 12, 203], ["-", 0, 212, 0, 16, 31, 241, 0, 23, 0, 25], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 241, 0, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 17, 85], ["-", 0, 7, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
268
19
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var n = Read().Long(); var r = ReadSplit(); var hl = new long[n]; var l1 = new long[n]; var l2 = new long[n]; var ansl = new long[200000]; for (int i = 0; i < n; i++) { var h = r[i].Long(); hl[i] = h; l1[i] = i + 1 + h; ansl[l1[i]] += 1; l2[i] = i + 1 - h; } long ans = 0; for (int i = 0; i < n; i++) { var tmp = l2[i]; if (tmp < 0) continue; ans += ansl[tmp]; } WriteRead(ans); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var n = Read().Long(); var r = ReadSplit(); var hl = new long[n]; var l1 = new long[n]; var l2 = new long[n]; var ansl = new long[600000]; for (int i = 0; i < n; i++) { var h = r[i].Long(); hl[i] = h; l1[i] = i + 1 + h; if (l1[i] > 600000) continue; ansl[l1[i]] += 1; l2[i] = i + 1 - h; } long ans = 0; for (int i = 0; i < n; i++) { var tmp = l2[i]; if (tmp < 0) continue; ans += ansl[tmp]; } WriteRead(ans); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117]]
8
539
13
using System; using System.Collections.Generic; using System.Linq; class Ho { static void Main() { long N = long.Parse(Console.ReadLine()); var A = new long[N]; var zen = Console.ReadLine().Split(); for (long i = 0; i < N; i++) { A[i] = long.Parse(zen[i]); } var Bi = new long[N]; for (int i = 0; i < N; i++) { Bi[i] = A[i] + i; } // Bj = j - A[j] var Bj = new long[N]; for (int j = 0; j < N; j++) { Bj[j] = j - A[j]; } var dic = new Dictionary<long, int>(); for (int i = 0; i < N; i++) { if (!dic.ContainsKey(Bj[i])) dic.Add(Bj[i], 1); // dic[Bj[i]]++; } long ans = 0; for (int i = 0; i < N; i++) { if (dic.ContainsKey(Bi[i])) ans += 1; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Ho { static void Main() { long N = long.Parse(Console.ReadLine()); var A = new long[N]; var zen = Console.ReadLine().Split(); for (long i = 0; i < N; i++) { A[i] = long.Parse(zen[i]); } var Bi = new long[N]; for (int i = 0; i < N; i++) { Bi[i] = A[i] + i; } // Bj = j - A[j] var Bj = new long[N]; for (int j = 0; j < N; j++) { Bj[j] = j - A[j]; } var dic = new Dictionary<long, int>(); for (int i = 0; i < N; i++) { if (!dic.ContainsKey(Bj[i])) dic.Add(Bj[i], 0); dic[Bj[i]]++; } var ans = 0L; for (int i = 0; i < N; i++) { if (dic.ContainsKey(Bi[i])) ans += dic[Bi[i]]; } Console.WriteLine(ans); } }
[["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 223, 0, 204, 205, 22], ["+", 0, 1, 0, 223, 0, 204, 206, 207, 0, 70], ["+", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 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, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 12, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
8
267
23
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public static void Main() { String S = Console.ReadLine(); long L = S.Length; int[] a = new int[L + 1]; long ans = 0; int mul = 1; for (int i = a.Length - 2; i >= 0; i--) { a[i] = (a[i + 1] + S[i] * mul) % 2019; mul = mul * 10 % 2019; } int[] b = new int[2019]; foreach (var e in a) { b[e]++; } for (int i = 0; i < 2019; i++) { ans += (long)b[i] * (b[i] - 1) / 2; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public static void Main() { var S = Console.ReadLine().Select(e => e - '0').ToArray(); long L = S.Length; long[] a = new long[L + 1]; long ans = 0; long mul = 1; for (long i = L - 1; i >= 0; i--) { a[i] = (a[i + 1] + S[i] * mul) % 2019; mul = mul * 10 % 2019; } int[] b = new int[2019]; foreach (var e in a) { b[e]++; } for (int i = 0; i < 2019; i++) { ans += (long)b[i] * (b[i] - 1) / 2; } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 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, 33], ["+", 0, 28, 0, 218, 8, 16, 12, 252, 0, 104], ["+", 0, 28, 0, 218, 8, 16, 12, 252, 0, 253], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 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, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 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, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
192
31
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var s = LnStr(); var S = s.Length; var dp = new int[S]; var remains = new int[2019]; s = new string(s.Reverse().ToArray()); print(s.Length); dp[0] = int.Parse(s[0].ToString()) % 2019; remains[dp[0]]++; var d = 1; for (int i = 0; i < s.Length - 1; i++) { d = (d * 10) % 2019; dp[i + 1] = (dp[i] + int.Parse(s[i + 1].ToString()) * d) % 2019; remains[dp[i + 1]]++; } var result = remains[0]; for (int i = 0; i < remains.Length; i++) { result += remains[i] * (remains[i] - 1) / 2; } print(result); } public static void print(object obj) { Console.WriteLine(obj); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var s = LnStr(); var S = s.Length; var dp = new int[S]; var remains = new int[2019]; s = new string(s.Reverse().ToArray()); dp[0] = int.Parse(s[0].ToString()) % 2019; remains[dp[0]]++; var d = 1; for (int i = 0; i < s.Length - 1; i++) { d = (d * 10) % 2019; dp[i + 1] = (dp[i] + int.Parse(s[i + 1].ToString()) * d) % 2019; remains[dp[i + 1]]++; } var result = remains[0]; for (int i = 0; i < remains.Length; i++) { result += remains[i] * (remains[i] - 1) / 2; } print(result); } public static void print(object obj) { Console.WriteLine(obj); } public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; } public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 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, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
713
7
using System; using System.Collections.Generic; using System.Linq; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } class StringComparator3 : IEqualityComparer<string> { public bool Equals(string b1, string b2) { return Compare(b1, b2) == 0; } public int GetHashCode(string bx) { return bx.GetHashCode(); } int Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class Class1 { // static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, // long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } class Tree { public HashSet<long> conn = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } static void Main(string[] args) { var N = ReadString(); int[] nn = new int[200000]; int[] mm = new int[200000]; int[] modCnt = new int[2020]; for (int i = 0; i < N.Length; i++) { nn[i] = int.Parse(N[i].ToString()); } long res = 0; int bs = 0; int mod10 = 1; for (int i = N.Length - 1; i >= 0; i--) { bs = bs + mod10 * nn[i]; bs = bs % 2019; modCnt[bs]++; mod10 = mod10 * 10 % 2019; } for (int i = 0; i < 2020; i++) { if (i == 0 && modCnt[i] == 1) res++; if (modCnt[i] == 0) continue; res += modCnt[i] * (modCnt[i] - 1) / 2; } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } class StringComparator3 : IEqualityComparer<string> { public bool Equals(string b1, string b2) { return Compare(b1, b2) == 0; } public int GetHashCode(string bx) { return bx.GetHashCode(); } int Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class Class1 { // static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, // long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } class Tree { public HashSet<long> conn = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } static void Main(string[] args) { var N = ReadString(); int[] nn = new int[200000]; int[] mm = new int[200000]; int[] modCnt = new int[2020]; for (int i = 0; i < N.Length; i++) { nn[i] = int.Parse(N[i].ToString()); } long res = 0; int bs = 0; int mod10 = 1; modCnt[0] = 1; for (int i = N.Length - 1; i >= 0; i--) { bs = bs + mod10 * nn[i]; bs = bs % 2019; modCnt[bs]++; mod10 = mod10 * 10 % 2019; } for (int i = 0; i < 2020; i++) { if (modCnt[i] == 0) continue; res += modCnt[i] * (modCnt[i] - 1) / 2; } Console.WriteLine(res); } } }
[["+", 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], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 7, 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, 7, 8, 196, 0, 57, 64, 1, 0, 35]]
8
2,143
23
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) { int input = int.Parse(Console.ReadLine()); double PI = 3.1415926535897931; double result = (input * input * PI) / 4.0; Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { int input = int.Parse(Console.ReadLine()); double PI = 3.1415926535897931; double result = (input * 2 * PI); Console.WriteLine(result); } } }
[["-", 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, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 250]]
8
85
11
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using System.Threading; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long A = inputLongArray[0]; long B = inputLongArray[1]; long C = inputLongArray[2]; long K = inputLongArray[3]; if (K <= A) { // 1 * K枚 Console.WriteLine(K); } else if (K <= A + B) { Console.WriteLine(A); } else { Console.WriteLine(A * 1 - (0 + (-1 * (K - A - B)))); } } } } //文字列の入力 // string s = Console.ReadLine(); //整数の入力 // long n = long.Parse(Console.ReadLine()); //文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); //整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(); // Console.ReadKey();
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using System.Threading; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); long A = inputLongArray[0]; long B = inputLongArray[1]; long C = inputLongArray[2]; long K = inputLongArray[3]; if (K <= A) { // 1 * K枚 Console.WriteLine(K); } else if (K <= A + B) { Console.WriteLine(A); } else { Console.WriteLine(A * 1 - 1 * (K - A - B)); } } } } //文字列の入力 // string s = Console.ReadLine(); //整数の入力 // long n = long.Parse(Console.ReadLine()); //文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); //整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(); // Console.ReadKey();
[["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 31, 203], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 72], ["-", 0, 16, 12, 23, 0, 16, 12, 23, 0, 24], ["-", 0, 16, 12, 23, 0, 16, 31, 241, 0, 33], ["-", 0, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
8
202
7
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] inputArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int A = inputArray[0]; int B = inputArray[1]; int C = inputArray[2]; int K = inputArray[3]; int num = 0; int ans = 0; if (A >= K || A + B >= K) { ans = K; } else { ans = A + ((A + B) - K); } Console.WriteLine(ans); } } } // 24579 = hon // 0168 = pon // 3 = bon // long n = long.Parse(Console.ReadLine()); // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(cnt); // Console.ReadKey();
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int[] inputArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int A = inputArray[0]; int B = inputArray[1]; int C = inputArray[2]; int K = inputArray[3]; int num = 0; int ans = 0; if (A >= K) { ans = K; } else if (A + B >= K) { ans = A; } else { ans = A + ((A + B) - K); } Console.WriteLine(ans); } } } // 24579 = hon // 0168 = pon // 3 = bon // long n = long.Parse(Console.ReadLine()); // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(cnt); // Console.ReadKey();
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 12, 22]]
8
153
13
using System; using System.Collections.Generic; class main { static void Main(string[] args) { string[] read = Console.ReadLine().Split(' '); long A = int.Parse(read[0]); long B = int.Parse(read[1]); long C = int.Parse(read[2]); long K = int.Parse(read[3]); if (K <= A + B) { Console.Write(A); } else { Console.Write(A - (K - (A + B))); } } }
using System; using System.Collections.Generic; class main { static void Main(string[] args) { string[] read = Console.ReadLine().Split(' '); long A = int.Parse(read[0]); long B = int.Parse(read[1]); long C = int.Parse(read[2]); long K = int.Parse(read[3]); if (K <= A) { Console.Write(K); } else if (K <= A + B) { Console.Write(A); } else { Console.Write(A - (K - (A + B))); } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22]]
8
132
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionB { /// <summary> /// B - Easy Linear Programming /// https://atcoder.jp/contests/abc167/tasks/abc167_b /// </summary> /// <param name="args"></param> public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列配列の入力 int[] str_ABCK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); //カード総枚数 int num_Sum = str_ABCK[0] + str_ABCK[1] + str_ABCK[2]; //マイナスカードの枚数 int num_Minus = str_ABCK[3] - (str_ABCK[0] + str_ABCK[1]); int result = 0; if (str_ABCK[3] <= str_ABCK[0]) { result = str_ABCK[0]; } else if (str_ABCK[3] <= str_ABCK[0] + str_ABCK[1]) { result = str_ABCK[0]; } else result = str_ABCK[0] - num_Minus; Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class QuestionB { /// <summary> /// B - Easy Linear Programming /// https://atcoder.jp/contests/abc167/tasks/abc167_b /// </summary> /// <param name="args"></param> public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列配列の入力 int[] str_ABCK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); //マイナスカードの枚数 int num_Minus = str_ABCK[3] - (str_ABCK[0] + str_ABCK[1]); int result = 0; if (str_ABCK[3] <= str_ABCK[0]) //引く枚数がAより少ないときは引く枚数が答え { result = str_ABCK[3]; } else if (str_ABCK[3] <= str_ABCK[0] + str_ABCK[1]) { result = str_ABCK[0]; } else result = str_ABCK[0] - num_Minus; Console.WriteLine(result); Console.Out.Flush(); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 212, 0, 16, 31, 16, 31, 204, 205, 22], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72], ["-", 0, 212, 0, 16, 31, 16, 12, 204, 205, 22], ["-", 0, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["-", 31, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203]]
8
236
20
using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Text; class Program { static void Main() { var inputList = Console.ReadLine().Split(' ').ToList(); var a = inputList[0].ToInt32(); var b = inputList[1].ToInt32(); var c = inputList[2].ToInt32(); var k = inputList[3].ToInt32(); var ans = 0; if (a + b >= k) { ans = a; } else { ans = a - (k - a - b); } Console.WriteLine(ans.ToString()); } } static class Extentions { #region 拡張メソッド(string) public static string LeftB(this string stTarget, int iByteSize) { return MidB(stTarget, 1, iByteSize); } public static string MidB(this string stTarget, int iStart) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, iStart - 1, bBytes.Length - iStart + 1); } public static string MidB(this string stTarget, int iStart, int iByteSize) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, iStart - 1, iByteSize); } public static string RightB(this string stTarget, int iByteSize) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, bBytes.Length - iByteSize, iByteSize); } public static bool IsNullOrEmpty(this string str) { return string.IsNullOrEmpty(str); } /// <summary> /// カルチャに依存した比較、または大文字と小文字を区別しない比較などの序数による比較を指定できる /// Contains。 /// </summary> /// <param name="value">対象文字列</param> /// <param name="partialValue">部分文字列</param> /// <param /// name="comparison">カルチャ、大文字と小文字の区別、および並べ替え規則を指定する /// StringComparison</param> <returns>一致する場合に true /// を返します。</returns> public static bool Contains(this string value, string partialValue, StringComparison comparison = 0) { return value.IndexOf(partialValue, comparison) >= 0; } public static bool IsNumeric(this string value) { return decimal.TryParse(value, out decimal d); } public static int ToInt32(this String number, int retValue = 0) { if (!number.IsNumeric()) return retValue; return int.Parse(number); } #endregion }
using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Text; class Program { static void Main() { var inputList = Console.ReadLine().Split(' ').ToList(); var a = inputList[0].ToInt32(); var b = inputList[1].ToInt32(); var c = inputList[2].ToInt32(); var k = inputList[3].ToInt32(); var ans = 0; if (k <= a) { ans = k; } else if (a < k && k <= a + b) { ans = a; } else if (a + b < k) { ans = a - (k - a - b); } Console.WriteLine(ans.ToString()); } } static class Extentions { #region 拡張メソッド(string) public static string LeftB(this string stTarget, int iByteSize) { return MidB(stTarget, 1, iByteSize); } public static string MidB(this string stTarget, int iStart) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, iStart - 1, bBytes.Length - iStart + 1); } public static string MidB(this string stTarget, int iStart, int iByteSize) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, iStart - 1, iByteSize); } public static string RightB(this string stTarget, int iByteSize) { System.Text.Encoding hEncoding = System.Text.Encoding.GetEncoding("utf-8"); byte[] bBytes = hEncoding.GetBytes(stTarget); return hEncoding.GetString(bBytes, bBytes.Length - iByteSize, iByteSize); } public static bool IsNullOrEmpty(this string str) { return string.IsNullOrEmpty(str); } /// <summary> /// カルチャに依存した比較、または大文字と小文字を区別しない比較などの序数による比較を指定できる /// Contains。 /// </summary> /// <param name="value">対象文字列</param> /// <param name="partialValue">部分文字列</param> /// <param /// name="comparison">カルチャ、大文字と小文字の区別、および並べ替え規則を指定する /// StringComparison</param> <returns>一致する場合に true /// を返します。</returns> public static bool Contains(this string value, string partialValue, StringComparison comparison = 0) { return value.IndexOf(partialValue, comparison) >= 0; } public static bool IsNumeric(this string value) { return decimal.TryParse(value, out decimal d); } public static int ToInt32(this String number, int retValue = 0) { if (!number.IsNumeric()) return retValue; return int.Parse(number); } #endregion }
[["+", 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, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 19], ["+", 75, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 72], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25]]
8
493
29
using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; namespace hello_world { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(" "); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int C = int.Parse(input[2]); int K = int.Parse(input[3]); int sum = 0; if (A + B >= K) sum += A; else if (A + B + C > K) sum = 2 * A + B - K; else if (A + B + C <= K) sum = A - C; Console.WriteLine(sum); } } }
using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; namespace hello_world { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(" "); int A = int.Parse(input[0]); int B = int.Parse(input[1]); int C = int.Parse(input[2]); int K = int.Parse(input[3]); int sum = 0; if (A >= K) sum += K; else if (A + B >= K) sum += A; else if (A + B + C > K) sum = 2 * A + B - K; else if (A + B + C <= K) sum = A - C; Console.WriteLine(sum); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 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, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22]]
8
184
11
using System; class Program { static void Main() { string[] In = Console.ReadLine().Split(' '); int a = int.Parse(In[0]); int b = int.Parse(In[1]); int c = int.Parse(In[2]); int k = int.Parse(In[3]); int sum = 0; sum += a; k -= a; if (k > 0) { k -= b; } if (k > 0) { sum -= k; } Console.WriteLine(sum); } }
using System; class Program { static void Main() { string[] In = Console.ReadLine().Split(' '); int a = int.Parse(In[0]); int b = int.Parse(In[1]); int c = int.Parse(In[2]); int k = int.Parse(In[3]); int sum = 0; if (k >= a) { sum += a; } else { sum += k; } k -= a; k -= b; if (k > 0) { sum -= k; } Console.WriteLine(sum); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 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, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
128
23
using System; using System.Collections.Generic; using System.Linq; namespace AtCorder { class Program { static void Main(string[] args) { // 標準入力:A,B,C,K string[] sline = Console.ReadLine().Split(" "); int a = int.Parse(sline[0]); int b = int.Parse(sline[1]); int c = int.Parse(sline[2]); int k = int.Parse(sline[3]); if (a >= k || (a + b) >= k) { Console.WriteLine(a); } else { if (c < k - (a + b)) { // 残りの使える枚数より、cのが多い int ans = a - c; if (ans < 0) ans = 0; Console.WriteLine(ans); } else { // 残りの使える枚数の方が、cより多い int ans = a - (k - (a + b)); Console.WriteLine(ans); } } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCorder { class Program { static void Main(string[] args) { // 標準入力:A,B,C,K string[] sline = Console.ReadLine().Split(" "); int a = int.Parse(sline[0]); int b = int.Parse(sline[1]); int c = int.Parse(sline[2]); int k = int.Parse(sline[3]); if (a > k) { Console.WriteLine(k); } else if (a + b >= k) { Console.WriteLine(a); } else { if (c < k - (a + b)) { // 残りの使える枚数より、cのが多い int ans = a - c; if (ans < 0) ans = 0; Console.WriteLine(ans); } else { // 残りの使える枚数の方が、cより多い int ans = a - (k - (a + b)); Console.WriteLine(ans); } } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25]]
8
196
16
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int sum = 0; int x = 0; int ans = 0; int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]); if (d <= a + b) { ans = a; } else { ans = a - (d - (a + b)); } Console.WriteLine(ans); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int sum = 0; int x = 0; int ans = 0; int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]);  if (d <= a) { ans = d; } else if (d <= a + b) { ans = a; } else { ans = a - (d - (a + b)); } Console.WriteLine(ans); } }
[["+", 0, 208, 0, 235, 8, 201, 0, 195, 8, 196], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 197], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 198], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 224], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 0, 200], ["+", 0, 197, 0, 198, 39, 224, 0, 200, 0, 197], ["+", 0, 198, 39, 224, 0, 200, 0, 197, 0, 198], ["+", 39, 224, 0, 200, 0, 197, 0, 198, 39, 199], ["+", 0, 200, 0, 197, 0, 198, 39, 199, 0, 200], ["+", 0, 197, 0, 198, 39, 199, 0, 200, 0, 197], ["+", 0, 198, 39, 199, 0, 200, 0, 197, 0, 198], ["+", 39, 199, 0, 200, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 39, 199, 0, 200, 0, 57], ["+", 0, 198, 39, 199, 0, 200, 0, 57, 15, 16], ["+", 39, 199, 0, 200, 0, 57, 15, 16, 31, 22], ["+", 0, 200, 0, 57, 15, 16, 31, 22, 12, 22], ["+", 0, 57, 15, 16, 31, 22, 12, 22, 64, 196], ["+", 15, 16, 31, 22, 12, 22, 64, 196, 0, 1], ["+", 31, 22, 12, 22, 64, 196, 0, 1, 75, 57], ["+", 12, 22, 64, 196, 0, 1, 75, 57, 15, 16], ["+", 64, 196, 0, 1, 75, 57, 15, 16, 64, 196], ["+", 0, 1, 75, 57, 15, 16, 64, 196, 75, 196], ["+", 75, 57, 15, 16, 64, 196, 75, 196, 0, 1], ["+", 15, 16, 64, 196, 75, 196, 0, 1, 0, 213], ["+", 64, 196, 75, 196, 0, 1, 0, 213, 63, 214], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 3, 4], ["+", 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, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
141
14
using System; namespace B { class Program { static void Main(string[] args) { var arr = Console.ReadLine().Split(' '); var a = int.Parse(arr[0]); var b = int.Parse(arr[1]); var c = int.Parse(arr[2]); var k = int.Parse(arr[3]); var result = 0; if (k < a) { result += k; } else if (k <= a + b) { result += a; } else if (k < a + b + c) { result += a - (k - a - b); } Console.WriteLine(result); } } }
using System; namespace B { class Program { static void Main(string[] args) { var arr = Console.ReadLine().Split(' '); var a = int.Parse(arr[0]); var b = int.Parse(arr[1]); var c = int.Parse(arr[2]); var k = int.Parse(arr[3]); var result = 0; if (k < a) { result += k; } else if (k <= a + b) { result += a; } else { result += a - (k - a - b); } Console.WriteLine(result); } } }
[["-", 8, 196, 0, 57, 75, 57, 75, 57, 0, 121], ["-", 8, 196, 0, 57, 75, 57, 75, 57, 0, 24], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 17, 18], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["-", 75, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 17, 72], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 75, 57, 75, 57, 0, 25]]
8
154
10
using System; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var A = input[0]; var B = input[1]; var C = input[2]; var K = input[3]; Console.WriteLine(A + B >= K ? A : 2 * A + B - K); } } }
using System; using System.Linq; namespace ConsoleApp { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var A = input[0]; var B = input[1]; var C = input[2]; var K = input[3]; Console.WriteLine(A + B >= K ? Math.Min(A, K) : 2 * A + B - K); } } }
[["+", 0, 28, 0, 41, 64, 213, 63, 214, 205, 22], ["+", 0, 28, 0, 41, 64, 213, 63, 214, 0, 131], ["+", 0, 28, 0, 41, 64, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 41, 64, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 41, 64, 213, 3, 4, 0, 21], ["+", 0, 41, 64, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 41, 64, 213, 3, 4, 0, 25]]
8
104
7
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public static void Main(string[] args) { new B().test(); } } public class B { public void test() { var cards = CommonRead.ReadLongL(); var A = cards[0]; var B = cards[1]; var C = cards[2]; var K = cards[3]; if (K <= A + B) { Console.WriteLine(A); } else { // -1する回数 = K - A + B var exec = K - A - B; Console.WriteLine(A - exec); } } } static class CommonRead { public static string ReadStr() { return Console.ReadLine(); } public static string[] ReadStrA() { return ReadStr().Split(' '); } public static List<string> ReadStrL() { return ReadStrA().ToList(); } public static int ReadInt() { return Convert.ToInt32(ReadStr()); } public static int[] ReadIntA() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray(); } public static List<int> ReadIntL() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToList(); } public static long ReadLong() { return Convert.ToInt64(ReadStr()); } public static long[] ReadLongA() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray(); } public static List<long> ReadLongL() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToList(); } public static decimal ReadDecimal() { return Convert.ToDecimal(ReadStr()); } public static decimal[] ReadDecimalA() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray(); } public static List<decimal> ReadDecimalL() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList(); } public static double ReadDouble() { return Convert.ToDouble(ReadStr()); } public static double[] ReadDoubleA() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray(); } public static List<double> ReadDoubleL() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToList(); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public static void Main(string[] args) { new B().test(); } } public class B { public void test() { var cards = CommonRead.ReadLongL(); var A = cards[0]; var B = cards[1]; var C = cards[2]; var K = cards[3]; if (K < A) { Console.WriteLine(K); } else if (K <= A + B) { Console.WriteLine(A); } else { // -1する回数 = K - A + B var exec = K - A - B; Console.WriteLine(A - exec); } } } static class CommonRead { public static string ReadStr() { return Console.ReadLine(); } public static string[] ReadStrA() { return ReadStr().Split(' '); } public static List<string> ReadStrL() { return ReadStrA().ToList(); } public static int ReadInt() { return Convert.ToInt32(ReadStr()); } public static int[] ReadIntA() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray(); } public static List<int> ReadIntL() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToList(); } public static long ReadLong() { return Convert.ToInt64(ReadStr()); } public static long[] ReadLongA() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray(); } public static List<long> ReadLongL() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToList(); } public static decimal ReadDecimal() { return Convert.ToDecimal(ReadStr()); } public static decimal[] ReadDecimalA() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray(); } public static List<decimal> ReadDecimalL() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList(); } public static double ReadDouble() { return Convert.ToDouble(ReadStr()); } public static double[] ReadDoubleA() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray(); } public static List<double> ReadDoubleL() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToList(); } }
[["+", 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, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22]]
8
524
16
namespace Test { using System; using System.Collections.Generic; using System.Linq; using System.Text; public class Test { public static void Main(string[] args) { var t = new Test(); var n = t.ParseLongList(t.ReadInput()); var a = n[0]; var b = n[1]; var c = n[2]; var k = n[3]; long ans = 0; k -= a; ans = a; k -= b; if (k > 0) { if (c >= k) { ans = ans - (k * 1); } else { ans = ans - (c * 1); } } Console.WriteLine(ans); } public string[] ReadInput() { return Console.ReadLine().Split(' '); } public List<int> ParseIntList(string[] x) { var convertedList = new List<int>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(int.Parse(x[i])); } return convertedList; } public List<double> ParseDoubleList(string[] x) { var convertedList = new List<double>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(double.Parse(x[i])); } return convertedList; } public List<long> ParseLongList(string[] x) { var convertedList = new List<long>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(long.Parse(x[i])); } return convertedList; } public int CountContainWords(string source, string word) { var count = 0; var loopCount = source.Length - (word.Length - 1); for (var i = 0; i < loopCount; i++) { if (source.Substring(i, word.Length) == word) { count++; } } return count; } } }
namespace Test { using System; using System.Collections.Generic; using System.Linq; using System.Text; public class Test { public static void Main(string[] args) { var t = new Test(); var n = t.ParseLongList(t.ReadInput()); var a = n[0]; var b = n[1]; var c = n[2]; var k = n[3]; long ans = 0; if (k >= a) { k -= a; ans = a; } else { ans = ans + (k * 1); k -= a; } k -= b; if (k > 0) { if (c >= k) { ans = ans - (k * 1); } else { ans = ans - (c * 1); } } Console.WriteLine(ans); } public string[] ReadInput() { return Console.ReadLine().Split(' '); } public List<int> ParseIntList(string[] x) { var convertedList = new List<int>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(int.Parse(x[i])); } return convertedList; } public List<double> ParseDoubleList(string[] x) { var convertedList = new List<double>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(double.Parse(x[i])); } return convertedList; } public List<long> ParseLongList(string[] x) { var convertedList = new List<long>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(long.Parse(x[i])); } return convertedList; } public int CountContainWords(string source, string word) { var count = 0; var loopCount = source.Length - (word.Length - 1); for (var i = 0; i < loopCount; i++) { if (source.Substring(i, word.Length) == word) { count++; } } return count; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 48], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
444
25
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { static class Program_B { class Solver { public void Solve() { var abck = Int64s(0); Int64 a = abck[0]; Int64 b = abck[1]; Int64 c = abck[2]; Int64 k = abck[3]; if (a >= k) { Console.WriteLine(a); return; } Int64 diff = k - a; if (b >= diff) { Console.WriteLine(a); return; } Int64 diff2 = diff - b; Console.WriteLine(a - diff2); } // ---------------------------------------------------------------------------- public int Int() { return int.Parse(Console.ReadLine()); } public int[] Ints(int subtract) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) - subtract) .ToArray(); } public Int64[] Int64s(Int64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => Int64.Parse(s) - subtract) .ToArray(); } public long[] Longs() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); } } static void Main(string[] args) { new Solver().Solve(); } } struct ModInt { const int MOD = 1000000007; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GetInverse(long a) { long div; long p = MOD; long x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; using System.Text; namespace AtCoder { static class Program_B { class Solver { public void Solve() { var abck = Int64s(0); Int64 a = abck[0]; Int64 b = abck[1]; Int64 c = abck[2]; Int64 k = abck[3]; if (a >= k) { Console.WriteLine(Math.Min(a, k)); return; } Int64 diff = k - a; if (b >= diff) { Console.WriteLine(a); return; } Int64 diff2 = diff - b; Console.WriteLine(a - diff2); } // ---------------------------------------------------------------------------- public int Int() { return int.Parse(Console.ReadLine()); } public int[] Ints(int subtract) { return Console.ReadLine() .Split(' ') .Select(s => int.Parse(s) - subtract) .ToArray(); } public Int64[] Int64s(Int64 subtract) { return Console.ReadLine() .Split(' ') .Select(s => Int64.Parse(s) - subtract) .ToArray(); } public long[] Longs() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); } } static void Main(string[] args) { new Solver().Solve(); } } struct ModInt { const int MOD = 1000000007; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GetInverse(long a) { long div; long p = MOD; long x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
763
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC167 { class Program { static void Main(string[] args) { b(); } public static void b() { long[] abck = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long a = abck[0], b = abck[1], c = abck[2], k = abck[3]; long ans = 0; if (a <= k) { ans += a; k -= a; } else { ans += k; Console.WriteLine(ans); return; } k -= b; if (c <= k) { ans -= c; } else { ans -= k; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC167 { class Program { static void Main(string[] args) { b(); } public static void b() { long[] abck = Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); long a = abck[0], b = abck[1], c = abck[2], k = abck[3]; long ans = 0; if (a <= k) { ans += a; k -= a; } else { ans += k; Console.WriteLine(ans); return; } k -= b; if (k <= 0) { Console.WriteLine(ans); return; } if (c <= k) { ans -= c; } else { ans -= k; } Console.WriteLine(ans); } } }
[["+", 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, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 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
183
17
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class CF { public static int[] ReadArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m)); } public static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } public static string ReadStr() { return Console.ReadLine(); } public static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m)); } public static void Main() { long[] A = ReadLongArray(); long ans = 0; if (A[3] >= A[0]) ans += A[0]; if (A[3] - (A[1] + A[0]) > 0) ans -= Math.Min(A[3] - (A[1] + A[0]), A[2]); Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class CF { public static int[] ReadArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt32(m)); } public static int ReadInt() { return Convert.ToInt32(Console.ReadLine()); } public static string ReadStr() { return Console.ReadLine(); } public static long ReadLong() { return Convert.ToInt64(Console.ReadLine()); } public static long[] ReadLongArray() { return Array.ConvertAll(Console.ReadLine().Split(' '), m => Convert.ToInt64(m)); } public static void Main() { long[] A = ReadLongArray(); long ans = 0; ans += Math.Min(A[0], A[3]); if (A[3] - (A[1] + A[0]) > 0) ans -= A[3] - (A[1] + A[0]); Console.WriteLine(ans); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 0, 195, 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], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 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, 107], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 64, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["-", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25], ["-", 64, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
254
28
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { string[] S = Console.ReadLine().Split(' '); long A, B, C, K; A = long.Parse(S[0]); B = long.Parse(S[1]); C = long.Parse(S[2]); K = long.Parse(S[3]); long max = 0; if (A + B >= K) max = A; else max = A - (K - B - A); Console.WriteLine(max); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { string[] S = Console.ReadLine().Split(' '); long A, B, C, K; A = long.Parse(S[0]); B = long.Parse(S[1]); C = long.Parse(S[2]); K = long.Parse(S[3]); long max = 0; if (A > K) max = K; else if (A + B >= K && K >= A) max = A; else max = A - (K - B - A); Console.WriteLine(max); } } }
[["+", 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], ["+", 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, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 17, 20], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 12, 22]]
8
146
15
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input1 = Console.ReadLine().Split(' '); var a = long.Parse(input1[0]); var b = long.Parse(input1[1]); var c = long.Parse(input1[2]); var k = long.Parse(input1[3]); long ans = 0; if (k <= a + b) { ans = a; } else { var n = k - a - b; ans = a - n; } Console.WriteLine(ans); Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input1 = Console.ReadLine().Split(' '); var a = long.Parse(input1[0]); var b = long.Parse(input1[1]); var c = long.Parse(input1[2]); var k = long.Parse(input1[3]); long ans = 0; if (k <= a) { ans = k; } else if (k <= a + b) { ans = a; } else { var n = k - a - b; ans = a - n; } Console.WriteLine(ans); Console.ReadLine(); } }
[["+", 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, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22]]
8
148
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string[] ABCK = Console.ReadLine().Split(' '); int A = int.Parse(ABCK[0]); int B = int.Parse(ABCK[1]); int C = int.Parse(ABCK[2]); int K = int.Parse(ABCK[3]); if (K <= A) { Console.WriteLine(A); } else if (K <= A + B) { Console.WriteLine(A); } else { Console.WriteLine(A - (K - A - B)); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string[] ABCK = Console.ReadLine().Split(' '); int A = int.Parse(ABCK[0]); int B = int.Parse(ABCK[1]); int C = int.Parse(ABCK[2]); int K = int.Parse(ABCK[3]); if (K <= A) { Console.WriteLine(K); } else if (K <= A + B) { Console.WriteLine(A); } else { Console.WriteLine(A - (K - A - B)); } Console.ReadLine(); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
167
8
using System; using System.Collections.Generic; using System.Linq; using IVN = System.Int64; class abc167_b { public static void Main() { String[] s = Console.ReadLine().Split(' '); IVN a = IVN.Parse(s[0]); IVN b = IVN.Parse(s[1]); IVN c = IVN.Parse(s[2]); IVN k = IVN.Parse(s[3]); IVN ans = 0; ans += a; k -= a; if (k > 0) { k -= b; if (k > 0) { ans -= k; } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using IVN = System.Int64; class abc167_b { public static void Main() { String[] s = Console.ReadLine().Split(' '); IVN a = IVN.Parse(s[0]); IVN b = IVN.Parse(s[1]); IVN c = IVN.Parse(s[2]); IVN k = IVN.Parse(s[3]); IVN ans = 0; if (a > k) { ans += k; } else { ans += a; k -= a; if (k > 0) { k -= b; if (k > 0) { ans -= k; } } } 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], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
148
15
using System; using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace Atcoder_Answer { class Program { const Int32 mod = 1000000007; static void Main(string[] args) { string[] Reader = ReadLine().Split(' '); int A = int.Parse(Reader[0]); int B = int.Parse(Reader[1]); int C = int.Parse(Reader[2]); int K = int.Parse(Reader[3]); WriteLine(Math.Min(A, K)); } #region Functions public static decimal floor(float d) => Math.Floor((decimal)d); public static double nqrt(int n, int value) { if (n >= 0) { // 通常のn乗根 return Math.Pow(n, 1.0 / (double)n); } else { if ((n % 2) != 0) { // 奇数乗根の場合 return -Math.Pow(-n, 1.0 / (double)n); } else { // 偶数乗根の場合 return double.NaN; } } } #endregion } public static class Extension { #region 拡張 : bool #region キャスト関連 public static int ToInt(this bool Bool) { if (Bool) return 1; else return 0; } public static string ToString(this bool Bool, string TrueStr, string FalseStr) { if (Bool) return TrueStr; else return FalseStr; } #endregion #endregion #region 拡張 : int #region キャスト関連 public static char ToAlphaBets(this int Base) => (char)Base; #endregion #endregion #region 拡張 : char #region 変換関連 public static char NextAlpha(this char Char) => (char)((Char) + 1); //次の文字を取得 #endregion #endregion #region 拡張 : int[] public static long Sum(this int[] Array) { int Ret = 0; for (int loop = 0; loop < Array.Length; loop++) Ret += Array[loop]; return Ret; } #endregion #region 拡張 : string public static string Multi(this string THIS, int Value) { string RetValue = ""; for (int loop = 0; loop < Value; loop++) RetValue += THIS; return RetValue; } #endregion #region 拡張 : List < string> public static string Sum(this List<string> THIS, string Split) { string RetValue = ""; for (int loop = 0; loop < THIS.Count; loop++) { RetValue += THIS[loop]; } return RetValue; } #endregion } }
using System; using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; namespace Atcoder_Answer { class Program { const Int32 mod = 1000000007; static void Main(string[] args) { string[] Reader = ReadLine().Split(' '); int A = int.Parse(Reader[0]); int B = int.Parse(Reader[1]); int C = int.Parse(Reader[2]); int K = int.Parse(Reader[3]); if (A > K) { WriteLine(K); return; } else { WriteLine(A + Math.Max(0, K - A - B) * -1); return; } } #region Functions public static decimal floor(float d) => Math.Floor((decimal)d); public static double nqrt(int n, int value) { if (n >= 0) { // 通常のn乗根 return Math.Pow(n, 1.0 / (double)n); } else { if ((n % 2) != 0) { // 奇数乗根の場合 return -Math.Pow(-n, 1.0 / (double)n); } else { // 偶数乗根の場合 return double.NaN; } } } #endregion } public static class Extension { #region 拡張 : bool #region キャスト関連 public static int ToInt(this bool Bool) { if (Bool) return 1; else return 0; } public static string ToString(this bool Bool, string TrueStr, string FalseStr) { if (Bool) return TrueStr; else return FalseStr; } #endregion #endregion #region 拡張 : int #region キャスト関連 public static char ToAlphaBets(this int Base) => (char)Base; #endregion #endregion #region 拡張 : char #region 変換関連 public static char NextAlpha(this char Char) => (char)((Char) + 1); //次の文字を取得 #endregion #endregion #region 拡張 : int[] public static long Sum(this int[] Array) { int Ret = 0; for (int loop = 0; loop < Array.Length; loop++) Ret += Array[loop]; return Ret; } #endregion #region 拡張 : string public static string Multi(this string THIS, int Value) { string RetValue = ""; for (int loop = 0; loop < Value; loop++) RetValue += THIS; return RetValue; } #endregion #region 拡張 : List < string> public static string Sum(this List<string> THIS, string Split) { string RetValue = ""; for (int loop = 0; loop < THIS.Count; loop++) { RetValue += THIS[loop]; } return RetValue; } #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, 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], ["+", 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, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 0, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["+", 0, 28, 0, 16, 12, 16, 12, 241, 0, 33], ["+", 0, 28, 0, 16, 12, 16, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 75, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
520
33
using System; namespace B { class Program { static void Main(string[] args) { var foo = Console.ReadLine().Trim().Split(); var A = int.Parse(foo[0]); var B = int.Parse(foo[1]); var C = int.Parse(foo[2]); var K = int.Parse(foo[3]); if (K <= A + B) { Console.WriteLine(A); } else { Console.WriteLine(A + (K - (A + B)) * -1); } Console.ReadLine(); } } }
using System; namespace B { class Program { static void Main(string[] args) { var foo = Console.ReadLine().Trim().Split(); var A = int.Parse(foo[0]); var B = int.Parse(foo[1]); var C = int.Parse(foo[2]); var K = int.Parse(foo[3]); if (K < A) { Console.WriteLine(K); } else if (K <= A + B) { Console.WriteLine(A); } else { Console.WriteLine(A + (K - (A + B)) * -1); } Console.ReadLine(); } } }
[["+", 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, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22]]
8
137
16
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { 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 nmx = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var query = new int[nmx[0]][]; var result = long.MaxValue; for (var i = 0; i < nmx[0]; i++) { query[i] = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } var max = query.Length * query.Length; for (var bit = 0; bit < max; bit++) { var list = new List<int>(); var scores = new int[nmx[1]]; for (var i = 0; i < nmx[0]; i++) { if ((bit & (1 << i)) == 0) continue; for (var j = 0; j < scores.Length; j++) { scores[j] += query[i][j]; }; } var isValid = true; for (var i = 1; i < scores.Length; i++) { if (scores[i] < nmx[2]) { isValid = false; break; } } if (isValid) result = Math.Min(scores[0], result); } Console.WriteLine(result < long.MaxValue ? result : -1); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace C { 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 nmx = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var query = new int[nmx[0]][]; var result = long.MaxValue; for (var i = 0; i < nmx[0]; i++) { query[i] = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } for (var bit = 0; bit < (1 << query.Length); bit++) { var scores = new int[nmx[1] + 1]; for (var i = 0; i < nmx[0]; i++) { if ((bit & (1 << i)) == 0) continue; for (var j = 0; j < scores.Length; j++) { scores[j] += query[i][j]; }; } var isValid = true; for (var i = 1; i < scores.Length; i++) { if (scores[i] < nmx[2]) { isValid = false; break; } } if (isValid) result = Math.Min(scores[0], result); } Console.WriteLine(result < long.MaxValue ? result : -1); } } }
[["-", 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, 16, 31, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 12, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 16, 12, 214, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 23, 0, 24], ["+", 0, 7, 15, 16, 12, 23, 0, 16, 31, 203], ["+", 0, 7, 15, 16, 12, 23, 0, 16, 17, 151], ["+", 15, 16, 12, 23, 0, 16, 12, 214, 205, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 214, 0, 131], ["+", 15, 16, 12, 23, 0, 16, 12, 214, 141, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 23, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203]]
8
388
32
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; using System.Numerics; using System.Text.RegularExpressions; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static long Gcd(long x, long y) { if (x < y) Gcd(y, x); while (y > 0) { var z = x; x = y; y = z % y; } return x; } public static long Lcm(long x, long y) { return x * y / Lcm(x, y); } public static bool IsLowercaseAlphabet(char target) { return new Regex("^[a-z]+$").IsMatch(target.ToString()); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var q = Reads(); var n = q[0]; var m = q[1]; var x = q[2]; var c = new long[n]; var a = new long [n][]; for (int i = 0; i < n; i++) { q = Reads(); c[i] = q[0]; a[i] = new long[m]; for (int j = 0; j < m; j++) { a[i][j] = q[j + 1]; } } var bit = new long[n]; for (int i = 0; i < n; i++) { bit[i] = (long)Math.Pow(2, i); } var s = 0; var cost = new List<long>(); for (int i = 0; i < (long)Math.Pow(2, n); i++) { var memo = new long[m]; long t = 0; for (int j = 0; j < n; j++) { if ((i & bit[j]) != 0) { t += c[j]; for (int k = 0; k < m; k++) { memo[k] += a[j][k]; } } } var f = true; for (int j = 0; j < m; j++) { if (x > memo[j]) f = false; } WriteLine(); if (f) cost.Add(t); } WriteLine(cost.Count != 0 ? cost.Min() : -1); WriteLine(s); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; using static System.Console; using System.Numerics; using System.Text.RegularExpressions; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static long Gcd(long x, long y) { if (x < y) Gcd(y, x); while (y > 0) { var z = x; x = y; y = z % y; } return x; } public static long Lcm(long x, long y) { return x * y / Lcm(x, y); } public static bool IsLowercaseAlphabet(char target) { return new Regex("^[a-z]+$").IsMatch(target.ToString()); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var q = Reads(); var n = q[0]; var m = q[1]; var x = q[2]; var c = new long[n]; var a = new long [n][]; for (int i = 0; i < n; i++) { q = Reads(); c[i] = q[0]; a[i] = new long[m]; for (int j = 0; j < m; j++) { a[i][j] = q[j + 1]; } } var bit = new long[n]; for (int i = 0; i < n; i++) { bit[i] = (long)Math.Pow(2, i); } var s = 0; var cost = new List<long>(); for (int i = 0; i < (long)Math.Pow(2, n); i++) { var memo = new long[m]; long t = 0; for (int j = 0; j < n; j++) { if ((i & bit[j]) != 0) { t += c[j]; for (int k = 0; k < m; k++) { memo[k] += a[j][k]; } } } var f = true; for (int j = 0; j < m; j++) { if (x > memo[j]) f = false; } if (f) cost.Add(t); } WriteLine(cost.Count != 0 ? cost.Min() : -1); Console.Out.Flush(); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
609
9
using System; using System.Linq; using System.Collections.Generic; namespace c { class Program { static void Main(string[] args) { var _ = Console.ReadLine().Split(); var n = long.Parse(_[0]); var m = long.Parse(_[1]); var x = long.Parse(_[2]); var l = new long[n, m]; for (var i = 0; i < n; i++) { var a = Console.ReadLine().Split().Select(t => long.Parse(t)).ToArray(); for (var j = 0; j < m; j++) { l[i, j] = a[j]; } } var ans = long.MaxValue; for (var b = 0; b < Math.Pow(2, n); b++) { var skill = new long[m]; var cost = 0L; for (var i = 0; i < n; i++) { if (((b >> i) & 1) == 1) { cost += l[i, 0]; for (var j = 1; j < m; j++) { skill[j] += l[i, j]; } } } var f = true; for (var k = 1; k < m; k++) { if (skill[k] < x) { f = false; break; } } if (f) { ans = Math.Min(ans, cost); } } Console.WriteLine(ans == long.MaxValue ? -1 : ans); } } }
using System; using System.Linq; using System.Collections.Generic; namespace c { class Program { static void Main(string[] args) { var _ = Console.ReadLine().Split(); var n = long.Parse(_[0]); var m = long.Parse(_[1]); var x = long.Parse(_[2]); var c = new long[n]; var l = new long[n, m]; for (var i = 0; i < n; i++) { var a = Console.ReadLine().Split().Select(t => long.Parse(t)).ToArray(); c[i] = a[0]; for (var j = 1; j <= m; j++) { l[i, j - 1] = a[j]; } } var ans = long.MaxValue; for (var b = 0; b < Math.Pow(2, n); b++) { var skill = new long[m]; var cost = 0L; for (var i = 0; i < n; i++) { if (((b >> i) & 1) == 1) { cost += c[i]; for (var j = 0; j < m; j++) { skill[j] += l[i, j]; } } } var f = true; for (var k = 0; k < m; k++) { if (skill[k] < x) { f = false; break; } } if (f) { ans = Math.Min(ans, cost); } } Console.WriteLine(ans == long.MaxValue ? -1 : ans); } } }
[["+", 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, 227, 0, 228], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 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], ["+", 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, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 204, 206, 207, 0, 21], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203]]
8
354
33
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToList(); int N = input[0]; int M = input[1]; int X = input[2]; var algorisms = new int[M]; List<List<int>> CArows = new List<List<int>>(); for (int i = 0; i < N; i++) { CArows.Add(Console.ReadLine().Split().Select(int.Parse).ToList()); } int result = Solve(0, N, X, CArows, 0, algorisms); Console.WriteLine(result); } static int Solve(int i, int N, int X, List<List<int>> rows, int price, int[] Algorisms) { if (Check(Algorisms, X)) return price; if (i >= N) return int.MaxValue; var row = rows[i]; int C = row[0]; int[] A = row.Skip(1).ToArray(); int used = Solve(i + 1, N, X, rows, price + C, Add(Algorisms, A)); int nonUsed = Solve(i + 1, N, X, rows, price, Algorisms); return (used <= nonUsed) ? used : nonUsed; } static int[] Add(int[] baseList, int[] listToAdd) { var x = baseList .Zip(listToAdd, (baselist, add) => new { Base = baselist, Add = add }) .Select(item => item.Base + item.Add) .ToArray(); return x; } static bool Check(int[] targetList, int X) { return targetList.All(x => x >= X); } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToList(); int N = input[0]; int M = input[1]; int X = input[2]; var algorisms = new int[M]; List<List<int>> CArows = new List<List<int>>(); for (int i = 0; i < N; i++) { CArows.Add(Console.ReadLine().Split().Select(int.Parse).ToList()); } int result = Solve(0, N, X, CArows, 0, algorisms); Console.WriteLine((result == int.MaxValue) ? -1 : result); } static int Solve(int i, int N, int X, List<List<int>> rows, int price, int[] Algorisms) { if (Check(Algorisms, X)) return price; if (i >= N) return int.MaxValue; var row = rows[i]; int C = row[0]; int[] A = row.Skip(1).ToArray(); int used = Solve(i + 1, N, X, rows, price + C, Add(Algorisms, A)); int nonUsed = Solve(i + 1, N, X, rows, price, Algorisms); return (used <= nonUsed) ? used : nonUsed; } static int[] Add(int[] baseList, int[] listToAdd) { var x = baseList .Zip(listToAdd, (baselist, add) => new { Base = baselist, Add = add }) .Select(item => item.Base + item.Add) .ToArray(); return x; } static bool Check(int[] targetList, int X) { return targetList.All(x => x >= X); } }
[["+", 3, 4, 0, 28, 0, 41, 15, 23, 0, 24], ["+", 0, 28, 0, 41, 15, 23, 0, 16, 17, 60], ["+", 0, 41, 15, 23, 0, 16, 12, 214, 205, 199], ["+", 0, 41, 15, 23, 0, 16, 12, 214, 0, 131], ["+", 0, 41, 15, 23, 0, 16, 12, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 3, 4, 0, 28, 0, 41, 64, 241, 0, 33], ["+", 3, 4, 0, 28, 0, 41, 64, 241, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
8
407
11
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; using System.Globalization; public class AtCoder { public static void Main() { const int INF = int.MaxValue; var a = new int[12, 12]; var nmx = Console.ReadLine().Trim().Split().Select(e => int.Parse(e)).ToArray(); var n = nmx[0]; var m = nmx[1]; var x = nmx[2]; var c = new int[n]; for (var i = 0; i < n; i++) { var splited = Console.ReadLine().Trim().Split().Select(e => int.Parse(e)).ToArray(); c[i] = splited[0]; for (var j = 0; j < m; j++) { a[i, j] = splited[j + 1]; } } var ans = INF; for (var s = 0; s < (1 << n); s++) { int cost = 0; var d = new int[m]; for (var i = 0; i < n; i++) { if (((s >> i) & 1) > 0) { cost += c[i]; for (var j = 0; j < m; j++) { d[j] += a[i, j]; } } bool ok = true; for (var j = 0; j < m; j++) { if (d[j] < x) ok = false; if (ok) ans = Math.Min(ans, cost); } } } if (ans == INF) { Console.WriteLine(-1); } else { Console.WriteLine(ans); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; public class AtCoder { public static void Main() { const int INF = int.MaxValue; var a = new int[12, 12]; var nmx = Console.ReadLine().Trim().Split().Select(e => int.Parse(e)).ToArray(); var n = nmx[0]; var m = nmx[1]; var x = nmx[2]; var c = new int[n]; for (var i = 0; i < n; i++) { var splited = Console.ReadLine().Trim().Split().Select(e => int.Parse(e)).ToArray(); c[i] = splited[0]; for (var j = 0; j < m; j++) { a[i, j] = splited[j + 1]; } } var ans = INF; for (var s = 0; s < (1 << n); s++) { int cost = 0; var d = new int[m]; for (var i = 0; i < n; i++) { if (((s >> i) & 1) > 0) { cost += c[i]; for (var j = 0; j < m; j++) { d[j] += a[i, j]; } } bool ok = true; for (var j = 0; j < m; j++) { if (d[j] < x) ok = false; } if (ok) ans = Math.Min(ans, cost); } } if (ans == INF) { Console.WriteLine(-1); } else { Console.WriteLine(ans); } } }
[["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 7, 8, 196, 0, 46]]
8
403
19
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; 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"); #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 m = int.Parse(spl[1]); var x = int.Parse(spl[2]); var ca = new int [n][]; for (int i = 0; i < n; i++) { ca[i] = ToIntArray(input.ReadLine(), m + 1); } var se = new BitSearch(m); var min = long.MaxValue; do { var sum = 0L; var score = new long[m]; for (int i = 0; i < se.Length; i++) { if (!se[i]) continue; for (int j = 1; j <= m; j++) { score[j - 1] += ca[i][j]; } sum += ca[i][0]; } if (score.All(z => z >= x)) { min = Math.Min(min, sum); } } while (se.Next()); return min; } class BitSearch { private int max; private int x; public int Length { get; } public BitSearch(int n) { this.Length = n; this.max = (int)Math.Pow(2, n); } public bool Next() { if (x >= max) { x = 0; return false; } x += 1; return true; } // 0~n-1 public bool this[int i] { get { return ((x >> (Length - i - 1)) & 0x01) == 1; } } } 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; using System.Text.RegularExpressions; 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"); #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 m = int.Parse(spl[1]); var x = int.Parse(spl[2]); var ca = new int [n][]; for (int i = 0; i < n; i++) { ca[i] = ToIntArray(input.ReadLine(), m + 1); } var se = new BitSearch(n); var min = long.MaxValue; do { var sum = 0L; var score = new long[m]; for (int i = 0; i < se.Length; i++) { if (!se[i]) continue; for (int j = 1; j <= m; j++) { score[j - 1] += ca[i][j]; } sum += ca[i][0]; } if (score.All(z => z >= x)) { min = Math.Min(min, sum); } } while (se.Next()); if (min == long.MaxValue) return -1; return min; } class BitSearch { private int max; private int x; public int Length { get; } public BitSearch(int n) { this.Length = n; this.max = (int)Math.Pow(2, n); this.x = 0; } public bool Next() { if (x >= max) { x = 0; return false; } x += 1; return true; } // 0~n-1 public bool this[int i] { get { return ((x >> (Length - i - 1)) & 0x01) == 1; } } } 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; } }
[["-", 0, 212, 0, 230, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 230, 3, 4, 0, 28, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 82, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 82, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 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], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 199], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 37, 0, 241, 0, 33], ["+", 8, 196, 0, 57, 64, 37, 0, 241, 0, 203], ["+", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 11, 31, 214, 205, 273, 0, 274], ["+", 8, 196, 0, 1, 0, 11, 31, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 11, 31, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 263, 8, 196, 0, 1, 0, 11, 12, 203]]
8
541
20
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; namespace C_ABC167 { class MainClass { static int[] s; static int x; public static void Main(string[] args) { s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); int n = s[0]; int m = s[1]; x = s[2]; var calist = new Dictionary<int, List<int>>(); for (int i = 0; i < n; i++) { var ca = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse).ToList(); calist.Add(i, ca); } int minval = int.MaxValue; var ca0 = calist[0]; var idx0 = new List<int>() { 0 }; idx0.AddRange(ca0); var q = new Queue<List<int>>(); q.Enqueue(idx0); if (IsAblOk(idx0)) { minval = idx0[1]; } var ca0no = new int [m + 2].ToList(); q.Enqueue(ca0no); while (q.Any()) { var item = q.Dequeue(); if (IsAblOk(item)) { minval = Min(minval, item[1]); } // WriteLine("itemidx {0} ", item[0]); var nextitem = calist[item[0] + 1]; var nextidx = new List<int>() { item[0] + 1 }; nextidx.AddRange(nextitem); var itemplus = new int [m + 2].ToList(); // WriteLine("nextitemlen {0}",nextitem.Count); itemplus[0] = item[0] + 1; for (int i = 1; i < m + 2; i++) { // WriteLine("itemidx : {0}", i); // WriteLine("itemplus : {0} ",itemplus[i]) itemplus[i] = item[i] + nextidx[i]; } if (IsAblOk(itemplus)) { minval = Min(minval, itemplus[1]); } item[0]++; if (item[0] + 1 < n) { // WriteLine("enque item len {0}", item.Count); // item[0] = item[0] + 1; q.Enqueue(item); // WriteLine("enque itemplus len {0}", itemplus.Count); q.Enqueue(itemplus); } } if (minval != int.MaxValue) { WriteLine(minval); } else { WriteLine(-1); } } public static bool IsAblOk(List<int> l) { for (int i = 2; i < l.Count; i++) { if (l[i] < x) { return false; } } return true; } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; namespace C_ABC167 { class MainClass { static int[] s; static int x; public static void Main(string[] args) { s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); int n = s[0]; int m = s[1]; x = s[2]; var calist = new Dictionary<int, List<int>>(); for (int i = 0; i < n; i++) { var ca = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse).ToList(); calist.Add(i, ca); } int minval = int.MaxValue; var ca0 = calist[0]; var idx0 = new List<int>() { 0 }; idx0.AddRange(ca0); var q = new Queue<List<int>>(); q.Enqueue(idx0); if (IsAblOk(idx0)) { minval = idx0[1]; } var ca0no = new int [m + 2].ToList(); q.Enqueue(ca0no); if (n == 1) { if (minval == int.MaxValue) { WriteLine(-1); } else { WriteLine(minval); } return; } while (q.Any()) { var item = q.Dequeue(); if (IsAblOk(item)) { minval = Min(minval, item[1]); } var nextitem = calist[item[0] + 1]; var nextidx = new List<int>() { item[0] + 1 }; nextidx.AddRange(nextitem); var itemplus = new int [m + 2].ToList(); itemplus[0] = item[0] + 1; for (int i = 1; i < m + 2; i++) { itemplus[i] = item[i] + nextidx[i]; } if (IsAblOk(itemplus)) { minval = Min(minval, itemplus[1]); } item[0]++; if (item[0] + 1 < n) { q.Enqueue(item); q.Enqueue(itemplus); } } if (minval != int.MaxValue) { WriteLine(minval); } else { WriteLine(-1); } } public static bool IsAblOk(List<int> l) { for (int i = 2; i < l.Count; i++) { if (l[i] < x) { return false; } } return true; } } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 205, 199], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 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, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 213, 63, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["+", 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
539
34
using static System.Math; using System; public class Hello { public static int n, m, x; public static int[] c; public static int[,] a; public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); n = int.Parse(line[0]); m = int.Parse(line[1]); x = int.Parse(line[2]); c = new int[n]; a = new int[n, 3]; for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); c[i] = int.Parse(line[0]); for (int j = 0; j < 3; j++) a[i, j] = int.Parse(line[j + 1]); } getAns(); } static void getAns() { var ans = int.MaxValue; var imax = 1 << n; for (int i = 0; i < imax; i++) { var w = check(i); if (w != -1) ans = Min(ans, w); } Console.WriteLine(ans == int.MaxValue ? -1 : ans); } static int check(int t) { var ans = 0; var s = new int[3]; for (int i = 0; i < n; i++) { if (((t >> i) & 1) == 1) { ans += c[i]; for (int j = 0; j < 3; j++) { s[j] += a[i, j]; } } } if (s[0] >= x && s[1] >= x && s[2] >= x) return ans; else return -1; } }
using System.Linq; using static System.Math; using System; public class Hello { public static int n, m, x; public static int[] c; public static int[,] a; public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); n = int.Parse(line[0]); m = int.Parse(line[1]); x = int.Parse(line[2]); c = new int[n]; a = new int[n, m]; for (int i = 0; i < n; i++) { line = Console.ReadLine().Trim().Split(' '); c[i] = int.Parse(line[0]); for (int j = 0; j < m; j++) a[i, j] = int.Parse(line[j + 1]); } getAns(); } static void getAns() { var ans = int.MaxValue; var imax = 1 << n; for (int i = 0; i < imax; i++) { var w = check(i); if (w != -1) ans = Min(ans, w); } Console.WriteLine(ans == int.MaxValue ? -1 : ans); } static int check(int t) { var ans = 0; var s = new int[m]; for (int i = 0; i < n; i++) { if (((t >> i) & 1) == 1) { ans += c[i]; for (int j = 0; j < m; j++) s[j] += a[i, j]; } } return s.All(y => y >= x) ? ans : -1; } }
[["+", 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], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 7, 8, 196, 0, 45], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 15, 16, 31, 16, 31, 16, 31, 204, 205, 22], ["-", 31, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 20], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["-", 15, 16, 31, 16, 12, 16, 31, 204, 205, 22], ["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 31, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 20], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 37, 0, 41, 15, 213, 63, 214, 0, 131], ["+", 0, 37, 0, 41, 15, 213, 63, 214, 141, 22], ["+", 0, 37, 0, 41, 15, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 15, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 37, 0, 41, 0, 101], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 37, 0, 41, 0, 102]]
8
407
47
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { #region Reader // static Vector2Int ReadVec2Int //{ // get // { // string[] s = Console.ReadLine().Split(' '); // return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); // } //} // static Vector2Int[] ReadVec2Ints(int n) //{ // List<Vector2Int> list = new List<Vector2Int>(); // for (int i = 0; i < n; ++i) // { // var ab = ReadInts; // list.Add(new Vector2Int(ab[0], ab[1])); // } // return list.ToArray(); //} // static HashSet<Vector2Int> ReadVec2IntHash(int n) //{ // HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); // for (int i = 0; i < n; ++i) // { // var ab = ReadInts; // hash.Add(new Vector2Int(ab[0], ab[1])); // } // return hash; //} static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static int mod = (int)Pow(10, 9) + 7; public static long GetInv(long a, long mod = 1000000007) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod = 1000000007) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a * b / Gcd(a, b); // return ( ((a * b)%mod) * GetInv( Gcd(a, b) ,mod ) )%mod; } /// <summary> /// 最大公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } static void Main() { int[] NMX = ReadInts; int N = NMX[0]; int M = NMX[1]; int X = NMX[2]; int[][] books = new int [N][]; for (int i = 0; i < N; i++) { books[i] = ReadInts; } int cost = (int)Pow(10, 8); for (int i = 0; i < 2 << (N - 1); i++) { int[] buy = new int[N]; for (int j = 0; j < N; j++) { buy[j] = ((i >> j) & 1); } int[] skill = new int[M]; int testCost = 0; for (int j = 0; j < N; j++) { if (buy[j] == 1) { for (int k = 0; k < M; k++) { skill[k] += books[j][k + 1]; } testCost += books[j][0]; } } bool OK = true; for (int j = 0; j < M; j++) { if (skill[j] < X) OK = false; break; } if (OK) { cost = Min(cost, testCost); } } WriteLine(cost != (int)Pow(10, 8) ? cost : -1); } }
using System.Collections; using System.Text; using System.Threading.Tasks; using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; using System.Numerics; class Program { #region Reader // static Vector2Int ReadVec2Int //{ // get // { // string[] s = Console.ReadLine().Split(' '); // return new Vector2Int(int.Parse(s[0]), int.Parse(s[1])); // } //} // static Vector2Int[] ReadVec2Ints(int n) //{ // List<Vector2Int> list = new List<Vector2Int>(); // for (int i = 0; i < n; ++i) // { // var ab = ReadInts; // list.Add(new Vector2Int(ab[0], ab[1])); // } // return list.ToArray(); //} // static HashSet<Vector2Int> ReadVec2IntHash(int n) //{ // HashSet<Vector2Int> hash = new HashSet<Vector2Int>(); // for (int i = 0; i < n; ++i) // { // var ab = ReadInts; // hash.Add(new Vector2Int(ab[0], ab[1])); // } // return hash; //} static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine()); static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine()); static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); static long[,] ReLongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = ReadLongs; for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } static Tuple<string, string>[] ReTupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = ReadStrs; list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<long, long>[] ReTupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<int, int>[] ReadTupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = ReadInts; list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } static Tuple<double, double>[] ReTupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = ReadLongs; list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } static Dictionary<int, HashSet<int>> ReAdjacencyList(int N, int M) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = ReadInts; dict[ab[0]].Add(ab[1]); dict[ab[1]].Add(ab[0]); } return dict; } #endregion static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static int mod = (int)Pow(10, 9) + 7; public static long GetInv(long a, long mod = 1000000007) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod = 1000000007) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } /// <summary> /// 最小公倍数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Lcm(long a, long b) { return a * b / Gcd(a, b); // return ( ((a * b)%mod) * GetInv( Gcd(a, b) ,mod ) )%mod; } /// <summary> /// 最大公約数 /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } static void Main() { int[] NMX = ReadInts; int totalBooks = NMX[0]; int allAlg = NMX[1]; int limit = NMX[2]; int[][] books = new int [totalBooks][]; for (int i = 0; i < totalBooks; i++) { books[i] = ReadInts; } int cost = (int)Pow(10, 8); for (int i = 0; i < 2 << (totalBooks - 1); i++) { int[] buy = new int[totalBooks]; for (int j = 0; j < totalBooks; j++) { buy[j] = ((i >> j) & 1); } int[] skill = new int[allAlg]; int testCost = 0; for (int j = 0; j < totalBooks; j++) { if (buy[j] == 1) { for (int k = 0; k < allAlg; k++) { skill[k] += books[j][k + 1]; } testCost += books[j][0]; } } bool OK = true; for (int j = 0; j < allAlg; j++) { if (skill[j] < limit) { OK = false; break; } } if (OK) { cost = Min(cost, testCost); } } WriteLine(cost != (int)Pow(10, 8) ? cost : -1); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 227, 39, 224, 39, 224, 225, 226, 0, 22], ["+", 0, 227, 39, 224, 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], ["-", 15, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,507
28
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; namespace AtCoder_1 { class Program { static int M = 0; static int X = 0; static void Main(string[] args) { var NMX = CinTAr(); M = NMX[1]; X = NMX[2]; List<int[]> books = new List<int[]>(); for (int i = 0; i < NMX[0]; i++) { int[] CA = CinTAr(); books.Add(CA); } // books.Sort((x, y) => //{ // return x[0] - y[0]; //}); var q = Get(books, 0); q.Sort(); if (q.Count == 0 || q[0] == MOD10_9_7) { Cout("-1"); } else { Cout(q[0]); } Cin(); } static List<int> Get(List<int[]> CA, int index, List<int> log = null) { bool f = log == null; if (f) { log = new List<int>(); } else { int[] CAAS = new int[M]; for (int i = 0; i < log.Count; i++) { for (int k = 0; k < M; k++) { CAAS[k] += CA[log[i]][k]; } } bool ok = true; for (int k = 1; k < M; k++) { ok &= CAAS[k] >= X; } if (ok) { return new List<int>() { CAAS[0] }; } } List<int> res = new List<int>(); for (int i = index; i < CA.Count; i++) { List<int> ax = new List<int>(log); ax.Add(i); res.AddRange(Get(CA, i + 1, ax)); } return res; } static Random Rand = new Random(); static string[] AlphabetTable = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; static int GetDigits(long num) { return (int)Math.Floor(Math.Log10(num)) + 1; } static int GetNumByDigit(long num, int digit) { return (int)((num / ((int)Math.Pow(10, digit - 1))) % 10); } static int Loop(int num, int max) { if (num > max) { return num % max; } else if (num < 0) { return max - (-num) % max; } else { return num; } } static long GCD(long a, long b) { if (a < b) { Swap(ref a, ref b); } if (a % b == 0) { return b; } else { return GCD(b, a % b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static readonly int MOD10_9_7 = (1000000000 + 7); static bool IsInt(double d) { return (int)d == d; } static string Cin() { return ReadLine(); } static string[] CinAr() { return ReadLine().Split(' '); } static int CinT() { return S2i(Cin()); } static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); } static long CinL() { return S2L(Cin()); } static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); } static double CinD() { return S2D(Cin()); } static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); } static int S2i(string s) { return int.Parse(s); } static long S2L(string s) { return long.Parse(s); } static double S2D(string s) { return double.Parse(s); } static void Cout(object s) { WriteLine(s); } static long[] Divisor(long n) { if (n == 1) { return new long[] { 1 }; } List<long> res = new List<long>(); res.Add(1); for (long i = 2; i <= n / 2 + 1; i++) { if (n % i == 0) { res.Add(i); } } res.Add(n); return res.ToArray(); } static bool IsPrime(long num) { if (num == 1) { return false; } for (long i = 2; i <= Math.Sqrt(num) + 1; i++) { if (num % i == 0) { return false; } } return true; } static void CoutAr<Type>(IEnumerable<Type> types) { WriteLine(string.Join(" ", types)); } public static long nCr(int n, int r) { // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r)); return nPr(n, r) / Factorial(r); } public static long nPr(int n, int r) { // naive: return Factorial(n) / Factorial(n - r); return FactorialDivision(n, n - r); } private static long FactorialDivision(int topFactorial, int divisorFactorial) { long result = 1; for (int i = topFactorial; i > divisorFactorial; i--) result *= i; return result; } private static long Factorial(int i) { if (i <= 1) return 1; return i * Factorial(i - 1); } } public struct Pair<T> { public T a; public T b; public T c; public Pair(T _a, T _b) { a = _a; b = _b; c = default(T); } public Pair(T _a, T _b, T _c) { a = _a; b = _b; c = _c; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; namespace AtCoder_1 { class Program { static int M = 0; static int X = 0; static void Main(string[] args) { var NMX = CinTAr(); M = NMX[1]; X = NMX[2]; List<int[]> books = new List<int[]>(); for (int i = 0; i < NMX[0]; i++) { int[] CA = CinTAr(); books.Add(CA); } var q = Get(books, 0); q.Sort(); if (q.Count == 0 || q[0] == MOD10_9_7) { Cout("-1"); } else { Cout(q[0]); } Cin(); } static List<int> Get(List<int[]> CA, int index, List<int> log = null) { bool f = log == null; if (f) { log = new List<int>(); } int[] CAAS = new int[M + 1]; for (int i = 0; i < log.Count; i++) { for (int k = 0; k < M + 1; k++) { CAAS[k] += CA[log[i]][k]; } } bool ok = true; for (int k = 1; k < M + 1; k++) { ok &= CAAS[k] >= X; } if (ok) { return new List<int>() { CAAS[0] }; } List<int> res = new List<int>(); for (int i = index; i < CA.Count; i++) { List<int> ax = new List<int>(log); ax.Add(i); res.AddRange(Get(CA, i + 1, ax)); } return res; } static Random Rand = new Random(); static string[] AlphabetTable = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; static int GetDigits(long num) { return (int)Math.Floor(Math.Log10(num)) + 1; } static int GetNumByDigit(long num, int digit) { return (int)((num / ((int)Math.Pow(10, digit - 1))) % 10); } static int Loop(int num, int max) { if (num > max) { return num % max; } else if (num < 0) { return max - (-num) % max; } else { return num; } } static long GCD(long a, long b) { if (a < b) { Swap(ref a, ref b); } if (a % b == 0) { return b; } else { return GCD(b, a % b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void Swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static readonly int MOD10_9_7 = (1000000000 + 7); static bool IsInt(double d) { return (int)d == d; } static string Cin() { return ReadLine(); } static string[] CinAr() { return ReadLine().Split(' '); } static int CinT() { return S2i(Cin()); } static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); } static long CinL() { return S2L(Cin()); } static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); } static double CinD() { return S2D(Cin()); } static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); } static int S2i(string s) { return int.Parse(s); } static long S2L(string s) { return long.Parse(s); } static double S2D(string s) { return double.Parse(s); } static void Cout(object s) { WriteLine(s); } static long[] Divisor(long n) { if (n == 1) { return new long[] { 1 }; } List<long> res = new List<long>(); res.Add(1); for (long i = 2; i <= n / 2 + 1; i++) { if (n % i == 0) { res.Add(i); } } res.Add(n); return res.ToArray(); } static bool IsPrime(long num) { if (num == 1) { return false; } for (long i = 2; i <= Math.Sqrt(num) + 1; i++) { if (num % i == 0) { return false; } } return true; } static void CoutAr<Type>(IEnumerable<Type> types) { WriteLine(string.Join(" ", types)); } public static long nCr(int n, int r) { // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r)); return nPr(n, r) / Factorial(r); } public static long nPr(int n, int r) { // naive: return Factorial(n) / Factorial(n - r); return FactorialDivision(n, n - r); } private static long FactorialDivision(int topFactorial, int divisorFactorial) { long result = 1; for (int i = topFactorial; i > divisorFactorial; i--) result *= i; return result; } private static long Factorial(int i) { if (i <= 1) return 1; return i * Factorial(i - 1); } } public struct Pair<T> { public T a; public T b; public T c; public Pair(T _a, T _b) { a = _a; b = _b; c = default(T); } public Pair(T _a, T _b, T _c) { a = _a; b = _b; c = _c; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 75, 196, 0, 57, 64, 196, 0, 46]]
8
1,445
9
// // ABC167C // URL : https://atcoder.jp/contests/abc167/tasks/abc167_c // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; namespace AtCoder { class ABC167C { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static int N, M, X; public static void Solve() { { long[] inputLongArray = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); N = (int)inputLongArray[0]; M = (int)inputLongArray[1]; X = (int)inputLongArray[2]; //目標理解度 } var CList = new int[N]; var AList = new int[N, M]; for (int i = 0; i < N; ++i) { long[] inputLongArray = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); CList[i] = (int)inputLongArray[0]; for (int m = 0; m < M; ++m) { AList[i, m] = (int)inputLongArray[m + 1]; } } // bit全探索する { for (int bit = 0; bit < (1 << N); ++bit) { var MList = new int[M]; //理解度 int ans = 0; for (int i = 0; i < N; ++i) { if ((bit & (1 << i)) > 0) // bitが立っていたら購入 { bool complete = true; //理解度up for (int mi = 0; mi < M; ++mi) { MList[mi] += AList[i, mi]; if (MList[mi] < X) { complete = false; } } //コストup ans += CList[i]; //全部完全に理解していたら if (complete == true) { Console.WriteLine(ans); return; } } } } //どんな組み合わせで参考書を買っても無理 Console.WriteLine("-1"); return; } } //--------------------------------------------------------------------------------- /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } } }
// // ABC167C // URL : https://atcoder.jp/contests/abc167/tasks/abc167_c // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; namespace AtCoder { class ABC167C { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static int N, M, X; public static void Solve() { { long[] inputLongArray = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); N = (int)inputLongArray[0]; M = (int)inputLongArray[1]; X = (int)inputLongArray[2]; //目標理解度 } var CList = new int[N]; var AList = new int[N, M]; for (int i = 0; i < N; ++i) { long[] inputLongArray = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); CList[i] = (int)inputLongArray[0]; for (int m = 0; m < M; ++m) { AList[i, m] = (int)inputLongArray[m + 1]; } } // bit全探索する { int ans = int.MaxValue; for (int bit = 0; bit < (1 << N); ++bit) { var MList = new int[M]; //理解度 int cost = 0; for (int i = 0; i < N; ++i) { if ((bit & (1 << i)) > 0) // bitが立っていたら購入 { bool complete = true; //理解度up for (int mi = 0; mi < M; ++mi) { MList[mi] += AList[i, mi]; if (MList[mi] < X) { complete = false; } } //コストup cost += CList[i]; //全部完全に理解していたら if (complete == true) { ans = Math.Min(ans, cost); } } } } //どんな組み合わせで参考書を買っても無理 if (ans == int.MaxValue) { Console.WriteLine("-1"); } else { Console.WriteLine(ans); } return; } } //--------------------------------------------------------------------------------- /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } } }
[["+", 8, 196, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 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, 60], ["+", 0, 196, 0, 57, 15, 16, 12, 214, 205, 199], ["+", 0, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 0, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 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], ["+", 8, 196, 0, 196, 0, 57, 75, 196, 0, 46]]
8
905
41
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public static void Main() { String[] input = Console.ReadLine().Split(); long N = long.Parse(input[0]); long M = long.Parse(input[1]); long X = long.Parse(input[2]); long[] C = new long[N]; long[,] A = new long[N, M]; for (int i = 0; i < N; i++) { input = Console.ReadLine().Split(); C[i] = long.Parse(input[0]); for (int j = 0; j < M; j++) { A[i, j] = long.Parse(input[j + 1]); } } long[] temp = new long[N + 1]; for (int i = 0; i < N; i++) { temp[i] = 0; } long ans = long.MaxValue; for (int x = 0; x < Math.Pow(2, N); x++) { long money = 0; long[] score = new long[N]; for (int i = 0; i < N; i++) { if (temp[i] == 1) { money += C[i]; for (int j = 0; j < M; j++) { score[j] += A[i, j]; } } } bool flag = true; for (int j = 0; j < M; j++) { if (score[j] < X) flag = false; } if (flag) { ans = Math.Min(ans, money); } for (int i = 0; i < N; i++) { if (i == 0) { if (temp[i] == 0) { temp[i] = 1; } else if (temp[i] == 1) { temp[0] = 0; temp[1] += 1; } } else { if (temp[i] == 0) { temp[i] = 0; } else if (temp[i] == 1) { temp[i] = 1; } else if (temp[i] == 2) { temp[i] = 0; temp[i + 1] += 1; } } } } if (ans != long.MaxValue) { Console.WriteLine(ans); } else { Console.WriteLine(-1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; class Program { public static void Main() { String[] input = Console.ReadLine().Split(); long N = long.Parse(input[0]); long M = long.Parse(input[1]); long X = long.Parse(input[2]); long[] C = new long[N]; long[,] A = new long[N, M]; for (int i = 0; i < N; i++) { input = Console.ReadLine().Split(); C[i] = long.Parse(input[0]); for (int j = 0; j < M; j++) { A[i, j] = long.Parse(input[j + 1]); } } long[] temp = new long[N + 1]; for (int i = 0; i < N; i++) { temp[i] = 0; } temp[0] = 1; long ans = long.MaxValue; for (int x = 0; x < Math.Pow(2, N); x++) { long money = 0; long[] score = new long[M]; for (int i = 0; i < N; i++) { if (temp[i] == 1) { money += C[i]; for (int j = 0; j < M; j++) { score[j] += A[i, j]; } } } bool flag = true; for (int j = 0; j < M; j++) { if (score[j] < X) flag = false; } if (flag) { ans = Math.Min(ans, money); } for (int i = 0; i < N; i++) { if (i == 0) { if (temp[i] == 0) { temp[i] = 1; } else if (temp[i] == 1) { temp[0] = 0; temp[1] += 1; } } else { if (temp[i] == 0) { temp[i] = 0; } else if (temp[i] == 1) { temp[i] = 1; } else if (temp[i] == 2) { temp[i] = 0; temp[i + 1] += 1; } } } } if (ans != long.MaxValue) { Console.WriteLine(ans); } else { Console.WriteLine(-1); } } }
[["+", 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, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22]]
8
548
9
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class D { 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 (N, K) = Scanner.Scan<int, long>(); var A = Scanner.ScanEnumerable<int>().Select(x => x - 1).ToArray(); var dict = new Dictionary<int, int>(); var current = 0; var loopStart = 0; var loopEnd = 0; var order = new List<int>(); for (var i = 0; i <= K; i++) { loopEnd = i; if (dict.ContainsKey(current)) { loopStart = dict[current]; break; } order.Add(current); dict[current] = i; current = A[current]; } if (loopEnd == K) { Console.WriteLine(current); return; } K -= loopStart; K %= (loopEnd - loopStart); var answer = order[loopStart + (int)K] + 1; Console.WriteLine(answer); } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace Tasks { public class D { 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 (N, K) = Scanner.Scan<int, long>(); var A = Scanner.ScanEnumerable<int>().Select(x => x - 1).ToArray(); var dict = new Dictionary<int, int>(); var current = 0; var loopStart = -1; var loopEnd = -1; var order = new List<int>(); for (var i = 0; i <= K; i++) { if (dict.ContainsKey(current)) { loopStart = dict[current]; loopEnd = i; break; } order.Add(current + 1); dict[current] = i; current = A[current]; } if (loopStart == -1) { Console.WriteLine(order.Last()); return; } K -= loopStart; K %= loopEnd - loopStart; var answer = order[loopStart + (int)K]; Console.WriteLine(answer); } public static class Scanner { private static Queue<string> queue = new Queue<string>(); public static T Next<T>() { if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item); return (T)Convert.ChangeType(queue.Dequeue(), typeof(T)); } public static T Scan<T>() => Next<T>(); public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>()); public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>()); public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>()); public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>()); public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select( x => (T)Convert.ChangeType(x, typeof(T))); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 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], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 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], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
636
31
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var sr = new StreamReader("sub1_21.txt"); var input = sr.ReadLine().Split(" "); var N = int.Parse(input[0]); var K = long.Parse(input[1]); var line = sr.ReadLine().Split(" "); var A = new List<int>(); var seenA = new List<bool>(); seenA.Add(false); for (int i = 0; i < N; i++) { A.Add(int.Parse(line[i])); seenA.Add(false); }; seenA[1] = true; int pos = -1; var log = new List<int>(); log.Add(1); var next = A[0]; while (true) { if (seenA[next]) { pos = next; break; } seenA[next] = true; log.Add(next); next = A[next - 1]; } var count = log.IndexOf(pos); for (int i = 0; i < count; i++) { K--; log.RemoveAt(0); if (K == 0) break; } if (K == 0) Console.WriteLine(log[0]); else Console.WriteLine(log.ElementAt((int)(K % log.Count))); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(" "); var N = int.Parse(input[0]); var K = long.Parse(input[1]); var line = Console.ReadLine().Split(" "); var A = new List<int>(); var seenA = new List<bool>(); seenA.Add(false); for (int i = 0; i < N; i++) { A.Add(int.Parse(line[i])); seenA.Add(false); }; seenA[1] = true; int pos = -1; var log = new List<int>(); log.Add(1); var next = A[0]; while (true) { if (seenA[next]) { pos = next; break; } seenA[next] = true; log.Add(next); next = A[next - 1]; } var count = log.IndexOf(pos); for (int i = 0; i < count; i++) { K--; log.RemoveAt(0); if (K == 0) break; } if (K == 0) Console.WriteLine(log[0]); else Console.WriteLine(log.ElementAt((int)(K % log.Count))); } }
[["-", 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, 230, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22]]
8
347
15
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var NK = Console.ReadLine().Split().Select(e => long.Parse(e)).ToArray(); var next = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); //町の数 var N = NK[0]; //移動回数 var K = NK[1]; var comb = new Dictionary<long, Tuple<long, bool, long>>(); for (long n = 1; n < N + 1; n++) { comb.Add(n, new Tuple<long, bool, long>(next[n - 1], false, 0L)); } var ans = 0; var nextT = 1L; var roopCnt = 1L; for (long visitCnt = K; 0 < visitCnt; visitCnt--) { if (comb[nextT].Item2 == true) { var remain = visitCnt % (roopCnt - comb[nextT].Item3); Console.WriteLine("remain : " + remain); for (long r = 0; r < remain; r++) { nextT = comb[nextT].Item1; } Console.WriteLine(nextT); return; } else { long n = comb[nextT].Item1; comb.Remove(nextT); comb.Add(nextT, new Tuple<long, bool, long>(n, true, roopCnt)); // comb[nextT].Item2=true; // comb[nextT].Item3=roopCnt; } roopCnt = roopCnt + 1; nextT = comb[nextT].Item1; Console.WriteLine(nextT); } Console.WriteLine(nextT); } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var NK = Console.ReadLine().Split().Select(e => long.Parse(e)).ToArray(); var next = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); //町の数 var N = NK[0]; //移動回数 var K = NK[1]; var comb = new Dictionary<long, Tuple<long, bool, long>>(); for (long n = 1; n < N + 1; n++) { comb.Add(n, new Tuple<long, bool, long>(next[n - 1], false, 0L)); } var ans = 0; var nextT = 1L; var roopCnt = 1L; for (long visitCnt = K; 0 < visitCnt; visitCnt--) { if (comb[nextT].Item2 == true) { var remain = visitCnt % (roopCnt - comb[nextT].Item3); // Console.WriteLine("remain : "+remain); for (long r = 0; r < remain; r++) { nextT = comb[nextT].Item1; } Console.WriteLine(nextT); return; } else { long n = comb[nextT].Item1; comb.Remove(nextT); comb.Add(nextT, new Tuple<long, bool, long>(n, true, roopCnt)); // comb[nextT].Item2=true; // comb[nextT].Item3=roopCnt; } roopCnt = roopCnt + 1; nextT = comb[nextT].Item1; // Console.WriteLine(nextT); } Console.WriteLine(nextT); } }
[["-", 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], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 16, 31, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
351
18